github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/routing/dht/notif.go (about) 1 package dht 2 3 import ( 4 ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" 5 6 inet "github.com/ipfs/go-ipfs/p2p/net" 7 ) 8 9 // netNotifiee defines methods to be used with the IpfsDHT 10 type netNotifiee IpfsDHT 11 12 func (nn *netNotifiee) DHT() *IpfsDHT { 13 return (*IpfsDHT)(nn) 14 } 15 16 func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) { 17 dht := nn.DHT() 18 select { 19 case <-dht.Process().Closing(): 20 return 21 default: 22 } 23 dht.Update(dht.Context(), v.RemotePeer()) 24 } 25 26 func (nn *netNotifiee) Disconnected(n inet.Network, v inet.Conn) { 27 dht := nn.DHT() 28 select { 29 case <-dht.Process().Closing(): 30 return 31 default: 32 } 33 dht.routingTable.Remove(v.RemotePeer()) 34 } 35 36 func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {} 37 func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) {} 38 func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) {} 39 func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) {}