Documentation ¶
Index ¶
- type SubPub
- func (ps *SubPub) Close() error
- func (ps *SubPub) FindTopic(namespace string, callback func(*bufio.ReadWriter)) error
- func (ps *SubPub) PeerStreamWrite(peerID string, msg []byte) error
- func (ps *SubPub) SendMessage(w *bufio.Writer, msg []byte) error
- func (ps *SubPub) Start(ctx context.Context)
- func (ps *SubPub) String() string
- func (ps *SubPub) Subscribe(ctx context.Context)
- func (ps *SubPub) TransportConnectPeer(maddr string) error
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 ¶
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) 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 ¶
PeerStreamWrite looks for an existing connection with peerID and calls the callback function with the writer channel as parameter
func (*SubPub) SendMessage ¶
SendMessage encrypts and writes a message on the readwriter buffer
func (*SubPub) Subscribe ¶
Subscribe advertises and subscribes the SubPub host to the network topics
func (*SubPub) TransportConnectPeer ¶
TransportConnectPeer creates a new libp2p peer connection (transport layer)