Involved Source Filesid.go Package protocol provides core interfaces for protocol routing and negotiation in libp2p.
Package-Level Type Names (total 5)
/* sort by: | */
HandlerFunc is a user-provided function used by the Router to
handle a protocol/stream.
Will be invoked with the protocol ID string as the first argument,
which may differ from the ID used for registration if the handler
was registered using a match function.
Negotiator is a component capable of reaching agreement over what protocols
to use for inbound streams of communication. Handle calls Negotiate to determine which protocol handler to use for an
inbound stream, then invokes the protocol handler function, passing it
the protocol ID and the stream. Returns an error if negotiation fails. Negotiate will return the registered protocol handler to use for a given
inbound stream, returning after the protocol has been determined and the
Negotiator has finished using the stream for negotiation. Returns an
error if negotiation fails.Switch(interface)
*github.com/multiformats/go-multistream.MultistreamMuxer[ID]
Router is an interface that allows users to add and remove protocol handlers,
which will be invoked when incoming stream requests for registered protocols
are accepted.
Upon receiving an incoming stream request, the Router will check all registered
protocol handlers to determine which (if any) is capable of handling the stream.
The handlers are checked in order of registration; if multiple handlers are
eligible, only the first to be registered will be invoked. AddHandler registers the given handler to be invoked for
an exact literal match of the given protocol ID string. AddHandlerWithFunc registers the given handler to be invoked
when the provided match function returns true.
The match function will be invoked with an incoming protocol
ID string, and should return true if the handler supports
the protocol. Note that the protocol ID argument is not
used for matching; if you want to match the protocol ID
string exactly, you must check for it in your match function. Protocols returns a list of all registered protocol ID strings.
Note that the Router may be able to handle protocol IDs not
included in this list if handlers were added with match functions
using AddHandlerWithFunc. RemoveHandler removes the registered handler (if any) for the
given protocol ID string.Switch(interface)
*github.com/multiformats/go-multistream.MultistreamMuxer[ID]
Switch is the component responsible for "dispatching" incoming stream requests to
their corresponding stream handlers. It is both a Negotiator and a Router. AddHandler registers the given handler to be invoked for
an exact literal match of the given protocol ID string. AddHandlerWithFunc registers the given handler to be invoked
when the provided match function returns true.
The match function will be invoked with an incoming protocol
ID string, and should return true if the handler supports
the protocol. Note that the protocol ID argument is not
used for matching; if you want to match the protocol ID
string exactly, you must check for it in your match function. Handle calls Negotiate to determine which protocol handler to use for an
inbound stream, then invokes the protocol handler function, passing it
the protocol ID and the stream. Returns an error if negotiation fails. Negotiate will return the registered protocol handler to use for a given
inbound stream, returning after the protocol has been determined and the
Negotiator has finished using the stream for negotiation. Returns an
error if negotiation fails. Protocols returns a list of all registered protocol ID strings.
Note that the Router may be able to handle protocol IDs not
included in this list if handlers were added with match functions
using AddHandlerWithFunc. RemoveHandler removes the registered handler (if any) for the
given protocol ID string.
*github.com/multiformats/go-multistream.MultistreamMuxer[ID]
Switch : Negotiator
Switch : Router
func github.com/libp2p/go-libp2p/core/host.Host.Mux() Switch
func github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).Mux() Switch
func github.com/libp2p/go-libp2p/p2p/host/blank.(*BlankHost).Mux() Switch
func github.com/libp2p/go-libp2p/p2p/host/routed.(*RoutedHost).Mux() Switch
Package-Level Functions (total 2)
ConvertFromStrings is a convenience function that takes a slice of strings and
converts it to a slice of protocol.ID.
ConvertToStrings is a convenience function that takes a slice of protocol.ID and
converts it to a slice of strings.
Package-Level Constants (only one)
These are reserved protocol.IDs.
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.