From 476f369638d91983e321b5c85dae079ffe4e785f Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Thu, 1 Jun 2023 09:54:54 +0200 Subject: [PATCH] increase score if peer status is direct set chosen vars if chosen and currID are empty updated log message --- client/internal/routemanager/client.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client/internal/routemanager/client.go b/client/internal/routemanager/client.go index 7ef2d6d4e..62937056e 100644 --- a/client/internal/routemanager/client.go +++ b/client/internal/routemanager/client.go @@ -71,7 +71,7 @@ func (c *clientNetwork) getRouterPeerStatuses() map[string]routerPeerStatus { } func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]routerPeerStatus) string { - var chosen string + chosen := "" chosenScore := 0 currID := "" @@ -85,17 +85,27 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro if !found || !peerStatus.connected { continue } + + if chosen == "" && currID == "" { + chosen = r.ID + chosenScore = 0 + continue + } + if r.Metric < route.MaxMetric { metricDiff := route.MaxMetric - r.Metric tempScore = metricDiff * 10 } + if !peerStatus.relayed { tempScore++ } - if !peerStatus.direct { + + if peerStatus.direct { tempScore++ } - if tempScore > chosenScore || (tempScore == chosenScore && currID == r.ID) { + + if tempScore > chosenScore { chosen = r.ID chosenScore = tempScore } @@ -106,7 +116,9 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro for _, r := range c.routes { peers = append(peers, r.Peer) } - log.Warnf("no route was chosen for network %s because no peers from list %s were connected", c.network, peers) + + log.Warnf("the network %s has not been assigned a routing peer as no peers from the list %s are currently connected", c.network, peers) + } else if chosen != currID { log.Infof("new chosen route is %s with peer %s with score %d", chosen, c.routes[chosen].Peer, chosenScore) }