-
Notifications
You must be signed in to change notification settings - Fork 1
/
notify.go
41 lines (31 loc) · 1.13 KB
/
notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package autonat
import (
"time"
inet "github.com/ipsn/go-ipfs/gxlibs/github.com/libp2p/go-libp2p-net"
ma "github.com/ipsn/go-ipfs/gxlibs/github.com/multiformats/go-multiaddr"
)
var _ inet.Notifiee = (*AmbientAutoNAT)(nil)
var AutoNATIdentifyDelay = 5 * time.Second
func (as *AmbientAutoNAT) Listen(net inet.Network, a ma.Multiaddr) {}
func (as *AmbientAutoNAT) ListenClose(net inet.Network, a ma.Multiaddr) {}
func (as *AmbientAutoNAT) OpenedStream(net inet.Network, s inet.Stream) {}
func (as *AmbientAutoNAT) ClosedStream(net inet.Network, s inet.Stream) {}
func (as *AmbientAutoNAT) Connected(net inet.Network, c inet.Conn) {
p := c.RemotePeer()
go func() {
// add some delay for identify
time.Sleep(AutoNATIdentifyDelay)
protos, err := as.host.Peerstore().SupportsProtocols(p, AutoNATProto)
if err != nil {
log.Debugf("error retrieving supported protocols for peer %s: %s", p, err)
return
}
if len(protos) > 0 {
log.Infof("Discovered AutoNAT peer %s", p.Pretty())
as.mx.Lock()
as.peers[p] = struct{}{}
as.mx.Unlock()
}
}()
}
func (as *AmbientAutoNAT) Disconnected(net inet.Network, c inet.Conn) {}