File tree 1 file changed +30
-1
lines changed
1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
1
package config
2
2
3
- import "time"
3
+ import (
4
+ "fmt"
5
+ "net"
6
+ "time"
7
+ )
4
8
5
9
// Transformer is a function which takes configuration and applies some filter to it
6
10
type Transformer func (c * Config ) error
@@ -160,6 +164,31 @@ fetching may be degraded.
160
164
return nil
161
165
},
162
166
},
167
+ "randomports" : {
168
+ Description : `Use a random port number for swarm.` ,
169
+
170
+ Transform : func (c * Config ) error {
171
+ port , err := getAvailablePort ()
172
+ if err != nil {
173
+ return err
174
+ }
175
+ c .Addresses .Swarm = []string {
176
+ fmt .Sprintf ("/ip4/0.0.0.0/tcp/%d" , port ),
177
+ fmt .Sprintf ("/ip6/::/tcp/%d" , port ),
178
+ }
179
+ return nil
180
+ },
181
+ },
182
+ }
183
+
184
+ func getAvailablePort () (port int , err error ) {
185
+ ln , err := net .Listen ("tcp" , "[::]:0" )
186
+ if err != nil {
187
+ return 0 , err
188
+ }
189
+ defer ln .Close ()
190
+ port = ln .Addr ().(* net.TCPAddr ).Port
191
+ return port , nil
163
192
}
164
193
165
194
func appendSingle (a []string , b []string ) []string {
You can’t perform that action at this time.
0 commit comments