aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-15 14:38:41 +0800
committerzelig <viktor.tron@gmail.com>2015-03-15 14:38:41 +0800
commite1508327342135fc43676f3778db70814ef82569 (patch)
tree1bee7fe4701ba68795a6fa74bc2bc45a4d0a8040
parent7279a485c24de3f0aaf839e1884151322a97dbf7 (diff)
downloaddexon-e1508327342135fc43676f3778db70814ef82569.tar.gz
dexon-e1508327342135fc43676f3778db70814ef82569.tar.zst
dexon-e1508327342135fc43676f3778db70814ef82569.zip
p2p: server>discover table Self=Node exported
-rw-r--r--p2p/discover/table.go6
-rw-r--r--p2p/server.go14
2 files changed, 12 insertions, 8 deletions
diff --git a/p2p/discover/table.go b/p2p/discover/table.go
index e3bec9328..33b705a12 100644
--- a/p2p/discover/table.go
+++ b/p2p/discover/table.go
@@ -51,9 +51,9 @@ func newTable(t transport, ourID NodeID, ourAddr *net.UDPAddr) *Table {
return tab
}
-// Self returns the local node ID.
-func (tab *Table) Self() NodeID {
- return tab.self.ID
+// Self returns the local node.
+func (tab *Table) Self() *Node {
+ return tab.self
}
// Close terminates the network listener.
diff --git a/p2p/server.go b/p2p/server.go
index 9762fcc6d..4d1437d80 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -180,7 +180,7 @@ func (srv *Server) Start() (err error) {
srv.ntab = ntab
// handshake
- srv.ourHandshake = &protoHandshake{Version: baseProtocolVersion, Name: srv.Name, ID: ntab.Self()}
+ srv.ourHandshake = &protoHandshake{Version: baseProtocolVersion, Name: srv.Name, ID: ntab.Self().ID}
for _, p := range srv.Protocols {
srv.ourHandshake.Caps = append(srv.ourHandshake.Caps, p.cap())
}
@@ -298,7 +298,7 @@ func (srv *Server) dialLoop() {
srv.lock.Lock()
_, isconnected := srv.peers[dest.ID]
srv.lock.Unlock()
- if isconnected || dialing[dest.ID] || dest.ID == srv.ntab.Self() {
+ if isconnected || dialing[dest.ID] || dest.ID == srv.Self().ID {
continue
}
@@ -332,12 +332,16 @@ func (srv *Server) dialNode(dest *discover.Node) {
srv.startPeer(conn, dest)
}
+func (srv *Server) Self() *discover.Node {
+ return srv.ntab.Self()
+}
+
func (srv *Server) findPeers() {
- far := srv.ntab.Self()
+ far := srv.Self().ID
for i := range far {
far[i] = ^far[i]
}
- closeToSelf := srv.ntab.Lookup(srv.ntab.Self())
+ closeToSelf := srv.ntab.Lookup(srv.Self().ID)
farFromSelf := srv.ntab.Lookup(far)
for i := 0; i < len(closeToSelf) || i < len(farFromSelf); i++ {
@@ -402,7 +406,7 @@ func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {
return false, DiscTooManyPeers
case srv.peers[id] != nil:
return false, DiscAlreadyConnected
- case id == srv.ntab.Self():
+ case id == srv.Self().ID:
return false, DiscSelf
}
srv.peers[id] = p