Module em_pop_http

em_pop_http — Cowboy HTTP handler for the Population Protocol gossip endpoint.

Behaviours: cowboy_handler.

Authors: Steve Roques.

Description

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.

Request flow

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.

Error handling

• Malformed JSON or a missing body field → 400 Bad Request. • Internal error from handle_gossip/2 → 500 with JSON error body.

The handler is stateless beyond the node pid passed in the Cowboy route options at startup.

Function Index

init/2Handle one POST /pop/gossip request.

Function Details

init/2

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.

On success returns {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