p2p/discover: add node URL functions, distinguish TCP/UDP ports

The discovery RPC protocol does not yet distinguish TCP and UDP ports.
But it can't hurt to do so in our internal model.
This commit is contained in:
Felix Lange
2015-02-06 14:40:53 +01:00
parent 56f777b2fc
commit 8564eb9f7e
8 changed files with 532 additions and 326 deletions

View File

@ -136,7 +136,7 @@ func (srv *Server) PeerCount() int {
// SuggestPeer creates a connection to the given Node if it
// is not already connected.
func (srv *Server) SuggestPeer(ip net.IP, port int, id discover.NodeID) {
srv.peerConnect <- &discover.Node{ID: id, Addr: &net.UDPAddr{IP: ip, Port: port}}
srv.peerConnect <- &discover.Node{ID: id, IP: ip, TCPPort: port}
}
// Broadcast sends an RLP-encoded message to all connected peers.
@ -364,8 +364,9 @@ func (srv *Server) dialLoop() {
}
func (srv *Server) dialNode(dest *discover.Node) {
srvlog.Debugf("Dialing %v\n", dest.Addr)
conn, err := srv.Dialer.Dial("tcp", dest.Addr.String())
addr := &net.TCPAddr{IP: dest.IP, Port: dest.TCPPort}
srvlog.Debugf("Dialing %v\n", dest)
conn, err := srv.Dialer.Dial("tcp", addr.String())
if err != nil {
srvlog.DebugDetailf("dial error: %v", err)
return