File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ var (
119119 utils .CachePreimagesFlag ,
120120 utils .FDLimitFlag ,
121121 utils .ListenPortFlag ,
122+ utils .DiscoveryPortFlag ,
122123 utils .MaxPeersFlag ,
123124 utils .MaxPendingPeersFlag ,
124125 utils .MiningEnabledFlag ,
Original file line number Diff line number Diff line change @@ -835,6 +835,12 @@ var (
835835 Usage : "Sets DNS discovery entry points (use \" \" to disable DNS)" ,
836836 Category : flags .NetworkingCategory ,
837837 }
838+ DiscoveryPortFlag = & cli.IntFlag {
839+ Name : "discovery.port" ,
840+ Usage : "Use a custom UDP port for P2P discovery" ,
841+ Value : 30303 ,
842+ Category : flags .NetworkingCategory ,
843+ }
838844
839845 // Console
840846 JSpathFlag = & flags.DirectoryFlag {
@@ -1116,12 +1122,15 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
11161122 }
11171123}
11181124
1119- // setListenAddress creates a TCP listening address string from set command
1120- // line flags.
1125+ // setListenAddress creates TCP/UDP listening address strings from set command
1126+ // line flags
11211127func setListenAddress (ctx * cli.Context , cfg * p2p.Config ) {
11221128 if ctx .IsSet (ListenPortFlag .Name ) {
11231129 cfg .ListenAddr = fmt .Sprintf (":%d" , ctx .Int (ListenPortFlag .Name ))
11241130 }
1131+ if ctx .IsSet (DiscoveryPortFlag .Name ) {
1132+ cfg .DiscAddr = fmt .Sprintf (":%d" , ctx .Int (DiscoveryPortFlag .Name ))
1133+ }
11251134}
11261135
11271136// setNAT creates a port mapper from command line flags.
Original file line number Diff line number Diff line change @@ -136,6 +136,10 @@ type Config struct {
136136 // the server is started.
137137 ListenAddr string
138138
139+ // If DiscAddr is set to a non-nil value, the server will use ListenAddr
140+ // for TCP and DiscAddr for the UDP discovery protocol.
141+ DiscAddr string
142+
139143 // If set to a non-nil value, the given NAT port mapper
140144 // is used to make the listening port available to the
141145 // Internet.
@@ -549,7 +553,15 @@ func (srv *Server) setupDiscovery() error {
549553 return nil
550554 }
551555
552- addr , err := net .ResolveUDPAddr ("udp" , srv .ListenAddr )
556+ listenAddr := srv .ListenAddr
557+
558+ // Use an alternate listening address for UDP if
559+ // a custom discovery address is configured.
560+ if srv .DiscAddr != "" {
561+ listenAddr = srv .DiscAddr
562+ }
563+
564+ addr , err := net .ResolveUDPAddr ("udp" , listenAddr )
553565 if err != nil {
554566 return err
555567 }
You can’t perform that action at this time.
0 commit comments