peer

package
v0.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SendQueueSize defines the size of the send queue of every created peer.
	SendQueueSize = 1500
	// CheckStaledAutopeerInterval is the interval autopeered neighbors
	// are checked whether they are staled.
	CheckStaledAutopeerInterval = 60 * time.Second
)

Variables

This section is empty.

Functions

func Caller

func Caller(handler interface{}, params ...interface{})

func IdentityCaller added in v0.5.0

func IdentityCaller(handler interface{}, params ...interface{})

func NewID

func NewID(ip string, port uint16) string

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 Events

type Events struct {
	HeartbeatUpdated *events.Event
}

Events happening on the peer instance.

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"`
	NumberOfStaleTransactions      uint32 `json:"numberOfStaleTransactions"`
	NumberOfReceivedTransactionReq uint32 `json:"numberOfReceivedTransactionReq"`
	NumberOfReceivedMilestoneReq   uint32 `json:"numberOfReceivedMilestoneReq"`
	NumberOfReceivedHeartbeats     uint32 `json:"numberOfReceivedHeartbeats"`
	NumberOfSentPackets            uint32 `json:"numberOfSentPackets"`
	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"`
	Autopeered                     bool   `json:"autopeered"`
	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 transactions of which their timestamp is stale.
	StaleTransactions 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 packets.
	SentPackets 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 packets.
	DroppedPackets 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
	// Time the last heartbeat was received.
	HeartbeatReceivedTime time.Time
	// Time the last heartbeat was sent.
	HeartbeatSentTime time.Time
	// 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
	// Events happening on the peer.
	Events Events
	// contains filtered or unexported fields
}

Peer is a node to which the node is connected to.

func NewInboundPeer

func NewInboundPeer(remoteAddr net.Addr) *Peer

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) CheckStaledAutopeer added in v0.5.0

func (p *Peer) CheckStaledAutopeer(maxPercentage int) (bool, float32)

CheckStaledAutopeer checks if the maximum percentage of dropped packages is exceeded.

func (*Peer) CouldHaveDataFor added in v0.5.0

func (p *Peer) CouldHaveDataFor(index milestone.Index) bool

CouldHaveDataFor tells whether the peer given the latest heartbeat message, could have parts of the cone data for the given milestone. Returns false if no heartbeat message was received yet.

func (*Peer) EnqueueForSending

func (p *Peer) EnqueueForSending(data []byte)

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

func (p *Peer) Handshaked() bool

Handshaked tells whether the peer was handshaked.

func (*Peer) HasDataFor

func (p *Peer) HasDataFor(index milestone.Index) bool

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.

func (*Peer) Info

func (p *Peer) Info() *Info

Info returns a snapshot of the peer in time of calling Info().

func (*Peer) IsInbound

func (p *Peer) IsInbound() bool

IsInbound tells whether the peer's connection was inbound.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL