Exemple #1
0
 def __init__(self,
              torrent_hash,
              num_pieces,
              coordinator_permid,
              coordinator=None):
     self.torrent_hash = torrent_hash
     self.coordinator = coordinator
     if coordinator_permid is not None and coordinator_permid == '':
         self.coordinator_permid = None
     else:
         self.coordinator_permid = coordinator_permid
     self.coordinator_ip = None
     self.coordinator_port = -1
     if self.coordinator_permid is not None:
         peerdb = PeerDBHandler.getInstance()
         peer = peerdb.getPeer(coordinator_permid)
         if peer is not None:
             self.coordinator_ip = peer['ip']
             self.coordinator_port = peer['port']
     self.overlay_bridge = OverlayThreadingBridge.getInstance()
     self.reserved_pieces = [False] * num_pieces
     self.ignored_pieces = [False] * num_pieces
     self.distr_reserved_pieces = [False] * num_pieces
     self.requested_pieces = deque()
     self.requested_pieces_lock = Lock()
     self.counter = 0
     self.completed = False
     self.marker = [True] * num_pieces
     self.round = 0
     self.encoder = None
     self.continuations = []
     self.outstanding = None
     self.last_req_time = 0
     self.challenge = None
Exemple #2
0
 def __init__(self, torrent_hash, num_pieces, coordinator_permid, coordinator = None):
     self.torrent_hash = torrent_hash
     self.coordinator = coordinator
     self.coordinator_permid = {}
     if coordinator_permid is not None and coordinator_permid == '':
         self.coordinator_permid[None] = [None, -1]
     else:
         peerdb = PeerDBHandler.getInstance()
         peer = peerdb.getPeer(coordinator_permid)
         if peer is not None:
             ip = peer['ip']
             port = peer['port']
             self.coordinator_permid[coordinator_permid] = [ip, port]
         else:
             self.coordinator_permid[None] = [None, -1]
         self.coordinator_ip = None
         self.coordinator_port = None
     self.overlay_bridge = OverlayThreadingBridge.getInstance()
     self.reserved_pieces = [False] * num_pieces
     self.ignored_pieces = [False] * num_pieces
     self.distr_reserved_pieces = [False] * num_pieces
     self.requested_pieces = deque()
     self.requested_pieces_lock = Lock()
     self.counter = 0
     self.completed = False
     self.marker = [True] * num_pieces
     self.round = 0
     self.encoder = None
     self.continuations = []
     self.outstanding = None
     self.last_req_time = 0
     self.received_challenges = {}
     self.downloader = None
 def set_stop_collecting_threshold(self, value):
     self.sesslock.acquire()
     try:
         from freestream.Core.Overlay.OverlayThreadingBridge import OverlayThreadingBridge
         SessionConfigInterface.set_stop_collecting_threshold(self, value)
         olbridge = OverlayThreadingBridge.getInstance()
         task = lambda : self.olthread_set_stop_collecting_threshold(value)
         olbridge.add_task(task, 0)
     finally:
         self.sesslock.release()
Exemple #4
0
 def __init__(self, session):
     if self.__singleton:
         raise RuntimeError, 'Crawler is Singleton'
     self._overlay_bridge = OverlayThreadingBridge.getInstance()
     self._session = session
     self._crawler_db = CrawlerDBHandler.getInstance()
     self._message_handlers = {}
     self._crawl_initiators = []
     self._initiator_deadlines = []
     self._dialback_deadlines = {}
     self._channels = {}
     self._check_deadlines(True)
     self._check_channels()
Exemple #5
0
 def __init__(self, session):
     if self.__singleton:
         raise RuntimeError, 'Crawler is Singleton'
     self._overlay_bridge = OverlayThreadingBridge.getInstance()
     self._session = session
     self._crawler_db = CrawlerDBHandler.getInstance()
     self._message_handlers = {}
     self._crawl_initiators = []
     self._initiator_deadlines = []
     self._dialback_deadlines = {}
     self._channels = {}
     self._check_deadlines(True)
     self._check_channels()
 def __init__(self):
     self.metadata_queue = {}
     self.metadata_queue_lock = Lock()
     self.overlay_bridge = OverlayThreadingBridge.getInstance()
     self.received_challenges = {}
Exemple #7
0
    def register(self, session, sesslock):
        self.session = session
        self.sesslock = sesslock
        self.downloads = {DLTYPE_TORRENT: {},
         DLTYPE_DIRECT: {}}
        config = session.sessconfig
        self.locally_guessed_ext_ip = self.guess_ext_ip_from_local_info()
        self.upnp_ext_ip = None
        self.dialback_ext_ip = None
        self.yourip_ext_ip = None
        self.udppuncture_handler = None
        self.sessdoneflag = Event()
        self.hashcheck_queue = []
        self.sdownloadtohashcheck = None
        self.upnp_thread = None
        self.upnp_type = config['upnp_nat_access']
        self.nat_detect = config['nat_detect']
        self.rawserver = RawServer(self.sessdoneflag, config['timeout_check_interval'], config['timeout'], ipv6_enable=config['ipv6_enabled'], failfunc=self.rawserver_fatalerrorfunc, errorfunc=self.rawserver_nonfatalerrorfunc, max_socket_connects=config['max_socket_connects'])
        self.rawserver.add_task(self.rawserver_keepalive, 1)
        self.listen_port = self.rawserver.find_and_bind(0, config['minport'], config['maxport'], config['bind'], reuse=True, ipv6_socket_style=config['ipv6_binds_v4'], randomizer=config['random_port'])
        if DEBUG:
            log('LM::register: got listen port', self.listen_port)
        self.multihandler = MultiHandler(self.rawserver, self.sessdoneflag)
        self.shutdownstarttime = None
        if config['megacache']:
            cachedb.init(config, self.rawserver_fatalerrorfunc)
            self.my_db = MyDBHandler.getInstance()
            self.torrent_db = TorrentDBHandler.getInstance()
            torrent_collecting_dir = os.path.abspath(config['torrent_collecting_dir'])
            self.torrent_db.register(Category.getInstance(), torrent_collecting_dir)
            self.url2torrent_db = Url2TorrentDBHandler.getInstance()
            self.adid2infohash_db = AdID2InfohashDBHandler.getInstance()
            self.tsplayers_db = TsPlayersDBHandler.getInstance()
            self.tsmetadata_db = TsMetadataDBHandler.getInstance()
            self.user_profile_db = UserProfileDBHandler.getInstance()
            self.peer_db = None
            self.mypref_db = None
            self.pref_db = None
            self.superpeer_db = None
            self.crawler_db = None
            self.seedingstats_db = None
            self.seedingstatssettings_db = None
            self.friendship_statistics_db = None
            self.friend_db = None
            self.bartercast_db = None
            self.votecast_db = None
            self.channelcast_db = None
            self.mm = None
            self.richmetadataDbHandler = None
        else:
            config['overlay'] = 0
            config['torrent_checking'] = 0
            self.my_db = None
            self.peer_db = None
            self.torrent_db = None
            self.mypref_db = None
            self.pref_db = None
            self.superpeer_db = None
            self.crawler_db = None
            self.seedingstats_db = None
            self.seedingstatssettings_db = None
            self.friendship_statistics_db = None
            self.friend_db = None
            self.bartercast_db = None
            self.votecast_db = None
            self.channelcast_db = None
            self.mm = None
            self.richmetadataDbHandler = None
            self.url2torrent_db = None
        if config['overlay']:
            raise RuntimeError, 'Overlay should not be enabled'
            from freestream.Core.Overlay.SecureOverlay import SecureOverlay
            from freestream.Core.Overlay.OverlayThreadingBridge import OverlayThreadingBridge
            from freestream.Core.Overlay.OverlayApps import OverlayApps
            from freestream.Core.RequestPolicy import FriendsCoopDLOtherRQueryQuotumCrawlerAllowAllRequestPolicy
            self.secure_overlay = SecureOverlay.getInstance()
            self.secure_overlay.register(self, config['overlay_max_message_length'])
            self.overlay_apps = OverlayApps.getInstance()
            policy = FriendsCoopDLOtherRQueryQuotumCrawlerAllowAllRequestPolicy(self.session)
            self.overlay_bridge = OverlayThreadingBridge.getInstance()
            self.overlay_bridge.register_bridge(self.secure_overlay, self.overlay_apps)
            self.overlay_apps.register(self.overlay_bridge, self.session, self, config, policy)
            self.overlay_bridge.start_listening()
            if config['multicast_local_peer_discovery']:
                self.setup_multicast_discovery()
        else:
            self.secure_overlay = None
            self.overlay_apps = None
            config['buddycast'] = 0
            config['download_help'] = 0
            config['socnet'] = 0
            config['rquery'] = 0
            try:
                some_dialback_handler = DialbackMsgHandler.getInstance()
                some_dialback_handler.register_yourip(self)
            except:
                if DEBUG:
                    log_exc()

        if config['megacache'] or config['overlay']:
            Category.getInstance(config['install_dir'])
        self.internaltracker = None
        if config['internaltracker']:
            self.internaltracker = Tracker(config, self.rawserver)
            if self.session.app_http_handler is None:
                self.httphandler = HTTPHandler(self.internaltracker.get, config['tracker_min_time_between_log_flushes'])
            else:
                self.session.app_http_handler.set_default_http_handler(self.internaltracker.get)
                self.httphandler = HTTPHandler(self.session.app_http_handler.get, config['tracker_min_time_between_log_flushes'])
        elif self.session.app_http_handler is not None:
            self.httphandler = HTTPHandler(self.session.app_http_handler.get, 60)
        else:
            self.httphandler = DummyHTTPHandler()
        self.multihandler.set_httphandler(self.httphandler)
        if config['mainline_dht']:
            mainlineDHT.init(('127.0.0.1', self.listen_port), config['state_dir'])
        if config['torrent_checking']:
            if config['mainline_dht']:
                from freestream.Core.DecentralizedTracking.mainlineDHTChecker import mainlineDHTChecker
                c = mainlineDHTChecker.getInstance()
                c.register(mainlineDHT.dht)
            self.torrent_checking_period = config['torrent_checking_period']
            self.rawserver.add_task(self.run_torrent_check, self.torrent_checking_period)
        if config['magnetlink']:
            MagnetHandler.get_instance(self.rawserver)
        self.dispersy = None
        self.session.dispersy_member = None
 def __init__(self):
     self.metadata_queue = {}
     self.metadata_queue_lock = Lock()
     self.overlay_bridge = OverlayThreadingBridge.getInstance()
     self.received_challenges = {}