Documentation ¶
Index ¶
- Constants
- Variables
- func RunTask(task task, server *Server, taskDone func())
- func StopTask(task task)
- type Config
- type DiscReason
- type Peer
- func (p *Peer) Close(reason error)
- func (p *Peer) Disconnect(reason error)
- func (p *Peer) HandleError(err error) bool
- func (p *Peer) ID() ID
- func (p *Peer) Inbound() bool
- func (p *Peer) IsClosed() bool
- func (p *Peer) Log(a ...interface{})
- func (p *Peer) Name() string
- func (p *Peer) NewMsg(to INode, msgType string, content interface{}, responseTo *Message, ...) *Message
- func (p *Peer) Node() INode
- func (p *Peer) Run()
- func (p *Peer) Self() INode
- func (p *Peer) SendPingMsg()
- func (p *Peer) SendPongMsg(pingMsg IMessage)
- func (p *Peer) Server() *Server
- func (p *Peer) String() string
- type PeerEventType
- type Server
- func (srv *Server) DeletePeer(p *Peer)
- func (srv *Server) FindPeer(node INode) IPeer
- func (srv *Server) GetProtocolManager() IProtocolManager
- func (srv *Server) GetProtocols() []IProtocol
- func (srv *Server) PeerCount() int
- func (srv *Server) Peers() []INode
- func (srv *Server) Refresh()
- func (srv *Server) RetrieveHandshakePeer(node INode) IPeer
- func (srv *Server) Self() INode
- func (srv *Server) SetOnline(online bool)
- func (srv *Server) SetupConn(flags connFlag, node INode) error
- func (srv *Server) SetupPeerConn(flags int32, node INode) error
- func (srv *Server) Start()
- func (srv *Server) Stop()
- func (srv *Server) String() string
Constants ¶
View Source
const ( DialTask = metrics.DialTask DiscoveryTask = metrics.DiscoveryTask )
View Source
const ( PeerCount = metrics.DEVp2pPeers DiscPeers = metrics.DEVp2pDisconnectedPeers )
Variables ¶
View Source
var (
ErrShuttingDown = errors.New("shutting down")
)
Functions ¶
Types ¶
type Config ¶
type Config struct { // MaxPeers is the maximum number of peers that can be // connected. It must be greater than zero. MaxPeers int // DialRatio controls the ratio of inbound to dialed connections. // Example: a DialRatio of 2 allows 1/2 of connections to be dialed. // Setting DialRatio to zero defaults it to 3. DialRatio int // NoDiscovery can be used to disable the peer discovery mechanism. // Disabling is useful for protocol debugging (manual topology). NoDiscovery bool // BootNodes are used to establish connectivity // with the rest of the network. BootNodes []INode // Static INodes are used as pre-configured connections which are always // maintained and re-connected on disconnects. StaticINodes []INode // Trusted INodes are used as pre-configured connections which are always // allowed to connect, even above the peer limit. TrustedINodes []INode // Protocols should contain the protocols supported // by the server. Matching protocols are launched for // each peer. Protocols []IProtocol // If NoDial is true, the server will not dial any peers. NoDial bool }
Config holds Server options.
type DiscReason ¶
type DiscReason uint
const ( DiscRequested DiscReason = iota DiscNetworkError DiscProtocolError DiscUselessPeer DiscTooManyPeers DiscAlreadyConnected DiscIncompatibleVersion DiscInvalidIdentity DiscQuitting DiscUnexpectedIdentity DiscSelf DiscReadTimeout DiscSubprotocolError = 0x10 )
func (DiscReason) Error ¶
func (d DiscReason) Error() string
func (DiscReason) String ¶
func (d DiscReason) String() string
type Peer ¶
Peer represents a connected remote INode.
func (*Peer) Disconnect ¶
Disconnect terminates the peer connection with the given reason. It returns immediately and does not wait until the connection is closed.
func (*Peer) HandleError ¶
func (*Peer) SendPingMsg ¶
func (p *Peer) SendPingMsg()
func (*Peer) SendPongMsg ¶
func (p *Peer) SendPongMsg(pingMsg IMessage)
type PeerEventType ¶
type PeerEventType string
const ( // PeerEventTypeAdd is the type of event emitted when a peer is added // to a p2p.Server PeerEventTypeAdd PeerEventType = "add" // PeerEventTypeDrop is the type of event emitted when a peer is // dropped from a p2p.Server PeerEventTypeDrop PeerEventType = "drop" // PeerEventTypeMsgSend is the type of event emitted when a // message is successfully sent to a peer PeerEventTypeMsgSend PeerEventType = "msgsend" // PeerEventTypeMsgRecv is the type of event emitted when a // message is received from a peer PeerEventTypeMsgRecv PeerEventType = "msgrecv" )
type Server ¶
type Server struct { // Config fields may not be modified while the server is running. Config IMetricCollector // contains filtered or unexported fields }
Server manages all peer connections.
func (*Server) DeletePeer ¶
func (*Server) GetProtocolManager ¶
func (srv *Server) GetProtocolManager() IProtocolManager
func (*Server) GetProtocols ¶
func (srv *Server) GetProtocols() []IProtocol
func (*Server) Refresh ¶
func (srv *Server) Refresh()
pobuduje taskove povezivanja sa peerovima kad se bilo koja promjena napravi ca se tice spojenih peer-ova potrebno je pozvat ovu metodu
func (*Server) RetrieveHandshakePeer ¶
func (srv *Server) RetrieveHandshakePeer(node INode) IPeer
func (*Server) Self ¶
func (srv *Server) Self() INode
Self returns the local INode's endpoint information.
func (*Server) SetOnline ¶
func (srv *Server) GetProtocolManager() IProtocolManager { return srv.pm }
func (*Server) SetupConn ¶
SetupConn runs the handshakes and attempts to add the connection as a peer. It returns when the connection has been added as a peer or the handshakes have failed.
func (*Server) SetupPeerConn ¶
func (*Server) Start ¶
func (srv *Server) Start()
Start starts running the server. Servers can not be re-used after stopping.
Click to show internal directories.
Click to hide internal directories.