p2p

package
v0.0.0-...-90c1326 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolID         = "/3ds/1.0.0"
	DiscoveryNamespace = "3ds-network"
	PubsubTopic        = "3ds-messages"
	ConnectionTimeout  = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Type    MessageType `json:"type"`
	Payload []byte      `json:"payload"`
	From    peer.ID     `json:"from"`
	To      peer.ID     `json:"to,omitempty"`
}

type MessageType

type MessageType int

Message types for network communication

const (
	MessageTypeModelAnnouncement MessageType = iota
	MessageTypeChunkRequest
	MessageTypeChunkResponse
	MessageTypeStorageProof
	MessageTypeNodeStatus
)

type Network

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

func NewNetwork

func NewNetwork(cfg *config.Config) (*Network, error)

func (*Network) Broadcast

func (n *Network) Broadcast(ctx context.Context, data []byte) error

func (*Network) ConnectToPeer

func (n *Network) ConnectToPeer(ctx context.Context, peerInfo peer.AddrInfo) error

ConnectToPeer exports the peer connection functionality

func (*Network) GetHost

func (n *Network) GetHost() host.Host

func (*Network) GetPeers

func (n *Network) GetPeers() []peer.ID

func (*Network) GetSubscription

func (n *Network) GetSubscription() *pubsub.Subscription

GetSubscription returns the pubsub subscription for testing

func (*Network) HandlePeerFound

func (n *Network) HandlePeerFound(pi peer.AddrInfo)

HandlePeerFound implements the mdns.Notifee interface

func (*Network) SendToPeer

func (n *Network) SendToPeer(ctx context.Context, peerID peer.ID, data []byte) error

func (*Network) Start

func (n *Network) Start(ctx context.Context) error

func (*Network) Stop

func (n *Network) Stop() error

Jump to

Keyboard shortcuts

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