aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/netutil
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2019-06-11 18:45:33 +0800
committerGitHub <noreply@github.com>2019-06-11 18:45:33 +0800
commitc420dcb39c342842f6c115376774c79162465c64 (patch)
tree5eeedb21d108132a16513bdd7bac5916b8124b7a /p2p/netutil
parentc0a034ec899655e6014a2c84f73e0c625bbd87d0 (diff)
downloadgo-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar.gz
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar.bz2
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar.lz
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar.xz
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.tar.zst
go-tangerine-c420dcb39c342842f6c115376774c79162465c64.zip
p2p: enforce connection retry limit on server side (#19684)
The dialer limits itself to one attempt every 30s. Apply the same limit in Server and reject peers which try to connect too eagerly. The check against the limit happens right after accepting the connection. Further changes in this commit ensure we pass the Server logger down to Peer instances, discovery and dialState. Unit test logging now works in all Server tests.
Diffstat (limited to 'p2p/netutil')
-rw-r--r--p2p/netutil/addrutil.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/p2p/netutil/addrutil.go b/p2p/netutil/addrutil.go
new file mode 100644
index 000000000..b261a5295
--- /dev/null
+++ b/p2p/netutil/addrutil.go
@@ -0,0 +1,33 @@
+// Copyright 2016 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 <http://www.gnu.org/licenses/>.
+
+package netutil
+
+import "net"
+
+// AddrIP gets the IP address contained in addr. It returns nil if no address is present.
+func AddrIP(addr net.Addr) net.IP {
+ switch a := addr.(type) {
+ case *net.IPAddr:
+ return a.IP
+ case *net.TCPAddr:
+ return a.IP
+ case *net.UDPAddr:
+ return a.IP
+ default:
+ return nil
+ }
+}