OSDN Git Service

Fix a bug (p2p pex enable pattern to connet not enable pattern) (#107)
authorGuanghua Guo <1536310027@qq.com>
Thu, 16 Nov 2017 04:04:19 +0000 (12:04 +0800)
committerGitHub <noreply@github.com>
Thu, 16 Nov 2017 04:04:19 +0000 (12:04 +0800)
#106

node/node.go
p2p/connection.go
p2p/peer.go

index bd417b3..32ca2f7 100644 (file)
@@ -268,10 +268,7 @@ func NewNode(config *cfg.Config) *Node {
        // run the profile server
        profileHost := config.ProfListenAddress
        if profileHost != "" {
-
-               go func() {
-                       log.WithField("error", http.ListenAndServe(profileHost, nil)).Error("Profile server")
-               }()
+               // to do: start profile host
        }
 
        node := &Node{
index ec43e4a..10222eb 100644 (file)
@@ -409,19 +409,19 @@ FOR_LOOP:
                // Block until .recvMonitor says we can read.
                c.recvMonitor.Limit(maxMsgPacketTotalSize, atomic.LoadInt64(&c.config.RecvRate), true)
 
-               /*
-                       // Peek into bufReader for debugging
-                       if numBytes := c.bufReader.Buffered(); numBytes > 0 {
-                               log.Info("Peek connection buffer", "numBytes", numBytes, "bytes", log15.Lazy{func() []byte {
-                                       bytes, err := c.bufReader.Peek(MinInt(numBytes, 100))
-                                       if err == nil {
-                                               return bytes
-                                       } else {
-                                               log.Warn("Error peeking connection buffer", "error", err)
-                                               return nil
-                                       }
-                               }})
+/*
+               // Peek into bufReader for debugging
+               if numBytes := c.bufReader.Buffered(); numBytes > 0 {
+                       log.Infof("Peek connection buffer numBytes:", numBytes)
+                       bytes, err := c.bufReader.Peek(cmn.MinInt(numBytes, 100))
+                       if err == nil {
+                               log.Infof("bytes:", bytes)
+                       } else {
+                               log.Warning("Error peeking connection buffer err:", err)
                        }
+               } else {
+                       log.Warning("Received bytes number is:", numBytes)
+               }
                */
 
                // Read packet type
@@ -465,7 +465,11 @@ FOR_LOOP:
                        }
                        channel, ok := c.channelsIdx[pkt.ChannelID]
                        if !ok || channel == nil {
-                               cmn.PanicQ(cmn.Fmt("Unknown channel %X", pkt.ChannelID))
+                               if pkt.ChannelID == PexChannel {
+                                       continue
+                               } else {
+                                       cmn.PanicQ(cmn.Fmt("Unknown channel %X", pkt.ChannelID))
+                               }
                        }
                        msgBytes, err := channel.recvMsgPacket(pkt)
                        if err != nil {
index 8d8580e..69861b9 100644 (file)
@@ -293,7 +293,11 @@ func createMConnection(conn net.Conn, p *Peer, reactorsByCh map[byte]Reactor, ch
        onReceive := func(chID byte, msgBytes []byte) {
                reactor := reactorsByCh[chID]
                if reactor == nil {
-                       cmn.PanicSanity(cmn.Fmt("Unknown channel %X", chID))
+                       if chID == PexChannel {
+                               return
+                       } else {
+                               cmn.PanicSanity(cmn.Fmt("Unknown channel %X", chID))
+                       }
                }
                reactor.Receive(chID, p, msgBytes)
        }