Commit 7fb80b9
authored
feat: prune old, inactive paths (#3666)
## Description
Whenever we insert a new path, trigger pruning paths.
We currently only prune IP paths, and pruning paths only occurs if we
have more than 30 IP paths.
We will prune any paths that did not successfully holepunch.
If there are still over 30 IP paths left, then we order the "inactive"
paths (paths that have been closed, but at one point holepunched), and
prune the paths that were closed earliest.
## Notes and Questions
- Added constants:
- `MAX_IP_PATHS` = 30 - maximum IP paths per endpoint
- `MAX_INACTIVE_IP_PATHS` = 10 - maximum inactive IP paths to keep
- New `PathState` field:
- `status` - tracks the `PathStatus` of the path
- New `PathStatus` enum:
- `PathStatus::Open` - is an open path
- `PathStatus::Inactive(Instant)` - was opened once, but currently inactive
- `PathStatus::Unusable` - we attempted to use it, but it never connected
- `PathStatus::Unknown` - we don't know the status yet
- New methods on `RemotePathState`:
- `abandoned_path` - marks a path as abandoned with timestamp, triggered when we get the `PathEvent::Abandoned` event
- `prune_paths` - triggers path pruning, occurs whenever we insert a path to the `RemotePathState`
- changed `insert` to `insert_open_path`
- New `prune_ip_paths` function with all the prune logic:
- Only prunes if IP paths exceed `MAX_IP_PATHS`
- Never prunes active paths or paths of unknown status
- Always prunes failed holepunch attempts (PathStatus::Unusable)
- Keeps 10 most recently inactive paths that were previously successful
- Special case: if all paths failed, keeps `MAX_IP_PATHS` instead of pruning everything
- Added tests for edge cases and the typical case1 parent 51ba699 commit 7fb80b9
File tree
3 files changed
+448
-32
lines changed- iroh/src/magicsock
- remote_map
- remote_state
3 files changed
+448
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 188 | | |
194 | 189 | | |
195 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 53 | | |
64 | 54 | | |
65 | 55 | | |
| |||
461 | 451 | | |
462 | 452 | | |
463 | 453 | | |
464 | | - | |
| 454 | + | |
465 | 455 | | |
466 | 456 | | |
467 | 457 | | |
| |||
779 | 769 | | |
780 | 770 | | |
781 | 771 | | |
782 | | - | |
| 772 | + | |
783 | 773 | | |
784 | 774 | | |
785 | 775 | | |
786 | 776 | | |
787 | 777 | | |
788 | 778 | | |
789 | 779 | | |
790 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
791 | 783 | | |
792 | 784 | | |
793 | 785 | | |
| |||
1073 | 1065 | | |
1074 | 1066 | | |
1075 | 1067 | | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1079 | 1072 | | |
1080 | 1073 | | |
| 1074 | + | |
1081 | 1075 | | |
1082 | 1076 | | |
1083 | 1077 | | |
| |||
0 commit comments