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 (
119
119
utils .CachePreimagesFlag ,
120
120
utils .FDLimitFlag ,
121
121
utils .ListenPortFlag ,
122
+ utils .DiscoveryPortFlag ,
122
123
utils .MaxPeersFlag ,
123
124
utils .MaxPendingPeersFlag ,
124
125
utils .MiningEnabledFlag ,
Original file line number Diff line number Diff line change @@ -835,6 +835,12 @@ var (
835
835
Usage : "Sets DNS discovery entry points (use \" \" to disable DNS)" ,
836
836
Category : flags .NetworkingCategory ,
837
837
}
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
+ }
838
844
839
845
// Console
840
846
JSpathFlag = & flags.DirectoryFlag {
@@ -1116,12 +1122,15 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
1116
1122
}
1117
1123
}
1118
1124
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
1121
1127
func setListenAddress (ctx * cli.Context , cfg * p2p.Config ) {
1122
1128
if ctx .IsSet (ListenPortFlag .Name ) {
1123
1129
cfg .ListenAddr = fmt .Sprintf (":%d" , ctx .Int (ListenPortFlag .Name ))
1124
1130
}
1131
+ if ctx .IsSet (DiscoveryPortFlag .Name ) {
1132
+ cfg .DiscAddr = fmt .Sprintf (":%d" , ctx .Int (DiscoveryPortFlag .Name ))
1133
+ }
1125
1134
}
1126
1135
1127
1136
// 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 {
136
136
// the server is started.
137
137
ListenAddr string
138
138
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
+
139
143
// If set to a non-nil value, the given NAT port mapper
140
144
// is used to make the listening port available to the
141
145
// Internet.
@@ -549,7 +553,15 @@ func (srv *Server) setupDiscovery() error {
549
553
return nil
550
554
}
551
555
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 )
553
565
if err != nil {
554
566
return err
555
567
}
You can’t perform that action at this time.
0 commit comments