コード例 #1
0
 def doReportDisconnected(self, *args, **kwargs):
     """
     Action method.
     """
     self.dht_lookup_use_cache = False
     for packet_id in self.outgoing_list_files_packets_ids:
         packetsToCancel = packet_out.search_by_packet_id(packet_id)
         for pkt_out in packetsToCancel:
             if pkt_out.outpacket.Command == commands.ListFiles():
                 lg.warn('sending "cancel" to %r from %r' % (
                     pkt_out,
                     self,
                 ))
                 pkt_out.automat('cancel')
     events.send('share-disconnected', data=dict(self.to_json()))
     if self.result_defer:
         self.result_defer.errback(Exception('disconnected'))
     for cb_id in list(self.connected_callbacks.keys()):
         if cb_id in self.connected_callbacks:
             cb = self.connected_callbacks[cb_id]
             cb(cb_id, False)
     if _Debug:
         lg.args(_DebugLevel,
                 key_id=self.key_id,
                 ecc_map=self.known_ecc_map)
コード例 #2
0
 def doCancelSendings(self, *args, **kwargs):
     """
     Action method.
     """
     for packet_id in self.outgoing_packets_ids:
         packetsToCancel = packet_out.search_by_packet_id(packet_id)
         for pkt_out in packetsToCancel:
             if pkt_out.outpacket.Command == commands.Data():
                 pkt_out.automat('cancel')
コード例 #3
0
 def _do_cancel_outbox_packets(self, fail_info):
     to_idurl = id_url.field(fail_info['to'])
     from_idurl = id_url.field(fail_info['from'])
     for p in packet_out.search_by_packet_id(fail_info['packet_id']):
         if p.outpacket.Command == fail_info['command']:
             if p.outpacket.RemoteID == to_idurl:
                 if p.outpacket.CreatorID == from_idurl or p.outpacket.OwnerID == from_idurl:
                     lg.warn(
                         'about to cancel %r because sending via proxy transport failed'
                         % p)
                     p.automat('cancel')
コード例 #4
0
 def doCancelPackets(self, *args, **kwargs):
     """
     Action method.
     """
     packetsToCancel = packet_out.search_by_packet_id(self.packetID)
     for pkt_out in packetsToCancel:
         if pkt_out.outpacket.Command == commands.Retrieve():
             if _Debug:
                 lg.dbg(_DebugLevel, 'sending "cancel" to %s addressed to %s because downloading cancelled' % (
                     pkt_out, pkt_out.remote_idurl, ))
             pkt_out.automat('cancel')
コード例 #5
0
 def _do_cancel_outbox_packets(self, fail_info):
     to_idurl = id_url.field(fail_info['to'])
     from_idurl = id_url.field(fail_info['from'])
     for p in packet_out.search_by_packet_id(fail_info['packet_id']):
         if p.outpacket.Command == fail_info['command']:
             if id_url.to_bin(to_idurl) == p.outpacket.RemoteID.to_bin():
                 if p.outpacket.CreatorID.to_bin() == id_url.to_bin(
                         from_idurl) or p.outpacket.OwnerID.to_bin(
                         ) == id_url.to_bin(from_idurl):
                     if _Debug:
                         lg.dbg(
                             _DebugLevel,
                             'about to cancel %r because sending via proxy transport is failed'
                             % p)
                     p.automat('cancel')
コード例 #6
0
 def doCancelSendings(self, *args, **kwargs):
     """
     Action method.
     """
     for packet_id in self.outgoing_packets_ids:
         packetsToCancel = packet_out.search_by_packet_id(packet_id)
         for pkt_out in packetsToCancel:
             if pkt_out.outpacket.Command == commands.Data():
                 lg.warn(
                     'sending "cancel" to %s addressed to %s from index_synchronizer'
                     % (
                         pkt_out,
                         pkt_out.remote_idurl,
                     ))
                 pkt_out.automat('cancel')
コード例 #7
0
 def doReportConnected(self, *args, **kwargs):
     """
     Action method.
     """
     self.dht_lookup_use_cache = True
     for packet_id in self.outgoing_list_files_packets_ids:
         packetsToCancel = packet_out.search_by_packet_id(packet_id)
         for pkt_out in packetsToCancel:
             if pkt_out.outpacket.Command == commands.ListFiles():
                 lg.warn('sending "cancel" to %r from %r' % (
                     pkt_out,
                     self,
                 ))
                 pkt_out.automat('cancel')
     events.send('share-connected', data=dict(self.to_json()))
     if self.result_defer:
         self.result_defer.callback(True)
     for cb_id in list(self.connected_callbacks.keys()):
         cb = self.connected_callbacks.get(cb_id)
         if cb:
             cb(cb_id, True)
コード例 #8
0
    def _do_process_inbox_packet(self, *args, **kwargs):
        newpacket, info, _, _ = args[0]
        block = encrypted.Unserialize(newpacket.Payload)
        if block is None:
            lg.err('reading data from %s' % newpacket.CreatorID)
            return
        try:
            session_key = key.DecryptLocalPrivateKey(block.EncryptedSessionKey)
            padded_data = key.DecryptWithSessionKey(session_key, block.EncryptedData, session_key_type=block.SessionKeyType)
            inpt = BytesIO(padded_data[:int(block.Length)])
            data = inpt.read()
        except:
            lg.err('reading data from %s' % newpacket.CreatorID)
            lg.exc()
            try:
                inpt.close()
            except:
                pass
            return
        inpt.close()

        if newpacket.Command == commands.RelayAck():
            try:
                ack_info = serialization.BytesToDict(data, keys_to_text=True, values_to_text=True)
            except:
                lg.exc()
                return
            if _Debug:
                lg.out(_DebugLevel, '<<<Relay-ACK %s:%s from %s://%s with %d bytes %s' % (
                    ack_info['command'], ack_info['packet_id'], info.proto, info.host, len(data), ack_info['error'], ))
            if _PacketLogFileEnabled:
                lg.out(0, '                \033[0;49;33mRELAY ACK %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                    ack_info['command'], ack_info['packet_id'], info.bytes_received,
                    global_id.UrlToGlobalID(ack_info['from']), global_id.UrlToGlobalID(ack_info['to']),
                    info.transfer_id), log_name='packet', showtime=True)
            from transport.proxy import proxy_sender
            if proxy_sender.A():
                proxy_sender.A('relay-ack', ack_info, info)
            return True

        if newpacket.Command == commands.RelayFail():
            try:
                fail_info = serialization.BytesToDict(data, keys_to_text=True, values_to_text=True)
            except:
                lg.exc()
                return
            if _Debug:
                lg.out(_DebugLevel, '<<<Relay-FAIL %s:%s from %s://%s with %d bytes %s' % (
                    fail_info['command'], fail_info['packet_id'], info.proto, info.host, len(data), fail_info['error'], ))
            if _PacketLogFileEnabled:
                lg.out(0, '                \033[0;49;33mRELAY FAIL %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                    fail_info['command'], fail_info['packet_id'], info.bytes_received,
                    global_id.UrlToGlobalID(fail_info['from']), global_id.UrlToGlobalID(fail_info['to']),
                    info.transfer_id), log_name='packet', showtime=True)
            from transport.proxy import proxy_sender
            if proxy_sender.A():
                proxy_sender.A('relay-failed', fail_info, info)
            return True

        routed_packet = signed.Unserialize(data)
        if not routed_packet:
            lg.err('unserialize packet failed from %s' % newpacket.CreatorID)
            return

        if _Debug:
            lg.out(_DebugLevel, '<<<Relay-IN %s from %s://%s with %d bytes' % (
                str(routed_packet), info.proto, info.host, len(data)))
        if _PacketLogFileEnabled:
            lg.out(0, '                \033[0;49;33mRELAY IN %s(%s) with %d bytes from %s to %s TID:%s\033[0m' % (
                routed_packet.Command, routed_packet.PacketID, info.bytes_received,
                global_id.UrlToGlobalID(info.sender_idurl), global_id.UrlToGlobalID(routed_packet.RemoteID),
                info.transfer_id), log_name='packet', showtime=True)

        if routed_packet.Command == commands.Identity():
            if _Debug:
                lg.out(_DebugLevel, '    found identity in relay packet %s' % routed_packet)
            newidentity = identity.identity(xmlsrc=routed_packet.Payload)
            idurl = newidentity.getIDURL()
            if not identitycache.HasKey(idurl):
                lg.info('received new identity %s rev %r' % (idurl.original(), newidentity.getRevisionValue(), ))
            if not identitycache.UpdateAfterChecking(idurl, routed_packet.Payload):
                lg.warn("ERROR has non-Valid identity")
                return

        if routed_packet.Command in [commands.Relay(), commands.RelayIn(), ] and routed_packet.PacketID.lower().startswith('identity:'):
            if _Debug:
                lg.out(_DebugLevel, '    found routed identity in relay packet %s' % routed_packet)
            try:
                routed_identity = signed.Unserialize(routed_packet.Payload)
                newidentity = identity.identity(xmlsrc=routed_identity.Payload)
                idurl = newidentity.getIDURL()
                if not identitycache.HasKey(idurl):
                    lg.warn('received new "routed" identity: %s' % idurl)
                if not identitycache.UpdateAfterChecking(idurl, routed_identity.Payload):
                    lg.warn("ERROR has non-Valid identity")
                    return
            except:
                lg.exc()

        if newpacket.Command == commands.RelayIn() and routed_packet.Command == commands.Fail():
            if routed_packet.Payload == b'route not exist' or routed_packet.Payload == b'route already closed':
                for pout in packet_out.search_by_packet_id(routed_packet.PacketID):
                    lg.warn('received %r from %r, outgoing packet is failed: %r' % (routed_packet.Payload, newpacket.CreatorID, pout, ))
                    pout.automat('request-failed')
                return

        self.traffic_in += len(data)
        packet_in.process(routed_packet, info)
        del block
        del data
        del padded_data
        del inpt
        del session_key
        del routed_packet