p2p

package
v0.0.0-...-e2cf2fa Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeoutConnecting maximum time for wait for peers to connect
	TimeoutConnecting = time.Second * 20

	StreamUnknown = "UNKNOWN"
	StreamMsgDone = "done"
)
View Source
const (
	LengthHeader        = 4 // LengthHeader represent how many bytes we used as header
	TimeoutReadPayload  = time.Second * 20
	TimeoutWritePayload = time.Second * 20
	MaxPayload          = 20000000 // 20M
)

Variables

View Source
var (
	TSSProtocolID        protocol.ID = "/p2p/tss"
	ObservedTxProtocolID protocol.ID = "/p2p/observed-tx"
)

TSSProtocolID protocol id used for tss

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

applyDeadline will be true , and only disable it when we are doing test the reason being the p2p network , mocknet, mock stream doesn't support SetReadDeadline ,SetWriteDeadline feature

Functions

func LeaderNode

func LeaderNode(msgID string, blockHeight int64, pIDs []string) (string, error)

LeaderNode use the given input buf to calculate a hash , and consistently choose a node as a master coordinate note

func ReadStreamWithBuffer

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

ReadStreamWithBuffer read data from the given stream

func ReadStreamWithBufferWithContext

func ReadStreamWithBufferWithContext(ctx context.Context, stream network.Stream) ([]byte, error)

ReadStreamWithBufferWithContext reads data from the given stream with context awareness

func WriteStreamWithBuffer

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

WriteStreamWithBuffer write the message to stream

func WriteStreamWithBufferWithContext

func WriteStreamWithBufferWithContext(ctx context.Context, msg []byte, stream network.Stream) error

WriteStreamWithBufferWithContext writes the message to stream with context awareness

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(cfg P2PConfig, stateManager *storage.FileStateMgr) (*Communication, error)

NewCommunication create a new instance of Communication

func StartP2P

func StartP2P(
	cfg P2PConfig,
	priKey tcrypto.PrivKey,
	baseFolder string,
) (*Communication, *storage.FileStateMgr, error)

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]addr.AddrList

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

func (c *Communication) ReleaseStream(msgID string)

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

func (*Config) GetBootstrapPeers

func (c *Config) GetBootstrapPeers() ([]maddr.Multiaddr, error)

func (*Config) GetExternalIP

func (c *Config) GetExternalIP() string

func (*Config) GetP2PPort

func (c *Config) GetP2PPort() int

func (*Config) GetRendezvous

func (c *Config) GetRendezvous() string

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 P2PConfig

type P2PConfig interface {
	GetBootstrapPeers() ([]maddr.Multiaddr, error)
	GetP2PPort() int
	GetExternalIP() string
	GetRendezvous() string
}

type PartyCoordinator

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

func NewPartyCoordinator

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

NewPartyCoordinator create a new instance of PartyCoordinator

func (*PartyCoordinator) HandleStream

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

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 []string,
	threshold int, sigChan chan string) ([]peer.ID, string, error)

func (*PartyCoordinator) JoinPartyWithRetry

func (pc *PartyCoordinator) JoinPartyWithRetry(msgID string, peers []string) ([]peer.ID, error)

JoinPartyWithRetry this method provide the functionality to join party with retry and back off

func (*PartyCoordinator) ReleaseStream

func (pc *PartyCoordinator) ReleaseStream(msgID string)

func (*PartyCoordinator) Stop

func (pc *PartyCoordinator) Stop()

Stop the PartyCoordinator rune

type StreamMgr

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

func NewStreamMgr

func NewStreamMgr() *StreamMgr

func (*StreamMgr) AddStream

func (sm *StreamMgr) AddStream(msgID string, stream network.Stream)

func (*StreamMgr) ReleaseStream

func (sm *StreamMgr) ReleaseStream(msgID string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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