Documentation ¶
Index ¶
- func DisableLog()
- func UseLogger(logger elalog.Logger)
- type Config
- type HostToNetAddrFunc
- type MessageFunc
- type Peer
- func (p *Peer) AddMessageFunc(messageFunc MessageFunc)
- func (p *Peer) Addr() string
- func (p *Peer) AssociateConnection(conn net.Conn)
- func (p *Peer) Connected() bool
- func (p *Peer) Disconnect()
- func (p *Peer) Height() uint32
- func (p *Peer) ID() uint64
- func (p *Peer) Inbound() bool
- func (p *Peer) LastPingMicros() int64
- func (p *Peer) LastPingTime() time.Time
- func (p *Peer) LastRecv() time.Time
- func (p *Peer) LastSend() time.Time
- func (p *Peer) LocalAddr() net.Addr
- func (p *Peer) NA() *p2p.NetAddress
- func (p *Peer) ProtocolVersion() uint32
- func (p *Peer) PushAddrMsg(addresses []*p2p.NetAddress) []*p2p.NetAddress
- func (p *Peer) QueueMessage(msg p2p.Message, doneChan chan<- struct{})
- func (p *Peer) Services() uint64
- func (p *Peer) SetStallHandler(handler StallHandler)
- func (p *Peer) StartingHeight() uint32
- func (p *Peer) StatsSnapshot() *StatsSnap
- func (p *Peer) String() string
- func (p *Peer) TimeConnected() time.Time
- func (p *Peer) TimeOffset() int64
- func (p *Peer) UpdateHeight(newHeight uint32)
- func (p *Peer) VerAckReceived() bool
- func (p *Peer) VersionKnown() bool
- func (p *Peer) WaitForDisconnect()
- type StallControlCmd
- type StallControlMsg
- type StallHandler
- type StatsSnap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
Types ¶
type Config ¶
type Config struct { Magic uint32 ProtocolVersion uint32 DefaultPort uint16 Services uint64 DisableRelayTx bool HostToNetAddress HostToNetAddrFunc MakeEmptyMessage func(cmd string) (p2p.Message, error) BestHeight func() uint64 IsSelfConnection func(ip net.IP, port int, nonce uint64) bool GetVersionNonce func() uint64 MessageFunc MessageFunc }
Config is a descriptor which specifies the peer instance configuration.
type HostToNetAddrFunc ¶
HostToNetAddrFunc is a func which takes a host, port, services and returns the netaddress.
type MessageFunc ¶
MessageFunc is a message handler in peer's configuration
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func NewInboundPeer ¶
NewInboundPeer returns a new inbound peer. Use Start to begin processing incoming and outgoing messages.
func NewOutboundPeer ¶
NewOutboundPeer returns a new outbound peer.
func (*Peer) AddMessageFunc ¶
func (p *Peer) AddMessageFunc(messageFunc MessageFunc)
AddMessageFunc add a new message handler for the peer.
func (*Peer) AssociateConnection ¶
AssociateConnection associates the given conn to the peer. Calling this function when the peer is already connected will have no effect.
func (*Peer) Connected ¶
Connected returns whether or not the peer is currently connected.
This function is safe for concurrent access.
func (*Peer) Disconnect ¶
func (p *Peer) Disconnect()
Disconnect disconnects the peer by closing the connection. Calling this function when the peer is already disconnected or in the process of disconnecting will have no effect.
func (*Peer) Height ¶
Height returns the height of the peer.
This function is safe for concurrent access.
func (*Peer) Inbound ¶
Inbound returns whether the peer is inbound.
This function is safe for concurrent access.
func (*Peer) LastPingMicros ¶
LastPingMicros returns the last ping micros of the remote peer.
This function is safe for concurrent access.
func (*Peer) LastPingTime ¶
LastPingTime returns the last ping time of the remote peer.
This function is safe for concurrent access.
func (*Peer) LastRecv ¶
LastRecv returns the last recv time of the peer.
This function is safe for concurrent access.
func (*Peer) LastSend ¶
LastSend returns the last send time of the peer.
This function is safe for concurrent access.
func (*Peer) LocalAddr ¶
LocalAddr returns the local address of the connection.
This function is safe fo concurrent access.
func (*Peer) NA ¶
func (p *Peer) NA() *p2p.NetAddress
NA returns the peer network address.
This function is safe for concurrent access.
func (*Peer) ProtocolVersion ¶
ProtocolVersion returns the negotiated peer protocol version.
This function is safe for concurrent access.
func (*Peer) PushAddrMsg ¶
func (p *Peer) PushAddrMsg(addresses []*p2p.NetAddress) []*p2p.NetAddress
PushAddrMsg sends an addr message to the connected peer using the provided addresses. This function is useful over manually sending the message via QueueMessage since it automatically limits the addresses to the maximum number allowed by the message and randomizes the chosen addresses when there are too many. It returns the addresses that were actually sent and no message will be sent if there are no entries in the provided addresses slice.
This function is safe for concurrent access.
func (*Peer) QueueMessage ¶ added in v0.3.2
QueueMessage adds the passed bitcoin message to the peer send queue.
This function is safe for concurrent access.
func (*Peer) Services ¶
Services returns the services flag of the remote peer.
This function is safe for concurrent access.
func (*Peer) SetStallHandler ¶ added in v0.3.2
func (p *Peer) SetStallHandler(handler StallHandler)
SetStallHandler set the stall handler for the peer.
func (*Peer) StartingHeight ¶
StartingHeight returns the last known height the peer reported during the initial negotiation phase.
This function is safe for concurrent access.
func (*Peer) StatsSnapshot ¶
StatsSnapshot returns a snapshot of the current peer flags and statistics.
This function is safe for concurrent access.
func (*Peer) String ¶
String returns the peer's address and directionality as a human-readable string.
This function is safe for concurrent access.
func (*Peer) TimeConnected ¶
TimeConnected returns the time at which the peer connected.
This function is safe for concurrent access.
func (*Peer) TimeOffset ¶
TimeOffset returns the number of seconds the local time was offset from the time the peer reported during the initial negotiation phase. Negative values indicate the remote peer's time is before the local time.
This function is safe for concurrent access.
func (*Peer) UpdateHeight ¶
UpdateHeight updates the last known block for the peer.
This function is safe for concurrent access.
func (*Peer) VerAckReceived ¶
VerAckReceived returns whether or not a verack message was received by the peer.
This function is safe for concurrent access.
func (*Peer) VersionKnown ¶
VersionKnown returns the whether or not the version of a peer is known locally.
This function is safe for concurrent access.
func (*Peer) WaitForDisconnect ¶
func (p *Peer) WaitForDisconnect()
WaitForDisconnect waits until the peer has completely disconnected and all resources are cleaned up. This will happen if either the local or remote side has been disconnected or the peer is forcibly disconnected via Disconnect.
type StallControlCmd ¶ added in v0.3.2
type StallControlCmd uint8
StallControlCmd represents the command of a stall control message.
const ( // SCCSendMessage indicates a message is being sent to the remote peer. SCCSendMessage StallControlCmd = iota // SCCReceiveMessage indicates a message has been received from the // remote peer. SCCReceiveMessage // SCCHandlerStart indicates a callback handler is about to be invoked. SCCHandlerStart // SCCHandlerDone indicates a callback handler has completed. SCCHandlerDone )
Constants for the command of a stall control message.
type StallControlMsg ¶ added in v0.3.2
type StallControlMsg struct { CMD StallControlCmd MSG p2p.Message }
StallControlMsg is used to signal the stall handler about specific events so it can properly detect and handle stalled remote peers.
type StallHandler ¶ added in v0.3.2
type StallHandler func(msg StallControlMsg)
StallHandler defines the interfaces to invoke stall control messages.
type StatsSnap ¶
type StatsSnap struct { ID uint64 Addr string Services uint64 RelayTx uint8 LastSend time.Time LastRecv time.Time ConnTime time.Time TimeOffset int64 Version uint32 Inbound bool StartingHeight uint32 LastBlock uint32 LastPingTime time.Time LastPingMicros int64 }
StatsSnap is a snapshot of peer stats at a point in time.