import (
"fmt"
"net"
+ "reflect"
"strconv"
"time"
"github.com/btcsuite/go-socks/socks"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
- crypto "github.com/tendermint/go-crypto"
- wire "github.com/tendermint/go-wire"
+ "github.com/tendermint/go-crypto"
+ "github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/flowrate"
*peerConn
mconn *connection.MConnection // multiplex connection
Key string
+ isLAN bool
}
// OnStart implements BaseService.
p.mconn.Stop()
}
-func newPeer(pc *peerConn, nodeInfo *NodeInfo, reactorsByCh map[byte]Reactor, chDescs []*connection.ChannelDescriptor, onPeerError func(*Peer, interface{})) *Peer {
+func newPeer(pc *peerConn, nodeInfo *NodeInfo, reactorsByCh map[byte]Reactor, chDescs []*connection.ChannelDescriptor, onPeerError func(*Peer, interface{}), isLAN bool) *Peer {
// Key and NodeInfo are set after Handshake
p := &Peer{
peerConn: pc,
NodeInfo: nodeInfo,
Key: nodeInfo.PubKey.KeyString(),
+ isLAN: isLAN,
}
p.mconn = createMConnection(pc.conn, p, reactorsByCh, chDescs, onPeerError, pc.config.MConfig)
p.BaseService = *cmn.NewBaseService(nil, "Peer", p)
func() {
var n int
wire.ReadBinary(peerNodeInfo, pc.conn, maxNodeInfoSize, &n, &err2)
- log.WithField("address", peerNodeInfo.ListenAddr).Info("Peer handshake")
+ log.WithFields(log.Fields{"module": logModule, "address": pc.conn.RemoteAddr().String()}).Info("Peer handshake")
})
if err1 != nil {
return peerNodeInfo, errors.Wrap(err1, "Error during handshake/write")
return p.outbound
}
+// IsLAN returns true if peer is LAN peer, false otherwise.
+func (p *Peer) IsLAN() bool {
+ return p.isLAN
+}
+
// PubKey returns peer's public key.
func (p *Peer) PubKey() crypto.PubKeyEd25519 {
return p.conn.(*connection.SecretConnection).RemotePubKey()
if !p.IsRunning() {
return false
}
+
+ log.WithFields(log.Fields{
+ "module": logModule,
+ "peer": p.Addr(),
+ "msg": msg,
+ "type": reflect.TypeOf(msg),
+ }).Info("send message to peer")
return p.mconn.TrySend(chID, msg)
}