subpub

package
v0.0.0-...-457749f Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SubPub

type SubPub struct {
	Key             ecdsa.PrivateKey
	GroupKey        [32]byte
	Topic           string
	BroadcastWriter chan []byte
	Reader          chan []byte
	NoBootStrap     bool
	BootNodes       []string
	PubKey          string
	Private         bool
	MultiAddr       string
	NodeID          string
	Port            int32
	Host            host.Host
	MaxDHTpeers     int

	PeersMu sync.RWMutex
	Peers   []peerSub

	DiscoveryPeriod  time.Duration
	CollectionPeriod time.Duration
	// contains filtered or unexported fields
}

SubPub is a simplified PubSub protocol using libp2p

func NewSubPub

func NewSubPub(key ecdsa.PrivateKey, groupKey []byte, port int32, private bool) *SubPub

NewSubPub creates a new SubPub instance. The private key is used to identify the node (by derivating its pubKey) on the p2p network. The groupKey is a secret shared among the PubSub participants. Only those with the key will be able to join. If private enabled, a libp2p private network is created using the groupKey as shared secret (experimental). If private enabled the default bootnodes will not work.

func (*SubPub) Close

func (ps *SubPub) Close() error

Close terminaters the subpub networking stack

func (*SubPub) FindTopic

func (ps *SubPub) FindTopic(namespace string, callback func(*bufio.ReadWriter)) error

FindTopic opens one or multiple new streams with the peers announcing the namespace. The callback function is executed once a new stream connection is created

func (*SubPub) PeerStreamWrite

func (ps *SubPub) PeerStreamWrite(peerID string, msg []byte) error

PeerStreamWrite looks for an existing connection with peerID and calls the callback function with the writer channel as parameter

func (*SubPub) SendMessage

func (ps *SubPub) SendMessage(w *bufio.Writer, msg []byte) error

SendMessage encrypts and writes a message on the readwriter buffer

func (*SubPub) Start

func (ps *SubPub) Start(ctx context.Context)

Connect starts the SubPub networking stack

func (*SubPub) String

func (ps *SubPub) String() string

func (*SubPub) Subscribe

func (ps *SubPub) Subscribe(ctx context.Context)

Subscribe advertises and subscribes the SubPub host to the network topics

func (*SubPub) TransportConnectPeer

func (ps *SubPub) TransportConnectPeer(maddr string) error

TransportConnectPeer creates a new libp2p peer connection (transport layer)

Jump to

Keyboard shortcuts

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