Esempio n. 1
0
    def __init__(self, trsession, ignore_singleton=False):
        if not ignore_singleton:
            if LibtorrentMgr.__single:
                raise RuntimeError("LibtorrentMgr is singleton")
            LibtorrentMgr.__single = self

        self.trsession = trsession
        settings = lt.session_settings()
        settings.user_agent = 'Tribler/' + version_id
        # Elric: Strip out the -rcX, -beta, -whatever tail on the version string.
        fingerprint = ['TL'] + map(int,
                                   version_id.split('-')[0].split('.')) + [0]
        # Workaround for libtorrent 0.16.3 segfault (see https://code.google.com/p/libtorrent/issues/detail?id=369)
        self.ltsession = lt.session(lt.fingerprint(*fingerprint), flags=1)
        self.ltsession.set_settings(settings)
        self.ltsession.set_alert_mask(
            lt.alert.category_t.stats_notification
            | lt.alert.category_t.error_notification
            | lt.alert.category_t.status_notification
            | lt.alert.category_t.storage_notification
            | lt.alert.category_t.performance_warning
            | lt.alert.category_t.debug_notification)
        self.ltsession.listen_on(self.trsession.get_listen_port(),
                                 self.trsession.get_listen_port() + 10)
        self.set_upload_rate_limit(-1)
        self.set_download_rate_limit(-1)
        self.upnp_mapper = self.ltsession.start_upnp()

        print >> sys.stderr, "LibtorrentMgr: listening on %d" % self.ltsession.listen_port(
        )

        # Start DHT
        self.dht_ready = False
        try:
            dht_state = open(
                os.path.join(self.trsession.get_state_dir(),
                             DHTSTATE_FILENAME)).read()
            self.ltsession.start_dht(lt.bdecode(dht_state))
        except:
            print >> sys.stderr, "LibtorrentMgr: could not restore dht state, starting from scratch"
            self.ltsession.start_dht(None)

        self.ltsession.add_dht_router('router.bittorrent.com', 6881)
        self.ltsession.add_dht_router('router.utorrent.com', 6881)
        self.ltsession.add_dht_router('router.bitcomet.com', 6881)

        self.torlock = NoDispersyRLock()
        self.torrents = {}

        self.metainfo_requests = {}
        self.metainfo_lock = threading.RLock()
        self.metainfo_cache = {}

        self.trsession.lm.rawserver.add_task(self.process_alerts, 1)
        self.trsession.lm.rawserver.add_task(self.reachability_check, 1)
        self.trsession.lm.rawserver.add_task(self.monitor_dht, 5)

        self.upnp_mappings = {}
Esempio n. 2
0
    def __init__(self, trsession, ignore_singleton=False):
        if not ignore_singleton:
            if LibtorrentMgr.__single:
                raise RuntimeError("LibtorrentMgr is singleton")
            LibtorrentMgr.__single = self

        self.trsession = trsession
        settings = lt.session_settings()
        settings.user_agent = 'Tribler/' + version_id
        # Elric: Strip out the -rcX, -beta, -whatever tail on the version string.
        fingerprint = ['TL'] + map(int, version_id.split('-')[0].split('.')) + [0]
        # Workaround for libtorrent 0.16.3 segfault (see https://code.google.com/p/libtorrent/issues/detail?id=369)
        self.ltsession = lt.session(lt.fingerprint(*fingerprint), flags=1)
        self.ltsession.set_settings(settings)
        self.ltsession.set_alert_mask(lt.alert.category_t.stats_notification |
                                      lt.alert.category_t.error_notification |
                                      lt.alert.category_t.status_notification |
                                      lt.alert.category_t.storage_notification |
                                      lt.alert.category_t.performance_warning |
                                      lt.alert.category_t.debug_notification)
        self.ltsession.listen_on(self.trsession.get_listen_port(), self.trsession.get_listen_port() + 10)
        self.set_upload_rate_limit(-1)
        self.set_download_rate_limit(-1)
        self.upnp_mapper = self.ltsession.start_upnp()

        print >> sys.stderr, "LibtorrentMgr: listening on %d" % self.ltsession.listen_port()

        # Start DHT
        self.dht_ready = False
        try:
            dht_state = open(os.path.join(self.trsession.get_state_dir(), DHTSTATE_FILENAME)).read()
            self.ltsession.start_dht(lt.bdecode(dht_state))
        except:
            print >> sys.stderr, "LibtorrentMgr: could not restore dht state, starting from scratch"
            self.ltsession.start_dht(None)

        self.ltsession.add_dht_router('router.bittorrent.com', 6881)
        self.ltsession.add_dht_router('router.utorrent.com', 6881)
        self.ltsession.add_dht_router('router.bitcomet.com', 6881)

        self.torlock = NoDispersyRLock()
        self.torrents = {}

        self.metainfo_requests = {}
        self.metainfo_lock = threading.RLock()
        self.metainfo_cache = {}

        self.trsession.lm.rawserver.add_task(self.process_alerts, 1)
        self.trsession.lm.rawserver.add_task(self.reachability_check, 1)
        self.trsession.lm.rawserver.add_task(self.monitor_dht, 5)

        self.upnp_mappings = {}
Esempio n. 3
0
    def __init__(self, trsession, utility):
        if LibtorrentMgr.__single:
            raise RuntimeError, "LibtorrentMgr is singleton"
        LibtorrentMgr.__single = self

        self.utility = utility
        self.trsession = trsession
        settings = lt.session_settings()
        settings.user_agent = 'Tribler/' + version_id
        fingerprint = ['TL'] + map(int, version_id.split('.')) + [0]
        # Workaround for libtorrent 0.16.3 segfault (see https://code.google.com/p/libtorrent/issues/detail?id=369)
        self.ltsession = lt.session(lt.fingerprint(*fingerprint), flags=1)
        self.ltsession.set_settings(settings)
        self.ltsession.set_alert_mask(
            lt.alert.category_t.stats_notification
            | lt.alert.category_t.error_notification
            | lt.alert.category_t.status_notification
            | lt.alert.category_t.storage_notification
            | lt.alert.category_t.performance_warning)
        self.ltsession.listen_on(self.trsession.get_listen_port(),
                                 self.trsession.get_listen_port() + 10)
        self.set_upload_rate_limit(-1)
        self.set_download_rate_limit(-1)
        self.ltsession.start_upnp()

        # Start DHT
        try:
            dht_state = open(
                os.path.join(self.trsession.get_state_dir(),
                             DHTSTATE_FILENAME)).read()
            self.ltsession.start_dht(lt.bdecode(dht_state))
        except:
            print >> sys.stderr, "LibtorrentMgr: could not restore dht state, starting from scratch"
            self.ltsession.start_dht(None)
        self.ltsession.add_dht_router('router.bittorrent.com', 6881)
        self.ltsession.add_dht_router('router.utorrent.com', 6881)
        self.ltsession.add_dht_router('router.bitcomet.com', 6881)

        self.torlock = NoDispersyRLock()
        self.torrents = {}
        self.trsession.lm.rawserver.add_task(self.process_alerts, 1)
        self.trsession.lm.rawserver.add_task(self.reachability_check, 1)
Esempio n. 4
0
 def __init__(self, trsession, utility):
     if LibtorrentMgr.__single:
         raise RuntimeError, "LibtorrentMgr is singleton"
     LibtorrentMgr.__single = self 
     
     self.utility = utility
     self.trsession = trsession
     settings = lt.session_settings()
     settings.user_agent = 'Tribler/' + version_id
     fingerprint = ['TL'] + map(int, version_id.split('.')) + [0]
     # Workaround for libtorrent 0.16.3 segfault (see https://code.google.com/p/libtorrent/issues/detail?id=369)
     self.ltsession = lt.session(lt.fingerprint(*fingerprint), flags = 1)
     self.ltsession.set_settings(settings)
     self.ltsession.set_alert_mask(lt.alert.category_t.stats_notification |
                                   lt.alert.category_t.error_notification |
                                   lt.alert.category_t.status_notification |
                                   lt.alert.category_t.storage_notification |
                                   lt.alert.category_t.performance_warning )
     self.ltsession.listen_on(self.trsession.get_listen_port(), self.trsession.get_listen_port()+10)
     self.set_upload_rate_limit(-1)
     self.set_download_rate_limit(-1)
     self.ltsession.start_upnp()
     
     # Start DHT
     try:
         dht_state = open(os.path.join(self.trsession.get_state_dir(), DHTSTATE_FILENAME)).read()
         self.ltsession.start_dht(lt.bdecode(dht_state))
     except:
         print >> sys.stderr, "LibtorrentMgr: could not restore dht state, starting from scratch"
         self.ltsession.start_dht(None)
     self.ltsession.add_dht_router('router.bittorrent.com', 6881)
     self.ltsession.add_dht_router('router.utorrent.com', 6881)
     self.ltsession.add_dht_router('router.bitcomet.com', 6881)
     
     self.torlock = NoDispersyRLock()
     self.torrents = {}
     self.trsession.lm.rawserver.add_task(self.process_alerts, 1)
     self.trsession.lm.rawserver.add_task(self.reachability_check, 1)