コード例 #1
0
 def create_good_simpleplustorrents_reply(self,id):
     d = self.create_good_simple_reply_dict(id)
     bmetainfo = bencode(self.tdef.get_metainfo())
     d['a'][self.tdef.get_infohash()]['torrent_size'] = len(bmetainfo)
     d['a'][self.tdef.get_infohash()]['metatype'] = 'application/x-tribler-stream' 
     d['a'][self.tdef.get_infohash()]['metadata'] = bmetainfo 
     b = bencode(d)
     return QUERY_REPLY+b
コード例 #2
0
ファイル: test_dlhelp.py プロジェクト: duy/tribler
 def create_bad_metadata_bad_torrent2(self):
     torrent = {}
     data = bencode(torrent)
     
     d = self.create_good_metadata_dict(data)
     d['metadata'] = data
     bd = bencode(d)
     return METADATA+bd
    def create_bad_metadata_bad_torrent3(self):
        torrent = {'info': 481}
        data = bencode(torrent)

        d = self.create_good_metadata_dict(data)
        d['metadata'] = data
        bd = bencode(d)
        return METADATA + bd
 def create_good_simpleplustorrents_reply(self,id):
     d = self.create_good_simple_reply_dict(id)
     bmetainfo = bencode(self.tdef.get_metainfo())
     d['a'][self.tdef.get_infohash()]['torrent_size'] = len(bmetainfo)
     d['a'][self.tdef.get_infohash()]['metatype'] = 'application/x-tribler-stream'
     d['a'][self.tdef.get_infohash()]['metadata'] = bmetainfo
     b = bencode(d)
     return QUERY_REPLY+b
コード例 #5
0
    def create_bad_metadata_bad_torrent3(self):
        torrent = {"info": 481}
        data = bencode(torrent)

        d = self.create_good_metadata_dict(data)
        d["metadata"] = data
        bd = bencode(d)
        return METADATA + bd
コード例 #6
0
    def save_torrent(self, torrent_data, source=''):
        if 'info' in torrent_data:
            infohash = sha.sha(bencode(torrent_data['info'])).digest()
            if not self.torrent_db.hasTorrent(infohash):
                if DEBUG:
                    print >> sys.stderr, "subscrip:Injecting", torrent_data[
                        "info"].get("name", infohash)

                hexinfohash = binascii.hexlify(infohash)
                if DEBUG:
                    print >> sys.stderr, "subscript: Writing", hexinfohash

                filename = os.path.join(self.torrent_dir,
                                        hexinfohash + '.torrent')
                f = open(filename, "wb")
                f.write(bencode(torrent_data))
                f.close()

                # Arno: hack, make sure these torrents are always good so they show up
                # in Torrent DBHandler.getTorrents()
                extra_info = {'status': 'good'}
                extra_info['filename'] = filename

                torrentdef = TorrentDef.load_from_dict(torrent_data)
                self.torrent_db.addExternalTorrent(torrentdef,
                                                   source=source,
                                                   extra_info=extra_info)

        # perform all url-specific callbacks
        for feed, on_torrent_callback, callback in self.feeds:
            if feed.feed_url == source:
                if on_torrent_callback:
                    if DEBUG:
                        print >> sys.stderr, "ON TORRENT CALLBACK"
                    on_torrent_callback(source, infohash, torrent_data)
                if callback:
                    if DEBUG:
                        print >> sys.stderr, "USER CALLBACK"
                    callback(source, infohash, torrent_data)
                break

        # perform all non-url-specific callbacks
        self.lock.acquire()
        callbacks = self.callbacks[:]
        self.lock.release()

        for callback in callbacks:
            try:
                if DEBUG:
                    print >> sys.stderr, "RSS CALLBACK"
                callback(source, infohash, torrent_data)
            except:
                traceback.print_exc()
コード例 #7
0
ファイル: rss_client.py プロジェクト: duy/tribler
    def save_torrent(self, torrent_data, source = ''):
        if 'info' in torrent_data:
            infohash = sha.sha(bencode(torrent_data['info'])).digest()
            if not self.torrent_db.hasTorrent(infohash):
                if DEBUG:
                    print >>sys.stderr,"subscrip:Injecting", torrent_data["info"].get("name", infohash)
                
                hexinfohash = binascii.hexlify(infohash)
                if DEBUG:
                    print >>sys.stderr,"subscript: Writing",hexinfohash
        
                filename = os.path.join(self.torrent_dir, hexinfohash+'.torrent' )
                f = open(filename,"wb")
                f.write(bencode(torrent_data))
                f.close()
        
                # Arno: hack, make sure these torrents are always good so they show up
                # in Torrent DBHandler.getTorrents()
                extra_info = {'status':'good'}
                extra_info['filename'] = filename
                
                torrentdef = TorrentDef.load_from_dict(torrent_data)
                self.torrent_db.addExternalTorrent(torrentdef,source=source,extra_info=extra_info)
                        
        # perform all url-specific callbacks
        for feed, on_torrent_callback, callback in self.feeds:
            if feed.feed_url == source:
                if on_torrent_callback:
                    if DEBUG: 
                        print >> sys.stderr , "ON TORRENT CALLBACK"
                    on_torrent_callback(source, infohash, torrent_data)
                if callback:
                    if DEBUG: 
                        print >> sys.stderr , "USER CALLBACK"
                    callback(source, infohash, torrent_data)
                break

        # perform all non-url-specific callbacks
        self.lock.acquire()
        callbacks = self.callbacks[:]
        self.lock.release()
        
        for callback in callbacks:
            try:
                if DEBUG:
                    print >> sys.stderr , "RSS CALLBACK"
                callback(source, infohash, torrent_data)
            except:
                traceback.print_exc()
コード例 #8
0
    def subtest_good_friendship_stats(self):
        """
        Send a valid message-id from a registered crawler peer
        """
        print >>sys.stderr, "-"*80, "\ntest: good friendship stats"

        s = OLConnection(self.my_keypair, "localhost", self.hisport)

        t = time.time() - 100.0
        msg_dict = {'current time':int(t)}
        payload = bencode(msg_dict)
        self.send_crawler_request(s, CRAWLER_FRIENDSHIP_STATS, 0, 0, payload)

        error, payload = self.receive_crawler_reply(s, CRAWLER_FRIENDSHIP_STATS, 0)
        assert error == 0
        
        d = bdecode(payload)
        if DEBUG:
            print >>sys.stderr, "test: Got FRIENDSHIPSTATISTICS",`d`
        stats = d['stats']
        self.assert_(len(stats) == 1)
        record = d['stats'][0]
        self.assert_(record[0] == bin2str(self.his_permid))  # source_permid
        self.assert_(record[1] == bin2str(self.some_permid)) # target_permid
        self.assert_(record[2] == 0) # isForwarder

        time.sleep(1)
        s.close()
コード例 #9
0
 def create_diff_ips(self, i):
     if self.NLISTENERS == 1:
         s = REPLY_IP
     else:
         s = '127.0.0.' + str(i)
     b = bencode(s)
     return DIALBACK_REPLY + b
コード例 #10
0
 def create_diff_ips(self,i):
     if self.NLISTENERS==1:
         s = REPLY_IP
     else:
         s = '127.0.0.'+str(i)
     b = bencode(s)
     return DIALBACK_REPLY+b
コード例 #11
0
    def get_default_torrent(self, filename, title, paths=None):
        metainfo = {}
        metainfo["announce"] = "http://localhost:0/announce"
        metainfo["announce-list"] = []
        metainfo["creation date"] = int(time.time())
        metainfo["encoding"] = "UTF-8"
        info = {}
        info["name"] = title.encode("UTF-8")
        info["piece length"] = 2 ** 16
        info["pieces"] = "*" * 20
        if paths is None:
            info["length"] = 481
        else:
            d1 = {}
            d1["path"] = [paths[0].encode("UTF-8")]
            d1["length"] = 201
            d2 = {}
            d2["path"] = [paths[1].encode("UTF-8")]
            d2["length"] = 280
            info["files"] = [d1, d2]

        metainfo["info"] = info
        path = os.path.join(self.config.get_torrent_collecting_dir(), filename)
        tdef = TorrentDef.load_from_dict(metainfo)
        tdef.save(path)
        return tdef, bencode(metainfo)
コード例 #12
0
def hack_make_default_merkletorrent(title):
    metainfo = {}
    metainfo['announce'] = 'http://localhost:0/announce'
    metainfo['creation date'] = int(time.time())
    info = {}
    info['name'] = title
    info['length'] = 2**30
    info['piece length'] = 2**16
    info['root hash'] = '*' * 20
    metainfo['info'] = info

    mdict = {}
    mdict['Publisher'] = 'Tribler'
    mdict['Description'] = ''
    mdict['Progressive'] = 1
    mdict['Speed Bps'] = str(2**16)
    mdict['Title'] = metainfo['info']['name']
    mdict['Creation Date'] = long(time.time())
    # Azureus client source code doesn't tell what this is, so just put in random value from real torrent
    mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY'
    mdict['Revision Date'] = long(time.time())
    cdict = {}
    cdict['Content'] = mdict
    metainfo['azureus_properties'] = cdict

    return bencode(metainfo)
コード例 #13
0
ファイル: test_ut_pex.py プロジェクト: duy/tribler
 def create_dropped_not_str(self):
     d = {}
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = 481
     bd = bencode(d)
     return EXTEND+chr(1)+bd
コード例 #14
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_not_hashpiece(self, chunkid):
     index, begin, length = chunkid
     ohlist = []
     bohlist = bencode(ohlist)
     chunk = self.read_chunk(index, begin, length)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + chr(231) + payload
    def test_receivedSUBSOtherRequest(self):
        langUtil = LanguagesProvider.getLanguagesInstance()
        data = {
                'permid' : testDestPermId,
                'channel_id' : testChannelId,
                'infohash' : testInfohash,
                'subtitles' : {"eng" : "This is content 1", "nld": "This is content  2",
                               "ita" : "This is content 3"},
                'selversion' : OLPROTO_VER_FOURTEENTH
                }
        langs = data['subtitles'].keys()

        bitmask = langUtil.langCodesToMask(langs)
        binaryBitmask = pack("!L", bitmask)
        expextedMessage = SUBS + \
                            bencode((
                                    data['channel_id'],
                                    data['infohash'],
                                    binaryBitmask,
                                    [data['subtitles']['eng'], data['subtitles']['ita'],
                                     data['subtitles']['nld']]
                                     ))

        list = MockMsgListener()
        self.underTest.registerListener(list)

        #invalid bitmask
        self.underTest._addToRequestedSubtitles(testChannelId, testInfohash, int(0xFFFFFFFF & ~bitmask), None)

        val = self.underTest.handleMessage(testDestPermId, OLPROTO_VER_FOURTEENTH, expextedMessage)
        # never had a request for this message should be dropped
        self.assertFalse(val)
        self.assertEquals(0,list.subsCount)
コード例 #16
0
    def do_GET(self):

        print >> sys.stderr, "test: tracker: Got GET request", self.path

        p = []
        p1 = {
            'peer id': self.server.myid,
            'ip': self.server.myip,
            'port': self.server.myport
        }
        p.append(p1)
        d = {}
        d['interval'] = 1800
        d['peers'] = p
        bd = bencode(d)
        size = len(bd)

        self.send_response(200)
        self.send_header("Content-Type", "application/octet-stream")
        self.send_header("Content-Length", size)
        self.end_headers()

        try:
            self.wfile.write(bd)
        except Exception, e:
            print_exc()
コード例 #17
0
 def create_good_ut_pex(self, pex_id=1):
     d = {}
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = ''
     bd = bencode(d)
     return EXTEND + chr(pex_id) + bd
コード例 #18
0
ファイル: ut_pex.py プロジェクト: Anbcorp/tribler
def create_ut_pex(addedconns, droppedconns, thisconn):
    # print >>sys.stderr,"ut_pex: create_ut_pex:",addedconns,droppedconns,thisconn

    # Niels: Force max 50 added/dropped connections
    # "Some clients may choose to enforce these limits and drop connections which don't obey these limits."
    # http://wiki.theory.org/BitTorrentPeerExchangeConventions
    addedconns = addedconns[:50]
    droppedconns = droppedconns[:50]

    d = {}
    compactedpeerstr = compact_connections(addedconns, thisconn)
    d['added'] = compactedpeerstr
    flags = ''
    for i in range(len(addedconns)):
        conn = addedconns[i]
        if conn == thisconn:
            continue
        flag = 0
        if conn.get_extend_encryption():
            flag |= 1
        if conn.download is not None and conn.download.peer_is_complete():
            flag |= 2
        if conn.is_tribler_peer():
            flag |= 4

        # print >>sys.stderr,"ut_pex: create_ut_pex: add flag",`flag`
        flags += chr(flag)
    d['added.f'] = flags
    compactedpeerstr = compact_connections(droppedconns)
    d['dropped'] = compactedpeerstr
    return bencode(d)
コード例 #19
0
ファイル: test_ut_pex.py プロジェクト: duy/tribler
 def create_dropped_too_small(self):
     d = {}        
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = '\x82\x25\xc1\x40\x00' # should be 6 bytes
     bd = bencode(d)
     return EXTEND+chr(1)+bd
コード例 #20
0
ファイル: test_ut_pex.py プロジェクト: duy/tribler
 def create_added_f_too_big(self):
     d = {}
     d['added'] = ''
     d['added.f'] = '\x00'
     d['dropped'] = ''
     bd = bencode(d)
     return EXTEND+chr(1)+bd
コード例 #21
0
ファイル: Search.py プロジェクト: Devristo/tribler
def hack_make_default_merkletorrent(title):
    metainfo = {}
    metainfo['announce'] = 'http://localhost:0/announce'
    metainfo['creation date'] = int(time.time())
    info = {}
    info['name'] = title
    info['length'] = 2 ** 30
    info['piece length'] = 2 ** 16
    info['root hash'] = '*' * 20
    metainfo['info'] = info

    mdict = {}
    mdict['Publisher'] = 'Tribler'
    mdict['Description'] = ''
    mdict['Progressive'] = 1
    mdict['Speed Bps'] = str(2 ** 16)
    mdict['Title'] = metainfo['info']['name']
    mdict['Creation Date'] = long(time.time())
    # Azureus client source code doesn't tell what this is, so just put in random value from real torrent
    mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY'
    mdict['Revision Date'] = long(time.time())
    cdict = {}
    cdict['Content'] = mdict
    metainfo['azureus_properties'] = cdict

    return bencode(metainfo)
コード例 #22
0
def create_ut_pex(addedconns,droppedconns,thisconn):
    #print >>sys.stderr,"ut_pex: create_ut_pex:",addedconns,droppedconns,thisconn

    #Niels: Force max 50 added/dropped connections
    #"Some clients may choose to enforce these limits and drop connections which don't obey these limits."
    #http://wiki.theory.org/BitTorrentPeerExchangeConventions
    addedconns = addedconns[:50]
    droppedconns = droppedconns[:50]

    d = {}
    compactedpeerstr = compact_connections(addedconns,thisconn)
    d['added'] = compactedpeerstr
    flags = ''
    for i in range(len(addedconns)):
        conn = addedconns[i]
        if conn == thisconn:
            continue
        flag = 0
        if conn.get_extend_encryption():
            flag |= 1
        if conn.download is not None and conn.download.peer_is_complete():
            flag |= 2
        if conn.is_tribler_peer():
            flag |= 4

        #print >>sys.stderr,"ut_pex: create_ut_pex: add flag",`flag`
        flags += chr(flag)
    d['added.f'] = flags
    compactedpeerstr = compact_connections(droppedconns)
    d['dropped'] = compactedpeerstr
    return bencode(d)
    def test_createSingleResponseMessage(self):
        langUtil = LanguagesProvider.getLanguagesInstance()
        data = {
                'permid' : testDestPermId,
                'channel_id' : testChannelId,
                'infohash' : testInfohash,
                'subtitles' : {"eng" : "This is content 1", "nld": "This is content  2",
                               "ita" : "This is content 3"},
                'selversion' : OLPROTO_VER_FOURTEENTH
                }
        langs = data['subtitles'].keys()

        bitmask = langUtil.langCodesToMask(langs)
        binaryBitmask = pack("!L", bitmask)
        expextedMessage = SUBS + \
                            bencode((
                                    data['channel_id'],
                                    data['infohash'],
                                    binaryBitmask,
                                    [data['subtitles']['eng'], data['subtitles']['ita'],
                                     data['subtitles']['nld']]
                                     ))
        msg = self.underTest._createSingleResponseMessage(data)
        decoded = bdecode(msg[1:])

        self.assertEquals(expextedMessage, msg)
コード例 #24
0
ファイル: test_permid.py プロジェクト: Devristo/tribler
 def check_response1(self,resp1_data,rB,myid):
     resp1 = bdecode(resp1_data)
     self.assert_(type(resp1) == DictType)
     self.assert_(resp1.has_key('certA'))
     self.assert_(resp1.has_key('rA'))
     self.assert_(resp1.has_key('B'))
     self.assert_(resp1.has_key('SA'))
     # show throw exception when key no good
     pubA = EC.pub_key_from_der(resp1['certA'])
     rA = resp1['rA']
     self.assert_(type(rA) == StringType)
     self.assert_(len(rA) == random_size)
     B = resp1['B']
     self.assert_(type(B) == StringType)
     self.assert_(B,myid)
     SA = resp1['SA']
     self.assert_(type(SA) == StringType)
     # verify signature
     sig_list = [rA,rB,myid]
     sig_data = bencode(sig_list)
     sig_hash = sha(sig_data).digest()
     self.assert_(pubA.verify_dsa_asn1(sig_hash,SA))
     # Cannot resign the data with his keypair to double check. Signing
     # appears to yield different, supposedly valid sigs each time.
     return resp1
コード例 #25
0
    def setUpPostSession(self):
        """ override TestAsServer """
        TestAsServer.setUpPostSession(self)

        self.mypermid = str(self.my_keypair.pub().get_der())
        self.hispermid = str(self.his_keypair.pub().get_der())

        # Calculating the infohash for proxyservice.test.torrent
        self.torrentfile = os.path.join('extend_hs_dir',
                                        'proxyservice.test.torrent')

        # Read torrentfile to calculate the infohash
        torrentfile_content = open(self.torrentfile, "rb")
        # Decode all the file
        metainfo = bdecode(torrentfile_content.read())
        # Re-encode only the info section
        self.infohash = hashlib.sha1(bencode(metainfo['info'])).digest()
        # Close the torrentfile
        torrentfile_content.close()

        # Add us as friend, so he will accept the ASK_FOR_HELP
        if False:  # TEMP
            friendsdb = FriendDBHandler.getInstance()
            friendsdb.addFriend(self.mypermid)
        else:
            self.session.set_overlay_request_policy(AllowAllRequestPolicy())

        self.session.set_download_states_callback(self.states_callback)
コード例 #26
0
    def subtest_invalidRequest3(self):
        """
        Trying to send an invalid message (valid for everythin except that there is one field more)
        The connection should be closed by the receiver
        """
        print >> sys.stderr, "test: test_subtitles_msgs_invalid_request_3 ------------------"
        ol_conn = OLConnection(self.my_keypair,'localhost',self.hisport)

        bitmask = LanguagesProvider.getLanguagesInstance().langCodesToMask(['nld','eng'])
        binmask = utilities.uintToBinaryString(bitmask, length=4)

        request = GET_SUBS + \
                      bencode((
                              self.anotherpermid,
                              self.testInfohash,
                              binmask,
                              42
                              ))

        ol_conn.send(request)
        self.assertEquals(0, len(ol_conn.recv()))
        print >> sys.stderr, "test: test_subtitles_msgs_invalid_request_3: connection closed as expected"

        ol_conn.close()
        print >> sys.stderr, "End of test_subtitles_msgs_invalid_request_3 ------------------"
コード例 #27
0
 def create_dropped_not_str(self):
     d = {}
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = 481
     bd = bencode(d)
     return EXTEND + chr(1) + bd
コード例 #28
0
ファイル: test_ut_pex.py プロジェクト: duy/tribler
 def create_good_ut_pex(self,pex_id=1):
     d = {}
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = ''
     bd = bencode(d)
     return EXTEND+chr(pex_id)+bd
コード例 #29
0
 def create_bad_chunk(self, chunkid):
     index, begin, length = chunkid
     ohlist = self.tree.get_hashes_for_piece(index)
     bohlist = bencode(ohlist)
     chunk = '*' * length
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload
コード例 #30
0
 def create_added_f_too_big(self):
     d = {}
     d['added'] = ''
     d['added.f'] = '\x00'
     d['dropped'] = ''
     bd = bencode(d)
     return EXTEND + chr(1) + bd
コード例 #31
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_bad_chunk(self, chunkid):
     index, begin, length = chunkid
     ohlist = self.tree.get_hashes_for_piece(index)
     bohlist = bencode(ohlist)
     chunk = "*" * length
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload
コード例 #32
0
 def create_dropped_too_small(self):
     d = {}
     d['added'] = ''
     d['added.f'] = ''
     d['dropped'] = '\x82\x25\xc1\x40\x00'  # should be 6 bytes
     bd = bencode(d)
     return EXTEND + chr(1) + bd
コード例 #33
0
ファイル: test_proxyservice.py プロジェクト: duy/tribler
    def setUpPostSession(self):
        """ override TestAsServer """
        TestAsServer.setUpPostSession(self)

        self.mypermid = str(self.my_keypair.pub().get_der())
        self.hispermid = str(self.his_keypair.pub().get_der())  
        
        # Calculating the infohash for proxyservice.test.torrent
        self.torrentfile = os.path.join('extend_hs_dir','proxyservice.test.torrent')
        
        # Read torrentfile to calculate the infohash
        torrentfile_content = open(self.torrentfile, "rb")
        # Decode all the file
        metainfo = bdecode(torrentfile_content.read())
        # Re-encode only the info section
        self.infohash = hashlib.sha1(bencode(metainfo['info'])).digest()
        # Close the torrentfile
        torrentfile_content.close()
        
        # Add us as friend, so he will accept the ASK_FOR_HELP
        if False:  # TEMP
            friendsdb = FriendDBHandler.getInstance()
            friendsdb.addFriend(self.mypermid)
        else:
            self.session.set_overlay_request_policy(AllowAllRequestPolicy())
          
        self.session.set_download_states_callback(self.states_callback)
コード例 #34
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_ohlist_wrong_no_hashes(self, chunkid):
     index, begin, length = chunkid
     ohlist = [(0, "#" * 20), (1, "$" * 20)]  # should contain 3 for file2.wmv: own, sibling and root
     bohlist = bencode(ohlist)
     chunk = "*" * (2 ** 14)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload
コード例 #35
0
 def check_response1(self, resp1_data, rB, myid):
     resp1 = bdecode(resp1_data)
     self.assert_(type(resp1) == DictType)
     self.assert_(resp1.has_key('certA'))
     self.assert_(resp1.has_key('rA'))
     self.assert_(resp1.has_key('B'))
     self.assert_(resp1.has_key('SA'))
     # show throw exception when key no good
     pubA = EC.pub_key_from_der(resp1['certA'])
     rA = resp1['rA']
     self.assert_(type(rA) == StringType)
     self.assert_(len(rA) == random_size)
     B = resp1['B']
     self.assert_(type(B) == StringType)
     self.assert_(B, myid)
     SA = resp1['SA']
     self.assert_(type(SA) == StringType)
     # verify signature
     sig_list = [rA, rB, myid]
     sig_data = bencode(sig_list)
     sig_hash = sha(sig_data).digest()
     self.assert_(pubA.verify_dsa_asn1(sig_hash, SA))
     # Cannot resign the data with his keypair to double check. Signing
     # appears to yield different, supposedly valid sigs each time.
     return resp1
コード例 #36
0
    def _create(metainfo):  # TODO: replace with constructor
        # raises ValueErrors if not good
        validTorrentFile(metainfo)

        t = TorrentDef()
        t.metainfo = metainfo
        t.metainfo_valid = True
        # copy stuff into self.input
        maketorrent.copy_metainfo_to_input(t.metainfo, t.input)

        # For testing EXISTING LIVE, or EXISTING MERKLE: DISABLE, i.e. keep true infohash
        if t.get_url_compat():
            t.infohash = makeurl.metainfo2swarmid(t.metainfo)
        else:
            # Two places where infohash calculated, here and in maketorrent.py
            # Elsewhere: must use TorrentDef.get_infohash() to allow P2PURLs.
            t.infohash = sha(bencode(metainfo['info'])).digest()

        assert isinstance(
            t.infohash,
            str), "INFOHASH has invalid type: %s" % type(t.infohash)
        assert len(
            t.infohash
        ) == INFOHASH_LENGTH, "INFOHASH has invalid length: %d" % len(
            t.infohash)

        #print >>sys.stderr,"INFOHASH",`t.infohash`

        return t
コード例 #37
0
ファイル: test_remote_query.py プロジェクト: duy/tribler
 def get_default_torrent(self,filename,title,paths=None):
     metainfo = {}
     metainfo['announce'] = 'http://localhost:0/announce'
     metainfo['announce-list'] = []
     metainfo['creation date'] = int(time.time())
     metainfo['encoding'] = 'UTF-8'
     info = {}
     info['name'] = title.encode("UTF-8")
     info['piece length'] = 2 ** 16
     info['pieces'] = '*' * 20
     if paths is None:
         info['length'] = 481
     else:
         d1 = {}
         d1['path'] = [paths[0].encode("UTF-8")]
         d1['length'] = 201
         d2 = {}
         d2['path'] = [paths[1].encode("UTF-8")]
         d2['length'] = 280
         info['files'] = [d1,d2]
         
     metainfo['info'] = info
     path = os.path.join(self.config.get_torrent_collecting_dir(),filename)
     tdef = TorrentDef.load_from_dict(metainfo)
     tdef.save(path)
     return tdef, bencode(metainfo)
コード例 #38
0
    def get_default_torrent(self, filename, title, paths=None):
        metainfo = {}
        metainfo['announce'] = 'http://localhost:0/announce'
        metainfo['announce-list'] = []
        metainfo['creation date'] = int(time.time())
        metainfo['encoding'] = 'UTF-8'
        info = {}
        info['name'] = title.encode("UTF-8")
        info['piece length'] = 2**16
        info['pieces'] = '*' * 20
        if paths is None:
            info['length'] = 481
        else:
            d1 = {}
            d1['path'] = [paths[0].encode("UTF-8")]
            d1['length'] = 201
            d2 = {}
            d2['path'] = [paths[1].encode("UTF-8")]
            d2['length'] = 280
            info['files'] = [d1, d2]

        metainfo['info'] = info
        path = os.path.join(self.config.get_torrent_collecting_dir(), filename)
        tdef = TorrentDef.load_from_dict(metainfo)
        tdef.save(path)
        return tdef, bencode(metainfo)
コード例 #39
0
 def create_not_hashpiece(self, chunkid):
     index, begin, length = chunkid
     ohlist = []
     bohlist = bencode(ohlist)
     chunk = self.read_chunk(index, begin, length)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + chr(231) + payload
コード例 #40
0
 def create_good_tribler_extend_hs(self):
     d = {}
     d['m'] = {'Tr_OVERLAYSWARM': 253}
     d['p'] = self.mylistenport
     d['v'] = 'Tribler 3.5.1'
     bd = bencode(d)
     return EXTEND + chr(0) + bd
コード例 #41
0
    def ValueToString(self, value, typex):
        if typex == "boolean":
            if value:
                text = "1"
            else:
                text = "0"
        elif typex == "color":
            red = str(value.Red())
            while len(red) < 3:
                red = "0" + red

            green = str(value.Green())
            while len(green) < 3:
                green = "0" + green

            blue = str(value.Blue())
            while len(blue) < 3:
                blue = "0" + blue

            text = str(red) + str(green) + str(blue)
        elif typex.startswith("bencode"):
            text = bencode(value)
        else:
            if type(value) is unicode:
                text = value
            else:
                text = str(value)

        return text
コード例 #42
0
 def test_receivedSUBSOtherRequest(self):
     langUtil = LanguagesProvider.getLanguagesInstance()
     data = {
             'permid' : testDestPermId,
             'channel_id' : testChannelId,
             'infohash' : testInfohash,
             'subtitles' : {"eng" : "This is content 1", "nld": "This is content  2",
                            "ita" : "This is content 3"},
             'selversion' : OLPROTO_VER_FOURTEENTH
             }
     langs = data['subtitles'].keys()
     
     bitmask = langUtil.langCodesToMask(langs)
     binaryBitmask = pack("!L", bitmask)
     expextedMessage = SUBS + \
                         bencode((
                                 data['channel_id'],
                                 data['infohash'],
                                 binaryBitmask,
                                 [data['subtitles']['eng'], data['subtitles']['ita'],
                                  data['subtitles']['nld']]
                                  ))
     
     list = MockMsgListener()
     self.underTest.registerListener(list) 
     
     #invalid bitmask
     self.underTest._addToRequestedSubtitles(testChannelId, testInfohash, int(0xFFFFFFFF & ~bitmask), None)                   
     
     val = self.underTest.handleMessage(testDestPermId, OLPROTO_VER_FOURTEENTH, expextedMessage)
     # never had a request for this message should be dropped
     self.assertFalse(val)
     self.assertEquals(0,list.subsCount)
コード例 #43
0
 def create_good_nontribler_extend_hs(self):
     d = {}
     d['m'] = {'hallo': 12, 'dag': 255}
     d['p'] = self.mylistenport
     d['v'] = 'TestSweet 1.2.3.4'
     bd = bencode(d)
     return EXTEND + chr(0) + bd
コード例 #44
0
ファイル: configreader.py プロジェクト: duy/tribler
    def ValueToString(self, value, typex):
        if typex == "boolean":
            if value:
                text = "1"
            else:
                text = "0"
        elif typex == "color":
            red = str(value.Red())
            while len(red) < 3:
                red = "0" + red

            green = str(value.Green())            
            while len(green) < 3:
                green = "0" + green
                
            blue = str(value.Blue())            
            while len(blue) < 3:
                blue = "0" + blue

            text = str(red) + str(green) + str(blue)
        elif typex.startswith("bencode"):
            text = bencode(value)
        else:
            if type(value) is unicode:
                text = value
            else:
                text = str(value)
        
        return text
コード例 #45
0
 def create_ohlist_wrong_no_hashes(self, chunkid):
     index, begin, length = chunkid
     ohlist = [(0, '#' * 20), (1, '$' * 20)]  # should contain 3 for file2.wmv: own, sibling and root
     bohlist = bencode(ohlist)
     chunk = '*' * (2 ** 14)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload
コード例 #46
0
ファイル: test_extend_hs.py プロジェクト: duy/tribler
 def create_good_tribler_extend_hs(self):
     d = {}
     d['m'] = {'Tr_OVERLAYSWARM':253}
     d['p'] = self.mylistenport
     d['v'] = 'Tribler 3.5.1'
     bd = bencode(d)
     return EXTEND+chr(0)+bd
コード例 #47
0
ファイル: test_extend_hs.py プロジェクト: duy/tribler
 def create_good_nontribler_extend_hs(self):
     d = {}
     d['m'] = {'hallo':12, 'dag':255 }
     d['p'] = self.mylistenport
     d['v'] = 'TestSweet 1.2.3.4'
     bd = bencode(d)
     return EXTEND+chr(0)+bd
    def subtest_invalidRequest3(self):
        """
        Trying to send an invalid message (valid for everythin except that there is one field more)
        The connection should be closed by the receiver
        """
        print >> sys.stderr, "test: test_subtitles_msgs_invalid_request_3 ------------------"
        ol_conn = OLConnection(self.my_keypair, 'localhost', self.hisport)

        bitmask = LanguagesProvider.getLanguagesInstance().langCodesToMask(
            ['nld', 'eng'])
        binmask = utilities.uintToBinaryString(bitmask, length=4)

        request = GET_SUBS + \
                      bencode((
                              self.anotherpermid,
                              self.testInfohash,
                              binmask,
                              42
                              ))

        ol_conn.send(request)
        self.assertEquals(0, len(ol_conn.recv()))
        print >> sys.stderr, "test: test_subtitles_msgs_invalid_request_3: connection closed as expected"

        ol_conn.close()
        print >> sys.stderr, "End of test_subtitles_msgs_invalid_request_3 ------------------"
コード例 #49
0
 def test_createSingleResponseMessage(self):
     langUtil = LanguagesProvider.getLanguagesInstance()
     data = {
             'permid' : testDestPermId,
             'channel_id' : testChannelId,
             'infohash' : testInfohash,
             'subtitles' : {"eng" : "This is content 1", "nld": "This is content  2",
                            "ita" : "This is content 3"},
             'selversion' : OLPROTO_VER_FOURTEENTH
             }
     langs = data['subtitles'].keys()
     
     bitmask = langUtil.langCodesToMask(langs)
     binaryBitmask = pack("!L", bitmask)
     expextedMessage = SUBS + \
                         bencode((
                                 data['channel_id'],
                                 data['infohash'],
                                 binaryBitmask,
                                 [data['subtitles']['eng'], data['subtitles']['ita'],
                                  data['subtitles']['nld']]
                                  ))
     msg = self.underTest._createSingleResponseMessage(data)
     decoded = bdecode(msg[1:])
     
     self.assertEquals(expextedMessage, msg)
コード例 #50
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_good_nontribler_extend_hs(self):
     """ Merkle BEP style """
     d = {}
     d["m"] = {"Tr_hashpiece": 250}
     d["p"] = self.mylistenport
     d["v"] = "TestSweet 1.2.3.4"
     bd = bencode(d)
     return EXTEND + chr(0) + bd
    def create_good_metadata(self):
        f = open(self.torrentfile, "rb")
        data = f.read()
        f.close()

        d = self.create_good_metadata_dict(data)
        bd = bencode(d)
        return METADATA + bd
コード例 #52
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_good_tribler_extend_hs(self):
     """ old Tribler style """
     d = {}
     d["m"] = {"Tr_OVERLAYSWARM": 253}
     d["p"] = self.mylistenport
     d["v"] = "Tribler 3.5.1"
     bd = bencode(d)
     return EXTEND + chr(0) + bd
コード例 #53
0
 def create_good_extend_metadata_reply(self, metadata_id, piece):
     payload = {
         "msg_type": 1,
         "piece": piece,
         "total_size": len(self.metadata_list[piece])
     }
     return EXTEND + chr(metadata_id) + bencode(
         payload) + self.metadata_list[piece]
コード例 #54
0
 def create_good_nontribler_extend_hs(self):
     """ Merkle BEP style """
     d = {}
     d['m'] = {'Tr_hashpiece': 250}
     d['p'] = self.mylistenport
     d['v'] = 'TestSweet 1.2.3.4'
     bd = bencode(d)
     return EXTEND + chr(0) + bd
コード例 #55
0
 def subtest_bad_votecast(self, vdata):
     s = OLConnection(self.my_keypair, 'localhost', self.hisport)
     vcast = VoteCastCore(None, s, self.session, None, log='', dnsindb=None)
     print >> sys.stderr, "Test Bad VoteCast", ` vdata `
     msg = VOTECAST + bencode(vdata)
     s.send(msg)
     self.assert_(len(s.recv()) == 0)
     s.close()
コード例 #56
0
    def create_good_metadata(self):
        f = open(self.torrentfile, "rb")
        data = f.read()
        f.close()

        d = self.create_good_metadata_dict(data)
        bd = bencode(d)
        return METADATA + bd
コード例 #57
0
 def create_ohlist_wrong_bad_hash(self, chunkid):
     index, begin, length = chunkid
     ohlist = self.tree.get_hashes_for_piece(index)
     ohlist[1][1] = '$' * 20
     bohlist = bencode(ohlist)
     chunk = self.read_chunk(index, begin, length)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload
コード例 #58
0
 def create_good_extend_handshake(self):
     payload = {
         "m": {
             "ut_metadata": 3
         },
         "metadata_size": self.metadata_size
     }
     return EXTEND + chr(0) + bencode(payload)
コード例 #59
0
ファイル: test_magnetlink.py プロジェクト: Devristo/tribler
    def bad_request_and_disconnect(self, payload):
        conn = BTConnection("localhost", self.hisport, user_infohash=self.tdef.get_infohash())
        conn.send(self.create_good_extend_handshake())
        conn.read_handshake_medium_rare()
        metadata_id = self.read_extend_handshake(conn)

        conn.send(EXTEND + chr(metadata_id) + bencode(payload))
        self.read_extend_metadata_close(conn)
コード例 #60
0
ファイル: test_merkle_msg.py プロジェクト: Barrykilby/tribler
 def create_ohlist_wrong_bad_hash(self, chunkid):
     index, begin, length = chunkid
     ohlist = self.tree.get_hashes_for_piece(index)
     ohlist[1][1] = "$" * 20
     bohlist = bencode(ohlist)
     chunk = self.read_chunk(index, begin, length)
     payload = tobinary(index) + tobinary(begin) + tobinary(len(bohlist)) + bohlist + chunk
     return EXTEND + HASHPIECE + payload