p2p

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: MIT, MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	SenderID string
	Content  string
	// contains filtered or unexported fields
}

Message represents a pubsub message

func (*Message) GetData

func (m *Message) GetData() []byte

GetData returns the message content

func (*Message) GetFrom

func (m *Message) GetFrom() string

GetFrom returns the sender ID

type P2P

type P2P struct {
	// Represents the host context layer
	Ctx context.Context

	// Represents the libp2p host
	Host host.Host

	// Represents the DHT routing table
	KadDHT *dht.IpfsDHT

	// Represents the peer discovery service
	Discovery *discoveryRouting.RoutingDiscovery

	// Represents the PubSub Handler
	PubSub *pubsub.PubSub
	// contains filtered or unexported fields
}

func NewP2P

func NewP2P(serviceName string, nodeHostIP string, nodeHostPort int) *P2P

func (*P2P) AdvertiseConnect

func (p2p *P2P) AdvertiseConnect()

A method of P2P to connect to service peers. This method uses the Advertise() functionality of the Peer Discovery Service to advertise the service and then disovers all peers advertising the same. The peer discovery is handled by a go-routine that will read from a channel of peer address information until the peer channel closes

func (*P2P) AnnounceConnect

func (p2p *P2P) AnnounceConnect()

A method of P2P to connect to service peers. This method uses the Provide() functionality of the Kademlia DHT directly to announce the ability to provide the service and then disovers all peers that provide the same. The peer discovery is handled by a go-routine that will read from a channel of peer address information until the peer channel closes

type PubSub

type PubSub struct {
	*pubsub.PubSub
	Topic    *pubsub.Topic
	Sub      *pubsub.Subscription
	Inbound  chan *Message
	Outbound chan string
}

PubSub wraps libp2p pubsub with our custom message handling

func JoinPubSub

func JoinPubSub(p2p *P2P, name string, topicName string) (*PubSub, error)

JoinPubSub joins a pubsub topic and sets up message handling

func (*PubSub) Exit

func (ps *PubSub) Exit()

Exit closes the pubsub channels

Jump to

Keyboard shortcuts

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