p2p

package
v0.0.0-...-f9c6c1d Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LengthHeader = 4        // LengthHeader represent how many bytes we used as header
	MaxPayload   = 20000000 // 20M
)

Variables

This section is empty.

Functions

func NewHost

func NewHost(privKey crypto.PrivKey, rconf *config.Config) (host.Host, error)

NewHost initiates libp2p host on a given port and configures Noise for the p2p communication.

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 interface {
	Broadcast(peers peer.IDSlice, msg []byte, msgType MessageType, sessionID string)
	Subscribe(topic MessageType, sessionID string, channel chan *WrappedMessage)
	UnSubscribe(topic MessageType, sessionID string)
}

func NewCommunication

func NewCommunication(h host.Host, protocolID protocol.ID) (Communication, error)

func SetupCommunication

func SetupCommunication(conf *config.Config) (host.Host, Communication, error)

SetupCommunication is a helper method to configure a host, communication and discovery of peers.

type MessageIDSubscriber

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

func NewMessageIDSubscriber

func NewMessageIDSubscriber() *MessageIDSubscriber

func (*MessageIDSubscriber) GetSubscriber

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

func (*MessageIDSubscriber) Subscribe

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

func (*MessageIDSubscriber) UnSubscribe

func (ms *MessageIDSubscriber) UnSubscribe(msgID string)

type MessageType

type MessageType uint8
const (
	TssKeyGenMsg MessageType = iota
	TssKeySignMsg
	TssReshareMsg
	TssInitiateMsg
	TssReadyMsg
	TssStartMsg
	Unknown
)

func (MessageType) String

func (msgType MessageType) String() string

String implement fmt.Stringer

type StreamManager

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

func NewStreamMgr

func NewStreamMgr() *StreamManager

func (*StreamManager) AddStream

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

func (*StreamManager) ReleaseStream

func (sm *StreamManager) ReleaseStream(msgID string)

type WrappedMessage

type WrappedMessage struct {
	MessageType MessageType `json:"message_type"`
	SessionID   string      `json:"message_id"`
	Payload     []byte      `json:"payload"`
	From        peer.ID     `json:"from"`
}

WrappedMessage is a message sent to the stream iwth Broadcast.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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