p2p

package
v0.0.0-...-5cd0125 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PayloadHeaderLen we use first 4 bytes (uint32)
	// to indicate the payload size over the wire.
	PayloadHeaderLen = 4

	// similar to TCP "ack"
	ResponseMessage         = "done"
	ResponseMessageBytesLen = 4
)
View Source
const NotificationSigReceived = "signature received"
View Source
const ProtocolJoinPartyWithLeader protocol.ID = "/p2p/join-party-leader"

ProtocolJoinPartyWithLeader "party with leader" is an entity that is responsible for picking a leader for signing a single msg_id and coordinating/propagating signature data across the "party". The leader is picked based on message data; see LeaderNode().

View Source
const ProtocolSignatureNotifier protocol.ID = "/p2p/signatureNotifier"

ProtocolSignatureNotifier is the protocol for notifying peers for signature data. Each peer is responsible for signature verification.

View Source
const ProtocolTSS protocol.ID = "/p2p/tss"

ProtocolTSS is the protocol for responsible for passing lib-tss messages across peers and performing keysign/keygen ceremonies.

Variables

View Source
var (
	ErrJoinPartyTimeout = errors.New("fail to join party, timeout")
	ErrLeaderNotReady   = errors.New("leader not reachable")
	ErrSigReceived      = errors.New(NotificationSigReceived)
	ErrNotActiveSigner  = errors.New("not active signer")
	ErrSigGenerated     = errors.New("signature generated")
)

Functions

func ApplyDeadline

func ApplyDeadline(stream network.Stream, timeout time.Duration, readOrWrite bool) error

ApplyDeadline applies read/write (read=true, write=false) deadline to the stream. Tolerates mocknet errors. Resets the stream on failure.

func GetFreePorts

func GetFreePorts(n int) ([]int, error)

GetFreePorts allocated N available ports for testing purposes See https://github.com/tendermint/tendermint/issues/3682

func PickLeader

func PickLeader(msgID string, blockHeight int64, peers []peer.ID) (peer.ID, error)

PickLeader picks party leader based on provided input The logic is preserved as in the original implementation.

func ReadStreamWithBuffer

func ReadStreamWithBuffer(stream network.Stream) ([]byte, error)

ReadStreamWithBuffer read data from the given stream

func WriteStreamWithBuffer

func WriteStreamWithBuffer(msg []byte, stream network.Stream) error

WriteStreamWithBuffer write the message to stream

Types

type Communication

type Communication struct {
	BroadcastMsgChan chan *messages.BroadcastMsgChan
	// contains filtered or unexported fields
}

Communication use p2p to broadcast messages among all the TSS nodes

func NewCommunication

func NewCommunication(
	bootstrapPeers []maddr.Multiaddr,
	port int,
	externalIP string,
	whitelistedPeers []peer.ID,
	logger zerolog.Logger,
) (*Communication, error)

NewCommunication create a new instance of Communication

func (*Communication) Broadcast

func (c *Communication) Broadcast(peers []peer.ID, msg []byte, msgID string)

Broadcast message to Peers

func (*Communication) CancelSubscribe

func (c *Communication) CancelSubscribe(topic messages.THORChainTSSMessageType, msgID string)

func (*Communication) ExportPeerAddress

func (c *Communication) ExportPeerAddress() map[peer.ID][]maddr.Multiaddr

func (*Communication) FreeStreams

func (c *Communication) FreeStreams(msgID string)

func (*Communication) GetHost

func (c *Communication) GetHost() host.Host

GetHost return the host

func (*Communication) GetLocalPeerID

func (c *Communication) GetLocalPeerID() string

GetLocalPeerID from p2p host

func (*Communication) ProcessBroadcast

func (c *Communication) ProcessBroadcast()

func (*Communication) SetSubscribe

func (c *Communication) SetSubscribe(topic messages.THORChainTSSMessageType, msgID string, channel chan *Message)

func (*Communication) Start

func (c *Communication) Start(priKeyBytes []byte) error

Start will start the communication

func (*Communication) Stop

func (c *Communication) Stop() error

Stop communication

type Config

type Config struct {
	RendezvousString string
	Port             int
	BootstrapPeers   addrList
	ExternalIP       string
}

Config is configuration for P2P

type Message

type Message struct {
	PeerID  peer.ID
	Payload []byte
}

Message that get transfer across the wire

type MessageIDSubscriber

type MessageIDSubscriber struct {
	// contains filtered or unexported fields
}

MessageIDSubscriber

func NewMessageIDSubscriber

func NewMessageIDSubscriber() *MessageIDSubscriber

NewMessageIDSubscriber create a new instance of MessageIDSubscriber

func (*MessageIDSubscriber) GetSubscriber

func (ms *MessageIDSubscriber) GetSubscriber(msgID string) chan *Message

GetSubscribers return a subscriber of given message id

func (*MessageIDSubscriber) IsEmpty

func (ms *MessageIDSubscriber) IsEmpty() bool

IsEmpty check whether there is subscribers

func (*MessageIDSubscriber) Subscribe

func (ms *MessageIDSubscriber) Subscribe(msgID string, channel chan *Message)

Subscribe a message id

func (*MessageIDSubscriber) UnSubscribe

func (ms *MessageIDSubscriber) UnSubscribe(msgID string)

UnSubscribe a messageid

type PartyCoordinator

type PartyCoordinator struct {
	// contains filtered or unexported fields
}

func NewPartyCoordinator

func NewPartyCoordinator(host host.Host, timeout time.Duration, logger zerolog.Logger) *PartyCoordinator

NewPartyCoordinator create a new instance of PartyCoordinator

func (*PartyCoordinator) FreeStreams

func (pc *PartyCoordinator) FreeStreams(msgID string)

func (*PartyCoordinator) HandleStreamWithLeader

func (pc *PartyCoordinator) HandleStreamWithLeader(stream network.Stream)

HandleStream handle party coordinate stream

func (*PartyCoordinator) JoinPartyWithLeader

func (pc *PartyCoordinator) JoinPartyWithLeader(
	msgID string,
	blockHeight int64,
	peers []peer.ID,
	threshold int,
	sigChan chan string,
) ([]peer.ID, peer.ID, error)

func (*PartyCoordinator) RemovePeerGroup

func (pc *PartyCoordinator) RemovePeerGroup(messageID string)

func (*PartyCoordinator) Stop

func (pc *PartyCoordinator) Stop()

Stop the PartyCoordinator rune

type ResourceMetricReporter

type ResourceMetricReporter struct {
	// contains filtered or unexported fields
}

func NewResourceMetricReporter

func NewResourceMetricReporter(logger zerolog.Logger) *ResourceMetricReporter

func (*ResourceMetricReporter) AllowConn

func (rmr *ResourceMetricReporter) AllowConn(_ network.Direction, _ bool)

AllowConn is invoked when opening a connection is allowed

func (*ResourceMetricReporter) AllowMemory

func (rmr *ResourceMetricReporter) AllowMemory(_ int)

AllowMemory is invoked when a memory reservation is allowed

func (*ResourceMetricReporter) AllowPeer

func (rmr *ResourceMetricReporter) AllowPeer(_ peer.ID)

AllowPeer is invoked when attaching ac connection to a peer is allowed

func (*ResourceMetricReporter) AllowProtocol

func (rmr *ResourceMetricReporter) AllowProtocol(_ protocol.ID)

AllowProtocol is invoked when setting the protocol for a stream is allowed

func (*ResourceMetricReporter) AllowService

func (rmr *ResourceMetricReporter) AllowService(_ string)

AllowService is invoked when setting the protocol for a stream is allowed

func (*ResourceMetricReporter) AllowStream

func (rmr *ResourceMetricReporter) AllowStream(_ peer.ID, _ network.Direction)

AllowStream is invoked when opening a stream is allowed

func (*ResourceMetricReporter) BlockConn

func (rmr *ResourceMetricReporter) BlockConn(dir network.Direction, useFD bool)

BlockConn is invoked when opening a connection is blocked

func (*ResourceMetricReporter) BlockMemory

func (rmr *ResourceMetricReporter) BlockMemory(size int)

BlockMemory is invoked when a memory reservation is blocked

func (*ResourceMetricReporter) BlockPeer

func (rmr *ResourceMetricReporter) BlockPeer(p peer.ID)

BlockPeer is invoked when attaching a connection to a peer is blocked

func (*ResourceMetricReporter) BlockProtocol

func (rmr *ResourceMetricReporter) BlockProtocol(proto protocol.ID)

BlockProtocol is invoked when setting the protocol for a stream is blocked

func (*ResourceMetricReporter) BlockProtocolPeer

func (rmr *ResourceMetricReporter) BlockProtocolPeer(proto protocol.ID, p peer.ID)

BlockProtocolPeer is invoked when setting the protocol for a stream is blocked at the per protocol peer scope

func (*ResourceMetricReporter) BlockService

func (rmr *ResourceMetricReporter) BlockService(svc string)

BlockService is invoked when setting the protocol for a stream is blocked

func (*ResourceMetricReporter) BlockServicePeer

func (rmr *ResourceMetricReporter) BlockServicePeer(svc string, p peer.ID)

BlockServicePeer is invoked when setting the service for a stream is blocked at the per service peer scope

func (*ResourceMetricReporter) BlockStream

func (rmr *ResourceMetricReporter) BlockStream(p peer.ID, dir network.Direction)

BlockStream is invoked when opening a stream is blocked

type StreamManager

type StreamManager struct {
	// contains filtered or unexported fields
}

StreamManager is responsible fro libp2p stream bookkeeping. It can store streams by message id for latter release as we can't have thousands of streams opened at the same time.

Currently, it's not a manager, but more a "garbage collector" for streams. It also runs a cleanup routine to remove UNUSED && STALE streams.

func NewStreamManager

func NewStreamManager(logger zerolog.Logger, maxAgeBeforeCleanup time.Duration) *StreamManager

NewStreamManager StreamManager constructor.

func (*StreamManager) Free

func (sm *StreamManager) Free(msgID string)

Free synchronously releases all streams by the given message id.

func (*StreamManager) ResetStream

func (sm *StreamManager) ResetStream(msgID string, stream network.Stream) bool

ResetStream resets given stream and logs the error if it fails. This is just a helper function to avoid error & logging handling. It doesn't add the stream to the manager.

func (*StreamManager) Stash

func (sm *StreamManager) Stash(msgID string, stream network.Stream)

Stash adds a stream to the manager for later release.

func (*StreamManager) StashUnknown

func (sm *StreamManager) StashUnknown(stream network.Stream)

StashUnknown adds an unknown stream to the manager for later release.

type WhitelistConnectionGater

type WhitelistConnectionGater struct {
	// contains filtered or unexported fields
}

func NewWhitelistConnectionGater

func NewWhitelistConnectionGater(whitelistedPeers []peer.ID, logger zerolog.Logger) *WhitelistConnectionGater

func (*WhitelistConnectionGater) InterceptAccept

func (wg *WhitelistConnectionGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)

func (*WhitelistConnectionGater) InterceptAddrDial

func (wg *WhitelistConnectionGater) InterceptAddrDial(p peer.ID, m maddr.Multiaddr) (allow bool)

func (*WhitelistConnectionGater) InterceptPeerDial

func (wg *WhitelistConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)

func (*WhitelistConnectionGater) InterceptSecured

func (wg *WhitelistConnectionGater) InterceptSecured(
	_ network.Direction,
	p peer.ID,
	m network.ConnMultiaddrs,
) (allow bool)

func (*WhitelistConnectionGater) InterceptUpgraded

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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