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.

Sunday, March 4, 2012

ejabberd Listeners

Previously...
  • The ECM module needs to send raw TCP instead of just the HTTP bodies.
  • I got my old computer working (go me!)
  • Investigation revealed that ECM is sending raw TCP traffic to megaphone.

The basic problem here is that, on the megaphone side, nothing is listening for new connections.  

With ejabberd's http_bind (BOSH) module, what normally happens is the ejabberd_listener module waits for new connections and then kicks off ejabberd_http_bind when it gets a new connection:


accept(ListenSocket, Module, Opts) ->
    case gen_tcp:accept(ListenSocket) of
    {ok, Socket} ->
        case {inet:sockname(Socket), inet:peername(Socket)} of
        {{ok, Addr}, {ok, PAddr}} ->
            ?INFO_MSG("(~w) Accepted connection ~w -> ~w",
                  [Socket, PAddr, Addr]);
        _ ->
            ok
        end,
        CallMod = case is_frontend(Module) of
              true -> ejabberd_frontend_socket;
              false -> ejabberd_socket
              end,
        CallMod:start(strip_frontend(Module), gen_tcp, Socket, Opts),
        accept(ListenSocket, Module, Opts);
    {error, Reason} ->
        ?INFO_MSG("(~w) Failed TCP accept: ~w",
              [ListenSocket, Reason]),
        accept(ListenSocket, Module, Opts)
    end.

In the case of megaphone, ejabberd_listener does not see a new connection.  This is because the connection is simply an ID that is passed along with the rest of the data through a single TCP connection.  megaphone needs something to watch the incoming stream of data for new connections and to kick off ejabberd_http_bind when it sees one.

Next time: (hopefully) the bit that watches for new connections.

No comments:

Post a Comment