Skip to main content

Module peer

Module peer 

Source
Expand description

Host-to-host peering — a mesh of zwire-host daemons.

A daemon can listen for peers on TCP (serve --tcp <addr>) and/or dial out to peers (--peer <addr>, or the peer_connect command). Peer links carry two things:

  • bus federation — a pub (or a scheme/ui change) on one host is forwarded to every peer, whose local subscribers then receive it, so the event bus spans all your machines; and
  • remote requests{"cmd":"remote","peer":"host:port","request":{…}} runs a request on another host and returns its reply.

TCP is guarded by a shared --token (or $ZWIRE_HOST_TOKEN): inbound TCP connections must auth / peer_hello with it before doing anything privileged. Local Unix-socket clients are trusted and never need it.

Federation is single-hop: a forwarded event is delivered locally but not re-forwarded, which covers star and fully-meshed topologies without loops.

Functions§

auth_required
Whether TCP connections must authenticate (a token is configured).
broadcast
Forward a published event to every peer; returns how many links took it.
configure
Set the peering token and this host’s advertised name (from CLI flags).
dial
Spawn a task that keeps a link to addr open, reconnecting on failure.
listen_tcp
Spawn the TCP listener that accepts peer/remote connections.
local_name
This host’s name, sent in handshakes and shown in peers.
peer_names
Names of currently connected peers.
register_link
Register a peer link, replacing any existing link with the same name (a reconnect, or the reverse direction of a mutual peering). Returns its id.
remote
Run one request on the peer at addr and return its reply. Uses a fresh connection (authenticating if a token is set), so it is independent of the long-lived federation link. Intended for RPC commands, not streams.
token_ok
Validate a presented token against the configured one (always ok if none).
unregister_link
Drop a peer link (its connection closed).