Skip to content

Commit

Permalink
set route if no current or chosen
Browse files Browse the repository at this point in the history
  • Loading branch information
mlsmaycon committed Jun 1, 2023
1 parent 3f8133a commit 74072f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/internal/routemanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro
tempScore++
}

if tempScore > chosenScore || (tempScore == chosenScore && r.ID > currID) {
if tempScore > chosenScore || (tempScore == chosenScore && r.ID == currID) {
chosen = r.ID
chosenScore = tempScore
}

if chosen == "" && currID == "" {
chosen = r.ID
chosenScore = tempScore
}
Expand Down
19 changes: 19 additions & 0 deletions client/internal/routemanager/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ func TestGetBestrouteFromStatuses(t *testing.T) {
currentRoute: nil,
expectedRouteID: "route1",
},
{
name: "one connected routes with relayed and no direct",
statuses: map[string]routerPeerStatus{
"route1": {
connected: true,
relayed: true,
direct: false,
},
},
existingRoutes: map[string]*route.Route{
"route1": {
ID: "route1",
Metric: route.MaxMetric,
Peer: "peer1",
},
},
currentRoute: nil,
expectedRouteID: "route1",
},
{
name: "no connected peers",
statuses: map[string]routerPeerStatus{
Expand Down

0 comments on commit 74072f6

Please sign in to comment.