class Prover(object): def __init__(self): self.__name = "Pat" self.__connection = Connection() self.__prover = Thread(target=self.prove, args=()) self.__state = State() def __del__(self): pass @staticmethod def create(): prover = Prover() Console.write(prover.__name, "Initialising ...") prover.__prover.start() prover.__prover.join() def prove(self): while True: Console.write(self.__name, "I know (x, w). I want to prove this knowledge.") Console.write(self.__name, "Transforming (x, w) -> \pi") ''' todo: transform (x,w) -> \pi ''' Console.write(self.__name, "Sending \pi") self.__connection.client_socket("\pi") return @staticmethod def getName(): prover = Prover() return prover.__name
def __init__(self, *args, **kwargs): """ Initializes the GOB sensor with the GOB-RabbitMQ connection """ super().__init__(*args, **kwargs) self.connection = Connection()
def process_data(self, data): print "This message is received" #: \n" + data #msg_type = data.split("_sep_") msg_type, msg = data.split("_sep_") #print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", len(msg_type), msg_type cs = self._controller.get_customers() if msg_type == "binding": src, dst = msg.split(",") src, private_address_src, public_address_src = src.split(":") dst, private_address_dst, public_address_dst = dst.split(":") connection = Connection() for customer in self._controller.get_customers(): if customer.get_private_ip_subnet().__contains__( IPAddress(private_address_dst)): connection.addStaticRoute( customer.get_router(), "sudo route add -host " + public_address_dst + " gw " + customer.get_next_hop() + " dev eth2", public_address_dst) self._public_to_private_a[public_address_dst] = private_address_dst self._public_to_private_b[public_address_src] = private_address_src elif msg_type == "dns_query" and cs[0].get_ns_domain_name( ) is not None: dns_query = pickle.loads(msg) counter = self._controller.get_packet_counter() counter = counter + 1 counter = self._controller.set_packet_counter(counter) CDNS = ControllerDNSHandlerAlg2(dns_query, self._controller) CDNS.handle_socket_msg() elif msg_type == "dns_response" and cs[0].get_ns_domain_name( ) is not None: #print '########################## DNS Packet has been recieved.' counter = self._controller.get_packet_counter() counter = counter + 1 counter = self._controller.set_packet_counter(counter) dns_query = pickle.loads(msg) CDNS = ControllerDNSResponseHandlerAlg2(dns_query, self._controller) CDNS.handle_socket_msg() elif msg_type == "dns_query" and cs[0].get_ns_domain_name() is None: #print '########################## DNS Packet has been recieved.' dns_query = pickle.loads(msg) CDNS = ControllerDNSHandler(dns_query, self._controller) CDNS.handle_socket_msg() elif msg_type == "dns_response" and cs[0].get_ns_domain_name() is None: dns_query = pickle.loads(msg) CDNS = ControllerDNSResponseHandler(dns_query, self._controller) CDNS.handle_socket_msg()
class Verifier(object): def __init__(self): self.__name = "Victor" self.__connection = Connection() self.__verifier = Thread(target = self.verify, args = ()) self.__state = State() def __del__(self): pass @staticmethod def create(): verifier = Verifier() Console.write(verifier.__name, "Initialising ...") verifier.__verifier.start() verifier.__verifier.join() def verify(self): while True: Console.write(self.__name, "I know (x). I want be convinced that this is true.") message = self.__connection.server_socket() Console.write(self.__name, "Receiving " + message) Console.write(self.__name, "I'm now verifying " + message + ". If this is true I accept, otherwise I reject." ) return @staticmethod def getName(): verifier = Verifier() return verifier.__name
def __init__(self, job_name=None, step_name=None, catalogue=None, collection=None, optional=None, *args, **kwargs): """ Initializes the GOB operator for the specific workflow """ super().__init__(*args, **kwargs) self.job_name = job_name self.step_name = step_name self.catalogue = catalogue self.collection = collection self.optional = optional or {} self.connection = Connection()
def from_cs_to_public(self, pkt): private_address_src = pkt.get_protocol(ipv4.ipv4).src if private_address_src in self._public_to_private_a.values(): for public, private in self._public_to_private_a.items(): if private_address_src == private: self._public_address_src = public else: ip_iterator_src = self._controller.get_public_subnet().iter_hosts() self._public_address_src = ip_iterator_src.next().__str__() # Genero un ip non in uso dal "MIO" pool per la sorgente. DA VERIFICARE IL PUNTATORE SU IP_ITERATOR!!!! while self._public_address_src in self._public_to_private_a.keys(): self._public_address_src = ip_iterator_src.next().__str__() self._public_to_private_a[ self._public_address_src] = private_address_src customer = self._dp_to_customer[self._datapath.id, str(self._in_port)] connection = Connection() connection.addStaticRoute( customer.get_router(), "sudo route add -host " + self._public_address_src + " gw " + customer.get_next_hop() + " dev eth2", self._public_address_src) ofp = self._datapath.ofproto parser = self._datapath.ofproto_parser actions = [ parser.OFPActionSetField(ipv4_src=self._public_address_src), parser.OFPActionOutput(1) ] out = parser.OFPPacketOut(datapath=self._datapath, data=self._data, in_port=self._in_port, actions=actions, buffer_id=OFP_NO_BUFFER) self._datapath.send_msg(out)
def upload_sample_(host, port, path): try: address = (host, port) r = reader.Reader(path) i = 0 for s in r: i = i + 1 if i % 150 == 0: click.echo('Pausing ...') time.sleep(3) soc = socket.socket() soc.connect(address) conn = Connection(soc) try: # Send hello message if r.user.gender == 0: gender = 'm' elif r.user.gender == 1: gender = 'f' else: # r.user.gender == 2 gender = 'o' hello = utils.protocol.Hello(r.user.user_id, r.user.username, r.user.birthday, gender) conn.send_message(hello.serialize()) # Receive config message config = utils.protocol.Config.deserialize( conn.receive_message()) # Send snapshot message snapshot = utils.protocol.Snapshot(s.datetime) if 'pose' in config.fields and s.pose: snapshot.translation = (s.pose.translation.x, s.pose.translation.y, s.pose.translation.z) snapshot.rotation = (s.pose.rotation.x, s.pose.rotation.y, s.pose.rotation.z, s.pose.rotation.w) if 'color_image' in config.fields and s.color_image: snapshot.color_image = s.color_image if 'depth_image' in config.fields and s.depth_image: snapshot.depth_image = s.depth_image if 'feelings' in config.fields and s.feelings: snapshot.hunger = s.feelings.hunger snapshot.thirst = s.feelings.thirst snapshot.exhaustion = s.feelings.exhaustion snapshot.happiness = s.feelings.happiness conn.send_message(snapshot.serialize()) print(i) except Exception as e: raise e finally: conn.close() return 0 except Exception as error: raise error print(f'ERROR: {error}') return 1 finally: print('done')
class GOBSensor(BaseSensorOperator): ui_color = Color("lime").hex @apply_defaults def __init__(self, *args, **kwargs): """ Initializes the GOB sensor with the GOB-RabbitMQ connection """ super().__init__(*args, **kwargs) self.connection = Connection() def poke(self, context): """ Try to read workflow messages for the current task (DAG run_id) :param context: Airflow context :return: final result message for the current task or None if not yet available """ # todo force reschedule when no result received result = None for msg in self.connection.consume(RESULT_QUEUE): if msg is None: logging.info("No message yet. Waiting...") break if msg['header']['airflow']["run_id"] != context['dag_run'].run_id: logging.info("Skip message for other workflow") continue self.connection.ack(msg) status = msg.get('status') if status is not None: logging.info(f"Status: {status}") continue summary = msg.get('summary') if summary is not None: result = self.handle_result(context, msg) continue return result def handle_result(self, context, msg): """ Handle a result message for the current task """ # Save result message for any successor task context['task_instance'].xcom_push(key=context['dag_run'].run_id, value=msg) # Handle errors and warnings logging.info("Result received") errors = msg["summary"].get("errors", []) warnings = msg["summary"].get("warnings", []) if warnings: logging.warning(f"Task warnings ({len(warnings)}):") logging.warning("\n".join(warnings)) if errors: logging.warning(f"Task errors ({len(errors)}):") logging.error("\n".join(errors)) raise AirflowException("Task has failed") return msg
def accept(self): return Connection(self.server.accept()[0])
def __init__(self): self.__name = "Pat" self.__connection = Connection() self.__prover = Thread(target=self.prove, args=()) self.__state = State()
def from_cs_to_private(self, pkt): private_address_src = pkt.get_protocol(ipv4.ipv4).src ip_dst = pkt.get_protocol(ipv4.ipv4).dst # Verifico se la destinazione e^ un ip fittizio (indirizzamento sovrapposto) if ip_dst in self._controller.get_fittizio_to_private().keys(): private_address_dst = self._controller.get_fittizio_to_private( )[ip_dst] else: private_address_dst = ip_dst # Verifico se ho gia^ un mapping (pubblico<-->privato) per l'ip del MIO customer if private_address_src in self._public_to_private_a.values(): for public, private in self._public_to_private_a.items(): if private_address_src == private: self._public_address_src = public else: ip_iterator_src = self._controller.get_public_subnet().iter_hosts() self._public_address_src = ip_iterator_src.next().__str__() # Genero un ip non in uso dal "MIO" pool per la sorgente. while self._public_address_src in self._public_to_private_a.keys(): self._public_address_src = ip_iterator_src.next().__str__() self._public_to_private_a[ self._public_address_src] = private_address_src # Aggiungo una rotta statica per il ip pubblico scelto per gestire il traffico di ritorno customer = self._dp_to_customer[self._datapath.id, str(self._in_port)] connection = Connection() connection.addStaticRoute( customer.get_router(), "sudo route add -host " + self._public_address_src + " gw " + customer.get_next_hop() + " dev eth2", self._public_address_src) # Verifico se ho gia^ un mapping (pubblico<-->privato) per l'ip del customer federato if private_address_dst in self._public_to_private_b.values(): for public1, private1 in self._public_to_private_b.items(): if private_address_dst == private1: self._public_address_dst = public1 else: # Devo individuare da quale federato (pool) devo prendere un ip per la destinazione. # Con l'implementazione della risoluzione dei nomi il controller sa individuare il federato a partitre dal nome. # Per ora so che esiste un solo federato con cui ho instaurato delle VPN ed utilizzo lui ip_iterator_dst = self._federazione[0].get_public_subnet( ).iter_hosts() self._public_address_dst = ip_iterator_dst.next().__str__() # Genero un ip non in uso dal pool di c2 per la destinazione while self._public_address_dst in self._public_to_private_b.keys(): self._public_address_dst = ip_iterator_dst.next().__str__() self._public_to_private_b[ self._public_address_dst] = private_address_dst # Segnalo l'associazio pubblico<-->privato client = Client() client.send_message( "binding;src:" + private_address_src + ":" + self._public_address_src + ",dst:" + private_address_dst + ":" + self._public_address_dst, self._federazione[0].get_ip(), self._federazione[0].get_port()) # print "from_cs_to_private dst :", ip_dst, " src: ", private_address_src ofp = self._datapath.ofproto parser = self._datapath.ofproto_parser actions = [ parser.OFPActionSetField(ipv4_src=self._public_address_src), parser.OFPActionSetField(ipv4_dst=self._public_address_dst), parser.OFPActionOutput(1) ] out = parser.OFPPacketOut(datapath=self._datapath, data=self._data, in_port=self._in_port, actions=actions, buffer_id=OFP_NO_BUFFER) self._datapath.send_msg(out) #Inserisco un flow-entry per i pacchetti in uscita match = parser.OFPMatch(eth_type=ether.ETH_TYPE_IP, ipv4_src=private_address_src, ipv4_dst=ip_dst) actions = [ parser.OFPActionSetField(ipv4_src=self._public_address_src), parser.OFPActionSetField(ipv4_dst=self._public_address_dst), parser.OFPActionOutput(1) ] inst = [parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] mod = parser.OFPFlowMod(datapath=self._datapath, match=match, instructions=inst, priority=1) self._datapath.send_msg(mod) # Inserisco una flow-entry per i pacchetti in entrata # Verifico la porta di uscita del datapath in funzione della subnet privata dei miei customer # Assunzione: customer sotto lo stesso datapath devono avere subnet private differenti for customer in self._controller.get_customers(): if customer.get_datapath( ) == self._datapath and customer.get_private_ip_subnet( ).__contains__(IPAddress(private_address_src)): out_port = int(customer.get_ingress_port()) match = parser.OFPMatch(eth_type=ether.ETH_TYPE_IP, ipv4_dst=self._public_address_src, ipv4_src=self._public_address_dst) actions = [ parser.OFPActionSetField(ipv4_src=ip_dst), parser.OFPActionSetField(ipv4_dst=private_address_src), parser.OFPActionOutput(out_port) ] inst = [parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] mod = parser.OFPFlowMod(datapath=self._datapath, match=match, instructions=inst, priority=1) self._datapath.send_msg(mod)
class GOBOperator(BaseOperator): ui_color = Color("lightgreen").hex @apply_defaults def __init__(self, job_name=None, step_name=None, catalogue=None, collection=None, optional=None, *args, **kwargs): """ Initializes the GOB operator for the specific workflow """ super().__init__(*args, **kwargs) self.job_name = job_name self.step_name = step_name self.catalogue = catalogue self.collection = collection self.optional = optional or {} self.connection = Connection() def execute(self, context): """ Execute the workflow step Any message that is the result of a previous step in a task is available in and read from a XCom. :param context: Airflow context :return: The result of the publish of the GOB Message """ message = context['task_instance'].xcom_pull(key=context['dag_run'].run_id) if message is None: # Initialize a message if no message from a previous step is available message = { "header": { "catalogue": self.catalogue, "collection": self.collection, **self.optional, "result_key": RESULT_KEY, "airflow": { "dag_id": context['dag_run'].dag_id, "task_id": context['task'].task_id, "run_id": context['dag_run'].run_id } } } message["workflow"] = { "workflow_name": self.job_name, "step_name": self.step_name, } message["summary"] = {} logging.info("Task started") return self.connection.publish(EXCHANGE, REQUEST_KEY, message)
def __init__(self, b2c2_base_url, api_token): self.b2c2_base_url = b2c2_base_url self.api_token = api_token self._connection = Connection(b2c2_base_url=b2c2_base_url, api_token=api_token) self.logger = logger
def __init__(self): self.__name = "Victor" self.__connection = Connection() self.__verifier = Thread(target = self.verify, args = ()) self.__state = State()
def __init__(self): self.config = Config() self.connection = Connection(self.config) self.strings = Strings(self.config)
import re from utils.connection import Connection import utils.output as out import utils.pickling as pick conn = Connection() sites = open("sites.txt", 'r') mails = {} regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" regexAt = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*\[at\](?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" regexAt2 = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)* \[at\] (?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" for site in sites: print("Elaboro ", site) html = conn.getpage(site) mails[site] = set( re.findall(r"" + regex + "", html) + re.findall(r"" + regexAt + "", html) + re.findall(r"" + regexAt2 + "", html)) print("\n\nRisutalti: ") out.printhash(mails) if len(mails.items()) > 0 and input( "Salvare in .pickle? INVIO per rifiutare, qualsiasi tasto e poi INVIO per accettare: " ): pick.savepickle("mails.pickle", mails)