Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appnet: filter duplicate paths in QueryPaths #161

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/appnet/path_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,41 @@ func QueryPaths(ia addr.IA) ([]snet.Path, error) {
if err != nil || len(paths) == 0 {
return nil, err
}
paths = filterDuplicates(paths)
return paths, nil
}
}

// filterDuplicates filters 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.
func filterDuplicates(paths []snet.Path) []snet.Path {

set := make(map[snet.PathFingerprint]int)
for i := range paths {
fingerprint := paths[i].Fingerprint() // Fingerprint is a hash of p.Interfaces()
e, dupe := set[fingerprint]
if !dupe || paths[e].Expiry().Before(paths[i].Expiry()) {
set[fingerprint] = i
}
}

// filter, keep paths in input order:
kept := make(map[int]struct{})
for _, p := range set {
kept[p] = struct{}{}
}
filtered := make([]snet.Path, 0, len(set))
for i := range paths {
if _, ok := kept[i]; ok {
filtered = append(filtered, paths[i])
}
}
return filtered
}

func pathSelection(paths []snet.Path, pathAlgo int) snet.Path {
var selectedPath snet.Path
var metric float64
Expand Down