Hop::Endpoint
Receive Hop messages in Crystal with a Sinatra/Rails-shaped surface, over the libhop C ABI.
hop = Hop::Endpoint.new hop.on("acme/orders") { |req, reply| reply.call(201, "ok") } # req.from is VERIFIED
Semantics: inbound is a durable store-and-forward consume; a reply is a new addressed message that
may arrive later. The DX is HTTP-shaped; delivery is delay-tolerant. core is poll-model, so the
endpoint runs a background pump FIBER (spawned; the node is thread-safe). Default runtime is single
fiber-scheduled thread; a reentrant Mutex still guards the node so #close can free it safely even
under -Dpreview_mt.
Constructors
Instance methods
Start an HTTPS server (WSS bearer at /_hop + /.well-known/hop) IN ONE CALL. public_url is where
senders reach it, e.g. "wss://myaddress.com/_hop". Returns the HTTP::Server (already listening).
The idiomatic Crystal/Go alternative to a block handler: receive verified requests for service
on a Channel and reply from your own fiber (a long-running server usually reads it in a loop, or
selects over several services). Same delivery, just channels instead of a callback.
orders = hop.channel("acme/orders") spawn do loop do req, reply = orders.receive reply.call(201, req.text) end end
Join the endpoint cluster so sibling replicas (same identity, no shared datastore) each handle a given request once. A String is a passphrase (interops with the standalone service's HOP_CLUSTER_SECRET); a 32-byte Bytes is a raw secret. Dedup then applies transparently.
Live replica count (self + peers within the membership TTL); 1 if not clustered.
Require at least min live cluster members visible before this replica will process a request using a TTL-based visibility threshold. This is a conservative failover heuristic, not consensus or an at-most-once guarantee. 0 or 1 disables it. Returns self.
Resolve a base HTTPS URL to a verified endpoint, dial its WSS, and return the reachable address (then use #request). Set insecure_tls: true only for a dev/self-signed cert.
Register a receiver for a hops:// service. The block gets (req, reply); reply is a callable reply.call(status, body). This is the surface shared with every Hop SDK.
Register a teardown hook (e.g. a bearer's listening socket). #close runs these before freeing the node so bearer fibers unblock and exit. If already closed, the hook fires immediately.
---- bearer seam (called from bearer fibers) ----
Offer a relay endpoint to the pool. configured marks an operator/user choice, which a gossiped endpoint can never demote. Returns true if the endpoint is now pooled.
The relay to dial right now, or nil when there is nothing dialable. nil with a non-zero
relay_pool total is the degraded "every candidate is backed off" state (wait and retry, this
endpoint is not offline); nil with a zero total is an empty pool.
Feed a dial outcome back to the pool. A success clears that endpoint's failure history; failures back it off exponentially and always eventually recover. Returns self.
Call a service on a remote endpoint. Blocks the calling fiber until the response returns
(delay-tolerant). dst is a base58 address String or the 32 raw bytes.