p2p

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 24 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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
}

P2P A structure that represents a P2P Host

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 {
	// Represents the P2P Host for the PubSub
	Host *P2P

	// Represents the channel of incoming messages
	Inbound chan chatmessage
	// Represents the channel of outgoing messages
	Outbound chan string
	// Represents the channel of chat log messages
	Logs chan chatlog

	// Represents the client of the chat room
	ClientName string
	// Represent the topic of the user in the chat room
	TopicName string
	// contains filtered or unexported fields
}

A structure that represents a PubSub Chat Room

func JoinPubSub

func JoinPubSub(p2phost *P2P, clientName string, topicName string) (*PubSub, error)

A constructor function that generates and returns a new PubSub for a given P2PHost, username and roomname

func (*PubSub) Exit

func (cr *PubSub) Exit()

A method of PubSub that updates the chat room by subscribing to the new topic

func (*PubSub) PeerList

func (cr *PubSub) PeerList() []peer.ID

A method of PubSub that returns a list of all peer IDs connected to it

func (*PubSub) PubLoop

func (cr *PubSub) PubLoop()

A method of PubSub that publishes a chatmessage to the PubSub topic until the pubsub context closes

func (*PubSub) SubLoop

func (cr *PubSub) SubLoop()

A method of PubSub that continously reads from the subscription until either the subscription or pubsub context closes. The received message is parsed sent into the inbound channel

func (*PubSub) UpdateUser

func (cr *PubSub) UpdateUser(username string)

A method of PubSub that updates the chat user name

Jump to

Keyboard shortcuts

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