2018-08-28 03:01:08 +00:00
|
|
|
package pubsub
|
2016-09-10 00:15:39 +00:00
|
|
|
|
|
|
|
import (
|
2019-05-26 16:19:03 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
2018-10-04 23:23:53 +00:00
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
2016-09-10 00:15:39 +00:00
|
|
|
)
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
var _ network.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
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) OpenedStream(n network.Network, s network.Stream) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) ClosedStream(n network.Network, s network.Stream) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) Connected(n network.Network, c network.Conn) {
|
2017-07-28 01:43:54 +00:00
|
|
|
go func() {
|
|
|
|
select {
|
2018-12-13 14:58:32 +00:00
|
|
|
case p.newPeers <- c.RemotePeer():
|
2017-07-28 01:43:54 +00:00
|
|
|
case <-p.ctx.Done():
|
|
|
|
}
|
|
|
|
}()
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) Disconnected(n network.Network, c network.Conn) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) Listen(n network.Network, _ ma.Multiaddr) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:19:03 +00:00
|
|
|
func (p *PubSubNotif) ListenClose(n network.Network, _ ma.Multiaddr) {
|
2016-09-10 00:15:39 +00:00
|
|
|
}
|
2020-12-06 19:53:25 +00:00
|
|
|
|
|
|
|
func (p *PubSubNotif) Initialize() {
|
|
|
|
for _, pr := range p.host.Network().Peers() {
|
|
|
|
select {
|
|
|
|
case p.newPeers <- pr:
|
|
|
|
case <-p.ctx.Done():
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|