aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/handshake.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-04 18:59:51 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-04 18:59:51 +0800
commit4accc187d5cf6a100d6c10c0e0f35780f52871a0 (patch)
treea106654ceccede0c8bcd1fb9402c4eec16bbb6e8 /p2p/handshake.go
parent2382da4179fa290582523f598e1be78469cdf274 (diff)
downloadgo-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar.gz
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar.bz2
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar.lz
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar.xz
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.tar.zst
go-tangerine-4accc187d5cf6a100d6c10c0e0f35780f52871a0.zip
eth, p2p: add trusted node list beside static list
Diffstat (limited to 'p2p/handshake.go')
-rw-r--r--p2p/handshake.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/p2p/handshake.go b/p2p/handshake.go
index 79395f23f..8e611cfd5 100644
--- a/p2p/handshake.go
+++ b/p2p/handshake.go
@@ -70,21 +70,21 @@ type protoHandshake struct {
// If dial is non-nil, the connection the local node is the initiator.
// If atcap is true, the connection will be disconnected with DiscTooManyPeers
// after the key exchange.
-func setupConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, dial *discover.Node, atcap bool) (*conn, error) {
+func setupConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, dial *discover.Node, atcap bool, trusted map[discover.NodeID]bool) (*conn, error) {
if dial == nil {
- return setupInboundConn(fd, prv, our, atcap)
+ return setupInboundConn(fd, prv, our, atcap, trusted)
} else {
- return setupOutboundConn(fd, prv, our, dial, atcap)
+ return setupOutboundConn(fd, prv, our, dial, atcap, trusted)
}
}
-func setupInboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, atcap bool) (*conn, error) {
+func setupInboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, atcap bool, trusted map[discover.NodeID]bool) (*conn, error) {
secrets, err := receiverEncHandshake(fd, prv, nil)
if err != nil {
return nil, fmt.Errorf("encryption handshake failed: %v", err)
}
rw := newRlpxFrameRW(fd, secrets)
- if atcap {
+ if atcap && !trusted[secrets.RemoteID] {
SendItems(rw, discMsg, DiscTooManyPeers)
return nil, errors.New("we have too many peers")
}
@@ -99,13 +99,13 @@ func setupInboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, a
return &conn{rw, rhs}, nil
}
-func setupOutboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, dial *discover.Node, atcap bool) (*conn, error) {
+func setupOutboundConn(fd net.Conn, prv *ecdsa.PrivateKey, our *protoHandshake, dial *discover.Node, atcap bool, trusted map[discover.NodeID]bool) (*conn, error) {
secrets, err := initiatorEncHandshake(fd, prv, dial.ID, nil)
if err != nil {
return nil, fmt.Errorf("encryption handshake failed: %v", err)
}
rw := newRlpxFrameRW(fd, secrets)
- if atcap {
+ if atcap && !trusted[secrets.RemoteID] {
SendItems(rw, discMsg, DiscTooManyPeers)
return nil, errors.New("we have too many peers")
}