go_p2p_node

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 14 Imported by: 0

README

go-p2p-node

Go module for p2p network node

Documentation

Index

Constants

View Source
const DefaultDiscoveryInterval = time.Minute * 10

DiscoveryInterval is how often we re-publish our mDNS records.

View Source
const DefaultDiscoveryServiceTag = "pubsub"

DiscoveryServiceTag is used in our mDNS advertisements to discover other chat peers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Messages chan ChannelMessage
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel(ctx context.Context, node *Node, name string) (*Channel, error)

func (*Channel) ListPeers

func (c *Channel) ListPeers() []peer.ID

func (*Channel) Listen

func (c *Channel) Listen()

func (*Channel) Publish

func (c *Channel) Publish(data []byte, mtype string) error

Publish sends a message to the pubsub topic.

type ChannelMessage

type ChannelMessage struct {
	Data []byte
	Type string
}

type LibP2pNodeOptions

type LibP2pNodeOptions struct {
	Ctx                 context.Context
	Addr                []string
	OnPeerFound         OnPeerFound
	DiscoveryServiceTag string
	DiscoveryInterval   time.Duration
}

type Node

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

func NewLibP2pNode

func NewLibP2pNode(opts *LibP2pNodeOptions) (*Node, error)

func (*Node) Channel

func (n *Node) Channel(name string) (cn *Channel, err error)

func (*Node) Close

func (n *Node) Close() error

func (*Node) ID

func (n *Node) ID() string

type OnPeerFound

type OnPeerFound = func(pi peer.AddrInfo) bool

Jump to

Keyboard shortcuts

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