@@ -192,36 +192,36 @@ def verify_nodes_ports(self, src_path):
192
192
193
193
try :
194
194
port_mapping = {}
195
- new_port_start = 50001
196
- for filename in os . listdir ( scenario_path ):
197
- if filename . endswith ( ".json" ) and filename . startswith ( "participant" ):
198
- file_path = os .path . join (scenario_path , filename )
199
-
200
- with open ( file_path ) as json_file :
201
- node = json . load ( json_file )
202
-
203
- current_port = node [ "network_args" ][ "port" ]
204
- port_mapping [ current_port ] = SocketUtils . find_free_port ( start_port = new_port_start )
205
- new_port_start = port_mapping [ current_port ] + 1
206
-
207
- for filename in os . listdir ( scenario_path ):
208
- if filename . endswith ( ".json" ) and filename . startswith ( "participant" ):
209
- file_path = os . path . join ( scenario_path , filename )
210
-
211
- with open ( file_path ) as json_file :
212
- node = json . load ( json_file )
213
-
214
- current_port = node ["network_args" ]["port" ]
215
- node ["network_args" ]["port" ] = port_mapping [current_port ]
216
- neighbors = node ["network_args" ]["neighbors" ]
217
-
218
- for old_port , new_port in port_mapping .items ():
219
- neighbors = neighbors .replace (f":{ old_port } " , f":{ new_port } " )
220
-
221
- node ["network_args" ]["neighbors" ] = neighbors
222
-
223
- with open (file_path , "w" ) as f :
224
- json .dump (node , f , indent = 4 )
195
+ new_port_start = 50000
196
+
197
+ participant_files = sorted (
198
+ f for f in os .listdir (scenario_path ) if f . endswith ( ".json" ) and f . startswith ( "participant" )
199
+ )
200
+
201
+ for filename in participant_files :
202
+ file_path = os . path . join ( scenario_path , filename )
203
+ with open ( file_path ) as json_file :
204
+ node = json . load ( json_file )
205
+ current_port = node [ "network_args" ][ "port" ]
206
+ port_mapping [ current_port ] = SocketUtils . find_free_port ( start_port = new_port_start )
207
+ logging . info ( f"Participant file: { filename } | Current port: { current_port } | New port: { port_mapping [ current_port ] } " )
208
+ new_port_start = port_mapping [ current_port ] + 1
209
+
210
+ for filename in participant_files :
211
+ file_path = os . path . join ( scenario_path , filename )
212
+ with open ( file_path ) as json_file :
213
+ node = json . load ( json_file )
214
+ current_port = node ["network_args" ]["port" ]
215
+ node ["network_args" ]["port" ] = port_mapping [current_port ]
216
+ neighbors = node ["network_args" ]["neighbors" ]
217
+
218
+ for old_port , new_port in port_mapping .items ():
219
+ neighbors = neighbors .replace (f":{ old_port } " , f":{ new_port } " )
220
+
221
+ node ["network_args" ]["neighbors" ] = neighbors
222
+
223
+ with open (file_path , "w" ) as f :
224
+ json .dump (node , f , indent = 4 )
225
225
226
226
except Exception as e :
227
227
print (f"Error processing JSON files: { e } " )
0 commit comments