Ejemplo n.º 1
0
 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]
Ejemplo n.º 2
0
    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.secure_overlay = secure_overlay
        self.votecastdb = VoteCastDBHandler.getInstance()
        self.my_permid = self.votecastdb.my_permid
        self.session = session
        self.max_length = SINGLE_VOTECAST_LENGTH * (session.get_votecast_random_votes() + session.get_votecast_recent_votes())       

        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
        
        
        self.notifier = Notifier.getInstance()
        
        #Extend logging with VoteCast-messages and status
        if self.log:
            self.overlay_log = OverlayLogger.getInstance(self.log)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
 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()   
Ejemplo n.º 6
0
 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]
Ejemplo n.º 7
0
    def __init__(self, data_handler, overlay_bridge, 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.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.hits = []
        
        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)
Ejemplo n.º 8
0
    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())
        self.subs_dir = os.path.abspath(subs_path)

        self.min_free_space = DEFAULT_MIN_FREE_SPACE
        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)

        diskManager = DiskManager(self.min_free_space, self.config_dir)
        self.diskManager = diskManager

        dmConfig = {
            "maxDiskUsage": MAX_SUBTITLE_DISK_USAGE,
            "diskPolicy": DISK_FULL_DELETE_SOME | DELETE_OLDEST_FIRST,
            "encoding": "utf-8",
        }
        self.diskManager.registerDir(self.subs_dir, dmConfig)

        freeSpace = self.diskManager.getAvailableSpace()
        if DEBUG:
            print >>sys.stderr, SUBS_LOG_PREFIX + "Avaialble %d MB for subtitle collecting" % (freeSpace / (2 ** 20))

        # event notifier
        self._notifier = Notifier.getInstance()

        self.registered = True