Exemplo n.º 1
0
 def create_msg():
     normal_msg = pack(
         '!20sQ', message.payload.infohash,
         message.payload.timestamp), message.payload.name, tuple(
             files), tuple(trackers)
     normal_msg = encode(normal_msg)
     return zlib.compress(normal_msg)
    def _encode_comment(self, message):
        dict = {
            "text": message.payload.text,
            "timestamp": message.payload.timestamp
        }

        playlist_packet = message.payload.playlist_packet
        infohash = message.payload.infohash

        if message.payload.reply_to_mid:
            dict["reply-to-mid"] = message.payload.reply_to_mid
            dict["reply-to-global-time"] = message.payload.reply_to_global_time

        if message.payload.reply_after_mid:
            dict["reply-after-mid"] = message.payload.reply_after_mid
            dict[
                "reply-after-global-time"] = message.payload.reply_after_global_time

        if playlist_packet:
            message = playlist_packet.load_message()
            dict["playlist-mid"] = message.authentication.member.mid
            dict["playlist-global-time"] = message.distribution.global_time

        if infohash:
            dict['infohash'] = infohash
        return encode(dict),
Exemplo n.º 3
0
    def _encode_moderation(self, message):
        dict = {"text":message.payload.text,
                "timestamp":message.payload.timestamp,
                "severity":message.payload.severity}

        dict["cause-mid"] = message.payload.cause_mid
        dict["cause-global-time"] = message.payload.cause_global_time
        return encode(dict),
    def _encode_mark_torrent(self, message):
        dict = {
            "infohash": message.payload.infohash,
            "timestamp": message.payload.timestamp,
            "type": message.payload.type
        }

        return encode(dict),
Exemplo n.º 5
0
 def _encode_search_request(self, message):
     packet = pack('!H',
                   message.payload.identifier), message.payload.keywords
     if message.payload.bloom_filter:
         packet = packet + (message.payload.bloom_filter.functions,
                            message.payload.bloom_filter.prefix,
                            message.payload.bloom_filter.bytes)
     packet = encode(packet)
     return packet,
Exemplo n.º 6
0
 def _encode_decode(self, encode, decode, message):
     result = encode(message)
     try:
         decode(None, 0, result[0])
         
     except DropPacket:
         raise
     except:
         pass
     return result
    def _encode_moderation(self, message):
        dict = {
            "text": message.payload.text,
            "timestamp": message.payload.timestamp,
            "severity": message.payload.severity
        }

        dict["cause-mid"] = message.payload.cause_mid
        dict["cause-global-time"] = message.payload.cause_global_time
        return encode(dict),
Exemplo n.º 8
0
    def _encode_decode(self, encode, decode, message):
        result = encode(message)
        try:
            decode(None, 0, result[0])

        except DropPacket:
            raise
        except:
            pass
        return result
Exemplo n.º 9
0
 def report(self):
     if DEBUG: print >> sys.stderr, "TUDelftReporter: report"
     events = self.get_events()
     if events:
         events = [{"name":event.get_name(), "time":event.get_time(), "values":event.get_values()} for event in events]
         data = (time(), self.device_id.encode("HEX"), events)
         compressed = compress(encode(data))
         if DEBUG: print >> sys.stderr, "TUDelftReporter: posting", len(compressed), "bytes payload"
         self.post(compressed)
     else:
         if DEBUG: print >> sys.stderr, "TUDelftReporter: Nothing to report"
 def _encode_encr_response(self, message):
     str_identifer = pack("!H", message.payload.identifier)
     str_prefs = pack(
         "!" + "128s" * len(message.payload.preference_list), *[
             long_to_bytes(preference, 128)
             for preference in message.payload.preference_list
         ])
     str_hprefs = pack(
         "!" + "20s" * len(message.payload.his_preference_list),
         *message.payload.his_preference_list)
     return encode([str_identifer, str_prefs, str_hprefs]),
Exemplo n.º 11
0
    def _encode_simi_response(self, message):
        def _encode_response(mid, preference_list, his_preference_list):
            str_mid = pack("!20s", mid) if mid else ''
            str_prefs = pack("!"+"128s"*len(preference_list), *[long_to_bytes(preference, 128) for preference in preference_list])
            str_hprefs = pack("!"+"20s"*len(his_preference_list), *his_preference_list)
            return (str_mid, str_prefs, str_hprefs)

        responses = []
        responses.append(_encode_response(None, message.payload.preference_list, message.payload.his_preference_list))
        for mid, list_tuple in message.payload.bundled_responses:
            responses.append(_encode_response(mid, list_tuple[0], list_tuple[1]))

        packet = pack('!H', message.payload.identifier), responses
        return encode(packet),
Exemplo n.º 12
0
    def _encode_modification(self, message):
        modification_on = message.payload.modification_on.load_message()
        dict = {"modification-type":message.payload.modification_type,
                "modification-value":message.payload.modification_value,
                "timestamp":message.payload.timestamp,
                "modification-on-mid":modification_on.authentication.member.mid,
                "modification-on-global-time":modification_on.distribution.global_time}

        prev_modification = message.payload.prev_modification_packet
        if prev_modification:
            message = prev_modification.load_message()
            dict["prev-modification-mid"] = message.authentication.member.mid
            dict["prev-modification-global-time"] = message.distribution.global_time

        return encode(dict),
Exemplo n.º 13
0
 def report(self):
     if DEBUG: print >> sys.stderr, "TUDelftReporter: report"
     events = self.get_events()
     if events:
         events = [{
             "name": event.get_name(),
             "time": event.get_time(),
             "values": event.get_values()
         } for event in events]
         data = (time(), self.device_id.encode("HEX"), events)
         compressed = compress(encode(data))
         if DEBUG:
             print >> sys.stderr, "TUDelftReporter: posting", len(
                 compressed), "bytes payload"
         self.post(compressed)
     else:
         if DEBUG: print >> sys.stderr, "TUDelftReporter: Nothing to report"
    def _encode_modification(self, message):
        modification_on = message.payload.modification_on.load_message()
        dict = {
            "modification-type": message.payload.modification_type,
            "modification-value": message.payload.modification_value,
            "timestamp": message.payload.timestamp,
            "modification-on-mid": modification_on.authentication.member.mid,
            "modification-on-global-time":
            modification_on.distribution.global_time
        }

        prev_modification = message.payload.prev_modification_packet
        if prev_modification:
            message = prev_modification.load_message()
            dict["prev-modification-mid"] = message.authentication.member.mid
            dict[
                "prev-modification-global-time"] = message.distribution.global_time

        return encode(dict),
    def _encode_simi_response(self, message):
        def _encode_response(mid, preference_list, his_preference_list):
            str_mid = pack("!20s", mid) if mid else ''
            str_prefs = pack(
                "!" + "128s" * len(preference_list), *[
                    long_to_bytes(preference, 128)
                    for preference in preference_list
                ])
            str_hprefs = pack("!" + "20s" * len(his_preference_list),
                              *his_preference_list)
            return (str_mid, str_prefs, str_hprefs)

        responses = []
        responses.append(
            _encode_response(None, message.payload.preference_list,
                             message.payload.his_preference_list))
        for mid, list_tuple in message.payload.bundled_responses:
            responses.append(
                _encode_response(mid, list_tuple[0], list_tuple[1]))

        packet = pack('!H', message.payload.identifier), responses
        return encode(packet),
Exemplo n.º 16
0
    def _encode_comment(self, message):
        dict = {"text":message.payload.text,
                "timestamp":message.payload.timestamp}

        playlist_packet = message.payload.playlist_packet
        infohash = message.payload.infohash

        if message.payload.reply_to_mid:
            dict["reply-to-mid"] = message.payload.reply_to_mid
            dict["reply-to-global-time"] = message.payload.reply_to_global_time

        if message.payload.reply_after_mid:
            dict["reply-after-mid"] = message.payload.reply_after_mid
            dict["reply-after-global-time"] = message.payload.reply_after_global_time

        if playlist_packet:
            message = playlist_packet.load_message()
            dict["playlist-mid"] = message.authentication.member.mid
            dict["playlist-global-time"] = message.distribution.global_time

        if infohash:
            dict['infohash'] = infohash
        return encode(dict),
Exemplo n.º 17
0
 def _encode_search_response(self, message):
     packet = pack('!H', message.payload.identifier), message.payload.results
     return encode(packet),
Exemplo n.º 18
0
        @param message The message payload
        @param reply_callback Call this function once to send the reply: reply_callback(payload [, error=123])
        """
        if DEBUG:
            print >> sys.stderr, "databasecrawler: handle_crawler_request", show_permid_short(
                permid), message

        # execute the sql
        try:
            cursor = self._sqlite_cache_db.execute_read(message)

        except Exception, e:
            reply_callback(str(e), error=1)
        else:
            if cursor:
                reply_callback(encode(list(cursor)))
                # reply_callback(cPickle.dumps(list(cursor), 2))
            else:
                reply_callback("error", error=2)

    def handle_crawler_reply(self, permid, selversion, channel_id,
                             channel_data, error, message, request_callback):
        """
        Received a CRAWLER_DATABASE_QUERY reply.
        @param permid The Crawler permid
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param error The error value. 0 indicates success.
        @param message The message payload
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
Exemplo n.º 19
0
 def _encode_channelsearch_response(self, message):
     packet = encode((message.payload.keywords, message.payload.torrents))
     return packet,
Exemplo n.º 20
0
 def _encode_channelsearch(self, message):
     packet = encode(message.payload.keywords)
     return packet,
Exemplo n.º 21
0
 def _encode_channel(self, message):
     return encode((message.payload.name, message.payload.description)),
Exemplo n.º 22
0
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param message The message payload
        @param reply_callback Call this function once to send the reply: reply_callback(payload [, error=123])
        """
        if DEBUG:
            print >> sys.stderr, "databasecrawler: handle_crawler_request", show_permid_short(permid), message

        # execute the sql
        try:
            cursor = self._sqlite_cache_db.execute_read(message)

        except Exception, e:
            reply_callback(str(e), error=1)
        else:
            if cursor:
                reply_callback(encode(list(cursor)))
                # reply_callback(cPickle.dumps(list(cursor), 2))
            else:
                reply_callback("error", error=2)

    def handle_crawler_reply(self, permid, selversion, channel_id, channel_data, error, message, request_callback):
        """
        Received a CRAWLER_DATABASE_QUERY reply.
        @param permid The Crawler permid
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param error The error value. 0 indicates success.
        @param message The message payload
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if error:
 def _encode_channel(self, message):
     return encode((message.payload.name, message.payload.description)),
Exemplo n.º 24
0
 def _encode_search_response(self, message):
     packet = pack('!H',
                   message.payload.identifier), message.payload.results
     return encode(packet),
Exemplo n.º 25
0
    def _encode_mark_torrent(self, message):
        dict = {"infohash":message.payload.infohash,
                "timestamp":message.payload.timestamp,
                "type":message.payload.type}

        return encode(dict),
Exemplo n.º 26
0
 def _encode_encr_response(self, message):
     str_identifer = pack("!H", message.payload.identifier)
     str_prefs = pack("!"+"128s"*len(message.payload.preference_list), *[long_to_bytes(preference, 128) for preference in message.payload.preference_list])
     str_hprefs = pack("!"+"20s"*len(message.payload.his_preference_list), *message.payload.his_preference_list)
     return encode([str_identifer, str_prefs, str_hprefs]),
Exemplo n.º 27
0
 def create_msg():
     return encode(message.payload.torrents) 
Exemplo n.º 28
0
 def _encode_channelsearch(self, message):
     packet = encode(message.payload.keywords)
     return packet,
Exemplo n.º 29
0
 def create_msg():
     normal_msg = pack('!20sQ', message.payload.infohash, message.payload.timestamp), message.payload.name, tuple(files), tuple(trackers)
     normal_msg = encode(normal_msg)
     return zlib.compress(normal_msg)
Exemplo n.º 30
0
 def _encode_channelsearch_response(self, message):
     packet = encode((message.payload.keywords, message.payload.torrents))
     return packet,
Exemplo n.º 31
0
 def _encode_search_request(self, message):
     packet = pack('!H', message.payload.identifier), message.payload.keywords
     if message.payload.bloom_filter:
         packet = packet + (message.payload.bloom_filter.functions, message.payload.bloom_filter.prefix, message.payload.bloom_filter.bytes)
     packet = encode(packet)
     return packet,
Exemplo n.º 32
0
 def create_msg():
     return encode(message.payload.torrents)
Exemplo n.º 33
0
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param message The message payload
        @param reply_callback Call this function once to send the reply: reply_callback(payload [, error=123])
        """
        if DEBUG:
            print >> sys.stderr, "repexcrawler: handle_crawler_request", show_permid_short(
                permid), message

        # retrieve repex history
        try:
            repexhistory = self._repexlog.getHistoryAndCleanup()

        except Exception, e:
            reply_callback(str(e), error=1)
        else:
            reply_callback(encode(repexhistory))
            # reply_callback(cPickle.dumps(repexhistory, 2))

    def handle_crawler_reply(self, permid, selversion, channel_id,
                             channel_data, error, message, request_callback):
        """
        Received a CRAWLER_REPEX_QUERY reply.
        @param permid The Crawler permid
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param error The error value. 0 indicates success.
        @param message The message payload
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if error:
            if DEBUG:
Exemplo n.º 34
0
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param message The message payload
        @param reply_callback Call this function once to send the reply: reply_callback(payload [, error=123])
        """
        if DEBUG:
            print >> sys.stderr, "repexcrawler: handle_crawler_request", show_permid_short(permid), message

        # retrieve repex history
        try:
            repexhistory = self._repexlog.getHistoryAndCleanup()

        except Exception, e:
            reply_callback(str(e), error=1)
        else:
            reply_callback(encode(repexhistory))
            # reply_callback(cPickle.dumps(repexhistory, 2))

    def handle_crawler_reply(self, permid, selversion, channel_id, channel_data, error, message, request_callback):
        """
        Received a CRAWLER_REPEX_QUERY reply.
        @param permid The Crawler permid
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param error The error value. 0 indicates success.
        @param message The message payload
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if error:
            if DEBUG:
                print >> sys.stderr, "repexcrawler: handle_crawler_reply", error, message