p2p/protocol/id: log version mismatch disconnects
Juan Batiz-Benet committed
Feb 2, 2015 at 20:53 UTC
37007b9c2b62c536228dfd0ba5884e0efb594098
1 file changed
+12
p2p/protocol/identify/id.go
+12
@@ -16,6 +16,7 @@ import (
16
pb "github.com/jbenet/go-ipfs/p2p/protocol/identify/pb"
17
config "github.com/jbenet/go-ipfs/repo/config"
18
eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
19
+ lgbl "github.com/jbenet/go-ipfs/util/eventlog/loggables"
20
)
21
22
var log = eventlog.Logger("net/identify")
@@ -191,6 +192,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
192
// TODO: at this point, we've already exchanged information.
193
// move this into a first handshake before the connection can open streams.
194
if !protocolVersionsAreCompatible(pv, IpfsVersion) {
195
+ logProtocolMismatchDisconnect(c, pv, av)
196
c.Close()
197
return
198
}
@@ -309,3 +311,13 @@ func (nn *netNotifiee) OpenedStream(n inet.Network, v inet.Stream) {}
311
func (nn *netNotifiee) ClosedStream(n inet.Network, v inet.Stream) {}
312
func (nn *netNotifiee) Listen(n inet.Network, a ma.Multiaddr) {}
313
func (nn *netNotifiee) ListenClose(n inet.Network, a ma.Multiaddr) {}
314
+
315
+func logProtocolMismatchDisconnect(c inet.Conn, protocol, agent string) {
316
+ lm := make(lgbl.DeferredMap)
317
+ lm["remotePeer"] = func() interface{} { return c.RemotePeer().Pretty() }
318
+ lm["remoteAddr"] = func() interface{} { return c.RemoteMultiaddr().String() }
319
+ lm["protocolVersion"] = protocol
320
+ lm["agentVersion"] = agent
321
+ log.Event(context.TODO(), "IdentifyProtocolMismatch", lm)
322
+ log.Debug("IdentifyProtocolMismatch %s %s %s (disconnected)", c.RemotePeer(), protocol, agent)
323
+}