Search documentation of macula

# macula_pubsub_routing (macula v0.44.2)

View Source

Pub/Sub routing for multi-hop DHT-routed pub/sub. Handles wrapping, unwrapping, and routing of PUBLISH messages through the Kademlia DHT mesh.

Pattern: Clone of macula_rpc_routing for pub/sub messages

# Summary

## Functions

route_or_deliver(LocalNodeId, PubSubRouteMsg, RoutingServerPid)

Route a pubsub_route message: either deliver locally or forward to next hop. Returns one of: {deliver, Topic, PublishMsg} - Message is for this node {forward, NextHopNodeInfo, UpdatedPubSubRouteMsg} - Forward to next hop {error, Reason} - Cannot route (TTL exceeded, no route, etc.)

should_deliver_locally(LocalNodeId, PubSubRouteMsg)

Determine if this node should deliver the message locally or forward it.

wrap_publish(SourceNodeId, DestinationNodeId, PublishMsg, MaxHops)

Wrap a PUBLISH message in pubsub_route envelope for DHT routing.

# Functions

# route_or_deliver(LocalNodeId, PubSubRouteMsg, RoutingServerPid)

    -spec route_or_deliver(binary(), macula_protocol_types:pubsub_route_msg(), pid()) ->
                              {deliver, binary(), map()} |
                              {deliver_and_forward,
                               binary(),
                               map(),
                               macula_routing_bucket:node_info(),
                               macula_protocol_types:pubsub_route_msg()} |
                              {forward,
                               macula_routing_bucket:node_info(),
                               macula_protocol_types:pubsub_route_msg()} |
                              {error, term()}.

Route a pubsub_route message: either deliver locally or forward to next hop. Returns one of: {deliver, Topic, PublishMsg} - Message is for this node {forward, NextHopNodeInfo, UpdatedPubSubRouteMsg} - Forward to next hop {error, Reason} - Cannot route (TTL exceeded, no route, etc.)

# should_deliver_locally(LocalNodeId, PubSubRouteMsg)

    -spec should_deliver_locally(binary(), macula_protocol_types:pubsub_route_msg()) -> boolean().

Determine if this node should deliver the message locally or forward it.

# wrap_publish(SourceNodeId, DestinationNodeId, PublishMsg, MaxHops)

    -spec wrap_publish(binary(), binary(), macula_protocol_types:publish_msg(), pos_integer()) ->
                          macula_protocol_types:pubsub_route_msg().

Wrap a PUBLISH message in pubsub_route envelope for DHT routing.