예제 #1
0
    def tryHolePunching(self):
        if DEBUG:
            print >> sys.stderr, "NatCheckMsgHandler: first element in peerlist", self.peerlist[
                len(self.peerlist) - 1]
            print >> sys.stderr, "NatCheckMsgHandler: second element in peerlist", self.peerlist[
                len(self.peerlist) - 2]

        holePunchingPort = random.randrange(3200, 4200, 1)
        holePunchingAddr = (self.holePunchingIP, holePunchingPort)

        peer1 = self.peerlist[len(self.peerlist) - 1]
        peer2 = self.peerlist[len(self.peerlist) - 2]

        request_id = str(
            show_permid_short(peer1[0]) + show_permid_short(peer2[0]) +
            str(random.randrange(0, 1000, 1)))

        self.udpConnect(peer1[0], request_id, holePunchingAddr)
        self.udpConnect(peer2[0], request_id, holePunchingAddr)

        # Register peerinfo on file
        self._file2.write("; ".join(
            (strftime("%Y/%m/%d %H:%M:%S"), "REQUEST", request_id,
             show_permid(peer1[0]), str(peer1[1]), str(peer1[2]),
             str(self._secure_overlay.get_dns_from_peerdb(peer1[0])),
             show_permid(peer2[0]), str(peer2[1]), str(peer2[2]),
             str(self._secure_overlay.get_dns_from_peerdb(peer2[0])), "\n")))
        self._file2.flush()

        self.trav[request_id] = (None, None)
        thread.start_new_thread(coordinateHolePunching,
                                (peer1, peer2, holePunchingAddr))
예제 #2
0
    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

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, "repexcrawler: handle_crawler_reply", show_permid_short(permid), len(message), "bytes"
            
            # The message is pickled, which we will just write to file.
            # To make later parsing easier, we base64 encode it
            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), base64.b64encode(message), "\n")))
            self._file.flush()
예제 #3
0
    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

            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, "repexcrawler: handle_crawler_reply", show_permid_short(
                    permid), len(message), "bytes"

            # The message is pickled, which we will just write to file.
            # To make later parsing easier, we base64 encode it
            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(error), base64.b64encode(message), "\n")))
            self._file.flush()
 def handle_crawler_reply(self, permid, selversion, channel_id, channel_data, error, message, request_callback):
     """
     Received a CRAWLER_USEREVENTLOG_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, "usereventlogcrawler: handle_crawler_reply", error, message
             
         msg = "; ".join(['REPLY', show_permid(permid), str(error), str(message)])
         self.__log(msg)
     else:
         if DEBUG:
             print >> sys.stderr, "usereventlogcrawler: handle_crawler_reply", show_permid_short(permid), len(message), "bytes"
         
         try:
             loaded_message = decode(message)
         except:
             print_exc()
             loaded_message = cPickle.loads(message)
             
         msg = "; ".join(['REPLY', show_permid(permid), str(error), str(loaded_message)])
         self.__log(msg)
예제 #5
0
    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:
            if DEBUG:
                print >> sys.stderr, "databasecrawler: handle_crawler_reply", error, message

            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, "databasecrawler: handle_crawler_reply", show_permid_short(
                    permid), len(message), "bytes"

            # 24/06/11 boudewijn: we are storing the received message in HEX format.  unfortunately
            # this will make it unreadable in the text file, however, it will protect against pickle
            # security issues while still being compatible with both the secure (encode) and the
            # unsecure (pickle) crawlers on the client side.  when parsing the logs care needs to be
            # taken when parsing the pickled data!
            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(error), message.encode("HEX"), "\n")))
            # self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), str(cPickle.loads(message)), "\n")))
            self._file.flush()
예제 #6
0
    def tryHolePunching(self):
        if DEBUG:
            print >> sys.stderr, time.asctime(),'-', "NatCheckMsgHandler: first element in peerlist", self.peerlist[len(self.peerlist)-1]
            print >> sys.stderr, time.asctime(),'-', "NatCheckMsgHandler: second element in peerlist", self.peerlist[len(self.peerlist)-2]

        holePunchingPort = random.randrange(3200, 4200, 1)
        holePunchingAddr = (self.holePunchingIP, holePunchingPort)
        
        peer1 = self.peerlist[len(self.peerlist)-1]
        peer2 = self.peerlist[len(self.peerlist)-2]

        request_id = str(show_permid_short(peer1[0]) + show_permid_short(peer2[0]) + str(random.randrange(0, 1000, 1)))

        self.udpConnect(peer1[0], request_id, holePunchingAddr)
        self.udpConnect(peer2[0], request_id, holePunchingAddr)

        # Register peerinfo on file
        self._file2.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"),
                                    "REQUEST",
                                    request_id,
                                    show_permid(peer1[0]),
                                    str(peer1[1]),
                                    str(peer1[2]),
                                    str(self._secure_overlay.get_dns_from_peerdb(peer1[0])),
                                    show_permid(peer2[0]),
                                    str(peer2[1]),
                                    str(peer2[2]),
                                    str(self._secure_overlay.get_dns_from_peerdb(peer2[0])),
                                    "\n")))
        self._file2.flush()

        self.trav[request_id] = (None, None)
        thread.start_new_thread(coordinateHolePunching, (peer1, peer2, holePunchingAddr))
    def process_query(self, permid, d, selversion):
        q = d['q'][len('SIMPLE '):]
        q = dunno2unicode(q)
        # Format: 'SIMPLE '+string of space separated keywords
        # In the future we could support full SQL queries:
        # SELECT infohash,torrent_name FROM torrent_db WHERE status = ALIVE
        kws = q.split()
        hits = self.search_manager.search(kws, maxhits=MAX_RESULTS)

        p = self.create_query_reply(d['id'], hits)
        m = QUERY_REPLY + p

        if self.overlay_log:
            nqueries = self.get_peer_nqueries(permid)
            # RECV_MSG PERMID OVERSION NUM_QUERIES MSG
            self.overlay_log('RECV_QRY', show_permid(permid), selversion,
                             nqueries, repr(d))

            # RPLY_QRY PERMID NUM_HITS MSG
            self.overlay_log('RPLY_QRY', show_permid(permid), len(hits),
                             repr(p))

        self.overlay_bridge.send(permid, m, self.send_callback)

        self.inc_peer_nqueries(permid)
    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:
            if DEBUG:
                print >> sys.stderr, "databasecrawler: handle_crawler_reply", error, message

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, "databasecrawler: handle_crawler_reply", show_permid_short(permid), len(message), "bytes"

            # 24/06/11 boudewijn: we are storing the received message in HEX format.  unfortunately
            # this will make it unreadable in the text file, however, it will protect against pickle
            # security issues while still being compatible with both the secure (encode) and the
            # unsecure (pickle) crawlers on the client side.  when parsing the logs care needs to be
            # taken when parsing the pickled data!
            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), message.encode("HEX"), "\n")))
            # self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), str(cPickle.loads(message)), "\n")))
            self._file.flush()
예제 #9
0
    def gotUdpConnectReply(self, permid, selversion, channel_id, channel_data, error, mhr_msg, request_callback):

        if DEBUG:
            print >>sys.stderr, "NatCheckMsgHandler: gotMakeHoleReplyMessage"

        try:
            mhr_data = bdecode(mhr_msg)
        except:
            print_exc()
            print >>sys.stderr, "NatCheckMsgHandler: bad encoded data:", mhr_msg
            return False

        if DEBUG:
            print >>sys.stderr, "NatCheckMsgHandler: message is", mhr_data

        try:
            request_id, reply = mhr_data.split(":")
        except:
            print_exc()
            print >>sys.stderr, "NatCheckMsgHandler: error in received data:", mhr_data
            return False

        if DEBUG:
            print >>sys.stderr, "NatCheckMsgHandler: request_id is", request_id

        if request_id in self.trav:
            if DEBUG:
                print >>sys.stderr, "NatCheckMsgHandler: request_id is in the list"
            peer, value = self.trav[request_id]
            if peer == None:  # first peer reply
                if DEBUG:
                    print >>sys.stderr, "NatCheckMsgHandler: first peer reply"
                self.trav[request_id] = ((permid, self._secure_overlay.get_dns_from_peerdb(permid)), reply)
            elif type(peer) == TupleType:  # second peer reply
                if DEBUG:
                    print >>sys.stderr, "NatCheckMsgHandler: second peer reply"

                # Register peerinfo on file
                self._file2.write(
                    "; ".join(
                        (
                            strftime("%Y/%m/%d %H:%M:%S"),
                            "  REPLY",
                            request_id,
                            show_permid(peer[0]),
                            str(peer[1]),
                            value,
                            show_permid(permid),
                            str(self._secure_overlay.get_dns_from_peerdb(permid)),
                            reply,
                            "\n",
                        )
                    )
                )

                del self.trav[request_id]

        self._file2.flush()
예제 #10
0
    def gotUdpConnectReply(self, permid, selversion, channel_id, channel_data,
                           error, mhr_msg, request_callback):

        if DEBUG:
            print >> sys.stderr, "NatCheckMsgHandler: gotMakeHoleReplyMessage"

        try:
            mhr_data = bdecode(mhr_msg)
        except:
            print_exc()
            print >> sys.stderr, "NatCheckMsgHandler: bad encoded data:", mhr_msg
            return False

        if DEBUG:
            print >> sys.stderr, "NatCheckMsgHandler: message is", mhr_data

        try:
            request_id, reply = mhr_data.split(":")
        except:
            print_exc()
            print >> sys.stderr, "NatCheckMsgHandler: error in received data:", mhr_data
            return False

        if DEBUG:
            print >> sys.stderr, "NatCheckMsgHandler: request_id is", request_id

        if request_id in self.trav:
            if DEBUG:
                print >> sys.stderr, "NatCheckMsgHandler: request_id is in the list"
            peer, value = self.trav[request_id]
            if peer == None:  # first peer reply
                if DEBUG:
                    print >> sys.stderr, "NatCheckMsgHandler: first peer reply"
                self.trav[request_id] = ((
                    permid, self._secure_overlay.get_dns_from_peerdb(permid)),
                                         reply)
            elif type(peer) == TupleType:  # second peer reply
                if DEBUG:
                    print >> sys.stderr, "NatCheckMsgHandler: second peer reply"

                # Register peerinfo on file
                self._file2.write("; ".join(
                    (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", request_id,
                     show_permid(peer[0]), str(peer[1]), value,
                     show_permid(permid),
                     str(self._secure_overlay.get_dns_from_peerdb(permid)),
                     reply, "\n")))

                del self.trav[request_id]

        self._file2.flush()
    def process_query(self, permid, d, selversion):
        hits = None
        p = None
        sendtorrents = False

        netwq = d['q']
        if netwq.startswith("SIMPLE"): # remote query
            # Format: 'SIMPLE '+string of space separated keywords or
            #         'SIMPLE+METADATA' +string of space separated keywords
            #
            # In the future we could support full SQL queries:
            # SELECT infohash,torrent_name FROM torrent_db WHERE status = ALIVE
            
            if netwq.startswith('SIMPLE+METADATA'):
                q = d['q'][len('SIMPLE+METADATA '):]
                sendtorrents = True
            else:
                q = d['q'][len('SIMPLE '):]
                    
            uq = self.clean_netwq(q)
            kws = split_into_keywords(uq)
            hits = self.search_torrents(kws, maxhits=MAX_RESULTS,sendtorrents=sendtorrents)
            p = self.create_remote_query_reply(d['id'],hits,selversion)
            
        elif netwq.startswith("CHANNEL"): # channel query
            if DEBUG:
                print>>sys.stderr, "Incoming channel query", d['q']
            q = d['q'][len('CHANNEL '):]
            uq = self.clean_netwq(q,channelquery=True)
            hits = self.channelcast_db.searchChannels(uq)
            p = self.create_channel_query_reply(d['id'],hits,selversion)

        # log incoming query, if logfile is set
        if self.logfile:
            self.log(permid, q)        
     
        m = QUERY_REPLY+p

        if self.overlay_log:
            nqueries = self.get_peer_nqueries(permid)
            # RECV_MSG PERMID OVERSION NUM_QUERIES MSG
            self.overlay_log('RECV_QRY', show_permid(permid), selversion, nqueries, repr(d))

            # RPLY_QRY PERMID NUM_HITS MSG
            self.overlay_log('RPLY_QRY', show_permid(permid), len(hits), repr(p))

        self.overlay_bridge.send(permid, m, self.send_callback)
        
        self.inc_peer_nqueries(permid)
예제 #12
0
    def emailFriend(self, event):
        ip = self.utility.config.Read('bind')
        if ip is None or ip == '':
            ip = self.utility.session.lm.get_ext_ip()
        mypermid = self.utility.session.get_permid()

        permid_txt = self.utility.lang.get('permid')+": "+show_permid(mypermid)
        ip_txt = self.utility.lang.get('ipaddress')+": "+ip

        # port = self.utility.controller.listen_port
        port = self.utility.config.Read('minport', 'int')
        port_txt = self.utility.lang.get('portnumber')+" "+str(port)

        subject = self.utility.lang.get('invitation_subject')
        invitation_body = self.utility.lang.get('invitation_body')
        invitation_body = invitation_body.replace('\\n', '\n')
        invitation_body += ip_txt + '\n\r'
        invitation_body += port_txt + '\n\r'
        invitation_body += permid_txt + '\n\r\n\r\n\r'
       
        if sys.platform == "darwin":
            body = invitation_body.replace('\\r','')
            body = body.replace('\r','')
        else:
            body = urllib.quote(invitation_body)
        mailToURL = 'mailto:%s?subject=%s&body=%s'%('', subject, body)
        try:
            webbrowser.open(mailToURL)
        except:
            text = invitation_body.split("\n")
            InviteFriendsDialog(text)
예제 #13
0
 def formatForText(self, friends):
     lines = []
     for friend in friends:
         permid = show_permid(friend["permid"])
         line = ", ".join([friend["name"], permid, friend["ip"], str(friend["port"])])
         line += "\n"
         lines.append(line)
     return lines
예제 #14
0
 def formatForText(self, friends):
     lines = []
     for friend in friends:
         permid = show_permid(friend['permid'])
         line = ', '.join([friend['name'], permid, friend['ip'], str(friend['port'])])
         line += '\n'
         lines.append(line)
     return lines
 def _after_request_callback(self, exc, permid):
     """
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG: print >>sys.stderr, "puncturecrawler: request sent to", show_permid_short(permid)
         self._file.write("REQUEST %s %.2f\n" % (show_permid(permid), time.time()))
         self._file.flush()
예제 #16
0
 def _after_request_callback(self, exc, permid):
     """
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG: print >>sys.stderr, "channelcrawler: request send to", show_permid_short(permid)
         self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "REQUEST", show_permid(permid), "\n")))
         self._file.flush()
 def _after_request_callback(self, exc, permid):
     """
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG: print >>sys.stderr, "databasecrawler: request send to", show_permid_short(permid)
         self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "REQUEST", show_permid(permid), "\n")))
         self._file.flush()
예제 #18
0
    def handle_crawler_reply(self, permid, selversion, channel_id,
                             channel_data, error, message, request_callback):
        """
        Received a CRAWLER_UDPUNCTURE_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)
        """
        try:
            if error:
                if DEBUG:
                    print >> sys.stderr, "puncturecrawler: handle_crawler_reply", error, message

                self._file.write(
                    "ERROR %s %.2f %d %s\n" %
                    (show_permid(permid), time.time(), error, message))
                self._file.flush()

            else:
                if DEBUG:
                    print >> sys.stderr, "puncturecrawler: handle_crawler_reply", show_permid_short(
                        permid)

                # 25/05/10 Boudewijn: We found that, for unknown
                # reasons, the decompressed(message) contains many
                # gigabytes worth of \0 characters.  For now we filter
                # them out until Gert Jan can determine the actual
                # cause.
                data = zlib.decompress(message)
                filtered = filter(lambda char: char != "\0", data)

                self._file.write("REPLY %s %.2f\n" %
                                 (show_permid(permid), time.time()))
                self._file.write(
                    "# reply sizes: on-the-wire=%d, decompressed=%d, filtered=%d\n"
                    % (len(message), len(data), len(filtered)))
                self._file.write(filtered)
                self._file.flush()
        except:
            if DEBUG:
                print >> sys.stderr, "puncturecrawler: error writing to file"
    def setUpPreSession(self):
        """ override TestAsServer """
        print >> sys.stderr,"test: Pre Tribler Init"
        TestAsServer.setUpPreSession(self)
        print >> sys.stderr,"test: Pre Tribler Init: config_path",self.config_path
        # Enable dialback support
        self.config.set_dialback(True)
        self.config.set_buddycast(True) # make sure overlay connections are being made
        self.config.set_start_recommender(True)

        # Write superpeers.txt
        self.install_path = tempfile.mkdtemp()
        spdir = os.path.join(self.install_path, LIBRARYNAME, 'Core')
        os.makedirs(spdir)

        statsdir = os.path.join(self.install_path, LIBRARYNAME, 'Core', 'Statistics')
        os.makedirs(statsdir)
        
        superpeerfilename = os.path.join(spdir, 'superpeer.txt')
        print >> sys.stderr,"test: writing",self.NLISTENERS,"superpeers to",superpeerfilename
        f = open(superpeerfilename, "w")

        self.mylistenport = []
        self.myss = []
        self.mykeypairs = []
        self.mypermids = []
        for i in range(self.NLISTENERS):
            # Start our server side, to with Tribler will try to connect
            self.mylistenport.append(4810+i)
            self.myss.append(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            self.myss[i].setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.myss[i].bind(('', self.mylistenport[i]))
            self.myss[i].listen(1)

            self.mykeypairs.append(EC.gen_params(EC.NID_sect233k1))
            self.mykeypairs[i].gen_key()
            self.mypermids.append(str(self.mykeypairs[i].pub().get_der()))

            content = '127.0.0.1, '+str(self.mylistenport[i])+', '+show_permid(self.mypermids[i])+', FakeSuperPeer\n'
            f.write(content)
        f.close()
        
        self.config.set_install_dir(self.install_path)
        
        srcfiles = []
        srcfiles.append(os.path.join(LIBRARYNAME,"schema_sdb_v"+str(CURRENT_MAIN_DB_VERSION)+".sql"))
        srcfiles.append(os.path.join(LIBRARYNAME,"Core","Statistics","tribler_seedingstats_sdb.sql"))
        srcfiles.append(os.path.join(LIBRARYNAME,"Core","Statistics","tribler_friendship_stats_sdb.sql"))
        srcfiles.append(os.path.join(LIBRARYNAME,"Core","Statistics","tribler_videoplayback_stats.sql"))
        for srcfile in srcfiles:
            sfn = os.path.join('..','..',srcfile)
            dfn = os.path.join(self.install_path,srcfile)
            print >>sys.stderr,"test: copying",sfn,dfn
            shutil.copyfile(sfn,dfn)

        """
예제 #20
0
 def _after_request_callback(self, exc, permid):
     """
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG: print >>sys.stderr, "usereventlogcrawler: request send to", show_permid_short(permid)
         
         msg = "; ".join(['REQUEST', show_permid(permid)])
         self.__log(msg)
예제 #21
0
 def _after_request_callback(self, exc, permid):
     """
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG:
             print >> sys.stderr, "puncturecrawler: request sent to", show_permid_short(
                 permid)
         self._file.write("REQUEST %s %.2f\n" %
                          (show_permid(permid), time.time()))
         self._file.flush()
예제 #22
0
    def _after_request_callback(self, exc, permid):
        """
        Called by the Crawler with the result of the request_callback
        call in the query_initiator method.
        """
        if not exc:
            if DEBUG:
                print >> sys.stderr, "usereventlogcrawler: request send to", show_permid_short(
                    permid)

            msg = "; ".join(['REQUEST', show_permid(permid)])
            self.__log(msg)
예제 #23
0
    def handle_crawler_reply(self, permid, selversion, channel_id,
                             channel_data, error, message, request_callback):
        """
        Received a CRAWLER_USEREVENTLOG_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, "usereventlogcrawler: handle_crawler_reply", error, message

            msg = "; ".join(
                ['REPLY',
                 show_permid(permid),
                 str(error),
                 str(message)])
            self.__log(msg)
        else:
            if DEBUG:
                print >> sys.stderr, "usereventlogcrawler: handle_crawler_reply", show_permid_short(
                    permid), len(message), "bytes"

            try:
                loaded_message = decode(message)
            except:
                print_exc()
                loaded_message = cPickle.loads(message)

            msg = "; ".join([
                'REPLY',
                show_permid(permid),
                str(error),
                str(loaded_message)
            ])
            self.__log(msg)
예제 #24
0
    def doNatCheckCallback(self, exc, permid):

        if exc is not None:
            return False
            if DEBUG:
                print >> sys.stderr, "NATCHECK_REQUEST was sent to", show_permid_short(
                    permid), exc

        # Register peerinfo on file
        self._file.write("; ".join(
            (strftime("%Y/%m/%d %H:%M:%S"), "REQUEST", show_permid(permid),
             str(self._secure_overlay.get_dns_from_peerdb(permid)), "\n")))
        self._file.flush()
        return True
예제 #25
0
    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:
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "databasecrawler: handle_crawler_reply", error, message

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "databasecrawler: handle_crawler_reply", show_permid_short(permid), cPickle.loads(message)

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid), str(error), str(cPickle.loads(message)), "\n")))
            self._file.flush()
예제 #26
0
    def query_initiator(self, permid, selversion, request_callback):
        """
        Established a new connection. Send a CRAWLER_DATABASE_QUERY request.
        @param permid The Tribler peer permid
        @param selversion The oberlay protocol version
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if DEBUG:
            print >> sys.stderr, "databasecrawler: query_initiator", show_permid_short(
                permid)
        sql = []
        if selversion >= OLPROTO_VER_SEVENTH:
            sql.extend(("SELECT 'peer_count', count(*) FROM Peer",
                        "SELECT 'torrent_count', count(*) FROM Torrent"))

        if selversion >= OLPROTO_VER_ELEVENTH:
            sql.extend((
                "SELECT 'my_subscriptions', count(*) FROM VoteCast where voter_id='"
                + show_permid(permid) + "' and vote=2",
                "SELECT 'my_negative_votes', count(*) FROM VoteCast where voter_id='"
                + show_permid(permid) + "' and vote=-1",
                "SELECT 'my_channel_files', count(*) FROM ChannelCast where publisher_id='"
                + show_permid(permid) + "'",
                "SELECT 'all_subscriptions', count(*) FROM VoteCast where vote=2",
                "SELECT 'all_negative_votes', count(*) FROM VoteCast where vote=-1"
            ))

        # if OLPROTO_VER_EIGHTH <= selversion <= 11:
        #     sql.extend(("SELECT 'moderations_count', count(*) FROM ModerationCast"))

        # if selversion >= OLPROTO_VER_EIGHTH:
        #     sql.extend(("SELECT 'positive_votes_count', count(*) FROM Moderators where status=1",
        #                 "SELECT 'negative_votes_count', count(*) FROM Moderators where status=-1"))

        request_callback(CRAWLER_DATABASE_QUERY,
                         ";".join(sql),
                         callback=self._after_request_callback)
    def handle_crawler_reply(self, permid, selversion, channel_id, channel_data, error, message, request_callback):
        """
        Received a CRAWLER_UDPUNCTURE_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)
        """
        try:
            if error:
                if DEBUG:
                    print >> sys.stderr, "puncturecrawler: handle_crawler_reply", error, message

                self._file.write("ERROR %s %.2f %d %s\n" % (show_permid(permid), time.time(), error, message))
                self._file.flush()

            else:
                if DEBUG:
                    print >> sys.stderr, "puncturecrawler: handle_crawler_reply", show_permid_short(permid)

                # 25/05/10 Boudewijn: We found that, for unknown
                # reasons, the decompressed(message) contains many
                # gigabytes worth of \0 characters.  For now we filter
                # them out until Gert Jan can determine the actual
                # cause.
                data = zlib.decompress(message)
                filtered = filter(lambda char: char != "\0", data)

                self._file.write("REPLY %s %.2f\n" % (show_permid(permid), time.time()))
                self._file.write("# reply sizes: on-the-wire=%d, decompressed=%d, filtered=%d\n" % (len(message), len(data), len(filtered)))
                self._file.write(filtered)
                self._file.flush()
        except:
            if DEBUG:
                print >>sys.stderr, "puncturecrawler: error writing to file"
예제 #28
0
    def doNatCheckCallback(self, exc, permid):

        if exc is not None:
            return False
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "NATCHECK_REQUEST was sent to", show_permid_short(permid), exc

        # Register peerinfo on file
        self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"),
                                    "REQUEST",
                                    show_permid(permid),
                                    str(self._secure_overlay.get_dns_from_peerdb(permid)),
                                    "\n")))
        self._file.flush()
        return True
예제 #29
0
    def udpConnectCallback(self, exc, permid):

        if exc is not None:
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "NATTRAVERSAL_REQUEST failed to", show_permid_short(permid), exc

            # Register peerinfo on file
            self._file2.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"),
                                    "REQUEST FAILED",
                                    show_permid(permid),
                                    str(self._secure_overlay.get_dns_from_peerdb(permid)),
                                    "\n")))
            return False

        if DEBUG:
            print >> sys.stderr, time.asctime(),'-', "NATTRAVERSAL_REQUEST was sent to", show_permid_short(permid), exc
        return True
예제 #30
0
    def udpConnectCallback(self, exc, permid):

        if exc is not None:
            if DEBUG:
                print >> sys.stderr, "NATTRAVERSAL_REQUEST failed to", show_permid_short(
                    permid), exc

            # Register peerinfo on file
            self._file2.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "REQUEST FAILED",
                 show_permid(permid),
                 str(self._secure_overlay.get_dns_from_peerdb(permid)), "\n")))
            return False

        if DEBUG:
            print >> sys.stderr, "NATTRAVERSAL_REQUEST was sent to", show_permid_short(
                permid), exc
        return True
예제 #31
0
    def setUpPreSession(self):
        """ override TestAsServer """
        print >> sys.stderr, "test: Pre Tribler Init"
        TestAsServer.setUpPreSession(self)
        print >> sys.stderr, "test: Pre Tribler Init: config_path", self.config_path
        # Enable dialback support
        self.config.set_dialback(True)
        self.config.set_buddycast(
            True)  # make sure overlay connections are being made
        self.config.set_start_recommender(True)

        # Write superpeers.txt
        self.install_path = tempfile.mkdtemp()
        spdir = os.path.join(self.install_path, 'Tribler', 'Core')
        os.makedirs(spdir)
        superpeerfilename = os.path.join(spdir, 'superpeer.txt')
        print >> sys.stderr, "test: writing", self.NLISTENERS, "superpeers to", superpeerfilename
        f = open(superpeerfilename, "w")

        self.mylistenport = []
        self.myss = []
        self.mykeypairs = []
        self.mypermids = []
        for i in range(self.NLISTENERS):
            # Start our server side, to with Tribler will try to connect
            self.mylistenport.append(4810 + i)
            self.myss.append(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            self.myss[i].setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.myss[i].bind(('', self.mylistenport[i]))
            self.myss[i].listen(1)

            self.mykeypairs.append(EC.gen_params(EC.NID_sect233k1))
            self.mykeypairs[i].gen_key()
            self.mypermids.append(str(self.mykeypairs[i].pub().get_der()))

            content = '127.0.0.1, ' + str(
                self.mylistenport[i]) + ', ' + show_permid(
                    self.mypermids[i]) + ', FakeSuperPeer\n'
            f.write(content)
        f.close()

        self.config.set_install_dir(self.install_path)
        """
    def setUpPreSession(self):
        """ override TestAsServer """
        print >> sys.stderr,"test: Pre Tribler Init"
        TestAsServer.setUpPreSession(self)
        print >> sys.stderr,"test: Pre Tribler Init: config_path",self.config_path
        # Enable dialback support
        self.config.set_dialback(True)
        self.config.set_buddycast(True) # make sure overlay connections are being made
        self.config.set_start_recommender(True)

        # Write superpeers.txt
        self.install_path = tempfile.mkdtemp()
        spdir = os.path.join(self.install_path, 'Tribler', 'Core')
        os.makedirs(spdir)
        superpeerfilename = os.path.join(spdir, 'superpeer.txt')
        print >> sys.stderr,"test: writing",self.NLISTENERS,"superpeers to",superpeerfilename
        f = open(superpeerfilename, "w")

        self.mylistenport = []
        self.myss = []
        self.mykeypairs = []
        self.mypermids = []
        for i in range(self.NLISTENERS):
            # Start our server side, to with Tribler will try to connect
            self.mylistenport.append(4810+i)
            self.myss.append(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            self.myss[i].setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.myss[i].bind(('', self.mylistenport[i]))
            self.myss[i].listen(1)

            self.mykeypairs.append(EC.gen_params(EC.NID_sect233k1))
            self.mykeypairs[i].gen_key()
            self.mypermids.append(str(self.mykeypairs[i].pub().get_der()))

            content = '127.0.0.1, '+str(self.mylistenport[i])+', '+show_permid(self.mypermids[i])+', FakeSuperPeer\n'
            f.write(content)
        f.close()
        
        self.config.set_install_dir(self.install_path)

        """
예제 #33
0
    def __init__(self, parent, utility, editfriend = None):
        #provider = wx.SimpleHelpProvider()
        #wx.HelpProvider_Set(provider)
        
        self.utility = utility
        self.editfriend = editfriend

        style = wx.DEFAULT_DIALOG_STYLE 
        #| wx.RESIZE_BORDER
        pos = wx.DefaultPosition
        size = wx.Size(600, 200)
        #size, split = self.getWindowSettings()

        if editfriend is None:
            title = self.utility.lang.get('addfriend')
        else:
            title = self.utility.lang.get('editfriend')
        wx.Dialog.__init__(self, parent, -1, title, size = size, style = style)
        pre = wx.PreDialog()
        pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        pre.Create(parent, -1, title, pos, size, style)
        self.PostCreate(pre)

        sizer = wx.BoxSizer(wx.VERTICAL)

        label = wx.StaticText(self, -1, title)
        sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        # name
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('name')+':',wx.DefaultPosition,wx.Size(40,18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None:
            name = editfriend['name']
        else:   
            name = ''
        self.name_text = wx.TextCtrl(self, -1, name, size=(140,-1))
        ##self.name_text.SetHelpText(self.utility.lang.get('nickname_help'))
        box.Add(self.name_text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        # text about e-mail invitation
        label = wx.StaticText(self, -1, self.utility.lang.get('pasteinvitationemail'),wx.DefaultPosition)
        label.Wrap( 500 )
        sizer.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        # ip
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('ipaddress')+':',wx.DefaultPosition,wx.Size(40,18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None:
            ip = editfriend['ip']
        else:   
            ip = ''
        self.ip_text = wx.TextCtrl(self, -1, ip, size=(140,-1))
        ##self.ip_text.SetHelpText(self.utility.lang.get('friendsipaddr_help'))
        box.Add(self.ip_text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)

        # port
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('portnumber'),wx.DefaultPosition,wx.Size(40,18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None:
            port_str = str(editfriend['port'])
        else:   
            port_str = ''
        self.port_text = wx.TextCtrl(self, -1, port_str, size=(140,-1))
        ##self.port_text.SetHelpText(self.utility.lang.get('friendsport_help'))
        box.Add(self.port_text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)

        # permid
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('permid')+':',wx.DefaultPosition,wx.Size(40,18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None:
            permid = show_permid(editfriend['permid'])
        else:   
            permid = ''
        self.permid_text = wx.TextCtrl(self, -1, permid, size=(300,-1))
        ## self.permid_text.SetHelpText(self.utility.lang.get('friendspermid_help'))
        box.Add(self.permid_text, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        """
        # picture
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('icon'))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None and editfriend.has_key('icon'):
            icon = str(editfriend['icon'])
        else:   
            icon = ''
        self.icon_path = wx.TextCtrl(self, -1, icon, size=(80,-1))
        ## self.icon_path.SetHelpText(self.utility.lang.get('friendsicon_help'))
        box.Add(self.icon_path, 3, wx.ALIGN_CENTRE|wx.ALL, 5)
        
        iconbtn = wx.Button(self, -1, label=self.utility.lang.get('browsebtn'))
        box.Add(iconbtn, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
        self.Bind(wx.EVT_BUTTON, self.OnIconButton, iconbtn)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        """  
        
        box = wx.BoxSizer(wx.HORIZONTAL)
        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
        sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
        btnsizer = wx.StdDialogButtonSizer()
        
        ##if (sys.platform != 'win32'):
        ##    btn = wx.ContextHelpButton(self)
        ##    btnsizer.AddButton(btn)
        
        if editfriend is None:
            lbl = self.utility.lang.get('buttons_add')
        else:
            lbl = self.utility.lang.get('buttons_update')
        btn = wx.Button(self, wx.ID_OK, label=lbl)
        btn.SetDefault()
        btnsizer.AddButton(btn)
        self.Bind(wx.EVT_BUTTON, self.OnAddEditFriend, btn)

        btn = wx.Button(self, wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        #sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)


        

        self.SetSizer(sizer)
        sizer.Fit(self)
예제 #34
0
    def handle_info_crawler_reply(self, permid, selversion, channel_id, error, message, request_callback):
        """
        <<Crawler-side>>
        Received a CRAWLER_VIDEOPLAYBACK_INFO_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, time.asctime(),'-', "videoplaybackcrawler: handle_crawler_reply", error, message

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "   INFO REPLY", show_permid(permid), str(error), message, "\n")))
            self._file.flush()

        else:
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "videoplaybackcrawler: handle_crawler_reply", show_permid_short(permid), cPickle.loads(message)

            info = cPickle.loads(message)
            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "   INFO REPLY", show_permid(permid), str(error), str(info), "\n")))
            self._file.flush()

            i = 0
            for key, timestamp, piece_size, num_pieces, bitrate, nat in info:
                i += 1
                # do not remove the first item. the list is ordered
                # DESC so the first item is the last that is added to
                # the database and we can't affored to remove it, as
                # it may cause exceptions in the running playback.
                if i == 1:
                    sql = """
SELECT timestamp, origin, event FROM playback_event WHERE key = '%s' ORDER BY timestamp ASC LIMIT 50;
DELETE FROM playback_event WHERE key = '%s';
""" % (key, key)
                else:
                    sql = """
SELECT timestamp, origin, event FROM playback_event WHERE key = '%s' ORDER BY timestamp ASC LIMIT 50;
DELETE FROM playback_event WHERE key = '%s';
DELETE FROM playback_info WHERE key = '%s';
""" % (key, key, key)
                    
                # todo: optimize to not select key for each row
                request_callback(CRAWLER_VIDEOPLAYBACK_EVENT_QUERY, sql, channel_data=key, callback=self._after_event_request_callback, frequency=0)
예제 #35
0
    def setUpPreSession(self):
        """ override TestAsServer """
        print >> sys.stderr, "test: Pre Tribler Init"
        TestAsServer.setUpPreSession(self)
        print >> sys.stderr, "test: Pre Tribler Init: config_path", self.config_path
        # Enable dialback support
        self.config.set_dialback(True)
        self.config.set_buddycast(
            True)  # make sure overlay connections are being made
        self.config.set_start_recommender(True)

        # Write superpeers.txt
        self.install_path = tempfile.mkdtemp()
        spdir = os.path.join(self.install_path, LIBRARYNAME, 'Core')
        os.makedirs(spdir)

        statsdir = os.path.join(self.install_path, LIBRARYNAME, 'Core',
                                'Statistics')
        os.makedirs(statsdir)

        superpeerfilename = os.path.join(spdir, 'superpeer.txt')
        print >> sys.stderr, "test: writing", self.NLISTENERS, "superpeers to", superpeerfilename
        f = open(superpeerfilename, "w")

        self.mylistenport = []
        self.myss = []
        self.mykeypairs = []
        self.mypermids = []
        for i in range(self.NLISTENERS):
            # Start our server side, to with Tribler will try to connect
            self.mylistenport.append(4810 + i)
            self.myss.append(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
            self.myss[i].setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.myss[i].bind(('', self.mylistenport[i]))
            self.myss[i].listen(1)

            self.mykeypairs.append(EC.gen_params(EC.NID_sect233k1))
            self.mykeypairs[i].gen_key()
            self.mypermids.append(str(self.mykeypairs[i].pub().get_der()))

            content = '127.0.0.1, ' + str(
                self.mylistenport[i]) + ', ' + show_permid(
                    self.mypermids[i]) + ', FakeSuperPeer\n'
            f.write(content)
        f.close()

        self.config.set_install_dir(self.install_path)

        srcfiles = []
        srcfiles.append(
            os.path.join(
                LIBRARYNAME,
                "schema_sdb_v" + str(CURRENT_MAIN_DB_VERSION) + ".sql"))
        srcfiles.append(
            os.path.join(LIBRARYNAME, "Core", "Statistics",
                         "tribler_seedingstats_sdb.sql"))
        srcfiles.append(
            os.path.join(LIBRARYNAME, "Core", "Statistics",
                         "tribler_friendship_stats_sdb.sql"))
        srcfiles.append(
            os.path.join(LIBRARYNAME, "Core", "Statistics",
                         "tribler_videoplayback_stats.sql"))
        for srcfile in srcfiles:
            sfn = os.path.join('..', '..', srcfile)
            dfn = os.path.join(self.install_path, srcfile)
            print >> sys.stderr, "test: copying", sfn, dfn
            shutil.copyfile(sfn, dfn)
        """
예제 #36
0
    def gotNatCheckReplyMessage(self, permid, selversion, channel_id,
                                channel_data, error, payload,
                                request_callback):
        """
        The handle-reply callback
        """
        if error:
            if DEBUG:
                print >> sys.stderr, "NatCheckMsgHandler: gotNatCheckReplyMessage"
                print >> sys.stderr, "NatCheckMsgHandler: error", error

            # generic error: another crawler already obtained these results
            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(self._secure_overlay.get_dns_from_peerdb(permid)),
                 "ERROR(%d)" % error, payload, "\n")))
            self._file.flush()

        else:
            try:
                recv_data = bdecode(payload)
            except:
                print_exc()
                print >> sys.stderr, "bad encoded data:", payload
                return False

            try:  # check natCheckReply message
                self.validNatCheckReplyMsg(recv_data)
            except RuntimeError, e:
                print >> sys.stderr, e
                return False

            if DEBUG:
                print >> sys.stderr, "NatCheckMsgHandler: received NAT_CHECK_REPLY message: ", recv_data

            # Register peerinfo on file
            self._file.write("; ".join(
                (strftime("%Y/%m/%d %H:%M:%S"), "  REPLY", show_permid(permid),
                 str(self._secure_overlay.get_dns_from_peerdb(permid)),
                 ":".join([str(x) for x in recv_data]), "\n")))
            self._file.flush()

            # for Tribler versions < 5.0 : do nothing
            if selversion < OLPROTO_VER_NINETH:
                if DEBUG:
                    print >> sys.stderr, "NatCheckMsgHandler: Tribler version too old for NATTRAVERSAL: do nothing"
                return True

            if DEBUG:
                print >> sys.stderr, "NatCheckMsgHandler: do NATTRAVERSAL"

            # Save peer in peerlist
            if len(self.peerlist) == PEERLIST_LEN:
                del self.peerlist[0]
            self.peerlist.append([permid, recv_data[1], recv_data[2]])
            if DEBUG:
                print >> sys.stderr, "NatCheckMsgHandler: peerlist length is: ", len(
                    self.peerlist)

            # Try to perform hole punching
            if len(self.peerlist) >= 2:
                self.tryHolePunching()
예제 #37
0
    def __init__(self, parent, utility, editfriend=None):
        #provider = wx.SimpleHelpProvider()
        #wx.HelpProvider_Set(provider)

        self.utility = utility
        self.editfriend = editfriend

        style = wx.DEFAULT_DIALOG_STYLE
        #| wx.RESIZE_BORDER
        pos = wx.DefaultPosition
        size = wx.Size(600, 200)
        #size, split = self.getWindowSettings()

        if editfriend is None:
            title = self.utility.lang.get('addfriend')
        else:
            title = self.utility.lang.get('editfriend')
        wx.Dialog.__init__(self, parent, -1, title, size=size, style=style)
        pre = wx.PreDialog()
        pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        pre.Create(parent, -1, title, pos, size, style)
        self.PostCreate(pre)

        sizer = wx.BoxSizer(wx.VERTICAL)

        label = wx.StaticText(self, -1, title)
        sizer.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        # name
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1,
                              self.utility.lang.get('name') + ':',
                              wx.DefaultPosition, wx.Size(40, 18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        if editfriend is not None:
            name = editfriend['name']
        else:
            name = ''
        self.name_text = wx.TextCtrl(self, -1, name, size=(140, -1))
        ##self.name_text.SetHelpText(self.utility.lang.get('nickname_help'))
        box.Add(self.name_text, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        # text about e-mail invitation
        label = wx.StaticText(self, -1,
                              self.utility.lang.get('pasteinvitationemail'),
                              wx.DefaultPosition)
        label.Wrap(500)
        sizer.Add(label, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        # ip
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1,
                              self.utility.lang.get('ipaddress') + ':',
                              wx.DefaultPosition, wx.Size(40, 18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        if editfriend is not None:
            ip = editfriend['ip']
        else:
            ip = ''
        self.ip_text = wx.TextCtrl(self, -1, ip, size=(140, -1))
        ##self.ip_text.SetHelpText(self.utility.lang.get('friendsipaddr_help'))
        box.Add(self.ip_text, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.Add(
            box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT
            | wx.BOTTOM, 5)

        # port
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('portnumber'),
                              wx.DefaultPosition, wx.Size(40, 18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        if editfriend is not None:
            port_str = str(editfriend['port'])
        else:
            port_str = ''
        self.port_text = wx.TextCtrl(self, -1, port_str, size=(140, -1))
        ##self.port_text.SetHelpText(self.utility.lang.get('friendsport_help'))
        box.Add(self.port_text, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.Add(
            box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT
            | wx.BOTTOM, 5)

        # permid
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1,
                              self.utility.lang.get('permid') + ':',
                              wx.DefaultPosition, wx.Size(40, 18))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        if editfriend is not None:
            permid = show_permid(editfriend['permid'])
        else:
            permid = ''
        self.permid_text = wx.TextCtrl(self, -1, permid, size=(300, -1))
        ## self.permid_text.SetHelpText(self.utility.lang.get('friendspermid_help'))
        box.Add(self.permid_text, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        """
        # picture
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, self.utility.lang.get('icon'))
        #label.SetHelpText("")
        box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        if editfriend is not None and editfriend.has_key('icon'):
            icon = str(editfriend['icon'])
        else:   
            icon = ''
        self.icon_path = wx.TextCtrl(self, -1, icon, size=(80,-1))
        ## self.icon_path.SetHelpText(self.utility.lang.get('friendsicon_help'))
        box.Add(self.icon_path, 3, wx.ALIGN_CENTRE|wx.ALL, 5)
        
        iconbtn = wx.Button(self, -1, label=self.utility.lang.get('browsebtn'))
        box.Add(iconbtn, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
        self.Bind(wx.EVT_BUTTON, self.OnIconButton, iconbtn)

        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        """

        box = wx.BoxSizer(wx.HORIZONTAL)
        line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL)
        sizer.Add(line, 0,
                  wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
        btnsizer = wx.StdDialogButtonSizer()

        ##if (sys.platform != 'win32'):
        ##    btn = wx.ContextHelpButton(self)
        ##    btnsizer.AddButton(btn)

        if editfriend is None:
            lbl = self.utility.lang.get('buttons_add')
        else:
            lbl = self.utility.lang.get('buttons_update')
        btn = wx.Button(self, wx.ID_OK, label=lbl)
        btn.SetDefault()
        btnsizer.AddButton(btn)
        self.Bind(wx.EVT_BUTTON, self.OnAddEditFriend, btn)

        btn = wx.Button(self, wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        #sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER | wx.ALL, 5)

        self.SetSizer(sizer)
        sizer.Fit(self)
예제 #38
0
    def __init__(self, parent, utility):
        self.utility = utility

        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        pos = wx.DefaultPosition
        size = wx.Size(530, 420)

        title = self.utility.lang.get('myinfo')
        wx.Dialog.__init__(self, parent, -1, title, size=size, style=style)

        # 1. Build My Info
        mainbox = wx.BoxSizer(wx.VERTICAL)

        # my info
        myinfobox_title = wx.StaticBox(self, -1,
                                       self.utility.lang.get('myinfo'))
        myinfobox = wx.StaticBoxSizer(myinfobox_title, wx.VERTICAL)

        ip = self.utility.session.get_external_ip()
        permid = self.utility.session.get_permid()
        self.permid_txt = self.utility.lang.get('permid') + ": " + show_permid(
            permid)
        self.ip_txt = self.utility.lang.get('ipaddress') + ": " + ip

        # port = self.utility.controller.listen_port
        port = self.utility.config.Read('minport', 'int')
        self.port_txt = self.utility.lang.get('portnumber') + " " + str(port)

        if True:
            # Make it copy-and-paste able
            self.textctrl = wx.TextCtrl(self,
                                        -1,
                                        size=(640, 100),
                                        style=wx.TE_MULTILINE | wx.TE_DONTWRAP
                                        | wx.TE_READONLY)
            self.textctrl.AppendText(self.permid_txt + '\n')
            self.textctrl.AppendText(self.ip_txt + '\n')
            self.textctrl.AppendText(self.port_txt + '\n')
            myinfobox.Add(self.textctrl, 0,
                          wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        else:
            label = wx.StaticText(self, -1, self.permid_txt)
            myinfobox.Add(label, 0,
                          wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

            label = wx.StaticText(self, -1, self.ip_txt)
            myinfobox.Add(label, 0,
                          wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

            label = wx.StaticText(self, -1, self.port_txt)
            myinfobox.Add(label, 0,
                          wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

    # 1.5 Explanatory text
        botbox = wx.BoxSizer(wx.VERTICAL)

        msg = self.utility.lang.get('myinfo_explanation')
        botbox.Add(wx.StaticText(self, -1, msg), 0,
                   wx.EXPAND | wx.ALIGN_LEFT | wx.ALL, 5)

        # 2. Invitation and Close buttons
        btnbox = wx.BoxSizer(wx.HORIZONTAL)
        invitation_btn = wx.Button(self,
                                   -1,
                                   self.utility.lang.get('invitationbtn'),
                                   style=wx.BU_EXACTFIT)
        #button.SetToolTipString(self.utility.lang.get('stopdlhelp_help'))
        wx.EVT_BUTTON(self, invitation_btn.GetId(), self.emailFriend)
        btnbox.Add(invitation_btn, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 3)

        button = wx.Button(self,
                           -1,
                           self.utility.lang.get('close'),
                           style=wx.BU_EXACTFIT)
        #button.SetToolTipString(self.utility.lang.get('stopdlhelp_help'))
        wx.EVT_BUTTON(self, button.GetId(), self.close)
        btnbox.Add(button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 3)

        # 3. Show GUI
        mainbox.Add(myinfobox, 0, wx.EXPAND)
        mainbox.Add(botbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)
        mainbox.Add(btnbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)
        self.SetSizerAndFit(mainbox)
    def query_initiator(self, permid, selversion, request_callback):
        """
        Established a new connection. Send a CRAWLER_DATABASE_QUERY request.
        @param permid The Tribler peer permid
        @param selversion The oberlay protocol version
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if DEBUG: print >>sys.stderr, "databasecrawler: query_initiator", show_permid_short(permid)
        sql = []
        if selversion >= OLPROTO_VER_SEVENTH:
            sql.extend(("SELECT 'peer_count', count(*) FROM Peer",
                        "SELECT 'torrent_count', count(*) FROM Torrent"))

        if selversion >= OLPROTO_VER_ELEVENTH:
            sql.extend(("SELECT 'my_subscriptions', count(*) FROM VoteCast where voter_id='" + show_permid(permid) + "' and vote=2",
                        "SELECT 'my_negative_votes', count(*) FROM VoteCast where voter_id='" + show_permid(permid) + "' and vote=-1",
                        "SELECT 'my_channel_files', count(*) FROM ChannelCast where publisher_id='" + show_permid(permid) + "'",
                        "SELECT 'all_subscriptions', count(*) FROM VoteCast where vote=2",
                        "SELECT 'all_negative_votes', count(*) FROM VoteCast where vote=-1"))

        # if OLPROTO_VER_EIGHTH <= selversion <= 11:
        #     sql.extend(("SELECT 'moderations_count', count(*) FROM ModerationCast"))

        # if selversion >= OLPROTO_VER_EIGHTH:
        #     sql.extend(("SELECT 'positive_votes_count', count(*) FROM Moderators where status=1",
        #                 "SELECT 'negative_votes_count', count(*) FROM Moderators where status=-1"))

        request_callback(CRAWLER_DATABASE_QUERY, ";".join(sql), callback=self._after_request_callback)
예제 #40
0
    def handle_event_crawler_reply(self, permid, selversion, channel_id, channel_data, error, message, request_callback):
        """
        <<Crawler-side>>
        Received a CRAWLER_VIDEOPLAYBACK_EVENT_QUERY reply.
        @param permid The Crawler permid
        @param selversion The overlay protocol version
        @param channel_id Identifies a CRAWLER_REQUEST/CRAWLER_REPLY pair
        @param channel_data Data associated with the request
        @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, time.asctime(),'-', "videoplaybackcrawler: handle_crawler_reply", error, message

            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  EVENT REPLY", show_permid(permid), str(error), str(channel_data), message, "\n")))
            self._file.flush()

        elif selversion >= OLPROTO_VER_TENTH:
            # Overlay version 10 sends the reply pickled and zipped
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "videoplaybackcrawler: handle_crawler_reply", show_permid_short(permid), len(message), "bytes zipped"

            info = cPickle.loads(zlib.decompress(message))
            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  EVENT REPLY", show_permid(permid), str(error), str(channel_data), str(info), "\n")))
            self._file.flush()
            
        elif selversion >= OLPROTO_VER_EIGHTH:
            if DEBUG:
                print >> sys.stderr, time.asctime(),'-', "videoplaybackcrawler: handle_crawler_reply", show_permid_short(permid), cPickle.loads(message)

            info = cPickle.loads(message)
            self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "  EVENT REPLY", show_permid(permid), str(error), str(channel_data), str(info), "\n")))
            self._file.flush()
예제 #41
0
    def gotNatCheckReplyMessage(self, permid, selversion, channel_id, channel_data, error, payload, request_callback):
        """
        The handle-reply callback
        """
        if error:
            if DEBUG:
                print >>sys.stderr, "NatCheckMsgHandler: gotNatCheckReplyMessage"
                print >>sys.stderr, "NatCheckMsgHandler: error", error

            # generic error: another crawler already obtained these results
            self._file.write(
                "; ".join(
                    (
                        strftime("%Y/%m/%d %H:%M:%S"),
                        "  REPLY",
                        show_permid(permid),
                        str(self._secure_overlay.get_dns_from_peerdb(permid)),
                        "ERROR(%d)" % error,
                        payload,
                        "\n",
                    )
                )
            )
            self._file.flush()

        else:
            try:
                recv_data = bdecode(payload)
            except:
                print_exc()
                print >>sys.stderr, "bad encoded data:", payload
                return False

            try:  # check natCheckReply message
                self.validNatCheckReplyMsg(recv_data)
            except RuntimeError, e:
                print >>sys.stderr, e
                return False

            if DEBUG:
                print >>sys.stderr, "NatCheckMsgHandler: received NAT_CHECK_REPLY message: ", recv_data

            # Register peerinfo on file
            self._file.write(
                "; ".join(
                    (
                        strftime("%Y/%m/%d %H:%M:%S"),
                        "  REPLY",
                        show_permid(permid),
                        str(self._secure_overlay.get_dns_from_peerdb(permid)),
                        ":".join([str(x) for x in recv_data]),
                        "\n",
                    )
                )
            )
            self._file.flush()

            # for Tribler versions < 5.0 : do nothing
            if selversion < OLPROTO_VER_NINETH:
                if DEBUG:
                    print >>sys.stderr, "NatCheckMsgHandler: Tribler version too old for NATTRAVERSAL: do nothing"
                return True

            if DEBUG:
                print >>sys.stderr, "NatCheckMsgHandler: do NATTRAVERSAL"

            # Save peer in peerlist
            if len(self.peerlist) == PEERLIST_LEN:
                del self.peerlist[0]
            self.peerlist.append([permid, recv_data[1], recv_data[2]])
            if DEBUG:
                print >>sys.stderr, "NatCheckMsgHandler: peerlist length is: ", len(self.peerlist)

            # Try to perform hole punching
            if len(self.peerlist) >= 2:
                self.tryHolePunching()
예제 #42
0
 def _after_info_request_callback(self, exc, permid):
     """
     <<Crawler-side>>
     Called by the Crawler with the result of the request_callback
     call in the query_initiator method.
     """
     if not exc:
         if DEBUG: print >>sys.stderr, time.asctime(),'-', "videoplaybackcrawler: request send to", show_permid_short(permid)
         self._file.write("; ".join((strftime("%Y/%m/%d %H:%M:%S"), "INFO REQUEST", show_permid(permid), "\n")))
         self._file.flush()
예제 #43
0
    def __init__(self, parent, utility):
        self.utility = utility

        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        pos = wx.DefaultPosition
        size = wx.Size(530, 420)
        
        title = self.utility.lang.get('myinfo')
        wx.Dialog.__init__(self, parent, -1, title, size = size, style = style)

        # 1. Build My Info
        mainbox = wx.BoxSizer(wx.VERTICAL)

        # my info
        myinfobox_title = wx.StaticBox(self, -1, self.utility.lang.get('myinfo'))
        myinfobox = wx.StaticBoxSizer(myinfobox_title, wx.VERTICAL)

        ip = self.utility.session.get_external_ip()
        permid = self.utility.session.get_permid()
        self.permid_txt = self.utility.lang.get('permid')+": "+show_permid(permid)
        self.ip_txt = self.utility.lang.get('ipaddress')+": "+ip

        # port = self.utility.controller.listen_port
        port = self.utility.config.Read('minport', 'int')
        self.port_txt = self.utility.lang.get('portnumber')+" "+str(port)

        if True:
            # Make it copy-and-paste able
            self.textctrl = wx.TextCtrl(self, -1, size = (640, 100), style = wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_READONLY)
            self.textctrl.AppendText( self.permid_txt + '\n' );
            self.textctrl.AppendText( self.ip_txt + '\n' );
            self.textctrl.AppendText( self.port_txt + '\n' );
            myinfobox.Add( self.textctrl, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        else:
            label = wx.StaticText(self, -1, self.permid_txt )
            myinfobox.Add( label, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

            label = wx.StaticText(self, -1, self.ip_txt )
            myinfobox.Add( label, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

            label = wx.StaticText(self, -1, self.port_txt )
            myinfobox.Add( label, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)


       # 1.5 Explanatory text
        botbox = wx.BoxSizer(wx.VERTICAL)

        msg = self.utility.lang.get('myinfo_explanation')
        botbox.Add(wx.StaticText(self, -1, msg), 0, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)

        # 2. Invitation and Close buttons
        btnbox = wx.BoxSizer(wx.HORIZONTAL)
        invitation_btn = wx.Button(self, -1, self.utility.lang.get('invitationbtn'), style = wx.BU_EXACTFIT)
        #button.SetToolTipString(self.utility.lang.get('stopdlhelp_help'))
        wx.EVT_BUTTON(self, invitation_btn.GetId(), self.emailFriend)
        btnbox.Add(invitation_btn, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 3)
        
        button = wx.Button(self, -1, self.utility.lang.get('close'), style = wx.BU_EXACTFIT)
        #button.SetToolTipString(self.utility.lang.get('stopdlhelp_help'))
        wx.EVT_BUTTON(self, button.GetId(), self.close)
        btnbox.Add(button, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 3)

        # 3. Show GUI
        mainbox.Add(myinfobox, 0, wx.EXPAND)
        mainbox.Add(botbox, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)
        mainbox.Add(btnbox, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)
        self.SetSizerAndFit(mainbox)
예제 #44
0
    def query_initiator(self, permid, selversion, request_callback):
        """
        Established a new connection. Send a CRAWLER_CHANNEL_QUERY request.
        @param permid The Tribler peer permid
        @param selversion The oberlay protocol version
        @param request_callback Call this function one or more times to send the requests: request_callback(message_id, payload)
        """
        if DEBUG: print >>sys.stderr, "channelcrawler: query_initiator", show_permid_short(permid)
        sql = []
        if selversion >= OLPROTO_VER_THIRTEENTH:
            sql.extend(("SELECT 'channel_files', publisher_id, count(*) FROM ChannelCast group by publisher_id",
                        "SELECT 'my_votes', mod_id, voter_id, vote, time_stamp FROM VoteCast where voter_id='" + show_permid(permid) + "' order by time_stamp desc limit 100",
                        "SELECT 'other_votes', mod_id, voter_id, vote, time_stamp FROM VoteCast where voter_id<>'" + show_permid(permid) + "' order by time_stamp desc limit 100"))

        request_callback(CRAWLER_CHANNEL_QUERY, ";".join(sql), callback=self._after_request_callback)