package protocol

Import Path
	github.com/libp2p/go-libp2p/core/protocol (on go.dev)

Dependency Relation
	imports 2 packages, and imported by 21 packages

Involved Source Files id.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.
ID is an identifier used to write protocol headers in streams. func ConvertFromStrings(ids []string) (res []ID) func Negotiator.Negotiate(rwc io.ReadWriteCloser) (ID, HandlerFunc, error) func Router.Protocols() []ID func Switch.Negotiate(rwc io.ReadWriteCloser) (ID, HandlerFunc, error) func Switch.Protocols() []ID func github.com/libp2p/go-libp2p/core/metrics.(*BandwidthCounter).GetBandwidthByProtocol() map[ID]metrics.Stats func github.com/libp2p/go-libp2p/core/metrics.Reporter.GetBandwidthByProtocol() map[ID]metrics.Stats func github.com/libp2p/go-libp2p/core/network.(*NullScope).Protocol() ID func github.com/libp2p/go-libp2p/core/network.ProtocolScope.Protocol() ID func github.com/libp2p/go-libp2p/core/network.Stream.Protocol() ID func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.FirstSupportedProtocol(peer.ID, ...ID) (ID, error) func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.GetProtocols(peer.ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.SupportsProtocols(peer.ID, ...ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.FirstSupportedProtocol(peer.ID, ...ID) (ID, error) func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.GetProtocols(peer.ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.SupportsProtocols(peer.ID, ...ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/sec.SecureTransport.ID() ID func github.com/libp2p/go-libp2p/core/sec/insecure.(*Transport).ID() ID func github.com/libp2p/go-libp2p/p2p/host/resource-manager.ResourceManagerState.ListProtocols() []ID func github.com/libp2p/go-libp2p/p2p/net/swarm.(*Stream).Protocol() ID func github.com/libp2p/go-libp2p/p2p/security/noise.(*SessionTransport).ID() ID func github.com/libp2p/go-libp2p/p2p/security/noise.(*Transport).ID() ID func github.com/libp2p/go-libp2p/p2p/security/tls.(*Transport).ID() ID func github.com/libp2p/go-libp2p-pubsub.(*FloodSubRouter).Protocols() []ID func github.com/libp2p/go-libp2p-pubsub.(*GossipSubRouter).Protocols() []ID func github.com/libp2p/go-libp2p-pubsub.PubSubRouter.Protocols() []ID func github.com/libp2p/go-libp2p-pubsub.(*RandomSubRouter).Protocols() []ID func ConvertToStrings(ids []ID) (res []string) func Router.AddHandler(protocol ID, handler HandlerFunc) func Router.AddHandlerWithFunc(protocol ID, match func(ID) bool, handler HandlerFunc) func Router.RemoveHandler(protocol ID) func Switch.AddHandler(protocol ID, handler HandlerFunc) func Switch.AddHandlerWithFunc(protocol ID, match func(ID) bool, handler HandlerFunc) func Switch.RemoveHandler(protocol ID) func github.com/libp2p/go-libp2p/core/host.Host.NewStream(ctx context.Context, p peer.ID, pids ...ID) (network.Stream, error) func github.com/libp2p/go-libp2p/core/host.Host.RemoveStreamHandler(pid ID) func github.com/libp2p/go-libp2p/core/host.Host.SetStreamHandler(pid ID, handler network.StreamHandler) func github.com/libp2p/go-libp2p/core/host.Host.SetStreamHandlerMatch(ID, func(ID) bool, network.StreamHandler) func github.com/libp2p/go-libp2p/core/metrics.(*BandwidthCounter).GetBandwidthForProtocol(proto ID) (out metrics.Stats) func github.com/libp2p/go-libp2p/core/metrics.(*BandwidthCounter).LogRecvMessageStream(size int64, proto ID, p peer.ID) func github.com/libp2p/go-libp2p/core/metrics.(*BandwidthCounter).LogSentMessageStream(size int64, proto ID, p peer.ID) func github.com/libp2p/go-libp2p/core/metrics.Reporter.GetBandwidthForProtocol(ID) metrics.Stats func github.com/libp2p/go-libp2p/core/metrics.Reporter.LogRecvMessageStream(int64, ID, peer.ID) func github.com/libp2p/go-libp2p/core/metrics.Reporter.LogSentMessageStream(int64, ID, peer.ID) func github.com/libp2p/go-libp2p/core/network.(*NullResourceManager).ViewProtocol(_ ID, f func(network.ProtocolScope) error) error func github.com/libp2p/go-libp2p/core/network.(*NullScope).SetProtocol(_ ID) error func github.com/libp2p/go-libp2p/core/network.ResourceManager.ViewProtocol(ID, func(network.ProtocolScope) error) error func github.com/libp2p/go-libp2p/core/network.ResourceScopeViewer.ViewProtocol(ID, func(network.ProtocolScope) error) error func github.com/libp2p/go-libp2p/core/network.Stream.SetProtocol(id ID) error func github.com/libp2p/go-libp2p/core/network.StreamManagementScope.SetProtocol(proto ID) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.AddProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.FirstSupportedProtocol(peer.ID, ...ID) (ID, error) func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.RemoveProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.SetProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.SupportsProtocols(peer.ID, ...ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.AddProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.FirstSupportedProtocol(peer.ID, ...ID) (ID, error) func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.RemoveProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.SetProtocols(peer.ID, ...ID) error func github.com/libp2p/go-libp2p/core/peerstore.ProtoBook.SupportsProtocols(peer.ID, ...ID) ([]ID, error) func github.com/libp2p/go-libp2p/core/sec/insecure.NewWithIdentity(protocolID ID, id peer.ID, key ci.PrivKey) *insecure.Transport func github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).NewStream(ctx context.Context, p peer.ID, pids ...ID) (str network.Stream, strErr error) func github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).RemoveStreamHandler(pid ID) func github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).SetStreamHandler(pid ID, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).SetStreamHandlerMatch(pid ID, m func(ID) bool, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/host/blank.(*BlankHost).NewStream(ctx context.Context, p peer.ID, protos ...ID) (network.Stream, error) func github.com/libp2p/go-libp2p/p2p/host/blank.(*BlankHost).RemoveStreamHandler(pid ID) func github.com/libp2p/go-libp2p/p2p/host/blank.(*BlankHost).SetStreamHandler(pid ID, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/host/blank.(*BlankHost).SetStreamHandlerMatch(pid ID, m func(ID) bool, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/host/resource-manager.Limiter.GetProtocolLimits(proto ID) rcmgr.Limit func github.com/libp2p/go-libp2p/p2p/host/resource-manager.Limiter.GetProtocolPeerLimits(proto ID) rcmgr.Limit func github.com/libp2p/go-libp2p/p2p/host/resource-manager.MetricsReporter.AllowProtocol(proto ID) func github.com/libp2p/go-libp2p/p2p/host/resource-manager.MetricsReporter.BlockProtocol(proto ID) func github.com/libp2p/go-libp2p/p2p/host/resource-manager.MetricsReporter.BlockProtocolPeer(proto ID, p peer.ID) func github.com/libp2p/go-libp2p/p2p/host/resource-manager.(*ScalingLimitConfig).AddProtocolLimit(proto ID, base rcmgr.BaseLimit, inc rcmgr.BaseLimitIncrease) func github.com/libp2p/go-libp2p/p2p/host/resource-manager.(*ScalingLimitConfig).AddProtocolPeerLimit(proto ID, base rcmgr.BaseLimit, inc rcmgr.BaseLimitIncrease) func github.com/libp2p/go-libp2p/p2p/host/routed.(*RoutedHost).NewStream(ctx context.Context, p peer.ID, pids ...ID) (network.Stream, error) func github.com/libp2p/go-libp2p/p2p/host/routed.(*RoutedHost).RemoveStreamHandler(pid ID) func github.com/libp2p/go-libp2p/p2p/host/routed.(*RoutedHost).SetStreamHandler(pid ID, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/host/routed.(*RoutedHost).SetStreamHandlerMatch(pid ID, m func(ID) bool, handler network.StreamHandler) func github.com/libp2p/go-libp2p/p2p/net/swarm.(*Stream).SetProtocol(p ID) error func github.com/libp2p/go-libp2p/p2p/security/noise.New(id ID, privkey crypto.PrivKey, muxers []tptu.StreamMuxer) (*noise.Transport, error) func github.com/libp2p/go-libp2p/p2p/security/noise.SessionWithConnState(s *noise.secureSession, muxer ID) *noise.secureSession func github.com/libp2p/go-libp2p/p2p/security/tls.New(id ID, key ci.PrivKey, muxers []tptu.StreamMuxer) (*libp2ptls.Transport, error) func github.com/libp2p/go-libp2p-pubsub.GossipSubDefaultFeatures(feat pubsub.GossipSubFeature, proto ID) bool func github.com/libp2p/go-libp2p-pubsub.NewFloodsubWithProtocols(ctx context.Context, h host.Host, ps []ID, opts ...pubsub.Option) (*pubsub.PubSub, error) func github.com/libp2p/go-libp2p-pubsub.WithGossipSubProtocols(protos []ID, feature pubsub.GossipSubFeatureTest) pubsub.Option func github.com/libp2p/go-libp2p-pubsub.(*FloodSubRouter).AddPeer(p peer.ID, proto ID) func github.com/libp2p/go-libp2p-pubsub.(*GossipSubRouter).AddPeer(p peer.ID, proto ID) func github.com/libp2p/go-libp2p-pubsub.PubSubRouter.AddPeer(peer.ID, ID) func github.com/libp2p/go-libp2p-pubsub.(*RandomSubRouter).AddPeer(p peer.ID, proto ID) func github.com/libp2p/go-libp2p-pubsub.RawTracer.AddPeer(p peer.ID, proto ID) const TestingID const github.com/libp2p/go-libp2p/p2p/protocol/holepunch.Protocol const github.com/libp2p/go-libp2p-pubsub.FloodSubID const github.com/libp2p/go-libp2p-pubsub.GossipSubID_v10 const github.com/libp2p/go-libp2p-pubsub.GossipSubID_v11 const github.com/libp2p/go-libp2p-pubsub.GossipSubID_v12 const github.com/libp2p/go-libp2p-pubsub.RandomSubID const github.com/libp2p/go-libp2p-pubsub.RemoteTracerProtoID
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.