From 355a5463e58f6e9ec2dc37d8e2ab36c635d6e17e Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Sat, 14 Aug 2021 21:28:38 +0200 Subject: [PATCH] introduce the initialization code for the aircraft data receiver --- aman/com/EuroscopeReceiver.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 aman/com/EuroscopeReceiver.py diff --git a/aman/com/EuroscopeReceiver.py b/aman/com/EuroscopeReceiver.py new file mode 100644 index 0000000..661f991 --- /dev/null +++ b/aman/com/EuroscopeReceiver.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import zmq +from zmq.asyncio import Context +import zmq.auth +from zmq.auth.asyncio import AsyncioAuthenticator + +from pathlib import Path +from typing import Union, Optional + +# @brief Receives the information of EuroScope +def EuroscopeReceiver(): + # @brief Initializes the ZMQ socket + # @param[in] address The server address + # @param[in] serverKeyPath Path to the server's keypair + # @param[in] clientKeys Path to the client's keypairs + def __init__(self, address: str, serverKeyPath: Union[str, Path], clientKeys: Union[str, Path]): + self.context = Context.instance() + + # initialize the authentication module + authLocation = ( + str(clientKeys) + ) + self.auth = AsyncioAuthenticator(context = self.context) + self.auth.configure_curve(domain='*', location = authLocation) + self.auth.allow('127.0.0.1') + self.auth.start() + + # initialize the socket + self.socket = self.context.socket(zmq.REP) + keys = zmq.auth.load_certificate(serverKeyPath) + self.socket.setsockopt(zmq.CURVE_PUBLICKEY, keys[0]) + self.socket.setsockopt(zmq.CURVE_SECRETKEY, keys[1]) + self.socket.setsockopt(zmq.CURVE_SERVER, True) + self.socket.bind(address) + + def __exit__(self, *_exc): + self.auth.stop()