Skip to content

Commit

Permalink
ADDR_ANY for local addr
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Nov 10, 2023
1 parent e403bdf commit 627488f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
14 changes: 8 additions & 6 deletions examples/cfdp-cli-udp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def transaction_finished_indication(self, params: TransactionFinishedParams):
ProxyPutResponseParams.from_finished_params(params.finished_params)
).to_generic_msg_to_user_tlv()
originating_id = self.active_proxy_put_reqs.get(params.transaction_id)
assert originating_id is not None
put_req = PutRequest(
destination_id=originating_id.source_id,
source_file=None,
Expand Down Expand Up @@ -187,9 +188,9 @@ def _handle_msgs_to_user(
):
for msg_to_user in msgs_to_user:
if msg_to_user.is_reserved_cfdp_message():
self._handle_reserved_cfdp_message(
transaction_id, msg_to_user.to_reserved_msg_tlv()
)
reserved_msg_tlv = msg_to_user.to_reserved_msg_tlv()
assert reserved_msg_tlv is not None
self._handle_reserved_cfdp_message(transaction_id, reserved_msg_tlv)
else:
_LOGGER.info(f"Received custom message to user: {msg_to_user}")

Expand Down Expand Up @@ -315,10 +316,10 @@ def run(self):
self.periodic_operation()
time.sleep(self.sleep_time)

def periodic_operation(self) -> bool:
def periodic_operation(self):
while True:
next_packet = self.poll_next_udp_packet()
if next_packet is None:
if next_packet is None or next_packet.pdu is None:
break
# Perform PDU routing.
packet_dest = get_packet_destination(next_packet.pdu)
Expand All @@ -335,7 +336,7 @@ def poll_next_udp_packet(self) -> Optional[PduHolder]:
return PduFactory.from_raw_to_holder(data)
return None

def send_packets(self) -> bool:
def send_packets(self):
while True:
try:
next_tm = self.tm_queue.get(False)
Expand Down Expand Up @@ -380,6 +381,7 @@ def _idle_handling(self) -> bool:
)
else:
self.source_handler.put_request(put_req)
return True
except Empty:
return False

Expand Down
13 changes: 8 additions & 5 deletions examples/cfdp-cli-udp/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ def main():
parser.add_argument("-v", "--verbose", action="count", default=0)
add_cfdp_procedure_arguments(parser)
args = parser.parse_args()
if args.verbose == 0:
logging_level = logging.INFO
elif args.verbose >= 1:
logging_level = logging.INFO
if args.verbose >= 1:
logging_level = logging.DEBUG
if args.source is not None and args.target is not None:
# Generate a put request from the CLI arguments.
Expand Down Expand Up @@ -114,10 +113,14 @@ def main():
TM_QUEUE,
)

# Address Any to accept CFDP packets from other address than localhost.
local_addr = "0.0.0.0"
# Localhost default address
remote_addr = "127.0.0.1"
udp_server = UdpServer(
0.1,
("127.0.0.1", LOCAL_PORT),
("127.0.0.1", REMOTE_PORT),
(local_addr, LOCAL_PORT),
(remote_addr, REMOTE_PORT),
TM_QUEUE,
SOURCE_ENTITY_QUEUE,
DEST_ENTITY_QUEUE,
Expand Down
13 changes: 8 additions & 5 deletions examples/cfdp-cli-udp/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def main():
parser = argparse.ArgumentParser(prog="CFDP Remote Entity Application")
parser.add_argument("-v", "--verbose", action="count", default=0)
args = parser.parse_args()
if args.verbose == 0:
logging_level = logging.INFO
elif args.verbose >= 1:
logging_level = logging.INFO
if args.verbose >= 1:
logging_level = logging.DEBUG
basicConfig(level=logging_level)

Expand Down Expand Up @@ -96,10 +95,14 @@ def main():
TM_QUEUE,
)

# Address Any to accept CFDP packets from other address than localhost.
local_addr = "0.0.0.0"
# Localhost default address
remote_addr = "127.0.0.1"
udp_server = UdpServer(
0.1,
("127.0.0.1", REMOTE_PORT),
("127.0.0.1", LOCAL_PORT),
(local_addr, REMOTE_PORT),
(remote_addr, LOCAL_PORT),
TM_QUEUE,
SOURCE_ENTITY_QUEUE,
DEST_ENTITY_QUEUE,
Expand Down

0 comments on commit 627488f

Please sign in to comment.