Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionManager ¶
type ConnectionManager interface { io.Closer // AddPeerConnection adds a connection to the peer identified by pid. // Returns true if the connection was successfully added. AddPeerConnection(pid peer.ID, conn network.Connection) bool // RemovePeerConnection removes a connection from the peer identified by pid. // Returns true if the connection was found and removed. RemovePeerConnection(pid peer.ID, conn network.Connection) bool // ExistPeerConnection checks if a connection exists for the peer identified by pid. // Returns true if the connection exists. ExistPeerConnection(pid peer.ID, conn network.Connection) bool // PeerConnection returns the connection associated with the peer identified by pid. PeerConnection(pid peer.ID) network.Connection // PeerAllConnection returns all connections associated with the peer identified by pid. PeerAllConnection(pid peer.ID) []network.Connection // Connected checks if the peer identified by pid is connected. // Returns true if the peer is connected. Connected(pid peer.ID) bool // Allowed checks if the peer identified by pid is allowed to establish connections. // Returns true if the peer is allowed. Allowed(pid peer.ID) bool // MaxCountOfPeersAllowed returns the maximum number of peers allowed to establish connections. MaxCountOfPeersAllowed() int // CountOfPeers returns the current count of connected peers. CountOfPeers() int // AllPeers returns a slice containing all the peer IDs of connected peers. AllPeers() []peer.ID }
type ConnectionSupervisor ¶
type ConnectionSupervisor interface { core.Switcher // SetPeerAddr will set a peer as a necessary peer and store the peer's address. SetPeerAddr(pid peer.ID, addr ma.Multiaddr) // RemovePeerAddr will unset a necessary peer. RemovePeerAddr(pid peer.ID) // RemoveAllPeer clean all necessary peers. RemoveAllPeer() // NoticePeerDisconnected tells the supervisor that a node is disconnected. NoticePeerDisconnected(pid peer.ID) }
ConnectionSupervisor maintains the connection state of the necessary peers. If a necessary peer is not connected to us, supervisor will try to dial to it.
type ProtocolExchanger ¶
type ProtocolExchanger interface { // ProtocolID returns the protocol.ID of the exchanger service. // The protocol ID will be registered using the host.RegisterMsgPayloadHandler method. ProtocolID() protocol.ID // Handle is the message payload handler of the exchanger service. // Implementations of the Handle method should handle the message payload according to the desired logic of the exchanger service. Handle(senderPID peer.ID, msgPayload []byte) // ExchangeProtocol sends the protocols supported by the local peer to the remote peer and receives the protocols supported by the remote peer. // This method is invoked during connection establishment. // It takes a network.Connection parameter representing the connection between the local and remote peer. // It returns a slice of protocol.IDs supported by the remote peer, or an error if the protocol exchange fails. ExchangeProtocol(conn network.Connection) ([]protocol.ID, error) // PushProtocols sends the protocols supported by the local peer to the remote peer. // This method is invoked when a new protocol is registered. // It takes a peer.ID parameter representing the remote peer ID to which the protocols will be pushed. // It returns an error if the protocol push fails. PushProtocols(pid peer.ID) error }
ProtocolExchanger is responsible for exchanging protocols supported by both peers.
type ProtocolManager ¶
type ProtocolManager interface { // RegisterMsgPayloadHandler registers a protocol and associates a handler.MsgPayloadHandler with it. // It returns an error if the registration fails. RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error // UnregisterMsgPayloadHandler unregisters a previously registered protocol. // It returns an error if the un-registration fails. UnregisterMsgPayloadHandler(protocolID protocol.ID) error // Registered checks if a protocol is registered and supported. // It returns true if the protocol is supported, and false otherwise. Registered(protocolID protocol.ID) bool // RegisteredAll returns a list of protocol.IDs that have registered. RegisteredAll() []protocol.ID // Handler returns the message payload handler associated with the registered protocol. // If the protocol is not registered or supported, it returns nil. Handler(protocolID protocol.ID) handler.MsgPayloadHandler // SupportedByPeer checks if a peer with the given peer.ID supports a specific protocol. // It returns true if the protocol is supported by the peer, and false otherwise. // If the peer is not connected, it returns false. SupportedByPeer(pid peer.ID, protocolID protocol.ID) bool // SupportedProtocolsOfPeer returns a list of protocol.IDs that are supported by the peer with the given peer.ID. // If the peer is not connected or doesn't support any protocols, it returns an empty list. SupportedProtocolsOfPeer(pid peer.ID) []protocol.ID // SetSupportedProtocolsOfPeer stores the protocols supported by the peer with the given peer.ID. SetSupportedProtocolsOfPeer(pid peer.ID, protocolIDs []protocol.ID) error // CleanPeer removes all records of protocols supported by the peer with the given peer.ID. CleanPeer(pid peer.ID) error // SetProtocolSupportedNotifyFunc sets a function to be called when a peer supports a protocol. // The function is called with the peer.ID of the supporting peer and the supported protocol ID. SetProtocolSupportedNotifyFunc(notifyFunc ProtocolSupportNotifyFunc) error // SetProtocolUnsupportedNotifyFunc sets a function to be called when a peer no longer supports a protocol. // The function is called with the peer.ID of the peer and the unsupported protocol ID. SetProtocolUnsupportedNotifyFunc(notifyFunc ProtocolSupportNotifyFunc) error }
ProtocolManager manages protocols and protocol message handlers for peers.
type ProtocolSupportNotifyFunc ¶
ProtocolSupportNotifyFunc is a function type used to notify whether a peer supports a protocol.
type ReceiveStreamManager ¶
type ReceiveStreamManager interface { // Reset the manager. Reset() // SetPeerReceiveStreamMaxCount sets the maximum count allowed. SetPeerReceiveStreamMaxCount(max int) // AddPeerReceiveStream appends a receiving stream to the manager. AddPeerReceiveStream(conn network.Connection, stream network.ReceiveStream) error // RemovePeerReceiveStream removes a receiving stream from the manager. RemovePeerReceiveStream(conn network.Connection, stream network.ReceiveStream) error // GetConnReceiveStreamCount returns the number of ReceiveStreams for the given conn. GetConnReceiveStreamCount(conn network.Connection) int // GetCurrentPeerReceiveStreamCount returns the current count of receive streams // whose remote peer ID is the given pid. GetCurrentPeerReceiveStreamCount(pid peer.ID) int // ClosePeerReceiveStreams closes all the receiving streams whose remote // peer ID is the given pid and which were created by the given connection. ClosePeerReceiveStreams(pid peer.ID, conn network.Connection) error }
ReceiveStreamManager manages all receive streams.
type SendStreamPool ¶
type SendStreamPool interface { io.Closer // Connection returns the connection for which the send streams are created. Connection() network.Connection // InitStreams opens a few send streams with the connection. InitStreams() error // BorrowStream gets a sending stream from the send stream queue in the pool. // The borrowed stream should be returned to this pool after successfully sending data, // or it should be dropped by invoking the DropStream method when errors are found in the sending data process. BorrowStream() (network.SendStream, error) // ReturnStream returns a sending stream borrowed from this pool. ReturnStream(network.SendStream) error // DropStream closes the sending stream and drops it. // This method should be invoked only when errors are found. DropStream(network.SendStream) // MaxSize returns the capacity of this pool. MaxSize() int // CurrentSize returns the current size of this pool. CurrentSize() int // IdleSize returns the current count of idle send streams. IdleSize() int }
SendStreamPool is a pool that stores send streams.
type SendStreamPoolBuilder ¶
type SendStreamPoolBuilder func(conn network.Connection) (SendStreamPool, error)
SendStreamPoolBuilder is a function type that builds a SendStreamPool for a given network connection.
type SendStreamPoolManager ¶
type SendStreamPoolManager interface { // Reset the manager. Reset() // AddPeerConnSendStreamPool appends a stream pool for a connection of a peer. AddPeerConnSendStreamPool(pid peer.ID, conn network.Connection, streamPool SendStreamPool) error // RemovePeerConnAndCloseSendStreamPool removes a connection of a peer and closes the stream pool for it. RemovePeerConnAndCloseSendStreamPool(pid peer.ID, conn network.Connection) error // GetPeerBestConnSendStreamPool returns a stream pool for the best connection of a peer. GetPeerBestConnSendStreamPool(pid peer.ID) SendStreamPool }
SendStreamPoolManager manages all send stream pools.