net

package
v0.0.0-...-e21d8b8 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

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 Message

type Message struct {
	Type    string
	Data    []byte
	PeerID  peer.ID
	Timeout time.Duration
}

Message represents a network message

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) Close

func (n *Network) Close() error

Close closes the network host and DHT

func (*Network) ClosedConn

func (n *Network) ClosedConn(net network.Network, conn network.Conn)

func (*Network) ClosedStream

func (n *Network) ClosedStream(net network.Network, s network.Stream)

func (*Network) Connected

func (n *Network) Connected(net network.Network, conn network.Conn)

Notifiee methods for network.Notifiee interface

func (*Network) Disconnected

func (n *Network) Disconnected(net network.Network, conn network.Conn)

func (*Network) GetContext

func (n *Network) GetContext() context.Context

GetContext returns the network's context

func (*Network) GetHost

func (n *Network) GetHost() host.Host

GetHost returns the libp2p host

func (*Network) GetPeerCount

func (n *Network) GetPeerCount() int

GetPeerCount returns the number of connected peers

func (*Network) GetPeers

func (n *Network) GetPeers() []string

GetPeers returns a list of connected peers as strings

func (*Network) HandlePeerFound

func (n *Network) HandlePeerFound(peerInfo peer.AddrInfo)

HandlePeerFound is called when a new peer is found via mDNS

func (*Network) Listen

func (n *Network) Listen(net network.Network, multiaddr multiaddr.Multiaddr)

func (*Network) ListenClose

func (n *Network) ListenClose(net network.Network, multiaddr multiaddr.Multiaddr)

func (*Network) OpenedConn

func (n *Network) OpenedConn(net network.Network, conn network.Conn)

func (*Network) OpenedStream

func (n *Network) OpenedStream(net network.Network, s network.Stream)

func (*Network) PublishBlock

func (n *Network) PublishBlock(blockData []byte) error

PublishBlock publishes a block to the network

func (*Network) PublishTransaction

func (n *Network) PublishTransaction(txData []byte) error

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

Jump to

Keyboard shortcuts

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