def send_data_to_clients(self, data):
     from defusedxml import ElementTree as etree
     try:
         if self.federates:
             xmlstring = data.xmlString
             detail = etree.fromstring(xmlstring).find('detail')
             if detail:
                 protobuf = ProtobufSerializer().from_fts_object_to_format(
                     data.modelObject)
                 try:
                     protobuf.event.other = etree.tostring(detail)
                     protobufstring = protobuf.SerializeToString()
                     header = self._generate_header(len(protobufstring))
                     protobufstring = header + protobufstring
                     print(protobufstring)
                 except Exception as e:
                     logger.warning("creating protobuf message failed " +
                                    str(e))
                     return None
                 for client in self.federates.values():
                     client.conn.send(protobufstring)
             else:
                 return None
         else:
             return None
     except Exception as e:
         import traceback
         trace = traceback.format_exc()
         logger.warning("sending data to federates failed " + str(e))
Exemplo n.º 2
0
 def test_to_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     xmlstring = '<event version="2.0" uid="ANDROID-R5CN70EYKQH" type="a-f-G-U-C" how="h-e" start="2020-12-24T18:16:22.325Z" time="2020-12-24T18:16:22.325Z" stale="2020-12-24T18:22:37.325Z"><detail><__group name="Teal" role="Team Member"/><status battery="76"/><takv version="4.2.0.4 (47e136dd).1607456856-CIV" platform="ATAK-CIV" device="SAMSUNG SM-N986U" os="29"/><track course="159.1462509079387" speed="0.0"/><contact callsign="SPAC3SLOTH" endpoint="*:-1:stcp" /><uid Droid="SPAC3SLOTH"/><precisionlocation altsrc="GPS" geopointsrc="GPS"/></detail><point le="9999999.0" ce="11.0" hae="178.84407323983876" lon="-76.675505" lat="39.664392"/></event>'
     fts_obj = XmlSerializer().from_format_to_fts_object(
         xmlstring, Event.Connection())
     y = ProtobufSerializer().from_fts_object_to_format(fts_obj)
     1 == 1
Exemplo n.º 3
0
    def main(self):
        from lxml import etree
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    pass
            else:
                pass
            try:
                data = self.receive_data_from_federate(1)
            except ssl.SSLWantReadError:
                data = None
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    # event = etree.Element('event')
                    # SpecificCoTObj = XMLCoTController().categorize_type(protobuf_object.type)
                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
Exemplo n.º 4
0
 def send_data_to_clients(self, data):
     from lxml import etree
     try:
         if self.federates:
             xmlstring = data.xmlString
             detail = etree.fromstring(xmlstring).find('detail')
             protobuf = ProtobufSerializer().from_fts_object_to_format(
                 data.modelObject)
             protobuf.event.other = etree.tostring(detail)
             protobufstring = protobuf.SerializeToString()
             header = self._generate_header(len(protobufstring))
             protobufstring = header + protobufstring
             print(protobufstring)
             for client in self.federates.values():
                 client.conn.send(protobufstring)
         else:
             return None
     except Exception as e:
         logger.warning("send data to clients failed with exception " +
                        str(e))
Exemplo n.º 5
0
 def test_from_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     from FreeTAKServer.model.protobufModel.fig_pb2 import FederatedEvent
     import lxml
     protobufString = b'\n\x83\x04\x08\xbe\xb9\xfb\x85\xeb.\x10\xbe\xb9\xfb\x85\xeb.\x18\x96\xab\x92\x86\xeb.!\xaf\xf6b\x88\\d<@) {Mcr\x1aG\xc01\x00\x00\x00\xe0\xcf\x12cA9\x00\x00\x00\xe0\xcf\x12cAA\x00\x00\x00\xe0\xcf\x12cAJ.S-1-5-21-2720623347-3037847324-4167270909-1002R\x0ba-f-G-U-C-IZ\x03h-eb\xfa\x02<detail><takv version="4.0.0.117" platform="WinTAK-CIV" os="Microsoft Windows 10 Home" device="Micro-Star International Co., Ltd MS-7C02"/><contact callsign="FEATHER" endpoint="*:-1:stcp"/><uid Droid="FEATHER"/><__group name="Cyan" role="Team Member"/><_flow-tags_ TAK-Server-c0581fed97ff4cb89eb8666a8794670cc9f77ddb-badf-48da-abe7-84545ecda69d="2020-12-29T23:04:27Z"/></detail>hd'
     # protobufString2 = b'"\x00\x00\x00="\x12;\x08\x01\x12.S-1-5-21-2720623347-3037847324-4167270909-1002\x1a\x07FEATHER'
     protobufObj = FederatedEvent()
     protobufObj.ParseFromString(protobufString)
     # protobufObj.ParseFromString(protobufString2)
     #y = [name.name for name in protobufObj.event.DESCRIPTOR.fields]
     fts_obj = ProtobufSerializer().from_format_to_fts_object(protobufObj, Event.Connection())
     z = lxml.etree.tostring(XmlSerializer().from_fts_object_to_format(fts_obj))
     1 == 1
    def main(self):
        from defusedxml import ElementTree as etree
        import time
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    logger.debug("exception in command chain " + str(e))
            else:
                pass

            data = self.receive_data_from_federate(1)
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass