go-libp2p-pubsub/notify.go

42 lines
854 B
Go

package floodsub
import (
"context"
ma "github.com/jbenet/go-multiaddr"
inet "github.com/libp2p/go-libp2p/p2p/net"
)
var _ inet.Notifiee = (*PubSubNotif)(nil)
type PubSubNotif PubSub
func (p *PubSubNotif) OpenedStream(n inet.Network, s inet.Stream) {
}
func (p *PubSubNotif) ClosedStream(n inet.Network, s inet.Stream) {
}
func (p *PubSubNotif) Connected(n inet.Network, c inet.Conn) {
s, err := p.host.NewStream(context.Background(), c.RemotePeer(), ID)
if err != nil {
log.Error("opening new stream to peer: ", err, c.LocalPeer(), c.RemotePeer())
return
}
select {
case p.newPeers <- s:
case <-p.ctx.Done():
s.Close()
}
}
func (p *PubSubNotif) Disconnected(n inet.Network, c inet.Conn) {
}
func (p *PubSubNotif) Listen(n inet.Network, _ ma.Multiaddr) {
}
func (p *PubSubNotif) ListenClose(n inet.Network, _ ma.Multiaddr) {
}