Diaspora taken apart - Part 1

Angelegt von niklas Thu, 07 Oct 2010 16:20:00 GMT

UPDATE 1 (Oct. 7, 9:05 PM CEST): The errors I had when writing this (see below) have been fixed by now. Going to #diaspora-dev@freenode helps a lot :) Thanks sofaer!


Everybody's talking about Diaspora these days, a distributed social network, written in Ruby. Working on social networks quite a bit myself I thought I'd take a walk through the code and write up what I discover.

I will do two things in parallel:

  • Get Diaspora up and running on my local machine
  • Dig around the code until I have enough information to understand the basic structure of how Diaspora distributes it's data amongst different installs
  • I won't write down my steps to install diaspora, as that's pretty good documented already. However, if I run into any severe problems following those instructions, I will cover that.

    So, let's get started. First of all we need to install all the dependencies. As Diaspora is based upon rails 3, installing the gem dependencies is as much as "bundle install", but I'd like to use that opportunity to find out more about Diaspora's secret internal workings.

    So, opening up the Gemfile...

    ... there is quite a list of things (actually I knew that, because I just ran bundle). The most interesting ones seem to be ...

    • ...devise - this is out-of-the-box authentication based on warden.
    • ...mongo_mapper - so Diaspora is using MongoDB as the data store. I haven't worked with it yet, but will enjoy getting into it!
    • ...haml - pretty much default these days I guess.
    • ...pubsubhubhub - PubSub! While the name of this implementation freaks me out a bit, it's a must-have pattern for (pseudo) real-time web applications. Looking forward to see what it's used for.
    • ...redfinger - WebFinger! I assume this is what publishes profile information.
    • ...em-http-request - EventMachine based HTTP client, way faster than Net::HTTP to my knowledge...
    • ...em-websocket - WebSocket implementation to get the real-time factor all the way to the browser.
    • ...magent - hm. this says it's a "simple job queue system based on mongodb". We will see.
    • ...carrierwave - Rack based file upload.
    • ...lots of more, some of them test specific, sprinkle for deployment (-preparation), ...

    Starting!

    I'm fed up with guessing, googling & githubing (ggg...), starting the server now!

    script/server
    Looking at localhost:3000 now, I see that this is apparently a "technology preview", so I'm signing up :) What happens when I do this? The routes say, that /signup points at registrations#new, looking in there... devise does all the magic. Looking at the create action, the only new thing to learn is that MongoMapper apparently raises MongoMapper::DocumentNotValid, if instantiate! fails. That's the companion piece to ActiveRecord's ActiveRecord::RecordInvalid.

    Being signed up & logged in now, I see a bunch of things:

    • A menu at the right top providing account / profile related links - pretty straight forward.
    • A tabnav showing me "All aspects", "Family" and "Work". I would probably be confused by those, hadn't someone recently mentioned them, when talking about a profile rework, planned for crabgrass. If I remember correclty, "aspects" are collections of people, defined by yourself. Similar to Roster Groups in XMPP I suppose.
    • On the right side of that tabnav (I completely blinded the out on the first look around), there are more tabs: "public" and "manage". The latter lets me remove / edit / create aspects, I'm removing "family" and keeping just "work" around, to see if it's working. Clicking on the "remove" link...
    ...and there I am on a beloved Rails error page! After being pissed for an instant, that there was no confirmation dialog for removing the aspect, I get this:
    NameError in AspectsController#destroy
    
    undefined local variable or method `i18n' for #
    
    I am familiar with that, so fixing it up (s/i18n/I18n/). Gives me a chance to take a look into the AspectsController. While searching & replacing that typo, I find 3 of them. Seems to be a bad day for checking out Diaspora's HEAD :)

    So, The AspectsController looks pretty much like any other RESTful controller in Rails. There are a few extra actions though: public, manage, move_friends and move_friend. The first two are obviously connected to the tabs mentioned above, the latter are used to move people between aspects.
    Now the only thing that looks unusual to me is this:

    @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create",
                                      :scope => MiniFB.scopes.join(","))
    
    This has probably something to do with the mini_fb (link) gem, which hadn't caught my immediate attention earlier, when investigating the Gemfile. Let's see what it does! Hm. Facebook API. I'm not so much into facebook, maybe someone else wants to get into this? Moving on!

    As I had some more errors, after the one I just fixed, I decided to switch to the production branch, which I hope to be more stable. Switching there, I notice that the error I fixed earlier is also in there. Not production-ish at all, that production branch... fixing, then firing up the server again.

    Continuing analyzing the UI, I get to the big box saying "Message", which allows me to enter text and click "share" afterwards. Straight forward again, and also similar to crabgrass again :) What is confusing though, is that the message doesn't appear. Reloading the page, it does. Now my JavaScript console tells me there is a syntax error:

    Unexpected token <
    
    I know those errors. They happen when the HTTP response is evaluated, because JavaScript code is expected, but rails sends HTML instead.

    I'm ending my session for today, know only a little more about Diaspora than before, but at least I know it's not stable :) I will continue this article another day, very soon... (kick me if I dont...)

Trackbacks

Verwenden Sie den folgenden Link zur Rückverlinkung von Ihrer eigenen Seite:
http://praktikanten.brueckenschlaeger.org/trackbacks?article_id=319

Leave a comment

Comments