diff --git a/client/internal/routemanager/client.go b/client/internal/routemanager/client.go index 93174be93..cf4cbe91b 100644 --- a/client/internal/routemanager/client.go +++ b/client/internal/routemanager/client.go @@ -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 } diff --git a/client/internal/routemanager/client_test.go b/client/internal/routemanager/client_test.go index b6659c870..3700d72ec 100644 --- a/client/internal/routemanager/client_test.go +++ b/client/internal/routemanager/client_test.go @@ -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{