Documentation
¶
Index ¶
- type BandwidthLimiter
- type ConnectionPool
- type Message
- type Network
- func (n *Network) Close() error
- func (n *Network) ClosedConn(net network.Network, conn network.Conn)
- func (n *Network) ClosedStream(net network.Network, s network.Stream)
- func (n *Network) Connected(net network.Network, conn network.Conn)
- func (n *Network) Disconnected(net network.Network, conn network.Conn)
- func (n *Network) GetContext() context.Context
- func (n *Network) GetHost() host.Host
- func (n *Network) GetPeerCount() int
- func (n *Network) GetPeers() []string
- func (n *Network) HandlePeerFound(peerInfo peer.AddrInfo)
- func (n *Network) Listen(net network.Network, multiaddr multiaddr.Multiaddr)
- func (n *Network) ListenClose(net network.Network, multiaddr multiaddr.Multiaddr)
- func (n *Network) OpenedConn(net network.Network, conn network.Conn)
- func (n *Network) OpenedStream(net network.Network, s network.Stream)
- func (n *Network) PublishBlock(blockData []byte) error
- func (n *Network) PublishTransaction(txData []byte) error
- func (n *Network) SubscribeToBlocks() (*pubsub.Subscription, error)
- func (n *Network) SubscribeToTransactions() (*pubsub.Subscription, error)
- type NetworkConfig
- type PeerInfo
- type PeerReputation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BandwidthLimiter ¶
type BandwidthLimiter struct {
// contains filtered or unexported fields
}
BandwidthLimiter controls bandwidth usage
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool manages connections to a peer
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network represents the P2P network layer
func NewNetwork ¶
func NewNetwork(config *NetworkConfig, chain *chain.Chain, mempool *mempool.Mempool) (*Network, error)
NewNetwork creates a new P2P network
func (*Network) ClosedStream ¶
func (*Network) Disconnected ¶
func (*Network) GetContext ¶
GetContext returns the network's context
func (*Network) GetPeerCount ¶
GetPeerCount returns the number of connected peers
func (*Network) HandlePeerFound ¶
HandlePeerFound is called when a new peer is found via mDNS
func (*Network) ListenClose ¶
func (*Network) OpenedStream ¶
func (*Network) PublishBlock ¶
PublishBlock publishes a block to the network
func (*Network) PublishTransaction ¶
PublishTransaction publishes a transaction to the network
func (*Network) SubscribeToBlocks ¶
func (n *Network) SubscribeToBlocks() (*pubsub.Subscription, error)
SubscribeToBlocks subscribes to the blocks topic
func (*Network) SubscribeToTransactions ¶
func (n *Network) SubscribeToTransactions() (*pubsub.Subscription, error)
SubscribeToTransactions subscribes to the transactions topic
type NetworkConfig ¶
type NetworkConfig struct {
ListenPort int
BootstrapPeers []string
EnableMDNS bool
EnableRelay bool
MaxPeers int
ConnectionTimeout time.Duration
}
NetworkConfig holds configuration for the network
func DefaultNetworkConfig ¶
func DefaultNetworkConfig() *NetworkConfig
DefaultNetworkConfig returns the default network configuration
type PeerInfo ¶
type PeerInfo struct {
ID peer.ID
Addrs []multiaddr.Multiaddr
Protocols []string
Connected time.Time
LastSeen time.Time
}
PeerInfo holds information about a connected peer
type PeerReputation ¶
type PeerReputation struct {
Score float64 // Overall reputation score (0-100)
GoodActions int // Number of good actions
BadActions int // Number of bad actions
LastSeen time.Time // Last time peer was seen
ConnectionCount int // Number of connections
MessageCount int // Total messages received
InvalidMessages int // Invalid messages received
SpamCount int // Spam messages detected
LastUpdate time.Time // Last reputation update
// contains filtered or unexported fields
}
SECURITY FIX: PeerReputation tracks peer behavior and reputation
func NewPeerReputation ¶
func NewPeerReputation() *PeerReputation
SECURITY FIX: NewPeerReputation creates a new peer reputation tracker
func (*PeerReputation) GetReputationScore ¶
func (pr *PeerReputation) GetReputationScore() float64
SECURITY FIX: GetReputationScore returns the current reputation score
func (*PeerReputation) IsBlocked ¶
func (pr *PeerReputation) IsBlocked() bool
SECURITY FIX: IsBlocked checks if peer should be blocked
func (*PeerReputation) IsTrusted ¶
func (pr *PeerReputation) IsTrusted() bool
SECURITY FIX: IsTrusted checks if peer is trusted based on reputation
func (*PeerReputation) UpdateReputation ¶
func (pr *PeerReputation) UpdateReputation(action string, isGood bool)
SECURITY FIX: UpdateReputation updates peer reputation based on action