aboutsummaryrefslogtreecommitdiffstats
path: root/dex/handler.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2019-03-18 08:43:39 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:23 +0800
commit671e8fb6441fef5365bc357fe27c9fda6c98f4db (patch)
tree2829e824fc972b76392b85f9940f2f08fdf38be6 /dex/handler.go
parent76d5bfcaf0a4c816842b561e3b3b995c1e766d1f (diff)
downloadgo-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar.gz
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar.bz2
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar.lz
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar.xz
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.tar.zst
go-tangerine-671e8fb6441fef5365bc357fe27c9fda6c98f4db.zip
p2p, dex: add debug log (#269)
Diffstat (limited to 'dex/handler.go')
-rw-r--r--dex/handler.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/dex/handler.go b/dex/handler.go
index e887d54d9..6cbd62a8f 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -259,13 +259,17 @@ func (pm *ProtocolManager) removePeer(id string) {
// Unregister the peer from the downloader and Ethereum peer set
pm.downloader.UnregisterPeer(id)
+ log.Debug("after downloader unregister peer", "id", id)
if err := pm.peers.Unregister(id); err != nil {
log.Error("Peer removal failed", "peer", id, "err", err)
}
+ log.Debug("after unregister peer", "id", id)
// Hard disconnect at the networking layer
if peer != nil {
+ log.Debug("removePeer: peer disconnect")
peer.Peer.Disconnect(p2p.DiscUselessPeer)
}
+ log.Debug("peer removed", "id", id)
}
func (pm *ProtocolManager) Start(srvr p2pServer, maxPeers int) {
@@ -392,16 +396,46 @@ func (pm *ProtocolManager) handle(p *peer) error {
// handleMsg is invoked whenever an inbound message is received from a remote
// peer. The remote connection is torn down upon returning any error.
func (pm *ProtocolManager) handleMsg(p *peer) error {
+ ch := make(chan struct{})
+ defer close(ch)
+
+ go func() {
+ n := 0
+ for {
+ select {
+ case <-time.After(time.Second):
+ p.Log().Debug("no msg more than 1s", "n", n)
+ n++
+ case <-ch:
+ return
+ }
+ }
+ }()
+
// Read the next message from the remote peer, and ensure it's fully consumed
msg, err := p.rw.ReadMsg()
if err != nil {
return err
}
+ ch <- struct{}{}
if msg.Size > ProtocolMaxMsgSize {
return errResp(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
}
defer msg.Discard()
+ go func() {
+ n := 0
+ for {
+ select {
+ case <-time.After(100 * time.Millisecond):
+ p.Log().Debug("handle msg more than 100ms", "n", n, "code", msg.Code)
+ n++
+ case <-ch:
+ return
+ }
+ }
+ }()
+
// Handle the message depending on its contents
switch {
case msg.Code == StatusMsg: