go-libp2p-pubsub/notify.go

44 lines
875 B
Go
Raw Normal View History

package pubsub
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"
)
2019-05-26 16:19:03 +00:00
var _ network.Notifiee = (*PubSubNotif)(nil)
type PubSubNotif PubSub
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) OpenedStream(n network.Network, s network.Stream) {
}
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) ClosedStream(n network.Network, s network.Stream) {
}
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) Connected(n network.Network, c network.Conn) {
go func() {
select {
case p.newPeers <- c.RemotePeer():
case <-p.ctx.Done():
}
}()
}
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) Disconnected(n network.Network, c network.Conn) {
}
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) Listen(n network.Network, _ ma.Multiaddr) {
}
2019-05-26 16:19:03 +00:00
func (p *PubSubNotif) ListenClose(n network.Network, _ ma.Multiaddr) {
}
func (p *PubSubNotif) Initialize() {
for _, pr := range p.host.Network().Peers() {
select {
case p.newPeers <- pr:
case <-p.ctx.Done():
}
}
}