aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-04-22 16:59:15 +0800
committerFelix Lange <fjl@twurst.com>2015-04-22 18:31:19 +0800
commit635b66acdccc1e9b3793c67a846675dfbb08b6f8 (patch)
tree383b8f3e8ebea656e8e8d5b4d3c0cfcef3727acc
parent96e2b6bc0749cde5ad76c51fba55c31f941512b6 (diff)
downloaddexon-635b66acdccc1e9b3793c67a846675dfbb08b6f8.tar.gz
dexon-635b66acdccc1e9b3793c67a846675dfbb08b6f8.tar.zst
dexon-635b66acdccc1e9b3793c67a846675dfbb08b6f8.zip
p2p: return zero node from Self if the server is not running
This helps with fixing the tests for cmd/geth to run without networking.
-rw-r--r--p2p/server.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/p2p/server.go b/p2p/server.go
index b5c4a1f59..ecf418d13 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -283,6 +283,11 @@ func (srv *Server) Stop() {
// Self returns the local node's endpoint information.
func (srv *Server) Self() *discover.Node {
+ srv.lock.RLock()
+ defer srv.lock.RUnlock()
+ if !srv.running {
+ return &discover.Node{IP: net.ParseIP("0.0.0.0")}
+ }
return srv.ntab.Self()
}
@@ -471,7 +476,7 @@ func (srv *Server) checkPeer(id discover.NodeID) (bool, DiscReason) {
return false, DiscTooManyPeers
case srv.peers[id] != nil:
return false, DiscAlreadyConnected
- case id == srv.Self().ID:
+ case id == srv.ntab.Self().ID:
return false, DiscSelf
default:
return true, 0