def __init__(self, db_dir=''): BasicDBHandler.__init__(self) self.notifier = Notifier.getInstance() self.torrent_db = TorrentDB.getInstance(db_dir=db_dir) self.mypref_db = MyPreferenceDB.getInstance(db_dir=db_dir) self.owner_db = OwnerDB.getInstance(db_dir=db_dir) self.dbs = [self.torrent_db]
def __init__(self, info_hash, raw_server, callback, max_connections=30): # _info_hash is the 20 byte binary info hash that identifies # the swarm. assert isinstance(info_hash, str), str assert len(info_hash) == 20 self._info_hash = info_hash # _raw_server provides threading support. All socket events # will run in this thread. self._raw_server = raw_server # _callback is called with the raw metadata string when it is # retrieved self._callback = callback # _max_connections limits the number of open TCP connections # while downloading self._max_connections = max_connections # _peer_id contains 20 semi random bytes self._peer_id = "-ST0100-" + "".join([chr(getrandbits(8)) for _ in range(12)]) assert isinstance(self._peer_id, str) assert len(self._peer_id) == 20, len(self._peer_id) # _lock protects several member variables that are accessed # from our RawServer and other threads. self._lock = RLock() # _connections contains all open socket connections. This # variable is protected by _lock. self._connections = [] # _metadata_blocks contains the blocks that form the metadata # that we want to download. This variable is protected by # _lock. self._metadata_blocks = [] # [requested, piece, data] # _metadata_size contains the size in bytes of the metadata. # This value is based on the opinions of other peers which is # accumulated in _metadata_size_opinions. self._metadata_size = 0 self._metadata_size_opinions = {} # size:number-of-votes # _potential_peers contains a dictionary of address::timestamp # pairs where potential BitTorrent peers can be found self._potential_peers = {} # _good_peers contains a dictionary of address:timestamp pairs # where valid BitTorrent peers can be found self._good_peers = {} # _closed indicates that we no longer need this swarm instance self._closed = False # scan for old connections self._raw_server.add_task(self._timeout_connections, 5) # notify gui that torrent is being collected using dht self._notifier = Notifier.getInstance() self._notifier.notify(NTFY_TORRENTS, NTFY_MAGNET_STARTED, self._info_hash)
def __init__(self, info_hash, raw_server, callback, max_connections=30): # _info_hash is the 20 byte binary info hash that identifies # the swarm. assert isinstance(info_hash, str), str assert len(info_hash) == 20 self._info_hash = info_hash # _raw_server provides threading support. All socket events # will run in this thread. self._raw_server = raw_server # _callback is called with the raw metadata string when it is # retrieved self._callback = callback # _max_connections limits the number of open TCP connections # while downloading self._max_connections = max_connections # _peer_id contains 20 semi random bytes self._peer_id = "-ST0100-" + "".join([chr(getrandbits(8)) for _ in range(12)]) assert isinstance(self._peer_id, str) assert len(self._peer_id) == 20, len(self._peer_id) # _lock protects several member variables that are accessed # from our RawServer and other threads. self._lock = RLock() # _connections contains all open socket connections. This # variable is protected by _lock. self._connections = [] # _metadata_blocks contains the blocks that form the metadata # that we want to download. This variable is protected by # _lock. self._metadata_blocks = [] # [requested, piece, data] # _metadata_size contains the size in bytes of the metadata. # This value is based on the opinions of other peers which is # accumulated in _metadata_size_opinions. self._metadata_size = 0 self._metadata_size_opinions = {} # size:number-of-votes # _potential_peers contains a dictionary of address::timestamp # pairs where potential BitTorrent peers can be found self._potential_peers = {} # _good_peers contains a dictionary of address:timestamp pairs # where valid BitTorrent peers can be found self._good_peers = {} # _closed indicates that we no longer need this swarm instance self._closed = False # scan for old connections self._raw_server.add_task(self._timeout_connections, 5) # notify gui that torrent is being collected using dht self._notifier = Notifier.getInstance() self._notifier.notify(NTFY_TORRENTS, NTFY_MAGNET_STARTED, self._info_hash)
def __init__(self, interval = 15): if TorrentChecking.__single: raise RuntimeError, "TorrentChecking is singleton" TorrentChecking.__single = self Thread.__init__(self) self.setName('TorrentChecking'+self.getName()) if DEBUG: print >> sys.stderr, 'TorrentChecking: Started torrentchecking', threading.currentThread().getName() self.setDaemon(True) self.retryThreshold = 10 self.gnThreashold = 0.9 self.interval = interval self.queue = deque() self.queueset = set() self.queueLock = Lock() self.mldhtchecker = mainlineDHTChecker.getInstance() self.torrentdb = TorrentDBHandler.getInstance() self.notifier = Notifier.getInstance() self.sleepEvent = threading.Event() self.start()
def __init__(self, master, integrate_with_tribler=True): super(SearchCommunity, self).__init__(master) self.integrate_with_tribler = integrate_with_tribler self.taste_buddies = [] if self.integrate_with_tribler: from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler from Tribler.Core.CacheDB.Notifier import Notifier # tribler channelcast database self._channelcast_db = ChannelCastDBHandler.getInstance() self._torrent_db = TorrentDBHandler.getInstance() self._mypref_db = MyPreferenceDBHandler.getInstance() self._notifier = Notifier.getInstance() # torrent collecting self._rtorrent_handler = RemoteTorrentHandler.getInstance() else: self._channelcast_db = ChannelCastDBStub(self._dispersy) self._torrent_db = None self._mypref_db = None self._notifier = None self.taste_bloom_filter = None self.taste_bloom_filter_key = None self.dispersy.callback.register(self.create_torrent_collect_requests, delay=CANDIDATE_WALK_LIFETIME)
def __init__(self, db_dir=""): BasicDBHandler.__init__(self) self.notifier = Notifier.getInstance() self.torrent_db = TorrentDB.getInstance(db_dir=db_dir) self.mypref_db = MyPreferenceDB.getInstance(db_dir=db_dir) self.owner_db = OwnerDB.getInstance(db_dir=db_dir) self.dbs = [self.torrent_db]
def __init__(self, data_handler, secure_overlay, session, buddycast_interval_function, log = '', dnsindb = None): """ Returns an instance of this class """ #Keep reference to interval-function of BuddycastFactory self.interval = buddycast_interval_function self.data_handler = data_handler self.dnsindb = dnsindb self.log = log self.peerdb = PeerDBHandler.getInstance() self.votecastdb = VoteCastDBHandler.getInstance() self.session = session self.my_permid = session.get_permid() self.max_length = SINGLE_VOTECAST_LENGTH * (session.get_votecast_random_votes() + session.get_votecast_recent_votes()) #Reference to buddycast-core, set by the buddycast-core (as it is created by the #buddycast-factory after calling this constructor). self.buddycast_core = None self.notifier = Notifier.getInstance() #Extend logging with VoteCast-messages and status if self.log: self.overlay_log = OverlayLogger.getInstance(self.log)
def __init__(self, master, integrate_with_tribler = True): super(SearchCommunity, self).__init__(master) self.integrate_with_tribler = integrate_with_tribler self.taste_buddies = [] #To always connect to a peer uncomment/modify the following line #self.taste_buddies.append([1, time(), Candidate(("127.0.0.1", 1234), False)) if self.integrate_with_tribler: from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler from Tribler.Core.CacheDB.Notifier import Notifier # tribler channelcast database self._channelcast_db = ChannelCastDBHandler.getInstance() self._torrent_db = TorrentDBHandler.getInstance() self._mypref_db = MyPreferenceDBHandler.getInstance() self._notifier = Notifier.getInstance() # torrent collecting self._rtorrent_handler = RemoteTorrentHandler.getInstance() else: self._channelcast_db = ChannelCastDBStub(self._dispersy) self._torrent_db = None self._mypref_db = None self._notifier = None self.taste_bloom_filter = None self.taste_bloom_filter_key = None self.torrent_cache = None self.dispersy.callback.register(self.create_torrent_collect_requests, delay = CANDIDATE_WALK_LIFETIME) self.dispersy.callback.register(self.fast_walker)
def __init__(self, dispersy, master, integrate_with_tribler=True): super(SearchCommunity, self).__init__(dispersy, master) self.integrate_with_tribler = integrate_with_tribler self.taste_buddies = [] # To always connect to a peer uncomment/modify the following line # self.taste_buddies.append([1, time(), Candidate(("127.0.0.1", 1234), False)) if self.integrate_with_tribler: from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler from Tribler.Core.CacheDB.Notifier import Notifier # tribler channelcast database self._channelcast_db = ChannelCastDBHandler.getInstance() self._torrent_db = TorrentDBHandler.getInstance() self._mypref_db = MyPreferenceDBHandler.getInstance() self._notifier = Notifier.getInstance() # torrent collecting self._rtorrent_handler = RemoteTorrentHandler.getInstance() else: self._channelcast_db = ChannelCastDBStub(self._dispersy) self._torrent_db = None self._mypref_db = None self._notifier = None self.taste_bloom_filter = None self.taste_bloom_filter_key = None self.torrent_cache = None self.dispersy.callback.register(self.create_torrent_collect_requests, delay=CANDIDATE_WALK_LIFETIME) self.dispersy.callback.register(self.fast_walker)
def __init__(self, data_handler, secure_overlay, session, buddycast_interval_function, log='', dnsindb=None): """ Returns an instance of this class """ #Keep reference to interval-function of BuddycastFactory self.interval = buddycast_interval_function self.data_handler = data_handler self.dnsindb = dnsindb self.log = log self.peerdb = PeerDBHandler.getInstance() self.votecastdb = VoteCastDBHandler.getInstance() self.session = session self.my_permid = session.get_permid() self.max_length = SINGLE_VOTECAST_LENGTH * ( session.get_votecast_random_votes() + session.get_votecast_recent_votes()) #Reference to buddycast-core, set by the buddycast-core (as it is created by the #buddycast-factory after calling this constructor). self.buddycast_core = None self.notifier = Notifier.getInstance() #Extend logging with VoteCast-messages and status if self.log: self.overlay_log = OverlayLogger.getInstance(self.log)
def __init__(self, interval=15): if TorrentChecking.__single: raise RuntimeError, "TorrentChecking is singleton" TorrentChecking.__single = self Thread.__init__(self) self.setName('TorrentChecking' + self.getName()) if DEBUG: print >> sys.stderr, 'TorrentChecking: Started torrentchecking', threading.currentThread( ).getName() self.setDaemon(True) self.retryThreshold = 10 self.gnThreashold = 0.9 self.interval = interval self.queue = deque() self.queueset = set() self.queueLock = Lock() self.mldhtchecker = mainlineDHTChecker.getInstance() self.torrentdb = TorrentDBHandler.getInstance() self.notifier = Notifier.getInstance() self.sleepEvent = threading.Event() self.start()
def __init__(self, master, integrate_with_tribler = True): super(SearchCommunity, self).__init__(master) self.integrate_with_tribler = integrate_with_tribler self.taste_buddies = [] if self.integrate_with_tribler: from Tribler.Core.CacheDB.SqliteCacheDBHandler import ChannelCastDBHandler, TorrentDBHandler, MyPreferenceDBHandler from Tribler.Core.CacheDB.Notifier import Notifier # tribler channelcast database self._channelcast_db = ChannelCastDBHandler.getInstance() self._torrent_db = TorrentDBHandler.getInstance() self._mypref_db = MyPreferenceDBHandler.getInstance() self._notifier = Notifier.getInstance() # torrent collecting self._rtorrent_handler = RemoteTorrentHandler.getInstance() else: self._channelcast_db = ChannelCastDBStub(self._dispersy) self._torrent_db = None self._mypref_db = None self._notifier = None self.taste_bloom_filter = None self.taste_bloom_filter_key = None self.dispersy.callback.register(self.create_torrent_collect_requests, delay = CANDIDATE_WALK_LIFETIME)
def __init__(self, session): self.session = session self.sesslock = session.sesslock self.sessconfig = session.sessconfig # Notifier for callbacks to API user self.threadpool = ThreadPool(2) self.notifier = Notifier.getInstance(self.threadpool)
def __init__(self,session): self.session = session self.sesslock = session.sesslock self.sessconfig = session.sessconfig # Notifier for callbacks to API user self.threadpool = ThreadPool(2) self.notifier = Notifier.getInstance(self.threadpool)
def __init__(self, config, db_dir=""): BasicDBHandler.__init__(self) self.peer_db = PeerDB.getInstance(db_dir=db_dir) self.dbs = [self.peer_db] self.notifier = Notifier.getInstance() filename = os.path.join(config["install_dir"], config["superpeer_file"]) self.superpeer_list = self.readSuperPeerList(filename) # print 'sp list: %s' % self.superpeer_list self.updatePeerDB()
def __init__(self, config, db_dir=''): BasicDBHandler.__init__(self) self.peer_db = PeerDB.getInstance(db_dir=db_dir) self.dbs = [self.peer_db] self.notifier = Notifier.getInstance() filename = os.path.join(config['install_dir'], config['superpeer_file']) self.superpeer_list = self.readSuperPeerList(filename) #print 'sp list: %s' % self.superpeer_list self.updatePeerDB()
def __init__(self, config, db_dir=""): BasicDBHandler.__init__(self) self.notifier = Notifier.getInstance() self.peer_db = PeerDB.getInstance(db_dir=db_dir) self.pref_db = PreferenceDB.getInstance(db_dir=db_dir) self.friends_db_handler = FriendDBHandler.getInstance() self.pref_db_handler = PreferenceDBHandler(db_dir=db_dir) self.ip_db = IP2PermIDDB.getInstance(db_dir=db_dir) # self.mm = Mugshot Manager.getInstance() # self.mm.register(config) self.dbs = [self.peer_db, self.ip_db]
def __init__(self, config, db_dir=''): BasicDBHandler.__init__(self) self.notifier = Notifier.getInstance() self.peer_db = PeerDB.getInstance(db_dir=db_dir) self.pref_db = PreferenceDB.getInstance(db_dir=db_dir) self.friends_db_handler = FriendDBHandler.getInstance() self.pref_db_handler = PreferenceDBHandler(db_dir=db_dir) self.ip_db = IP2PermIDDB.getInstance(db_dir=db_dir) self.mm = MugshotManager.getInstance() self.mm.register(config) self.dbs = [self.peer_db, self.ip_db]
def __init__(self, data_handler, overlay_bridge, session, buddycast_interval_function, log='', dnsindb=None): """ Returns an instance of this class """ if ChannelCastCore.__single: raise RuntimeError, "ChannelCastCore is singleton" ChannelCastCore.__single = self #Keep reference to interval-function of BuddycastFactory self.interval = buddycast_interval_function self.data_handler = data_handler self.dnsindb = dnsindb self.log = log self.overlay_bridge = overlay_bridge self.channelcastdb = ChannelCastDBHandler.getInstance() self.votecastdb = VoteCastDBHandler.getInstance() self.rtorrent_handler = RemoteTorrentHandler.getInstance() self.session = session self.database_thread = session.lm.database_thread self.my_permid = session.get_permid() self.network_delay = 30 #Reference to buddycast-core, set by the buddycast-core (as it is created by the #buddycast-factory after calling this constructor). self.buddycast_core = None #Extend logging with ChannelCast-messages and status if self.log: self.overlay_log = OverlayLogger.getInstance(self.log) self.dnsindb = self.data_handler.get_dns_from_peerdb self.notifier = Notifier.getInstance() self.metadataDbHandler = MetadataDBHandler.getInstance() #subtitlesHandler = SubtitlesHandler.getInstance() subtitleSupport = SubtitlesSupport.getInstance() # better if an instance of RMDInterceptor was provided from the # outside self.peersHaveManger = PeersHaveManager.getInstance() if not self.peersHaveManger.isRegistered(): self.peersHaveManger.register(self.metadataDbHandler, self.overlay_bridge)
def register(self, overlay_bridge, metadataDBHandler, session): """ Injects the required dependencies on the instance. @param overlay_bridge: a reference to a working instance of OverlayTrheadingBridge @param metadataDBHandler: a reference to the current instance of L{MetadataDBHandler} @param session: a reference to the running session """ self.overlay_bridge = overlay_bridge self.subtitlesDb = metadataDBHandler self.config_dir = os.path.abspath(session.get_state_dir()) subs_path = os.path.join(self.config_dir, session.get_subtitles_collecting_dir()) # George Milescu, 19.11.2010 # I replaced self.subs_dir because os.path.abspath(subs_path) returns an inexistent path for non-standard tribler paths # self.subs_dir = os.path.abspath(subs_path) self.subs_dir = os.path.abspath(session.get_subtitles_collecting_dir()) self._upload_rate = session.get_subtitles_upload_rate() self.max_subs_message_size = MAX_SUBS_MESSAGE_SIZE self._session = session #the upload rate is controlled by a token bucket. #a token corresponds to 1 KB. #The max burst size corresponds to 2 subtitles of the maximum size (2 MBs) tokenBucket = SimpleTokenBucket(self._upload_rate, self.max_subs_message_size) self._subsMsgHndlr = SubsMessageHandler(self.overlay_bridge, tokenBucket, MAX_SUBTITLE_SIZE) self._subsMsgHndlr.registerListener(self) #assure that the directory exists if os.path.isdir(self.config_dir) : if not os.path.isdir(self.subs_dir): try: os.mkdir(self.subs_dir) except: msg = u"Cannot create collecting dir %s " % self.subs_dir print >> sys.stderr, "Error: %s" % msg raise IOError(msg) else: msg = u"Configuration dir %s does not exists" % self.subs_dir print >> sys.stderr, "Error: %s" % msg raise IOError(msg) #event notifier self._notifier = Notifier.getInstance() self.registered = True
def __init__(self, data_handler, overlay_bridge, session, buddycast_interval_function, log = '', dnsindb = None): """ Returns an instance of this class """ if ChannelCastCore.__single: raise RuntimeError, "ChannelCastCore is singleton" ChannelCastCore.__single = self #Keep reference to interval-function of BuddycastFactory self.interval = buddycast_interval_function self.data_handler = data_handler self.dnsindb = dnsindb self.log = log self.overlay_bridge = overlay_bridge self.channelcastdb = ChannelCastDBHandler.getInstance() self.votecastdb = VoteCastDBHandler.getInstance() self.rtorrent_handler = RemoteTorrentHandler.getInstance() self.my_permid = self.channelcastdb.my_permid self.session = session self.network_delay = 30 #Reference to buddycast-core, set by the buddycast-core (as it is created by the #buddycast-factory after calling this constructor). self.buddycast_core = None #Extend logging with ChannelCast-messages and status if self.log: self.overlay_log = OverlayLogger.getInstance(self.log) self.dnsindb = self.data_handler.get_dns_from_peerdb self.notifier = Notifier.getInstance() self.metadataDbHandler = MetadataDBHandler.getInstance() #subtitlesHandler = SubtitlesHandler.getInstance() subtitleSupport = SubtitlesSupport.getInstance() # better if an instance of RMDInterceptor was provided from the # outside self.peersHaveManger = PeersHaveManager.getInstance() if not self.peersHaveManger.isRegistered(): self.peersHaveManger.register(self.metadataDbHandler, self.overlay_bridge) self.richMetadataInterceptor = RichMetadataInterceptor(self.metadataDbHandler,self.votecastdb, self.my_permid, subtitleSupport, self.peersHaveManger, self.notifier)
def sesscb_states_callback(self, dslist): if not self.ready: return (5.0, []) wantpeers = [] self.ratestatecallbackcount += 1 if DEBUG: torrentdb = self.utility.session.open_dbhandler(NTFY_TORRENTS) peerdb = self.utility.session.open_dbhandler(NTFY_PEERS) print >> sys.stderr, "main: Stats: Total torrents found", torrentdb.size(), "peers", peerdb.size() try: # Print stats on Console if DEBUG: if self.ratestatecallbackcount % 5 == 0: for ds in dslist: safename = repr(ds.get_download().get_def().get_name()) if DEBUG: print >> sys.stderr, "%s %s %.1f%% dl %.1f ul %.1f n %d" % (safename, dlstatus_strings[ds.get_status()], 100.0 * ds.get_progress(), ds.get_current_speed(DOWNLOAD), ds.get_current_speed(UPLOAD), ds.get_num_peers()) # print >>sys.stderr,"main: Infohash:",`ds.get_download().get_def().get_infohash()` if ds.get_status() == DLSTATUS_STOPPED_ON_ERROR: print >> sys.stderr, "main: Error:", repr(ds.get_error()) # Pass DownloadStates to libaryView no_collected_list = [] try: coldir = os.path.basename(os.path.abspath(self.utility.session.get_torrent_collecting_dir())) for ds in dslist: destdir = os.path.basename(ds.get_download().get_dest_dir()) if destdir != coldir: no_collected_list.append(ds) # Arno, 2012-07-17: Retrieving peerlist for the DownloadStates takes CPU # so only do it when needed for display. wantpeers.extend(self.guiUtility.library_manager.download_state_callback(no_collected_list)) except: print_exc() # Update bandwidth statistics in the Barter Community if not self.barter_community: self.barter_community = self.dispersy.callback.call(self._dispersy_get_barter_community) if self.barter_community and not isinstance(self.barter_community, HardKilledCommunity): if self.barter_community.has_been_killed: # set BARTER_COMMUNITY to None. next state callback we will again get the # community resulting in the HardKilledCommunity instead self.barter_community = None else: if True in self.lastwantpeers: self.dispersy.callback.register(self.barter_community.download_state_callback, (dslist, True)) # only request peer info every 120 intervals if self.ratestatecallbackcount % 120 == 0: wantpeers.append(True) # Find State of currently playing video playds = None d = self.videoplayer.get_vod_download() for ds in dslist: if ds.get_download() == d: playds = ds # Apply status displaying from SwarmPlayer if playds: def do_video(): if playds.get_status() == DLSTATUS_HASHCHECKING: progress = progress_consec = playds.get_progress() else: progress = playds.get_vod_prebuffering_progress() progress_consec = playds.get_vod_prebuffering_progress_consec() self.videoplayer.set_player_status_and_progress(progress, progress_consec, \ playds.get_pieces_complete() if playds.get_progress() < 1.0 else [True]) wx.CallAfter(do_video) # Check to see if a download has finished newActiveDownloads = [] doCheckpoint = False for ds in dslist: state = ds.get_status() safename = ds.get_download().get_def().get_name() if state == DLSTATUS_DOWNLOADING: newActiveDownloads.append(safename) elif state == DLSTATUS_SEEDING: if safename in self.prevActiveDownloads: download = ds.get_download() cdef = download.get_def() coldir = os.path.basename(os.path.abspath(self.utility.session.get_torrent_collecting_dir())) destdir = os.path.basename(download.get_dest_dir()) if destdir != coldir: hash = cdef.get_id() notifier = Notifier.getInstance() notifier.notify(NTFY_TORRENTS, NTFY_FINISHED, hash, safename) # Arno, 2012-05-04: Swift reseeding if self.utility.config.Read('swiftreseed') == 1 and cdef.get_def_type() == 'torrent' and not download.get_selected_files(): self.sesscb_reseed_via_swift(download) doCheckpoint = True self.prevActiveDownloads = newActiveDownloads if doCheckpoint: self.utility.session.checkpoint() self.seedingmanager.apply_seeding_policy(no_collected_list) # Adjust speeds once every 4 seconds adjustspeeds = False if self.ratestatecallbackcount % 4 == 0: adjustspeeds = True if adjustspeeds: swift_dslist = [ds for ds in no_collected_list if ds.get_download().get_def().get_def_type() == 'swift'] self.ratelimiter.add_downloadstatelist(swift_dslist) self.ratelimiter.adjust_speeds() if DEBUG_DOWNLOADS: for ds in dslist: cdef = ds.get_download().get_def() state = ds.get_status() if cdef.get_def_type() == 'swift': safename = cdef.get_name() print >> sys.stderr, "tribler: SW", dlstatus_strings[state], safename, ds.get_current_speed(UPLOAD) else: print >> sys.stderr, "tribler: BT", dlstatus_strings[state], cdef.get_name(), ds.get_current_speed(UPLOAD) except: print_exc() self.lastwantpeers = wantpeers return (1.0, wantpeers)