Documentation ¶
Index ¶
Constants ¶
const SendQueueSize = 1500
SendQueueSize defines the size of the send queue of every created peer.
Variables ¶
This section is empty.
Functions ¶
func NewID ¶
NewID returns a peer ID which consists of the given IP address and server socket port number.
func OriginAddressCaller ¶
func OriginAddressCaller(handler interface{}, params ...interface{})
Types ¶
type ConnectionOrigin ¶
type ConnectionOrigin byte
ConnectionOrigin defines whether a connection was initialized inbound or outbound.
const ( // Inbound connection. Inbound ConnectionOrigin = iota // Outbound connection. Outbound )
type Info ¶
type Info struct { Peer *Peer `json:"-"` Address string `json:"address"` Port uint16 `json:"port,omitempty"` Domain string `json:"domain,omitempty"` DomainWithPort string `json:"-"` Alias string `json:"alias,omitempty"` PreferIPv6 bool `json:"-"` NumberOfAllTransactions uint32 `json:"numberOfAllTransactions"` NumberOfNewTransactions uint32 `json:"numberOfNewTransactions"` NumberOfKnownTransactions uint32 `json:"numberOfKnownTransactions"` NumberOfInvalidTransactions uint32 `json:"numberOfInvalidTransactions"` NumberOfInvalidRequests uint32 `json:"numberOfInvalidRequests"` NumberOfStaleTransactions uint32 `json:"numberOfStaleTransactions"` NumberOfReceivedTransactionReq uint32 `json:"numberOfReceivedTransactionReq"` NumberOfReceivedMilestoneReq uint32 `json:"numberOfReceivedMilestoneReq"` NumberOfReceivedHeartbeats uint32 `json:"numberOfReceivedHeartbeats"` NumberOfSentTransactions uint32 `json:"numberOfSentTransactions"` NumberOfSentTransactionsReq uint32 `json:"numberOfSentTransactionsReq"` NumberOfSentMilestoneReq uint32 `json:"numberOfSentMilestoneReq"` NumberOfSentHeartbeats uint32 `json:"numberOfSentHeartbeats"` NumberOfDroppedSentPackets uint32 `json:"numberOfDroppedSentPackets"` ConnectionType string `json:"connectionType"` Connected bool `json:"connected"` AutopeeringID string `json:"autopeeringId,omitempty"` }
Info acts as a static snapshot of information about a peer.
type Metrics ¶
type Metrics struct { // The number of received transactions which are new. NewTransactions atomic.Uint32 // The number of received transactions which are already known. KnownTransactions atomic.Uint32 // The number of received invalid transactions. InvalidTransactions atomic.Uint32 // The number of received transactions of which their timestamp is stale. StaleTransactions atomic.Uint32 // The number of received invalid requests (both transactions and milestones). InvalidRequests atomic.Uint32 // The number of received transactions. ReceivedTransactions atomic.Uint32 // The number of received transaction requests. ReceivedTransactionRequests atomic.Uint32 // The number of received milestone requests. ReceivedMilestoneRequests atomic.Uint32 // The number of received heartbeats. ReceivedHeartbeats atomic.Uint32 // The number of sent transactions. SentTransactions atomic.Uint32 // The number of sent transaction requests. SentTransactionRequests atomic.Uint32 // The number of sent milestone requests. SentMilestoneRequests atomic.Uint32 // The number of sent heartbeats. SentHeartbeats atomic.Uint32 // The number of dropped messages. DroppedMessages atomic.Uint32 }
Metrics defines a set of metrics regarding a peer.
type Peer ¶
type Peer struct { // The ip/port combination of the peer. ID string // The underlying connection of the peer. Conn *network.ManagedConnection // The original address of this peer. InitAddress *iputils.OriginAddress // The address IP address under which the peer is connected. PrimaryAddress net.IP // The IP addresses which were looked up during peer initialisation. Addresses *iputils.IPAddresses // The protocol instance under which this peer operates. Protocol *protocol.Protocol // Metrics about the peer. Metrics Metrics // Whether the connection for this peer was handled inbound or was created outbound. ConnectionOrigin ConnectionOrigin // Whether to place this peer back into the reconnect pool when the connection is closed. MoveBackToReconnectPool bool // Whether the peer is a duplicate, as it is already connected. Duplicate bool // The peer's latest heartbeat message. LatestHeartbeat *sting.Heartbeat // Holds the autopeering info if this peer was added via autopeering. Autopeering *peer.Peer // A channel which contains messages to be sent to the given peer. SendQueue chan []byte // Whether this peer is marked as disconnected. // Used to suppress errors stemming from connection closure. Disconnected bool }
Peer is a node to which the node is connected to.
func NewInboundPeer ¶
NewInboundPeer creates a new peer instance which is marked as being inbound.
func NewOutboundPeer ¶
func NewOutboundPeer(originAddr *iputils.OriginAddress, primaryAddr net.IP, port uint16, addresses *iputils.IPAddresses) *Peer
NewOutboundPeer creates a new peer instance which is marked as being outbound.
func (*Peer) EnqueueForSending ¶
EnqueueForSending enqueues the given data to be sent to the peer. If it can't because the send queue is over capacity, the message gets dropped.
func (*Peer) Handshaked ¶
Handshaked tells whether the peer was handshaked.
func (*Peer) HasDataFor ¶
HasDataFor tells whether the peer given the latest heartbeat message, has the cone data for the given milestone. Returns false if no heartbeat message was received yet.