Skip to content

Commit 6f9416b

Browse files
authored
appnet: filter duplicate paths in QueryPaths (#161)
Filter paths with identical sequence of interfaces. These duplicates occur because sciond may return the same "effective" path with different short-cut "upstream" parts. We don't need these duplicates, they are identical for our purposes; we simply pick the one with latest expiry. See also discussion in scionproto/scion#2445 (currently not merged).
1 parent af13021 commit 6f9416b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/appnet/path_selection.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,41 @@ func QueryPaths(ia addr.IA) ([]snet.Path, error) {
112112
if err != nil || len(paths) == 0 {
113113
return nil, err
114114
}
115+
paths = filterDuplicates(paths)
115116
return paths, nil
116117
}
117118
}
118119

120+
// filterDuplicates filters paths with identical sequence of interfaces.
121+
// These duplicates occur because sciond may return the same "effective" path with
122+
// different short-cut "upstream" parts.
123+
// We don't need these duplicates, they are identical for our purposes; we simply pick
124+
// the one with latest expiry.
125+
func filterDuplicates(paths []snet.Path) []snet.Path {
126+
127+
chosenPath := make(map[snet.PathFingerprint]int)
128+
for i := range paths {
129+
fingerprint := paths[i].Fingerprint() // Fingerprint is a hash of p.Interfaces()
130+
e, dupe := chosenPath[fingerprint]
131+
if !dupe || paths[e].Expiry().Before(paths[i].Expiry()) {
132+
chosenPath[fingerprint] = i
133+
}
134+
}
135+
136+
// filter, keep paths in input order:
137+
kept := make(map[int]struct{})
138+
for _, p := range chosenPath {
139+
kept[p] = struct{}{}
140+
}
141+
filtered := make([]snet.Path, 0, len(kept))
142+
for i := range paths {
143+
if _, ok := kept[i]; ok {
144+
filtered = append(filtered, paths[i])
145+
}
146+
}
147+
return filtered
148+
}
149+
119150
func pathSelection(paths []snet.Path, pathAlgo int) snet.Path {
120151
var selectedPath snet.Path
121152
var metric float64

0 commit comments

Comments
 (0)