p2p

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: BSD-3-Clause, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const BlockCheckProtocolID = protocol.ID("/p2pool/blockcheck/1.0.0")
View Source
const BlockRelayProtocolID = protocol.ID("/p2pool/blockrelay/1.0.0")
View Source
const HeaderProofProtocolID = protocol.ID("/p2pool/headerproof/1.0.0")
View Source
const P2PNetworkTopic = "vtc-p2pool-shares-v1"
View Source
const PeerExProtocolID = protocol.ID("/p2pool/peers/1.0.0")
View Source
const ShareReqProtocolID = protocol.ID("/p2pool/sharereq/1.0.0")
View Source
const ShareReqZProtocolID = protocol.ID("/p2pool/sharereq/1.1.0")
View Source
const SyncProtocolID = protocol.ID("/p2pool/sync/1.0.0")
View Source
const SyncZProtocolID = protocol.ID("/p2pool/sync/1.1.0")

The 1.1.0 protocols carry the same JSON as their 1.0.0 versions, zstd-compressed in each direction. Dialers offer both and peers that predate them get 1.0.0.

View Source
const TemplateProtocolID = protocol.ID("/p2pool/template/1.0.0")
View Source
const VersionProtocolID = protocol.ID("/p2pool/version/1.0.0")

Variables

This section is empty.

Functions

This section is empty.

Types

type IncomingShare

type IncomingShare struct {
	Data []byte
	From peer.ID
}

IncomingShare is a gossiped share and the peer that relayed it.

type Node

type Node struct {
	Host   host.Host
	DHT    *dht.IpfsDHT
	PubSub *pubsub.PubSub
	Topic  *pubsub.Topic
	Sub    *pubsub.Subscription

	IncomingShares chan IncomingShare

	GetSyncDataFunc      func(withShares bool) ([]byte, []byte)
	OnSyncDataFunc       func(sharesJSON []byte, blocksJSON []byte)
	GetSharesByHashFunc  func(hashes []string, parents int, stops []string) []byte
	GetMissingSharesFunc func() []string
	GetStopHashesFunc    func() []string
	GetBestShareFunc     func() string
	HasShareFunc         func(hash string) bool
	GetTemplateFunc      func() []byte
	OnTemplateFunc       func(peerID string, voterKey string, tmplJSON []byte)
	OnRawBlockFunc       func(peerID string, rawHex string) bool
	CheckBlockFunc       func(blockHash string) int
	GetRawHeaderFunc     func(blockHash string) string
	GetChallengeHashFunc func() string
	// contains filtered or unexported fields
}

func NewNode

func NewNode(listenPort int, bindAddr string, disableUPnP bool) (*Node, error)

NewNode starts the libp2p host on bindAddr:listenPort. When bindAddr is a loopback address the node runs outbound-only: it opens no non-loopback sockets (no UPnP, mDNS or UDP transports), advertises no addresses and uses the DHT in client mode, so peers never try to dial it.

func (*Node) Bootstrap

func (n *Node) Bootstrap(bootstrapPeers []string) error

func (*Node) BroadcastShare

func (n *Node) BroadcastShare(shareData []byte) error

func (*Node) BroadcastTemplate

func (n *Node) BroadcastTemplate(b []byte)

func (*Node) Close

func (n *Node) Close()

func (*Node) DownloadShares

func (n *Node) DownloadShares()

DownloadShares requests missing parent shares from peers until the node closes.

func (*Node) ExchangePeers

func (n *Node) ExchangePeers(pid peer.ID)

func (*Node) PullTemplateFromPeers

func (n *Node) PullTemplateFromPeers()

func (*Node) QueryBlockConfirmations

func (n *Node) QueryBlockConfirmations(blockHash string) int

func (*Node) RecordShareOutcome

func (n *Node) RecordShareOutcome(id peer.ID, bad bool)

RecordShareOutcome counts a share relayed by id as accepted or provably invalid, and disconnects id when its invalid shares cross the threshold. A peer's score starts over when it reconnects.

func (*Node) RelaySolvedBlockHex

func (n *Node) RelaySolvedBlockHex(hexStr string) int

func (*Node) SetShareValidator

func (n *Node) SetShareValidator(f func(data []byte) ShareVerdict) error

SetShareValidator runs f on every gossip share before it is delivered or forwarded.

func (*Node) SyncWithPeer

func (n *Node) SyncWithPeer(pid peer.ID)

type ShareReq

type ShareReq struct {
	Hashes  []string `json:"hashes"`
	Parents int      `json:"parents"`
	Stops   []string `json:"stops,omitempty"`
}

ShareReq asks a peer for the shares in Hashes, each followed by up to Parents ancestors. The walk back from each hash ends before any hash in Stops. Peers that predate Stops ignore it.

type ShareVerdict

type ShareVerdict int

ShareVerdict is a gossip share validator's decision.

const (
	ShareAccept ShareVerdict = iota
	// ShareReject drops an invalid share so it is neither delivered nor forwarded.
	ShareReject
	// ShareIgnore drops a share without counting it as invalid, for checks against
	// our own clock that a peer could pass honestly.
	ShareIgnore
)

type SyncPayload

type SyncPayload struct {
	Shares   json.RawMessage `json:"shares"`
	Blocks   json.RawMessage `json:"blocks"`
	FullNode bool            `json:"full_node,omitempty"`
	// Pull is set by a sender that fetches shares with share requests instead. It
	// sends no shares, and a responder that understands the field replies with none.
	Pull bool `json:"pull,omitempty"`
}

type VersionMsg

type VersionMsg struct {
	BestShareHash string `json:"best_share_hash,omitempty"`
}

VersionMsg is swapped when a node contacts a peer, like p2pool's version message, so each side can request the other's best share right away.

Jump to

Keyboard shortcuts

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