"fmt"
"net"
"reflect"
- "strconv"
"time"
"github.com/btcsuite/go-socks/socks"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
- "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/flowrate"
cfg "github.com/vapor/config"
"github.com/vapor/consensus"
"github.com/vapor/p2p/connection"
+ "github.com/vapor/p2p/signlib"
)
// peerConn contains the raw connection and its config.
ProxyAddress: config.ProxyAddress,
ProxyUsername: config.ProxyUsername,
ProxyPassword: config.ProxyPassword,
- MConfig: connection.DefaultMConnConfig(),
+ MConfig: connection.DefaultMConnConfig(config.Compression),
}
}
p := &Peer{
peerConn: pc,
NodeInfo: nodeInfo,
- Key: nodeInfo.PubKey.KeyString(),
+ Key: nodeInfo.PubKey,
isLAN: isLAN,
}
p.mconn = createMConnection(pc.conn, p, reactorsByCh, chDescs, onPeerError, pc.config.MConfig)
return p
}
-func newOutboundPeerConn(addr *NetAddress, ourNodePrivKey crypto.PrivKeyEd25519, config *PeerConfig) (*peerConn, error) {
+func newOutboundPeerConn(addr *NetAddress, ourNodePrivKey signlib.PrivKey, config *PeerConfig) (*peerConn, error) {
conn, err := dial(addr, config)
if err != nil {
return nil, errors.Wrap(err, "Error dial peer")
return pc, nil
}
-func newInboundPeerConn(conn net.Conn, ourNodePrivKey crypto.PrivKeyEd25519, config *cfg.P2PConfig) (*peerConn, error) {
+func newInboundPeerConn(conn net.Conn, ourNodePrivKey signlib.PrivKey, config *cfg.P2PConfig) (*peerConn, error) {
return newPeerConn(conn, false, ourNodePrivKey, DefaultPeerConfig(config))
}
-func newPeerConn(rawConn net.Conn, outbound bool, ourNodePrivKey crypto.PrivKeyEd25519, config *PeerConfig) (*peerConn, error) {
+func newPeerConn(rawConn net.Conn, outbound bool, ourNodePrivKey signlib.PrivKey, config *PeerConfig) (*peerConn, error) {
rawConn.SetDeadline(time.Now().Add(config.HandshakeTimeout))
conn, err := connection.MakeSecretConnection(rawConn, ourNodePrivKey)
if err != nil {
return nil, errors.Wrap(err, "Error creating peer")
}
+ // Remove deadline
+ if err := rawConn.SetDeadline(time.Time{}); err != nil {
+ return nil, err
+ }
+
return &peerConn{
config: config,
outbound: outbound,
}
// PubKey returns peer's public key.
-func (p *Peer) PubKey() crypto.PubKeyEd25519 {
- return p.conn.(*connection.SecretConnection).RemotePubKey()
+func (p *Peer) PubKey() string {
+ return p.conn.(*connection.SecretConnection).RemotePubKey().String()
}
// Send msg to the channel identified by chID byte. Returns false if the send
// ServiceFlag return the ServiceFlag of this peer
func (p *Peer) ServiceFlag() consensus.ServiceFlag {
- services := consensus.SFFullNode
- if len(p.Other) == 0 {
- return services
- }
-
- if serviceFlag, err := strconv.ParseUint(p.Other[0], 10, 64); err == nil {
- services = consensus.ServiceFlag(serviceFlag)
- }
- return services
+ // ServiceFlag return the ServiceFlag of this peer
+ return p.NodeInfo.ServiceFlag
}
// String representation.
"peer": p.Addr(),
"msg": msg,
"type": reflect.TypeOf(msg),
- }).Info("send message to peer")
+ }).Debug("send message to peer")
return p.mconn.TrySend(chID, msg)
}