Files

81 lines
2.3 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package peer
import (
"context"
"sync/atomic"
"time"
validators "github.com/luxfi/consensus/validator"
"github.com/luxfi/consensus/validator/uptime"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/math/set"
"github.com/luxfi/node/utils/timer/mockable"
"github.com/luxfi/p2p/message"
"github.com/luxfi/p2p/throttling"
"github.com/luxfi/p2p/tracker"
"github.com/luxfi/version"
)
// InboundHandler handles inbound messages
type InboundHandler interface {
HandleInbound(ctx context.Context, msg message.InboundMessage)
}
// InboundHandlerFunc is a function adapter for InboundHandler
type InboundHandlerFunc func(context.Context, message.InboundMessage)
func (f InboundHandlerFunc) HandleInbound(ctx context.Context, msg message.InboundMessage) {
f(ctx, msg)
}
type Config struct {
// Size, in bytes, of the buffer this peer reads messages into
ReadBufferSize int
// Size, in bytes, of the buffer this peer writes messages into
WriteBufferSize int
Clock mockable.Clock
Metrics *Metrics
MessageCreator message.Creator
Log log.Logger
InboundMsgThrottler throttling.InboundMsgThrottler
Network Network
Router InboundHandler
VersionCompatibility version.Compatibility
MyNodeID ids.NodeID
// MyChains does not include the primary network ID
MyChains set.Set[ids.ID]
Beacons validators.Manager
Validators validators.Manager
NetworkID uint32
PingFrequency time.Duration
PongTimeout time.Duration
MaxClockDifference time.Duration
SupportedLPs []uint32
ObjectedLPs []uint32
// Unix time of the last message sent and received respectively
// Must only be accessed atomically
LastSent, LastReceived int64
// Tracks CPU/disk usage caused by each peer.
ResourceTracker tracker.ResourceTracker
// Calculates uptime of peers
UptimeCalculator uptime.Calculator
// Signs my IP so I can send my signed IP address in the Handshake message
IPSigner *IPSigner
// IngressConnectionCount counts the ingress (to us) connections.
IngressConnectionCount atomic.Int64
}