@@ -51,41 +51,40 @@ async def is_running(self):
51
51
52
52
async def _change_network_conditions_based_on_distances (self , gpsevent : GPSEvent ):
53
53
distances = await gpsevent .get_event_data ()
54
- while await self .is_running ():
55
- if self ._verbose :
56
- logging .info ("Refresh | conditions based on distances..." )
57
- try :
58
- for addr , (distance , _ ) in distances .items ():
59
- if distance is None :
60
- # If the distance is not found, we skip the node
61
- continue
62
- conditions = await self ._calculate_network_conditions (distance )
63
- # Only update the network conditions if they have changed
64
- if (
65
- addr not in self ._current_network_conditions
66
- or self ._current_network_conditions [addr ] != conditions
67
- ):
68
- addr_ip = addr .split (":" )[0 ]
69
- self ._set_network_condition_for_addr (
70
- self ._node_interface , addr_ip , conditions ["bandwidth" ], conditions ["delay" ]
71
- )
72
- self ._set_network_condition_for_multicast (
73
- self ._node_interface ,
74
- addr_ip ,
75
- self .IP_MULTICAST ,
76
- conditions ["bandwidth" ],
77
- conditions ["delay" ],
78
- )
79
- async with self ._network_conditions_lock :
80
- self ._current_network_conditions [addr ] = conditions
81
- else :
82
- if self ._verbose :
83
- logging .info ("network conditions havent changed since last time" )
84
- except KeyError :
85
- logging .exception (f"📍 Connection { addr } not found" )
86
- except Exception :
87
- logging .exception ("📍 Error changing connections based on distance" )
88
- await asyncio .sleep (self ._refresh_interval )
54
+ if self ._verbose :
55
+ logging .info ("Refresh | conditions based on distances..." )
56
+ try :
57
+ for addr , (distance , _ ) in distances .items ():
58
+ if distance is None :
59
+ # If the distance is not found, we skip the node
60
+ continue
61
+ conditions = await self ._calculate_network_conditions (distance )
62
+ # Only update the network conditions if they have changed
63
+ if (
64
+ addr not in self ._current_network_conditions
65
+ or self ._current_network_conditions [addr ] != conditions
66
+ ):
67
+ addr_ip = addr .split (":" )[0 ]
68
+ self ._set_network_condition_for_addr (
69
+ self ._node_interface , addr_ip , conditions ["bandwidth" ], conditions ["delay" ]
70
+ )
71
+ self ._set_network_condition_for_multicast (
72
+ self ._node_interface ,
73
+ addr_ip ,
74
+ self .IP_MULTICAST ,
75
+ conditions ["bandwidth" ],
76
+ conditions ["delay" ],
77
+ )
78
+ async with self ._network_conditions_lock :
79
+ self ._current_network_conditions [addr ] = conditions
80
+ else :
81
+ if self ._verbose :
82
+ logging .info ("network conditions havent changed since last time" )
83
+ except KeyError :
84
+ logging .exception (f"📍 Connection { addr } not found" )
85
+ except Exception :
86
+ logging .exception ("📍 Error changing connections based on distance" )
87
+ await asyncio .sleep (self ._refresh_interval )
89
88
90
89
async def set_thresholds (self , thresholds : dict ):
91
90
async with self ._network_conditions_lock :
0 commit comments