What is Megaphone?

What is Megaphone?
The Megaphone project is about enhancing open source chat software. Specifically, the goal is to allow ejabberd to support 1,000,000 simultaneous users. See The Plan page for more details on how I plan to solve this problem. See the About this Blog page for more details on why I created this blog.

Wednesday, March 14, 2012

Consuming Headers with erlang:decode_packet

Previously...
  • I came up with a new plan.
  • I wrote some new code to process requests.
  • I turned it on and...it didn't work.

Last time I decided that the problem was that I was sending "raw" HTTP traffic to ejabberd_http_bind whereas it was expecting just the body of the request.  I therefore modified a small portion of the code to the following:

parse_packet(Data) ->
    {ok, Request, Remainder} = erlang:decode_packet(http, Data, []),
    consume_headers([Request], Remainder).

consume_headers(Headers, Data) ->
    case erlang:decode_packet(httph, Data, []) of
        { ok, http_eoh, Rest } ->
            Rest ;
        { ok, Header, Rest } ->
            consume_headers(Headers ++ [Header], Rest)
    end.

I actually got a little farther with this --- I didn't even get an error message --- instead the following was in the log:

=INFO REPORT==== 2012-03-14 20:21:28 ===
D(<0.390.0>:ejabberd_http_bind:1128) : --- incoming data --- 
<body content='text/xml; charset=utf-8' secure='true' to='ubuntu2' xml:lang='en' xmpp:version='1.0' ver='1.6' xmlns:xmpp='urn:xmpp:xbosh' rid='566658449718079' wait='60' hold='1' xmlns='http://jabber.org/protocol/httpbind'/>
 --- END --- 

=INFO REPORT==== 2012-03-14 20:21:28 ===
D(<0.390.0>:ejabberd_http_bind:124) : Starting session

=INFO REPORT==== 2012-03-14 20:21:28 ===
D(<0.391.0>:ejabberd_http_bind:310) : started: {"4d606f92e76e5b152eba41dbdb2caa35091eef1c",
                                                [],
                                                <<127,0,0,1>>}

=INFO REPORT==== 2012-03-14 20:21:33 ===
D(<0.391.0>:ejabberd_http_bind:547) : terminate: Deleting session 4d606f92e76e5b152eba41dbdb2caa35091eef1c

The system starts up the session just fine.  The only problem is that it deletes the session immediately.  Well, one thing at a time.

Next time: the next thing.

No comments:

Post a Comment