2016-09-10 03:13:50 +00:00
|
|
|
package floodsub
|
2016-09-10 00:15:39 +00:00
|
|
|
|
|
|
|
import (
|
2018-10-04 23:23:53 +00:00
|
|
|
inet "github.com/libp2p/go-libp2p-net"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
2016-09-10 00:15:39 +00:00
|
|
|
)
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
var _ inet.Notifiee = (*PubSubNotif)(nil)
|
2016-09-10 00:15:39 +00:00
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
type PubSubNotif PubSub
|
2016-09-10 00:15:39 +00:00
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) OpenedStream(n inet.Network, s inet.Stream) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) ClosedStream(n inet.Network, s inet.Stream) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) Connected(n inet.Network, c inet.Conn) {
|
2017-07-28 01:43:54 +00:00
|
|
|
go func() {
|
2018-01-24 14:04:39 +00:00
|
|
|
s, err := p.host.NewStream(p.ctx, c.RemotePeer(), p.rt.Protocols()...)
|
2017-07-28 01:43:54 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Warning("opening new stream to peer: ", err, c.LocalPeer(), c.RemotePeer())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case p.newPeers <- s:
|
|
|
|
case <-p.ctx.Done():
|
2017-09-15 23:28:46 +00:00
|
|
|
s.Reset()
|
2017-07-28 01:43:54 +00:00
|
|
|
}
|
|
|
|
}()
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) Disconnected(n inet.Network, c inet.Conn) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) Listen(n inet.Network, _ ma.Multiaddr) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:22:16 +00:00
|
|
|
func (p *PubSubNotif) ListenClose(n inet.Network, _ ma.Multiaddr) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|