Documentation
¶
Index ¶
- type ConnInfo
- type Handler
- type RouteTable
- func (rt *RouteTable) AddCallback(f func()) (remove func())
- func (rt *RouteTable) Connections() []ConnInfo
- func (rt *RouteTable) GetAllPrefixes() []string
- func (rt *RouteTable) GetPrefixesExcluding(exclude map[*jsonrpc2.Conn]bool) []string
- func (rt *RouteTable) IDFor(conn *jsonrpc2.Conn) string
- func (rt *RouteTable) Lookup(method string) *jsonrpc2.Conn
- func (rt *RouteTable) LookupWithPrefix(method string) (*jsonrpc2.Conn, string)
- func (rt *RouteTable) Register(conn *jsonrpc2.Conn, id, socketPath string) *ConnInfo
- func (rt *RouteTable) RemoveConn(conn *jsonrpc2.Conn)
- func (rt *RouteTable) Snapshot() map[string]string
- func (rt *RouteTable) Update(conn *jsonrpc2.Conn, prefixes []string)
- func (rt *RouteTable) WaitUntilRoutable(ctx context.Context, method string) error
- type SubscriptionTable
- func (st *SubscriptionTable) RemoveConn(conn *jsonrpc2.Conn)
- func (st *SubscriptionTable) Snapshot() map[mesh.Subscription][]*jsonrpc2.Conn
- func (st *SubscriptionTable) Subscribers(sub mesh.Subscription) []*jsonrpc2.Conn
- func (st *SubscriptionTable) Update(conn *jsonrpc2.Conn, subs []mesh.Subscription)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnInfo ¶
type ConnInfo struct {
ID string
SocketPath string // set for outbound peer connections (via AddPeerProxy); always "" on LocalRoutes
ConnectedAt time.Time
}
ConnInfo describes a connection tracked by a RouteTable, for debugging.
type Handler ¶
type Handler struct {
LocalRoutes *RouteTable // Routes from local services
PeerRoutes *RouteTable // Routes from peer proxies
Subscriptions *SubscriptionTable
// contains filtered or unexported fields
}
Handler implements jsonrpc2.Handler for the jrpc-mesh proxy.
func NewHandler ¶
func NewHandler() *Handler
NewHandler creates a new Handler with all necessary fields initialized.
func (*Handler) HandleWithError ¶
func (h *Handler) HandleWithError(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error)
HandleWithError processes incoming JSON RPC requests, returning the result or error.
type RouteTable ¶
type RouteTable struct {
// contains filtered or unexported fields
}
RouteTable manages prefix-based routing to JSON-RPC connections, along with debug identity metadata for those connections.
func NewRouteTable ¶
func NewRouteTable() *RouteTable
NewRouteTable creates a new RouteTable with all necessary fields initialized.
func (*RouteTable) AddCallback ¶
func (rt *RouteTable) AddCallback(f func()) (remove func())
AddCallback registers a callback to be called when routes change. Returns a function to remove the callback.
func (*RouteTable) Connections ¶
func (rt *RouteTable) Connections() []ConnInfo
Connections returns a snapshot of all registered connection identities.
func (*RouteTable) GetAllPrefixes ¶
func (rt *RouteTable) GetAllPrefixes() []string
GetAllPrefixes returns all registered prefixes.
func (*RouteTable) GetPrefixesExcluding ¶
func (rt *RouteTable) GetPrefixesExcluding(exclude map[*jsonrpc2.Conn]bool) []string
GetPrefixesExcluding returns all registered prefixes except those owned by excluded connections.
func (*RouteTable) IDFor ¶
func (rt *RouteTable) IDFor(conn *jsonrpc2.Conn) string
IDFor returns the registered debug ID for conn, or "" if unknown.
func (*RouteTable) Lookup ¶
func (rt *RouteTable) Lookup(method string) *jsonrpc2.Conn
Lookup returns the connection for the longest matching prefix, or nil if none match.
func (*RouteTable) LookupWithPrefix ¶
func (rt *RouteTable) LookupWithPrefix(method string) (*jsonrpc2.Conn, string)
LookupWithPrefix returns the connection and matched prefix for the longest matching prefix. Returns (nil, "") if no match is found.
func (*RouteTable) Register ¶
func (rt *RouteTable) Register(conn *jsonrpc2.Conn, id, socketPath string) *ConnInfo
Register records a connection's debug identity, reusing id if non-empty, otherwise generating a new UUID. Called once when a connection is established, independent of Update, since a connection may own zero routes for its entire lifetime (e.g. a pure pubsub subscriber, or a peer before its first UpdateRoutes).
func (*RouteTable) RemoveConn ¶
func (rt *RouteTable) RemoveConn(conn *jsonrpc2.Conn)
RemoveConn removes all routes registered to the given connection, along with its debug identity.
func (*RouteTable) Snapshot ¶
func (rt *RouteTable) Snapshot() map[string]string
Snapshot returns a copy of the prefix -> connection ID map.
func (*RouteTable) Update ¶
func (rt *RouteTable) Update(conn *jsonrpc2.Conn, prefixes []string)
Update sets the prefixes for a connection, removing any previous prefixes for that connection that are not in the new list.
func (*RouteTable) WaitUntilRoutable ¶
func (rt *RouteTable) WaitUntilRoutable(ctx context.Context, method string) error
WaitUntilRoutable blocks until the given method becomes routable or the context is cancelled. Returns nil on success, or the context's error if cancelled.
type SubscriptionTable ¶
type SubscriptionTable struct {
// contains filtered or unexported fields
}
SubscriptionTable tracks which connections are subscribed to which (publisher, topic) pairs.
func NewSubscriptionTable ¶
func NewSubscriptionTable() *SubscriptionTable
NewSubscriptionTable creates a new empty SubscriptionTable.
func (*SubscriptionTable) RemoveConn ¶
func (st *SubscriptionTable) RemoveConn(conn *jsonrpc2.Conn)
RemoveConn removes all subscriptions for the given connection.
func (*SubscriptionTable) Snapshot ¶
func (st *SubscriptionTable) Snapshot() map[mesh.Subscription][]*jsonrpc2.Conn
Snapshot returns, for each subscription, the set of subscribed connections.
func (*SubscriptionTable) Subscribers ¶
func (st *SubscriptionTable) Subscribers(sub mesh.Subscription) []*jsonrpc2.Conn
Subscribers returns a snapshot of the connections subscribed to sub.
func (*SubscriptionTable) Update ¶
func (st *SubscriptionTable) Update(conn *jsonrpc2.Conn, subs []mesh.Subscription)
Update replaces the connection's subscription set with the given list.