Commit 37defe0
committed
Allow binding to port 0 for OS-assigned ports
Add support for configuring listening addresses with port 0, letting
the OS pick a free port. After binding, the actual port is resolved
via local_addr() and stored in two new fields on Node:
- active_listening_addresses: set on start(), cleared on stop()
- last_bound_addresses: set on start(), preserved across restarts
so the node rebinds the same ports (important for peer reconnection
with persisted addresses)
The listening_addresses() and announcement_addresses() getters return
the active addresses when running, last bound when stopped, and fall
back to configured addresses if the node was never started. The gossip
broadcast task also prefers active addresses over config.
This eliminates the need for the deterministic port picker in tests,
which was fragile due to potential port collisions. Tests now use
127.0.0.1:0 and query the actual port after start().
AI tools were used in preparing this commit.1 parent 3aef2b3 commit 37defe0
File tree
4 files changed
+71
-26
lines changed- src
- tests
- common
4 files changed
+71
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1988 | 1988 | | |
1989 | 1989 | | |
1990 | 1990 | | |
| 1991 | + | |
| 1992 | + | |
1991 | 1993 | | |
1992 | 1994 | | |
1993 | 1995 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
237 | 242 | | |
238 | 243 | | |
239 | 244 | | |
| |||
356 | 361 | | |
357 | 362 | | |
358 | 363 | | |
359 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
360 | 372 | | |
361 | 373 | | |
362 | 374 | | |
| |||
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
406 | 448 | | |
407 | 449 | | |
408 | 450 | | |
| |||
478 | 520 | | |
479 | 521 | | |
480 | 522 | | |
| 523 | + | |
481 | 524 | | |
482 | 525 | | |
483 | 526 | | |
| |||
525 | 568 | | |
526 | 569 | | |
527 | 570 | | |
| 571 | + | |
| 572 | + | |
528 | 573 | | |
529 | 574 | | |
530 | 575 | | |
| |||
740 | 785 | | |
741 | 786 | | |
742 | 787 | | |
| 788 | + | |
743 | 789 | | |
744 | 790 | | |
745 | 791 | | |
| |||
842 | 888 | | |
843 | 889 | | |
844 | 890 | | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
845 | 895 | | |
846 | | - | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
847 | 902 | | |
848 | 903 | | |
849 | 904 | | |
850 | 905 | | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
| 906 | + | |
855 | 907 | | |
856 | 908 | | |
857 | 909 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
269 | 268 | | |
270 | 269 | | |
271 | 270 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | 271 | | |
283 | 272 | | |
284 | 273 | | |
| |||
302 | 291 | | |
303 | 292 | | |
304 | 293 | | |
305 | | - | |
| 294 | + | |
306 | 295 | | |
307 | 296 | | |
308 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
1431 | 1432 | | |
1432 | 1433 | | |
1433 | 1434 | | |
1434 | | - | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
1435 | 1439 | | |
1436 | | - | |
1437 | 1440 | | |
1438 | 1441 | | |
1439 | 1442 | | |
| |||
1443 | 1446 | | |
1444 | 1447 | | |
1445 | 1448 | | |
1446 | | - | |
1447 | 1449 | | |
1448 | | - | |
1449 | 1450 | | |
1450 | 1451 | | |
1451 | 1452 | | |
| |||
1505 | 1506 | | |
1506 | 1507 | | |
1507 | 1508 | | |
| 1509 | + | |
1508 | 1510 | | |
1509 | 1511 | | |
1510 | 1512 | | |
| |||
0 commit comments