Documentation ¶
Index ¶
- Variables
- func DisableLog()
- func RandomUint64() uint64
- func UseLogger(logger elalog.Logger)
- type Config
- type HostToNetAddrFunc
- type MessageFunc
- type PID
- type Peer
- func (p *Peer) AddMessageFunc(fn 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) 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) PID() PID
- func (p *Peer) PK() *crypto.PublicKey
- func (p *Peer) QueueMessage(msg p2p.Message, doneChan chan<- error)
- func (p *Peer) StatsSnapshot() *StatsSnap
- func (p *Peer) String() string
- func (p *Peer) TimeConnected() time.Time
- func (p *Peer) WaitForDisconnect()
- type StatsSnap
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPeerDisconnected is the error to return when attempt to send message // to peer, but the peer was disconnected. ErrPeerDisconnected = errors.New("peer already disconnected") )
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 { PID PID Target [16]byte Magic uint32 Port uint16 PingInterval time.Duration Sign func(data []byte) []byte PingNonce func(pid PID) uint64 PongNonce func(pid PID) uint64 MakeEmptyMessage func(cmd string) (p2p.Message, error) 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 PID ¶
type PID [33]byte
PID is the encoded public key data used as peer's ID.
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(fn 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) 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) PK ¶ added in v0.3.0
PK returns the peer public key.
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) 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) 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.