diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 4cfa8e6be83d..33bb41d06c03 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -49,7 +49,6 @@ var ( // Timeouts const ( respTimeout = 500 * time.Millisecond - sendTimeout = 500 * time.Millisecond expiration = 20 * time.Second ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP diff --git a/p2p/discv5/database.go b/p2p/discv5/database.go index aedc8a60fc87..149fd926f3db 100644 --- a/p2p/discv5/database.go +++ b/p2p/discv5/database.go @@ -62,7 +62,6 @@ var ( nodeDBDiscoverPing = nodeDBDiscoverRoot + ":lastping" nodeDBDiscoverPong = nodeDBDiscoverRoot + ":lastpong" nodeDBDiscoverFindFails = nodeDBDiscoverRoot + ":findfail" - nodeDBDiscoverLocalEndpoint = nodeDBDiscoverRoot + ":localendpoint" nodeDBTopicRegTickets = ":tickets" ) @@ -311,20 +310,6 @@ func (db *nodeDB) updateFindFails(id NodeID, fails int) error { return db.storeInt64(makeKey(id, nodeDBDiscoverFindFails), int64(fails)) } -// localEndpoint returns the last local endpoint communicated to the -// given remote node. -func (db *nodeDB) localEndpoint(id NodeID) *rpcEndpoint { - var ep rpcEndpoint - if err := db.fetchRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep); err != nil { - return nil - } - return &ep -} - -func (db *nodeDB) updateLocalEndpoint(id NodeID, ep rpcEndpoint) error { - return db.storeRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep) -} - // querySeeds retrieves random nodes to be used as potential seed nodes // for bootstrapping. func (db *nodeDB) querySeeds(n int, maxAge time.Duration) []*Node { diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go index d165d57138e9..30c992d2527f 100644 --- a/p2p/discv5/net.go +++ b/p2p/discv5/net.go @@ -36,7 +36,6 @@ import ( var ( errInvalidEvent = errors.New("invalid in current state") errNoQuery = errors.New("no pending query") - errWrongAddress = errors.New("unknown sender address") ) const ( @@ -78,14 +77,6 @@ type Network struct { nursery []*Node nodes map[NodeID]*Node // tracks active nodes with state != known timeoutTimers map[timeoutEvent]*time.Timer - - // Revalidation queues. - // Nodes put on these queues will be pinged eventually. - slowRevalidateQueue []*Node - fastRevalidateQueue []*Node - - // Buffers for state transition. - sendBuf []*ingressPacket } // transport is implemented by the UDP transport. diff --git a/p2p/discv5/net_test.go b/p2p/discv5/net_test.go index b1216f70a9ce..193fe671eb80 100644 --- a/p2p/discv5/net_test.go +++ b/p2p/discv5/net_test.go @@ -265,10 +265,6 @@ type preminedTestnet struct { net *Network } -func (tn *preminedTestnet) sendFindnode(to *Node, target NodeID) { - panic("sendFindnode called") -} - func (tn *preminedTestnet) sendFindnodeHash(to *Node, target common.Hash) { // current log distance is encoded in port number // fmt.Println("findnode query at dist", toaddr.Port) @@ -316,10 +312,6 @@ func (tn *preminedTestnet) sendNeighbours(to *Node, nodes []*Node) { panic("sendNeighbours called") } -func (tn *preminedTestnet) sendTopicQuery(to *Node, topic Topic) { - panic("sendTopicQuery called") -} - func (tn *preminedTestnet) sendTopicNodes(to *Node, queryHash common.Hash, nodes []*Node) { panic("sendTopicNodes called") } diff --git a/p2p/discv5/table_test.go b/p2p/discv5/table_test.go index 015b6bfd4134..0d9f5ff559db 100644 --- a/p2p/discv5/table_test.go +++ b/p2p/discv5/table_test.go @@ -34,8 +34,6 @@ import ( type nullTransport struct{} func (nullTransport) sendPing(remote *Node, remoteAddr *net.UDPAddr) []byte { return []byte{1} } -func (nullTransport) sendPong(remote *Node, pingHash []byte) {} -func (nullTransport) sendFindnode(remote *Node, target NodeID) {} func (nullTransport) sendNeighbours(remote *Node, nodes []*Node) {} func (nullTransport) localAddr() *net.UDPAddr { return new(net.UDPAddr) } func (nullTransport) Close() {} @@ -159,28 +157,6 @@ func nodeAtDistance(base common.Hash, ld int) (n *Node) { return n } -type pingRecorder struct{ responding, pinged map[NodeID]bool } - -func newPingRecorder() *pingRecorder { - return &pingRecorder{make(map[NodeID]bool), make(map[NodeID]bool)} -} - -func (t *pingRecorder) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node, error) { - panic("findnode called on pingRecorder") -} -func (t *pingRecorder) close() {} -func (t *pingRecorder) waitping(from NodeID) error { - return nil // remote always pings -} -func (t *pingRecorder) ping(toid NodeID, toaddr *net.UDPAddr) error { - t.pinged[toid] = true - if t.responding[toid] { - return nil - } else { - return errTimeout - } -} - func TestTable_closest(t *testing.T) { t.Parallel() diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go index 9dc9e557a21a..0766d5478e33 100644 --- a/p2p/discv5/udp.go +++ b/p2p/discv5/udp.go @@ -36,25 +36,16 @@ const Version = 4 // Errors var ( - errPacketTooSmall = errors.New("too small") - errBadPrefix = errors.New("bad prefix") - errExpired = errors.New("expired") - errUnsolicitedReply = errors.New("unsolicited reply") - errUnknownNode = errors.New("unknown node") - errTimeout = errors.New("RPC timeout") - errClockWarp = errors.New("reply deadline too far in the future") - errClosed = errors.New("socket closed") + errPacketTooSmall = errors.New("too small") + errBadPrefix = errors.New("bad prefix") + errTimeout = errors.New("RPC timeout") ) // Timeouts const ( - respTimeout = 500 * time.Millisecond - queryDelay = 1000 * time.Millisecond - expiration = 20 * time.Second - - ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP - ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning - driftThreshold = 10 * time.Second // Allowed clock drift before warning user + respTimeout = 500 * time.Millisecond + expiration = 20 * time.Second + driftThreshold = 10 * time.Second // Allowed clock drift before warning user ) // RPC request structures @@ -195,10 +186,6 @@ func makeEndpoint(addr *net.UDPAddr, tcpPort uint16) rpcEndpoint { return rpcEndpoint{IP: ip, UDP: uint16(addr.Port), TCP: tcpPort} } -func (e1 rpcEndpoint) equal(e2 rpcEndpoint) bool { - return e1.UDP == e2.UDP && e1.TCP == e2.TCP && e1.IP.Equal(e2.IP) -} - func nodeFromRPC(sender *net.UDPAddr, rn rpcNode) (*Node, error) { if err := netutil.CheckRelayIP(sender.IP, rn.IP); err != nil { return nil, err @@ -281,13 +268,6 @@ func (t *udp) sendPing(remote *Node, toaddr *net.UDPAddr, topics []Topic) (hash return hash } -func (t *udp) sendFindnode(remote *Node, target NodeID) { - t.sendPacket(remote.ID, remote.addr(), byte(findnodePacket), findnode{ - Target: target, - Expiration: uint64(time.Now().Add(expiration).Unix()), - }) -} - func (t *udp) sendNeighbours(remote *Node, results []*Node) { // Send neighbors in chunks with at most maxNeighbors per packet // to stay below the 1280 byte limit. diff --git a/p2p/enr/enr.go b/p2p/enr/enr.go index 940b1ca3ab01..53aaa53382b2 100644 --- a/p2p/enr/enr.go +++ b/p2p/enr/enr.go @@ -46,7 +46,6 @@ const ID_SECP256k1_KECCAK = ID("secp256k1-keccak") // the default identity schem var ( errNoID = errors.New("unknown or unspecified identity scheme") - errInvalidSigsize = errors.New("invalid signature size") errInvalidSig = errors.New("invalid signature") errNotSorted = errors.New("record key/value pairs are not sorted by key") errDuplicateKey = errors.New("record contains duplicate key") diff --git a/p2p/protocols/protocol_test.go b/p2p/protocols/protocol_test.go deleted file mode 100644 index 72d96f41ea25..000000000000 --- a/p2p/protocols/protocol_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2017 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package protocols - -import ( - "fmt" - - "github.com/XinFinOrg/XDPoSChain/p2p/discover" -) - -// handshake message type -type hs0 struct { - C uint -} - -// message to kill/drop the peer with nodeID -type kill struct { - C discover.NodeID -} - -// message to drop connection -type drop struct { -} - -// / protoHandshake represents module-independent aspects of the protocol and is -// the first message peers send and receive as part the initial exchange -type protoHandshake struct { - Version uint // local and remote peer should have identical version - NetworkID string // local and remote peer should have identical network id -} - -// checkProtoHandshake verifies local and remote protoHandshakes match -func checkProtoHandshake(testVersion uint, testNetworkID string) func(interface{}) error { - return func(rhs interface{}) error { - remote := rhs.(*protoHandshake) - if remote.NetworkID != testNetworkID { - return fmt.Errorf("%s (!= %s)", remote.NetworkID, testNetworkID) - } - - if remote.Version != testVersion { - return fmt.Errorf("%d (!= %d)", remote.Version, testVersion) - } - return nil - } -} diff --git a/p2p/rlpx.go b/p2p/rlpx.go index 3cfb62007bb9..fea1ce64de37 100644 --- a/p2p/rlpx.go +++ b/p2p/rlpx.go @@ -429,16 +429,6 @@ func (h *encHandshake) makeAuthResp() (msg *authRespV4, err error) { return msg, nil } -func (msg *authMsgV4) sealPlain(h *encHandshake) ([]byte, error) { - buf := make([]byte, authMsgLen) - n := copy(buf, msg.Signature[:]) - n += copy(buf[n:], crypto.Keccak256(exportPubkey(&h.randomPrivKey.PublicKey))) - n += copy(buf[n:], msg.InitiatorPubkey[:]) - n += copy(buf[n:], msg.Nonce[:]) - buf[n] = 0 // token-flag - return ecies.Encrypt(rand.Reader, h.remotePub, buf, nil, nil) -} - func (msg *authMsgV4) decodePlain(input []byte) { n := copy(msg.Signature[:], input) n += shaLen // skip sha3(initiator-ephemeral-pubk)