Ver Fonte

Bugfix: det_id_roles_and_msgs

The method assumed, that in the chosen communication interval, for every reply there was a request before. This is correct most of the time, but not always and can result in an error.
Now: In the above scenario, replies without requests will be skipped, resulting in the same behavior we could observe when ID2T was called without an error (in terms of output)
Marcel Juschak há 6 anos atrás
pai
commit
d9bc745674
1 ficheiros alterados com 5 adições e 1 exclusões
  1. 5 1
      code/ID2TLib/CommunicationProcessor.py

+ 5 - 1
code/ID2TLib/CommunicationProcessor.py

@@ -125,6 +125,9 @@ class CommunicationProcessor():
         msgs, msg_id = [], 0
         # keep track of previous request to find connections
         prev_reqs = {}
+        # used to determine whether a request has been seen yet, so that replies before the first request are skipped and do not throw an error by
+        # accessing the empty dict prev_reqs (this is not a perfect solution, but it works most of the time)
+        req_seen = False
         local_init_ids = self.local_init_ids
         external_init_ids = set()
 
@@ -154,9 +157,10 @@ class CommunicationProcessor():
                 msgs.append(msg)
                 prev_reqs[msg_str] = msg_id
                 msg_id += 1
+                req_seen = True
 
             # process a reply
-            elif msg_type in {MessageType.SALITY_HELLO_REPLY, MessageType.SALITY_NL_REPLY}:
+            elif msg_type in {MessageType.SALITY_HELLO_REPLY, MessageType.SALITY_NL_REPLY} and req_seen:
                 if not self.nat and id_src in local_init_ids and id_dst not in local_init_ids:
                     # process ID's role
                     external_init_ids.add(id_dst)