// 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.Infof("Peek connection buffer numBytes:", numBytes)
- bytes, err := c.bufReader.Peek(cmn.MinInt(numBytes, 100))
- if err == nil {
- log.Infof("bytes:", bytes)
+ /*
+ // 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("Error peeking connection buffer err:", err)
+ log.Warning("Received bytes number is:", numBytes)
}
- } else {
- log.Warning("Received bytes number is:", numBytes)
- }
*/
// Read packet type
"fmt"
"math/rand"
"reflect"
- "time"
"strings"
+ "time"
+ "github.com/bytom/errors"
log "github.com/sirupsen/logrus"
wire "github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
- "github.com/bytom/errors"
)
const (
return
}
+ newBias := cmn.MinInt(numOutPeers, 8)*10 + 10
toDial := make(map[string]*NetAddress)
// Try to pick numToDial addresses to dial.
// if we already have many connections. This algorithm isn't perfect, but
// it somewhat ensures that we prioritize connecting to more-vetted
// peers.
- newBias := cmn.MinInt(numOutPeers, 8)*10 + 10
+
var picked *NetAddress
// Try to fetch a new peer 3 times.
// This caps the maximum number of tries to 3 * numToDial.
_, alreadySelected := toDial[try.IP.String()]
alreadyDialing := r.Switch.IsDialing(try)
var alreadyConnected bool
+
for _, v := range r.Switch.Peers().list {
if strings.Compare(v.mconn.RemoteAddress.IP.String(), try.IP.String()) == 0 {
alreadyConnected = true
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
+ "strings"
+
cfg "github.com/bytom/config"
"github.com/bytom/errors"
"github.com/bytom/p2p/trust"
- "strings"
)
const (
// ignore connection if we already have enough
maxPeers := sw.config.MaxNumPeers
if maxPeers <= sw.peers.Size() {
+ // close inConn
+ inConn.Close()
log.WithFields(log.Fields{
"address": inConn.RemoteAddr().String(),
"numPeers": sw.peers.Size(),
// New inbound connection!
err := sw.addPeerWithConnectionAndConfig(inConn, sw.peerConfig)
if err != nil {
+ // conn close for returing err
+ inConn.Close()
log.WithFields(log.Fields{
"address": inConn.RemoteAddr().String(),
"error": err,
peer, err := newInboundPeerWithConfig(conn, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.nodePrivKey, config)
if err != nil {
- conn.Close()
return err
}
peer.SetLogger(sw.Logger.With("peer", conn.RemoteAddr()))
if err = sw.AddPeer(peer); err != nil {
- conn.Close()
return err
}