Behaviours: cowboy_handler.
Authors: Steve Roques.
em_pop_http — Cowboy HTTP handler for the Population Protocol gossip endpoint.
Route: POST /pop/gossip
This handler is the network entry point for peer-to-peer gossip exchanges. When a remote em_pop node wants to exchange state with this node, it sends an HTTP POST here carrying its own serialised state as a JSON body.
1. Read the full request body.
2. JSON-decode it into an Erlang map (the remote node's payload).
3. Forward the payload to em_pop_node:handle_gossip/2, which
updates the local peer table and returns our own state as a
response payload.
4. JSON-encode the response and reply with HTTP 200.
• Malformed JSON or a missing body field → 400 Bad Request.
• Internal error from handle_gossip/2 → 500 with JSON error body.
node pid passed in the
Cowboy route options at startup.
| init/2 | Handle one POST /pop/gossip request. |
init(Req0, State) -> any()
Handle one POST /pop/gossip request.
The Cowboy route must be configured with #{node => NodePid} as
the route options map, where NodePid is the em_pop_node
gen_server that owns this listener.
{ok, Req, State} as required by Cowboy.
All error paths also return {ok, Req, State} — the HTTP status
code in the reply carries the error information.
Generated by EDoc