p2p, p2p/discover, p2p/discv5: implement UDP port sharing (#15200)
This commit affects p2p/discv5 "topic discovery" by running it on the same UDP port where the old discovery works. This is realized by giving an "unhandled" packet channel to the old v4 discovery packet handler where all invalid packets are sent. These packets are then processed by v5. v5 packets are always invalid when interpreted by v4 and vice versa. This is ensured by adding one to the first byte of the packet hash in v5 packets. DiscoveryV5Bootnodes is also changed to point to new bootnodes that are implementing the changed packet format with modified hash. Existing and new v5 bootnodes are both running on different ports ATM.
This commit is contained in:
		
				
					committed by
					
						 Felix Lange
						Felix Lange
					
				
			
			
				
	
			
			
			
						parent
						
							02aeb3d766
						
					
				
				
					commit
					92580d69d3
				
			| @@ -21,6 +21,7 @@ import ( | ||||
| 	"crypto/ecdsa" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/ethereum/go-ethereum/cmd/utils" | ||||
| @@ -96,12 +97,32 @@ func main() { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	addr, err := net.ResolveUDPAddr("udp", *listenAddr) | ||||
| 	if err != nil { | ||||
| 		utils.Fatalf("-ResolveUDPAddr: %v", err) | ||||
| 	} | ||||
| 	conn, err := net.ListenUDP("udp", addr) | ||||
| 	if err != nil { | ||||
| 		utils.Fatalf("-ListenUDP: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	realaddr := conn.LocalAddr().(*net.UDPAddr) | ||||
| 	if natm != nil { | ||||
| 		if !realaddr.IP.IsLoopback() { | ||||
| 			go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery") | ||||
| 		} | ||||
| 		// TODO: react to external IP changes over time. | ||||
| 		if ext, err := natm.ExternalIP(); err == nil { | ||||
| 			realaddr = &net.UDPAddr{IP: ext, Port: realaddr.Port} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if *runv5 { | ||||
| 		if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { | ||||
| 		if _, err := discv5.ListenUDP(nodeKey, conn, realaddr, "", restrictList); err != nil { | ||||
| 			utils.Fatalf("%v", err) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { | ||||
| 		if _, err := discover.ListenUDP(nodeKey, conn, realaddr, nil, "", restrictList); err != nil { | ||||
| 			utils.Fatalf("%v", err) | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user