def register(self,session,metadata_handler,helpdir,dlconfig):
     self.session = session
     self.helpdir = helpdir
     # The default DownloadStartupConfig dict as set in the Session
     self.dlconfig = dlconfig
     self.torrent_db = TorrentDBHandler.getInstance()
     self.metadata_handler = metadata_handler
 def register(self, session, metadata_handler, helpdir, dlconfig):
     self.session = session
     self.helpdir = helpdir
     # The default DownloadStartupConfig dict as set in the Session
     self.dlconfig = dlconfig
     self.torrent_db = TorrentDBHandler.getInstance()
     self.metadata_handler = metadata_handler
    def __init__(self):

        if DEBUG:
            print >>sys.stderr,time.asctime(),'-', 'mainlineDHTChecker: initialization'
        if mainlineDHTChecker.__single:
            raise RuntimeError, "mainlineDHTChecker is Singleton"
        mainlineDHTChecker.__single = self
        
        self.dht = None
        self.torrent_db = TorrentDBHandler.getInstance()
Beispiel #4
0
    def __init__(self):

        if DEBUG:
            print >>sys.stderr,'mainlineDHTChecker: initialization'
        if mainlineDHTChecker.__single:
            raise RuntimeError, "mainlineDHTChecker is Singleton"
        mainlineDHTChecker.__single = self
        
        self.dht = None
        self.torrent_db = TorrentDBHandler.getInstance()
Beispiel #5
0
    def run(self):
        """ Gets one torrent from good or unknown list and checks it """

        try:
            if DEBUG:
                print >>sys.stderr, time.asctime(), "-", "Torrent Checking: RUN", threading.currentThread().getName()

            event = threading.Event()
            return_value = safe_dict()
            return_value["event"] = event
            return_value["torrent"] = None
            if self.infohash is None:  # select torrent by a policy
                policy = self.selectPolicy()
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance().selectTorrentToCheck(
                            policy=policy, return_value=return_value
                        )
                    )
                else:
                    TorrentDBHandler.getInstance().selectTorrentToCheck(policy=policy, return_value=return_value)
            else:  # know which torrent to check
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance().selectTorrentToCheck(
                            infohash=self.infohash, return_value=return_value
                        )
                    )
                else:
                    TorrentDBHandler.getInstance().selectTorrentToCheck(
                        infohash=self.infohash, return_value=return_value
                    )
            event.wait(60.0)

            torrent = return_value["torrent"]
            if DEBUG:
                print >>sys.stderr, time.asctime(), "-", "Torrent Checking: get value from DB:", torrent

            if not torrent:
                return

            if self.infohash is None and torrent["ignored_times"] > 0:
                if DEBUG:
                    print >>sys.stderr, time.asctime(), "-", "Torrent_checking: torrent: %s" % torrent
                kw = {"ignored_times": torrent["ignored_times"] - 1}
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance().updateTracker(torrent["infohash"], kw)
                    )
                else:
                    TorrentDBHandler.getInstance().updateTracker(torrent["infohash"], kw)
                return

            # may be block here because the internet IO
            torrent = self.readTorrent(torrent)  # read the torrent
            if "info" not in torrent:  # torrent has been deleted
                if self.db_thread:
                    self.db_thread.add_task(lambda: TorrentDBHandler.getInstance().deleteTorrent(torrent["infohash"]))
                else:
                    TorrentDBHandler.getInstance().deleteTorrent(torrent["infohash"])
                return

            # TODO: tracker checking also needs to be update
            if DEBUG:
                print >>sys.stderr, time.asctime(), "-", "Tracker Checking"
            trackerChecking(torrent)

            # Must come after tracker check, such that if tracker dead and DHT still alive, the
            # status is still set to good
            self.mldhtchecker.lookup(torrent["infohash"])

            self.updateTorrentInfo(torrent)  # set the ignored_times

            kw = {
                "last_check_time": int(time()),
                "seeder": torrent["seeder"],
                "leecher": torrent["leecher"],
                "status": torrent["status"],
                "ignored_times": torrent["ignored_times"],
                "retried_times": torrent["retried_times"],
                #'info': torrent['info']
            }

            if DEBUG:
                print >>sys.stderr, time.asctime(), "-", "Torrent Checking: selectTorrentToCheck:", kw

            if self.db_thread:
                self.db_thread.add_task(lambda: TorrentDBHandler.getInstance().updateTorrent(torrent["infohash"], **kw))
            else:
                TorrentDBHandler.getInstance().updateTorrent(torrent["infohash"], **kw)
        finally:
            if not self.db_thread:
                TorrentDBHandler.getInstance().close()
Beispiel #6
0
 def __init__(self):
     if RemoteTorrentHandler.__single:
         raise RuntimeError, "RemoteTorrentHandler is singleton"
     RemoteTorrentHandler.__single = self
     self.torrent_db = TorrentDBHandler.getInstance()
     self.requestedtorrents = {}
    def run(self):
        """ Gets one torrent from good or unknown list and checks it """

        try:
            if DEBUG:
                print >> sys.stderr, "Torrent Checking: RUN", threading.currentThread(
                ).getName()

            event = threading.Event()
            return_value = safe_dict()
            return_value['event'] = event
            return_value['torrent'] = None
            if self.infohash is None:  # select torrent by a policy
                policy = self.selectPolicy()
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance(
                        ).selectTorrentToCheck(policy=policy,
                                               return_value=return_value))
                else:
                    TorrentDBHandler.getInstance().selectTorrentToCheck(
                        policy=policy, return_value=return_value)
            else:  # know which torrent to check
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance(
                        ).selectTorrentToCheck(infohash=self.infohash,
                                               return_value=return_value))
                else:
                    TorrentDBHandler.getInstance().selectTorrentToCheck(
                        infohash=self.infohash, return_value=return_value)
            event.wait(60.0)

            torrent = return_value['torrent']
            if DEBUG:
                print >> sys.stderr, "Torrent Checking: get value from DB:", torrent

            if not torrent:
                return

            if self.infohash is None and torrent['ignored_times'] > 0:
                if DEBUG:
                    print >> sys.stderr, 'Torrent_checking: torrent: %s' % torrent
                kw = {'ignored_times': torrent['ignored_times'] - 1}
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance().updateTracker(
                            torrent['infohash'], kw))
                else:
                    TorrentDBHandler.getInstance().updateTracker(
                        torrent['infohash'], kw)
                return

            # may be block here because the internet IO
            torrent = self.readTorrent(torrent)  # read the torrent
            if 'info' not in torrent:  #torrent has been deleted
                if self.db_thread:
                    self.db_thread.add_task(
                        lambda: TorrentDBHandler.getInstance().deleteTorrent(
                            torrent['infohash']))
                else:
                    TorrentDBHandler.getInstance().deleteTorrent(
                        torrent['infohash'])
                return

            # TODO: tracker checking also needs to be update
            if DEBUG:
                print >> sys.stderr, "Tracker Checking"
            trackerChecking(torrent)

            # Must come after tracker check, such that if tracker dead and DHT still alive, the
            # status is still set to good
            self.mldhtchecker.lookup(torrent['infohash'])

            self.updateTorrentInfo(torrent)  # set the ignored_times

            kw = {
                'last_check_time': int(time()),
                'seeder': torrent['seeder'],
                'leecher': torrent['leecher'],
                'status': torrent['status'],
                'ignored_times': torrent['ignored_times'],
                'retried_times': torrent['retried_times'],
                #'info': torrent['info']
            }

            if DEBUG:
                print >> sys.stderr, "Torrent Checking: selectTorrentToCheck:", kw

            if self.db_thread:
                self.db_thread.add_task(lambda: TorrentDBHandler.getInstance(
                ).updateTorrent(torrent['infohash'], **kw))
            else:
                TorrentDBHandler.getInstance().updateTorrent(
                    torrent['infohash'], **kw)
        finally:
            if not self.db_thread:
                TorrentDBHandler.getInstance().close()