p2p

package
v3.11.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MessageHandshakeChallenge = MessageId(iota)
	MessageHandshakeSolution
	MessageListenPort
	MessageBlockRequest
	MessageBlockResponse
	MessageBlockBroadcast
	MessagePeerListRequest
	MessagePeerListResponse
	// MessageBlockBroadcastCompact Protocol 1.1
	MessageBlockBroadcastCompact
	// MessageBlockNotify Protocol 1.2
	MessageBlockNotify

	MessageInternal = 0xff
)

from p2p_server.h

View Source
const DefaultBanTime = time.Second * 600
View Source
const HandshakeChallengeDifficulty = 10000
View Source
const HandshakeChallengeSize = 8
View Source
const MaxBufferSize = 128 * 1024
View Source
const PeerListResponseMaxPeers = 16
View Source
const PeerRequestDelay = 60

Variables

This section is empty.

Functions

func CalculateChallengeHash

func CalculateChallengeHash(challenge HandshakeChallenge, consensusId types.Hash, solution uint64) (hash types.Hash, ok bool)

func FindChallengeSolution

func FindChallengeSolution(challenge HandshakeChallenge, consensusId types.Hash, stop *atomic.Bool) (solution uint64, hash types.Hash, ok bool)

Types

type BanEntry

type BanEntry struct {
	Expiration uint64
	Error      error
}

type Client

type Client struct {
	// Peer general static-ish information
	PeerId             atomic.Uint64
	VersionInformation p2pooltypes.PeerVersionInformation
	ListenPort         atomic.Uint32
	ConnectionTime     time.Time
	AddressPort        netip.AddrPort

	// Peer general dynamic-ish information
	BroadcastMaxHeight atomic.Uint64
	PingDuration       atomic.Uint64

	// Internal values
	Owner      *Server
	Connection *net.TCPConn

	LastBroadcastTimestamp               atomic.Uint64
	LastBlockRequestTimestamp            atomic.Uint64
	LastIncomingPeerListRequestTime      time.Time
	LastActiveTimestamp                  atomic.Uint64
	LastPeerListRequestTimestamp         atomic.Uint64
	NextOutgoingPeerListRequestTimestamp atomic.Uint64

	IsIncomingConnection bool

	Closed atomic.Bool
	//State properties
	HandshakeComplete     atomic.Bool
	SentHandshakeSolution atomic.Bool

	LastKnownTip atomic.Pointer[sidechain.PoolBlock]

	BroadcastedHashes *utils.CircularBuffer[types.Hash]
	RequestedHashes   *utils.CircularBuffer[types.Hash]
	// contains filtered or unexported fields
}

func NewClient

func NewClient(owner *Server, conn *net.TCPConn) *Client

func (*Client) Ban

func (c *Client) Ban(duration time.Duration, err error)

func (*Client) BanError

func (c *Client) BanError() error

func (*Client) Close

func (c *Client) Close() bool

func (*Client) IsGood

func (c *Client) IsGood() bool

func (*Client) OnAfterHandshake

func (c *Client) OnAfterHandshake()

func (*Client) OnConnection

func (c *Client) OnConnection()

func (*Client) PreferredAddressPort added in v3.6.0

func (c *Client) PreferredAddressPort() netip.AddrPort

PreferredAddressPort Return the address and port to which the peer is most probably reachable

func (*Client) Read

func (c *Client) Read(buf []byte) (n int, err error)

Read reads from underlying connection, on error it will Close

func (*Client) ReadByte

func (c *Client) ReadByte() (b byte, err error)

ReadByte reads from underlying connection, on error it will Close

func (*Client) SendBlockNotify

func (c *Client) SendBlockNotify(id types.Hash)

func (*Client) SendBlockRequest

func (c *Client) SendBlockRequest(id types.Hash)

func (*Client) SendBlockRequestWithBound

func (c *Client) SendBlockRequestWithBound(id types.Hash, bound int) bool

func (*Client) SendBlockResponse

func (c *Client) SendBlockResponse(block *sidechain.PoolBlock)

func (*Client) SendListenPort

func (c *Client) SendListenPort()

func (*Client) SendMessage

func (c *Client) SendMessage(message *ClientMessage)

func (*Client) SendMissingBlockRequest

func (c *Client) SendMissingBlockRequest(hash types.Hash)

func (*Client) SendMissingBlockRequestAtRandom

func (c *Client) SendMissingBlockRequestAtRandom(hash types.Hash, allowedClients []*Client) []*Client

func (*Client) SendPeerListRequest

func (c *Client) SendPeerListRequest()

func (*Client) SendPeerListResponse

func (c *Client) SendPeerListResponse(list []netip.AddrPort)

func (*Client) SendUniqueBlockRequest

func (c *Client) SendUniqueBlockRequest(hash types.Hash)

func (*Client) SetError

func (c *Client) SetError(err error)

type ClientMessage

type ClientMessage struct {
	MessageId MessageId
	Buffer    []byte
}

type HandshakeChallenge

type HandshakeChallenge [HandshakeChallengeSize]byte

type InternalMessageId

type InternalMessageId uint64

type MessageId

type MessageId uint8

type P2PoolInterface

type P2PoolInterface interface {
	sidechain.ConsensusProvider
	SideChain() *sidechain.SideChain
	MainChain() *mainchain.MainChain
	GetChainMainTip() *sidechain.ChainMain
	GetMinerDataTip() *p2pooltypes.MinerData
	ClientRPC() *client.Client
}

type PeerList

type PeerList []*PeerListEntry

func (PeerList) Delete

func (l PeerList) Delete(addr netip.Addr) PeerList

func (PeerList) Get

func (l PeerList) Get(addr netip.Addr) *PeerListEntry

type PeerListEntry

type PeerListEntry struct {
	AddressPort       netip.AddrPort
	FailedConnections atomic.Uint32
	LastSeenTimestamp atomic.Uint64
}

type Server

type Server struct {
	MaxOutgoingPeers uint32
	MaxIncomingPeers uint32

	NumOutgoingConnections atomic.Int32
	NumIncomingConnections atomic.Int32

	PendingOutgoingConnections *utils.CircularBuffer[string]
	// contains filtered or unexported fields
}

func NewServer

func NewServer(p2pool P2PoolInterface, listenAddress string, externalListenPort uint16, maxOutgoingPeers, maxIncomingPeers uint32, useIPv4, useIPv6 bool, ctx context.Context) (*Server, error)

func (*Server) AddCachedBlock

func (s *Server) AddCachedBlock(block *sidechain.PoolBlock)

func (*Server) AddToPeerList

func (s *Server) AddToPeerList(addressPort netip.AddrPort)

func (*Server) Ban

func (s *Server) Ban(ip netip.Addr, duration time.Duration, err error)

func (*Server) Broadcast

func (s *Server) Broadcast(block *sidechain.PoolBlock)

func (*Server) CleanupBanList

func (s *Server) CleanupBanList()

func (*Server) ClearCachedBlocks

func (s *Server) ClearCachedBlocks()

func (*Server) Clients

func (s *Server) Clients() []*Client

func (*Server) Close

func (s *Server) Close()

func (*Server) Connect

func (s *Server) Connect(addrPort netip.AddrPort) error

func (*Server) Consensus

func (s *Server) Consensus() *sidechain.Consensus

func (*Server) DirectConnect

func (s *Server) DirectConnect(addrPort netip.AddrPort) (*Client, error)

func (*Server) DownloadMissingBlocks

func (s *Server) DownloadMissingBlocks()

func (*Server) ExternalListenPort

func (s *Server) ExternalListenPort() uint16

func (*Server) GetAddressConnected

func (s *Server) GetAddressConnected(addr netip.Addr) (result []*Client)

func (*Server) GetAddressConnectedPrefix

func (s *Server) GetAddressConnectedPrefix(prefix netip.Prefix) (result []*Client)

func (*Server) GetCachedBlock

func (s *Server) GetCachedBlock(hash types.Hash) *sidechain.PoolBlock

func (*Server) GetFastestClient

func (s *Server) GetFastestClient() *Client

func (*Server) GetOutgoingIPv6

func (s *Server) GetOutgoingIPv6() []netip.Addr

func (*Server) HandshakeConsensusId added in v3.4.0

func (s *Server) HandshakeConsensusId() types.Hash

func (*Server) IsBanned

func (s *Server) IsBanned(ip netip.Addr) (bool, *BanEntry)

func (*Server) Listen

func (s *Server) Listen() (err error)

func (*Server) ListenPort

func (s *Server) ListenPort() uint16

func (*Server) MainChain

func (s *Server) MainChain() *mainchain.MainChain

func (*Server) PeerId

func (s *Server) PeerId() uint64

func (*Server) PeerList

func (s *Server) PeerList() PeerList

func (*Server) RefreshOutgoingIPv6

func (s *Server) RefreshOutgoingIPv6()

func (*Server) RemoveFromPeerList

func (s *Server) RemoveFromPeerList(ip netip.Addr)

func (*Server) SideChain

func (s *Server) SideChain() *sidechain.SideChain

func (*Server) UpdateClientConnections

func (s *Server) UpdateClientConnections()

func (*Server) UpdateInPeerList

func (s *Server) UpdateInPeerList(addressPort netip.AddrPort)

func (*Server) UpdatePeerList

func (s *Server) UpdatePeerList()

func (*Server) VersionInformation

func (s *Server) VersionInformation() *p2pooltypes.PeerVersionInformation

Jump to

Keyboard shortcuts

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