|
30 | 30 | * @author Gianlu |
31 | 31 | */ |
32 | 32 | public class ZeroconfServer implements Closeable { |
33 | | - private final static int MAX_PORT = 65536; |
34 | | - private final static int MIN_PORT = 1024; |
| 33 | + public final static int MAX_PORT = 65536; |
| 34 | + public final static int MIN_PORT = 1024; |
35 | 35 | private static final Logger LOGGER = Logger.getLogger(ZeroconfServer.class); |
36 | 36 | private static final byte[] EOL = new byte[]{'\r', '\n'}; |
37 | 37 | private static final JsonObject DEFAULT_GET_INFO_FIELDS = new JsonObject(); |
@@ -77,14 +77,17 @@ public class ZeroconfServer implements Closeable { |
77 | 77 | private final HttpRunner runner; |
78 | 78 | private final Session.Inner inner; |
79 | 79 | private final DiffieHellman keys; |
80 | | - private Session session; |
81 | 80 | private final JmDNS[] instances; |
| 81 | + private Session session; |
82 | 82 |
|
83 | 83 | private ZeroconfServer(Session.Inner inner, Configuration conf) throws IOException { |
84 | 84 | this.inner = inner; |
85 | 85 | this.keys = new DiffieHellman(inner.random); |
86 | 86 |
|
87 | | - int port = inner.random.nextInt((MAX_PORT - MIN_PORT) + 1) + MIN_PORT; |
| 87 | + int port = conf.zeroconfListenPort(); |
| 88 | + if (port == -1) |
| 89 | + port = inner.random.nextInt((MAX_PORT - MIN_PORT) + 1) + MIN_PORT; |
| 90 | + |
88 | 91 | new Thread(this.runner = new HttpRunner(port), "zeroconf-http-server").start(); |
89 | 92 |
|
90 | 93 | InetAddress[] bound; |
@@ -300,6 +303,8 @@ private void handleAddUser(OutputStream out, Map<String, String> params, String |
300 | 303 | public interface Configuration { |
301 | 304 | boolean zeroconfListenAll(); |
302 | 305 |
|
| 306 | + int zeroconfListenPort(); |
| 307 | + |
303 | 308 | @NotNull |
304 | 309 | String[] zeroconfInterfaces(); |
305 | 310 | } |
|
0 commit comments