X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fgraph.c;fp=src%2Fgraph.c;h=5bec2c165762d121b0f47dc4ee68cb9341744b16;hp=5a7a16a77d52cd92a5305afde0c47209fbacfd9a;hb=7eeb29220a73ab9c5367f652873042f8a81c6cef;hpb=3990f75b2326a173a727bb2daf73a2c53567ffe0 diff --git a/src/graph.c b/src/graph.c index 5a7a16a7..5bec2c16 100644 --- a/src/graph.c +++ b/src/graph.c @@ -141,6 +141,7 @@ void sssp_bfs(void) { myself->prevedge = NULL; myself->via = myself; myself->distance = 0; + myself->weighted_distance = 0; list_insert_head(todo_list, myself); /* Loop while todo_list is filled */ @@ -178,14 +179,15 @@ void sssp_bfs(void) { if(e->to->status.visited && (!e->to->status.indirect || indirect) - && (e->to->distance != n->distance + 1 || e->weight >= e->to->prevedge->weight)) { + && (e->to->distance != n->distance + 1 || e->to->weighted_distance <= n->weighted_distance + e->weight)) { continue; } // Only update nexthop if it doesn't increase the path length - if(!e->to->status.visited || (e->to->distance == n->distance + 1 && e->weight < e->to->prevedge->weight)) { + if(!e->to->status.visited || (e->to->distance == n->distance + 1 && e->to->weighted_distance > n->weighted_distance + e->weight)) { e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop; + e->to->weighted_distance = n->weighted_distance + e->weight; } e->to->status.visited = true;