Documentation
¶
Overview ¶
Package hop is the Go server-side endpoint SDK: receive Hop messages with an net/http-shaped surface, over the libhop C ABI via cgo. This file is the thin cgo layer; endpoint.go has the ergonomics. libhop is found via -L below; build it with `cargo build -p hop`.
Index ¶
- Constants
- Variables
- func ConnectInProcess(a, b *Endpoint)
- func Dial(e *Endpoint, host string, port int) (net.Conn, error)
- func Listen(e *Endpoint, port int) (net.Listener, error)
- func Resolve(client *http.Client, baseURL string) (address, wssURL string, err error)
- type Endpoint
- func (e *Endpoint) AcceptServiceResponse(requestID []byte) (bool, error)
- func (e *Endpoint) Address() string
- func (e *Endpoint) Attach(server *HTTPServer, publicURL string) error
- func (e *Endpoint) Close()
- func (e *Endpoint) ClusterMembers() uint32
- func (e *Endpoint) ClusterQuorum(min uint32)
- func (e *Endpoint) DialByName(baseURL string, insecureTLS bool) (string, error)
- func (e *Endpoint) On(service string, h Handler)
- func (e *Endpoint) Request(dst, service, method string, args []byte) (uint16, []byte, error)
- func (e *Endpoint) RequestTimeout(dst, service, method string, args []byte, timeout time.Duration) (uint16, []byte, error)
- func (e *Endpoint) SignReach(endpoint string, ttlSecs uint32) []byte
- func (e *Endpoint) WellKnownHandler(publicURL string, ttlSecs uint32) http.Handler
- type HTTPServer
- type Handler
- type Option
- type OutPacket
- type ReachInfo
- type Reply
- type Request
- type ServiceReq
- type ServiceResp
Constants ¶
const ( MaxWSSMessageBytes = MaxFrameBytes MaxWSSHeaderBytes = 16 << 10 MaxPendingHTTPSocks = 64 MaxPendingWSSLinks = 64 WSSHandshakeTimeout = 5 * time.Second WSSReadTimeout = 15 * time.Second WSSWriteTimeout = 5 * time.Second )
const DefaultRequestTimeout = 15 * time.Second
DefaultRequestTimeout bounds Request when no explicit timeout is given (aligns with the other SDKs, which default the timeout too).
const MaxFrameBytes = 1 << 20
Variables ¶
var ( // ErrHTTPServerNotAttached prevents starting a server without Hop's pre-handler admission limits. ErrHTTPServerNotAttached = errors.New("Hop HTTP server must be attached before serving") // ErrHTTPServerStarted prevents changing admission after any socket could have been accepted. ErrHTTPServerStarted = errors.New("Hop HTTP server has already started") )
Functions ¶
func ConnectInProcess ¶
func ConnectInProcess(a, b *Endpoint)
ConnectInProcess wires two endpoints directly (in-process bearer), no sockets.
Types ¶
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
Endpoint receives Hop messages with an net/http-shaped surface, over hop-core.
func (*Endpoint) AcceptServiceResponse ¶
AcceptServiceResponse durably accepts a previously-polled response by its correlation request id. Asynchronous consumers call this only after their own processing has completed.
func (*Endpoint) Attach ¶
func (e *Endpoint) Attach(server *HTTPServer, publicURL string) error
Attach wires the WSS bearer and discovery responder into an unstarted HTTPServer and atomically installs acceptance-time admission, TLS/header deadlines, parser caps, and worker limits.
func (*Endpoint) Close ¶
func (e *Endpoint) Close()
Close stops the pump, shuts the bearers, and frees the node. Safe against a late bearer goroutine: once closed is set, every withNode call short-circuits, so a recvLoop firing linkDown as its socket closes cannot dereference a freed node.
func (*Endpoint) ClusterMembers ¶
ClusterMembers reports the live replica count (self + peers within the membership TTL); 1 if not clustered.
func (*Endpoint) ClusterQuorum ¶
ClusterQuorum requires at least min live cluster members visible before this replica will process a request (CP: hold-until-coordinated); see WithQuorum. 0 or 1 disables the hold.
func (*Endpoint) DialByName ¶
DialByName resolves a base HTTPS URL to a verified endpoint, dials its WSS, and returns the reachable address (then use Request). Set insecureTLS only for a dev/self-signed cert.
func (*Endpoint) Request ¶
Request calls a service on a remote endpoint (dst is a base58 address). Blocks until the response returns (delay-tolerant) or DefaultRequestTimeout elapses. Use RequestTimeout to override.
func (*Endpoint) RequestTimeout ¶
func (e *Endpoint) RequestTimeout(dst, service, method string, args []byte, timeout time.Duration) (uint16, []byte, error)
RequestTimeout is Request with an explicit timeout.
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer owns the only supported public serve path for an attached endpoint. It cannot start until Endpoint.Attach has installed raw-connection admission and all net/http limits.
func NewHTTPServer ¶
func NewHTTPServer(addr string, handler http.Handler) *HTTPServer
NewHTTPServer creates an unstarted server. handler receives every route except /_hop and /.well-known/hop; nil uses http.DefaultServeMux.
func (*HTTPServer) Close ¶
func (s *HTTPServer) Close() error
Close immediately closes the listener and all accepted connections.
func (*HTTPServer) ListenAndServe ¶
func (s *HTTPServer) ListenAndServe() error
ListenAndServe starts an attached plaintext server. Production WSS deployments should use TLS.
func (*HTTPServer) ListenAndServeTLS ¶
func (s *HTTPServer) ListenAndServeTLS(certFile, keyFile string) error
ListenAndServeTLS starts an attached TLS server with the configured absolute handshake deadline.
type Handler ¶
Handler receives an inbound request. Delivery is durable store-and-forward; a reply may arrive later. Treat it like a queue consumer, not a synchronous HTTP handler.
type Option ¶
type Option func(*config)
Option configures New.
func WithCluster ¶
WithCluster joins the endpoint cluster keyed by a passphrase, so sibling replicas (same identity, no shared datastore) each handle a given request once. The same string interops with the standalone service's HOP_CLUSTER_SECRET. Dedup then applies transparently to inbound requests.
func WithQuorum ¶
WithQuorum sets a TTL-based visibility threshold before this replica processes a request. It is a conservative failover heuristic, not consensus or an at-most-once guarantee. 0 or 1 disables it.
type ReachInfo ¶
ReachInfo is a verified reachability record: which Address is reachable at which Endpoint.
type Reply ¶
Reply seals a hops:// response back to the request's caller. status is a uint16 (HTTP-shaped).
type Request ¶
type Request struct {
From string // base58
FromBytes []byte
Service string
Method string
Args []byte
}
Request is an inbound service request. From is the cryptographically verified sender identity.
type ServiceReq ¶
ServiceReq is an inbound hops:// service request.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hop-install
command
Command hop-install installs one signed libhop release outside Go's read-only module cache.
|
Command hop-install installs one signed libhop release outside Go's read-only module cache. |
|
examples
|
|
|
client
command
Calls a self-hosted Hop endpoint over TCP.
|
Calls a self-hosted Hop endpoint over TCP. |
|
discovery
command
Proves the full DNS-free discovery chain: a client resolves a domain by name, the TLS cert proves the domain (WebPKI), the served reach record self-certifies the address, and the WSS handshake confirms it, then a hops:// round trip runs over the WebSocket.
|
Proves the full DNS-free discovery chain: a client resolves a domain by name, the TLS cert proves the domain (WebPKI), the served reach record self-certifies the address, and the WSS handshake confirms it, then a hops:// round trip runs over the WebSocket. |
|
echo
command
The net/http-shaped DX, running on real hop-core over the C ABI.
|
The net/http-shaped DX, running on real hop-core over the C ABI. |
|
server
command
A standalone, self-hostable Hop endpoint (the two-process deployment shape).
|
A standalone, self-hostable Hop endpoint (the two-process deployment shape). |
|
tcp
command
Proves the Internet bearer: a server endpoint LISTENS on TCP, a client DIALS it over a real socket, and the hops:// round trip completes over TCP with real Noise.
|
Proves the Internet bearer: a server endpoint LISTENS on TCP, a client DIALS it over a real socket, and the hops:// round trip completes over TCP with real Noise. |