increase score if peer status is direct

set chosen vars if chosen and currID are empty

updated log message
This commit is contained in:
Maycon Santos
2023-06-01 09:54:54 +02:00
parent 2f6636b6e4
commit 476f369638

View File

@@ -71,7 +71,7 @@ func (c *clientNetwork) getRouterPeerStatuses() map[string]routerPeerStatus {
} }
func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]routerPeerStatus) string { func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]routerPeerStatus) string {
var chosen string chosen := ""
chosenScore := 0 chosenScore := 0
currID := "" currID := ""
@@ -85,17 +85,27 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro
if !found || !peerStatus.connected { if !found || !peerStatus.connected {
continue continue
} }
if chosen == "" && currID == "" {
chosen = r.ID
chosenScore = 0
continue
}
if r.Metric < route.MaxMetric { if r.Metric < route.MaxMetric {
metricDiff := route.MaxMetric - r.Metric metricDiff := route.MaxMetric - r.Metric
tempScore = metricDiff * 10 tempScore = metricDiff * 10
} }
if !peerStatus.relayed { if !peerStatus.relayed {
tempScore++ tempScore++
} }
if !peerStatus.direct {
if peerStatus.direct {
tempScore++ tempScore++
} }
if tempScore > chosenScore || (tempScore == chosenScore && currID == r.ID) {
if tempScore > chosenScore {
chosen = r.ID chosen = r.ID
chosenScore = tempScore chosenScore = tempScore
} }
@@ -106,7 +116,9 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro
for _, r := range c.routes { for _, r := range c.routes {
peers = append(peers, r.Peer) 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 { } else if chosen != currID {
log.Infof("new chosen route is %s with peer %s with score %d", chosen, c.routes[chosen].Peer, chosenScore) log.Infof("new chosen route is %s with peer %s with score %d", chosen, c.routes[chosen].Peer, chosenScore)
} }