Documentation ¶
Index ¶
- func IsErrGaterDisallowedConnection(err error) bool
- func IsErrProtocolNotSupported(err error) bool
- func IsErrSecurityProtocolNegotiationFailed(err error) bool
- func NewLibP2PStreamFactory(h host.Host) p2p.StreamFactory
- type ErrGaterDisallowedConnection
- type ErrProtocolNotSupported
- type ErrSecurityProtocolNegotiationFailed
- type LibP2PStreamFactory
- type PlainStream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrGaterDisallowedConnection ¶
IsErrGaterDisallowedConnection returns whether an error is ErrGaterDisallowedConnection.
func IsErrProtocolNotSupported ¶
IsErrProtocolNotSupported returns whether an error is ErrProtocolNotSupported.
func IsErrSecurityProtocolNegotiationFailed ¶
IsErrSecurityProtocolNegotiationFailed returns whether an error is ErrSecurityProtocolNegotiationFailed.
func NewLibP2PStreamFactory ¶
func NewLibP2PStreamFactory(h host.Host) p2p.StreamFactory
Types ¶
type ErrGaterDisallowedConnection ¶
type ErrGaterDisallowedConnection struct {
// contains filtered or unexported fields
}
ErrGaterDisallowedConnection wrapper around github.com/libp2p/go-libp2p/p2p/net/swarm.ErrGaterDisallowedConnection.
func NewGaterDisallowedConnectionErr ¶
func NewGaterDisallowedConnectionErr(err error) ErrGaterDisallowedConnection
NewGaterDisallowedConnectionErr returns a new ErrGaterDisallowedConnection.
func (ErrGaterDisallowedConnection) Error ¶
func (e ErrGaterDisallowedConnection) Error() string
type ErrProtocolNotSupported ¶
type ErrProtocolNotSupported struct {
// contains filtered or unexported fields
}
ErrProtocolNotSupported indicates node is running on a different spork.
func NewProtocolNotSupportedErr ¶
func NewProtocolNotSupportedErr(peerID peer.ID, protocolID protocol.ID, err error) ErrProtocolNotSupported
NewProtocolNotSupportedErr returns a new ErrSecurityProtocolNegotiationFailed.
func (ErrProtocolNotSupported) Error ¶
func (e ErrProtocolNotSupported) Error() string
type ErrSecurityProtocolNegotiationFailed ¶
type ErrSecurityProtocolNegotiationFailed struct {
// contains filtered or unexported fields
}
ErrSecurityProtocolNegotiationFailed indicates security protocol negotiation failed during the stream factory connect attempt.
func NewSecurityProtocolNegotiationErr ¶
func NewSecurityProtocolNegotiationErr(pid peer.ID, err error) ErrSecurityProtocolNegotiationFailed
NewSecurityProtocolNegotiationErr returns a new ErrSecurityProtocolNegotiationFailed.
func (ErrSecurityProtocolNegotiationFailed) Error ¶
func (e ErrSecurityProtocolNegotiationFailed) Error() string
type LibP2PStreamFactory ¶
type LibP2PStreamFactory struct {
// contains filtered or unexported fields
}
func (*LibP2PStreamFactory) NewStream ¶
func (l *LibP2PStreamFactory) NewStream(ctx context.Context, p peer.ID, pid protocol.ID) (network.Stream, error)
NewStream establishes a new stream with the given peer using the provided protocol.ID on the libp2p host. This function is a critical part of the network communication, facilitating the creation of a dedicated bidirectional channel (stream) between two nodes in the network. If there exists no connection between the two nodes, the function attempts to establish one before creating the stream. If there are multiple connections between the two nodes, the function selects the best one (based on libp2p internal criteria) to create the stream.
Usage: The function is intended to be used when there is a need to initiate a direct communication stream with a peer. It is typically invoked in scenarios where a node wants to send a message or start a series of messages to another node using a specific protocol. The protocol ID is used to ensure that both nodes communicate over the same protocol, which defines the structure and semantics of the communication.
Expected errors: During normal operation, the function may encounter specific expected errors, which are handled as follows:
ErrProtocolNotSupported: This error occurs when the remote node does not support the specified protocol ID, which may indicate that the remote node is running a different version of the software or a different spork. The error contains details about the peer ID and the unsupported protocol, and it is generated when the underlying error message indicates a protocol mismatch. This is a critical error as it signifies that the two nodes cannot communicate using the requested protocol, and it must be handled by either retrying with a different protocol ID or by performing some form of negotiation or fallback.
ErrSecurityProtocolNegotiationFailed this indicates there was an issue upgrading the connection.
ErrGaterDisallowedConnection this indicates the connection was disallowed by the gater.
Any other error returned by the libp2p host: This error indicates that the stream creation failed due to some unexpected error, which may be caused by a variety of reasons. This is NOT a critical error, and it can be handled by retrying the stream creation or by performing some other action. Crashing node upon this error is NOT recommended.
Arguments:
- ctx: A context.Context that governs the lifetime of the stream creation. It can be used to cancel the operation or to set deadlines.
- p: The peer.ID of the target node with which the stream is to be established.
- pid: The protocol.ID that specifies the communication protocol to be used for the stream.
Returns:
- network.Stream: The successfully created stream, ready for reading and writing, or nil if an error occurs.
- error: An error encountered during stream creation, wrapped in a contextually appropriate error type when necessary, or nil if the operation is successful.
func (*LibP2PStreamFactory) SetStreamHandler ¶
func (l *LibP2PStreamFactory) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
type PlainStream ¶ added in v0.32.2
type PlainStream struct {
// contains filtered or unexported fields
}
PlainStream is a stream factory that reflects the same input stream without any modification.
func NewPlainStream ¶ added in v0.32.2
func NewPlainStream(handler libp2pnet.StreamHandler, protocolId protocol.ID) PlainStream
NewPlainStream creates a new PlainStream. Args: - handler: the stream handler that handles the input stream. - protocolId: the protocol id of the stream. Returns:
- PlainStream instance.
func (PlainStream) Handler ¶ added in v0.32.2
func (p PlainStream) Handler(s libp2pnet.Stream)
func (PlainStream) ProtocolId ¶ added in v0.32.2
func (p PlainStream) ProtocolId() protocol.ID
func (PlainStream) UpgradeRawStream ¶ added in v0.32.2
UpgradeRawStream implements protocol interface and returns the input stream without any modification.