Documentation ¶
Index ¶
- Variables
- type BasicHost
- func (bh *BasicHost) AddDirectPeer(mA ma.Multiaddr)
- func (bh *BasicHost) Blacklist() blacklist.BlackList
- func (bh *BasicHost) CheckClosedConnWithErr(conn network.Conn, err error) bool
- func (bh *BasicHost) ClearDirectPeers()
- func (bh *BasicHost) ConnMgr() mgr.ConnMgr
- func (bh *BasicHost) Context() context.Context
- func (bh *BasicHost) Dial(remoteAddr ma.Multiaddr) (network.Conn, error)
- func (bh *BasicHost) ID() peer.ID
- func (bh *BasicHost) IsPeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool
- func (bh *BasicHost) LocalAddresses() []ma.Multiaddr
- func (bh *BasicHost) Notify(notifiee host.Notifiee)
- func (bh *BasicHost) PeerProtocols(protocolIDs []protocol.ID) ([]*host.PeerProtocols, error)
- func (bh *BasicHost) PeerStore() store.PeerStore
- func (bh *BasicHost) PrivateKey() crypto.PrivateKey
- func (bh *BasicHost) ProtocolMgr() mgr.ProtocolManager
- func (bh *BasicHost) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
- func (bh *BasicHost) SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) error
- func (bh *BasicHost) Start() error
- func (bh *BasicHost) Stop() error
- func (bh *BasicHost) UnregisterMsgPayloadHandler(protocolID protocol.ID) error
- type HostConfig
- type NetworkType
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProtocolIDNotSupportedByPeer will be returned if protocol not supported by remote peer // when calling SendMsg method. ErrProtocolIDNotSupportedByPeer = errors.New("protocol id not supported by remote peer") // ErrPeerNotConnected will be returned if remote peer not connect to us when calling SendMsg method. ErrPeerNotConnected = errors.New("peer not connected") // ErrConnClosed will be returned if the current connection closed when calling SendMsg method. ErrConnClosed = errors.New("connection closed") // ErrStreamPoolNotFound will be returned if the stream pool of remote peer not found when calling SendMsg method. ErrStreamPoolNotFound = errors.New("peer stream pool not found") // ErrSendMsgIncompletely will be returned if the msg sent incompletely when calling SendMsg method. ErrSendMsgIncompletely = errors.New("send msg incompletely") // ErrPeerAddrNotFoundInPeerStore will be returned if peer address not found in peer store when calling Dial method. ErrPeerAddrNotFoundInPeerStore = errors.New("peer address not found in peer store") // ErrAllDialFailed will be returned if all dialing return errors when calling Dial method. ErrAllDialFailed = errors.New("all dial failed") // ErrBlackPeer will be returned if remote peer id in blacklist when handling new peer connected. ErrBlackPeer = errors.New("black peer") )
Functions ¶
This section is empty.
Types ¶
type BasicHost ¶
type BasicHost struct {
// contains filtered or unexported fields
}
BasicHost is an implementation of host.Host interface. BasicHost can build a network with the same one of different implementations of network.Network. It provides connections management and streams management and protocol management. It uses a mgr.ConnSupervisor to maintain the stat of connections with necessary directed peers.
func (*BasicHost) AddDirectPeer ¶
AddDirectPeer append a directed peer.
func (*BasicHost) Blacklist ¶
Blacklist return the blacklist.BlackList instance of the host.
func (*BasicHost) CheckClosedConnWithErr ¶
CheckClosedConnWithErr return whether the connection has closed. If conn.IsClosed() is true, return true. If err contains closed info, return true. Otherwise return false.
func (*BasicHost) ClearDirectPeers ¶
func (bh *BasicHost) ClearDirectPeers()
ClearDirectPeers remove all directed peers.
func (*BasicHost) ConnMgr ¶
ConnMgr return the mgr.ConnMgr instance of the host.
func (*BasicHost) Context ¶
Context of the host instance.
func (*BasicHost) Dial ¶
Dial try to establish a connection with peer whose address is the given.
func (*BasicHost) IsPeerSupportProtocol ¶
IsPeerSupportProtocol return true if peer which id is the given pid support the given protocol. Otherwise, return false.
func (*BasicHost) LocalAddresses ¶
LocalAddresses return the list of net addresses for listener listening.
func (*BasicHost) Notify ¶
Notify registers a Notifiee to host.
func (*BasicHost) PeerProtocols ¶
PeerProtocols query peer.ID and the protocol.ID list supported by peer. If protocolIDs is nil ,return the list of all connected to us. Otherwise, return the list of part of all which support the protocols that id contains in the given protocolIDs.
func (*BasicHost) PeerStore ¶
PeerStore return the store.PeerStore instance of the host.
func (*BasicHost) PrivateKey ¶
func (bh *BasicHost) PrivateKey() crypto.PrivateKey
PrivateKey of the crypto private key.
func (*BasicHost) ProtocolMgr ¶
func (bh *BasicHost) ProtocolMgr() mgr.ProtocolManager
ProtocolMgr return the mgr.ProtocolManager instance of the host.
func (*BasicHost) RegisterMsgPayloadHandler ¶
func (bh *BasicHost) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
RegisterMsgPayloadHandler register a handler.MsgPayloadHandler for handling the msg received with the protocol which id is the given protocolID .
func (*BasicHost) SendMsg ¶
SendMsg will send a msg with the protocol which id is the given protocolID to the receiver whose peer.ID is the given receiverPID.
func (*BasicHost) Start ¶
Start to listen on local addresses and run all managers.
func (*BasicHost) Stop ¶
Stop listening and close all the connections.
type HostConfig ¶
type HostConfig struct { // PrivateKey of crypto. // Local peer.ID will be generated with it. PrivateKey crypto.PrivateKey // TlsCfg is the configuration for both tls server and client. TlsCfg *cmTls.Config // LoadPidFunc is a function which type is types.LoadPeerIdFromCMTlsCertFunc, used to load peer.ID from x509 certs. LoadPidFunc types.LoadPeerIdFromCMTlsCertFunc // SendStreamPoolInitSize is the size of sending streams will be created when a sending stream pool initialing. SendStreamPoolInitSize int32 // SendStreamPoolCap is the max size of the sending stream pool of each conn. SendStreamPoolCap int32 // PeerReceiveStreamMaxCount is the max limit count of receive streams for each peer. PeerReceiveStreamMaxCount int32 // MaxPeerCountAllowed is the max count of peers allowed to connect to us. MaxPeerCountAllowed int // MaxConnCountEachPeerAllowed is the max count of connections for each peer allowed. MaxConnCountEachPeerAllowed int // ConnEliminationStrategy is the strategy for connection manager eliminating connections. ConnEliminationStrategy int // ListenAddresses is the local addresses for listeners listening. ListenAddresses []ma.Multiaddr // DirectPeers stores the peer.ID and its remote address of peers need keeping connected. // ConnSupervisor will check the connection stat of these peers. // If anyone disconnected to us, supervisor will try to dial to it automatically. DirectPeers map[peer.ID]ma.Multiaddr // BlackNetAddr is the list of net addresses that will be appended into blacklist. // e.g. "127.0.0.1","127.0.0.1:8080","[::1]","[::1]:8080" BlackNetAddr []string // BlackPeers is the list of peer.ID that will be appended into blacklist. BlackPeers []peer.ID // MsgCompress decides whether net message payload compress enable. MsgCompress bool // Insecurity decides whether insecurity enable. // It is invalid in some implementations of network. Insecurity bool }
HostConfig contains necessary parameters for BasicHost.
func (*HostConfig) AddBlackPeers ¶
func (c *HostConfig) AddBlackPeers(pidStr ...string) error
func (*HostConfig) AddDirectPeer ¶
func (c *HostConfig) AddDirectPeer(addr string) error
func (*HostConfig) NewHost ¶
func (c *HostConfig) NewHost(networkType NetworkType, ctx context.Context, logger api.Logger) (*BasicHost, error)
NewHost create a BasicHost instance. Supported network type : QuicNetwork, TcpNetwork
type NetworkType ¶
type NetworkType string
NetworkType is the type of transport layer.
const ( // UnknownNetwork type UnknownNetwork NetworkType = "UNKNOWN" // QuicNetwork type QuicNetwork NetworkType = "QUIC" // TcpNetwork type TcpNetwork NetworkType = "TCP" )
func ConfirmNetworkTypeByAddr ¶
func ConfirmNetworkTypeByAddr(addr ma.Multiaddr) NetworkType
ConfirmNetworkTypeByAddr return a network type supported that for the address. If the format of address is wrong, or it is an unsupported address, return UnknownNetwork.
type Option ¶
type Option func(cfg *networkConfig) error
Option of network instance.
func WithCtx ¶
WithCtx designate ctx given as the context of network.
func WithLoadPidFunc ¶
func WithLoadPidFunc(loadPidFunc types.LoadPeerIdFromCMTlsCertFunc) Option
WithLoadPidFunc set a types.LoadPeerIdFromTlsCertFunc for loading peer.ID from x509 certs.
func WithLocalPID ¶
WithLocalPID designate the local peer.ID of network.