Improved announce queue processing
This commit is contained in:
		
							parent
							
								
									e95e9e6a89
								
							
						
					
					
						commit
						1b50f5267a
					
				| @ -592,7 +592,6 @@ class Transport: | |||||||
|                                             interface.announce_queue = [] |                                             interface.announce_queue = [] | ||||||
| 
 | 
 | ||||||
|                                     queued_announces = True if len(interface.announce_queue) > 0 else False |                                     queued_announces = True if len(interface.announce_queue) > 0 else False | ||||||
| 
 |  | ||||||
|                                     if not queued_announces and outbound_time > interface.announce_allowed_at: |                                     if not queued_announces and outbound_time > interface.announce_allowed_at: | ||||||
|                                         tx_time   = (len(packet.raw)*8) / interface.bitrate |                                         tx_time   = (len(packet.raw)*8) / interface.bitrate | ||||||
|                                         wait_time = (tx_time / interface.announce_cap) |                                         wait_time = (tx_time / interface.announce_cap) | ||||||
| @ -605,7 +604,33 @@ class Transport: | |||||||
|                                     else: |                                     else: | ||||||
|                                         should_transmit = False |                                         should_transmit = False | ||||||
|                                         if not len(interface.announce_queue) >= RNS.Reticulum.MAX_QUEUED_ANNOUNCES: |                                         if not len(interface.announce_queue) >= RNS.Reticulum.MAX_QUEUED_ANNOUNCES: | ||||||
|                                             entry = {"time": outbound_time, "hops": packet.hops, "raw": packet.raw} |                                             should_queue = True | ||||||
|  | 
 | ||||||
|  |                                             already_queued = False | ||||||
|  |                                             for e in interface.announce_queue: | ||||||
|  |                                                 if e["destination"] == packet.destination_hash: | ||||||
|  |                                                     already_queued = True | ||||||
|  |                                                     existing_entry = e | ||||||
|  | 
 | ||||||
|  |                                             emission_timestamp = Transport.announce_emitted(packet) | ||||||
|  |                                             if already_queued: | ||||||
|  |                                                 should_queue = False | ||||||
|  | 
 | ||||||
|  |                                                 if emission_timestamp > existing_entry["emitted"]: | ||||||
|  |                                                     e["time"] = outbound_time | ||||||
|  |                                                     e["hops"] = packet.hops | ||||||
|  |                                                     e["emitted"] = emission_timestamp | ||||||
|  |                                                     e["raw"] = packet.raw | ||||||
|  | 
 | ||||||
|  |                                             if should_queue: | ||||||
|  |                                                 entry = { | ||||||
|  |                                                     "destination": packet.destination_hash, | ||||||
|  |                                                     "time": outbound_time, | ||||||
|  |                                                     "hops": packet.hops, | ||||||
|  |                                                     "emitted": Transport.announce_emitted(packet), | ||||||
|  |                                                     "raw": packet.raw | ||||||
|  |                                                 } | ||||||
|  | 
 | ||||||
|                                                 queued_announces = True if len(interface.announce_queue) > 0 else False |                                                 queued_announces = True if len(interface.announce_queue) > 0 else False | ||||||
|                                                 interface.announce_queue.append(entry) |                                                 interface.announce_queue.append(entry) | ||||||
| 
 | 
 | ||||||
| @ -985,8 +1010,9 @@ class Transport: | |||||||
|                     # First, check that the announce is not for a destination |                     # First, check that the announce is not for a destination | ||||||
|                     # local to this system, and that hops are less than the max |                     # local to this system, and that hops are less than the max | ||||||
|                     if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1): |                     if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1): | ||||||
|  |                         announce_emitted = Transport.announce_emitted(packet) | ||||||
|  |                          | ||||||
|                         random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8] |                         random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8] | ||||||
|                         announce_emitted = int.from_bytes(random_blob[5:10], "big") |  | ||||||
|                         random_blobs = [] |                         random_blobs = [] | ||||||
|                         if packet.destination_hash in Transport.destination_table: |                         if packet.destination_hash in Transport.destination_table: | ||||||
|                             random_blobs = Transport.destination_table[packet.destination_hash][4] |                             random_blobs = Transport.destination_table[packet.destination_hash][4] | ||||||
| @ -1772,6 +1798,13 @@ class Transport: | |||||||
|                 if registered_destination.type == RNS.Destination.SINGLE: |                 if registered_destination.type == RNS.Destination.SINGLE: | ||||||
|                     registered_destination.announce(path_response=True) |                     registered_destination.announce(path_response=True) | ||||||
| 
 | 
 | ||||||
|  |     @staticmethod | ||||||
|  |     def announce_emitted(packet): | ||||||
|  |         random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8] | ||||||
|  |         announce_emitted = int.from_bytes(random_blob[5:10], "big") | ||||||
|  | 
 | ||||||
|  |         return announce_emitted | ||||||
|  | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def exit_handler(): |     def exit_handler(): | ||||||
|         try: |         try: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user