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@dexon.org>2019-04-09 21:32:58 +0800
commit74c022a7679cb03a5ad027dc659e723638ff6a78 (patch)
treee7e2da6913d7a4e076e4fa4ade9bada6e01a0fcb /dex/handler.go
parent829d04922ade426eee1302753fe1bbf34abc11db (diff)
downloadgo-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar.gz
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar.bz2
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar.lz
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar.xz
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.tar.zst
go-tangerine-74c022a7679cb03a5ad027dc659e723638ff6a78.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: