def __init__(
        self,
        infohash,
        metainfo,
        kvconfig,
        multihandler,
        get_extip_func,
        listenport,
        videoanalyserpath,
        vodfileindex,
        set_error_func,
        pstate,
        lmvodeventcallback,
        lmhashcheckcompletecallback,
        peer_type="-",
        is_supporter_seed=False,
        supporter_ips=[],
    ):
        # SmoothIT_
        self.is_supporter_seed = is_supporter_seed
        print >>sys.stderr, "SingleDownload: Supporter Ips=%s" % supporter_ips
        self.supporter_ips = supporter_ips
        # _SmoothIT
        self.dow = None
        self.set_error_func = set_error_func
        self.videoinfo = None
        self.videostatus = None
        self.lmvodeventcallback = lmvodeventcallback
        self.lmhashcheckcompletecallback = lmhashcheckcompletecallback
        self.logmsgs = []
        self._hashcheckfunc = None
        self._getstatsfunc = None
        self.infohash = infohash
        self.b64_infohash = b64encode(infohash)
        try:
            self.dldoneflag = Event()
            self.dlrawserver = multihandler.newRawServer(infohash, self.dldoneflag)
            self.lmvodeventcallback = lmvodeventcallback

            if pstate is not None:
                self.hashcheckfrac = pstate["dlstate"]["progress"]
            else:
                self.hashcheckfrac = 0.0

            self.peerid = createPeerID("-" + peer_type + "-")

            # LOGGING
            from BaseLib.Core.Statistics.StatusReporter import get_reporter_instance

            event_reporter = get_reporter_instance()
            event_reporter.add_event(self.b64_infohash, "peerid:%s" % b64encode(self.peerid))

            # print >>sys.stderr,"SingleDownload: __init__: My peer ID is",`peerid`

            self.dow = BT1Download(
                self.hashcheckprogressfunc,
                self.finishedfunc,
                self.fatalerrorfunc,
                self.nonfatalerrorfunc,
                self.logerrorfunc,
                self.dldoneflag,
                kvconfig,
                metainfo,
                infohash,
                self.peerid,
                self.dlrawserver,
                get_extip_func,
                listenport,
                videoanalyserpath,
            )

            self.filename = file = self.dow.saveAs(self.save_as)
            # if DEBUG:
            #    print >>sys.stderr,"SingleDownload: dow.saveAs returned",file

            # Set local filename in vodfileindex
            if vodfileindex is not None:
                # Ric: for SVC the index is a list of indexes
                index = vodfileindex["index"]
                if type(index) == ListType:
                    svc = len(index) > 1
                else:
                    svc = False

                if svc:
                    outpathindex = self.dow.get_dest(index[0])
                else:
                    if index == -1:
                        index = 0
                    outpathindex = self.dow.get_dest(index)

                vodfileindex["outpath"] = outpathindex
                self.videoinfo = vodfileindex
                if "live" in metainfo["info"]:
                    authparams = metainfo["info"]["live"]
                else:
                    authparams = None
                if svc:
                    self.videostatus = SVCVideoStatus(
                        metainfo["info"]["piece length"], self.dow.files, vodfileindex, authparams
                    )
                else:
                    self.videostatus = VideoStatus(
                        metainfo["info"]["piece length"], self.dow.files, vodfileindex, authparams
                    )
                self.videoinfo["status"] = self.videostatus
                self.dow.set_videoinfo(vodfileindex, self.videostatus)

            # if DEBUG:
            #    print >>sys.stderr,"SingleDownload: setting vodfileindex",vodfileindex

            # RePEX: Start in RePEX mode
            if kvconfig["initialdlstatus"] == DLSTATUS_REPEXING:
                if pstate is not None and pstate.has_key("dlstate"):
                    swarmcache = pstate["dlstate"].get("swarmcache", {})
                else:
                    swarmcache = {}
                self.repexer = RePEXer(self.infohash, swarmcache)
            else:
                self.repexer = None

            if pstate is None:
                resumedata = None
            else:
                # Restarting download
                resumedata = pstate["engineresumedata"]
            self._hashcheckfunc = self.dow.initFiles(resumedata=resumedata)

        except Exception, e:
            self.fatalerrorfunc(e)
Example #2
0
def create_my_peer_id(my_listen_port):
    myid = createPeerID()
    myid = myid[:14] + pack('<H', my_listen_port) + myid[16:]
    return myid
Example #3
0
    def __init__(self,infohash,metainfo,kvconfig,multihandler,get_extip_func,listenport,videoanalyserpath,vodfileindex,set_error_func,pstate,lmvodeventcallback,lmhashcheckcompletecallback):
        self.dow = None
        self.set_error_func = set_error_func
        self.videoinfo = None
        self.videostatus = None
        self.lmvodeventcallback = lmvodeventcallback
        self.lmhashcheckcompletecallback = lmhashcheckcompletecallback
        self.logmsgs = []
        self._hashcheckfunc = None
        self._getstatsfunc = None
        self.infohash = infohash
        self.b64_infohash = b64encode(infohash)
        self.repexer = None
        try:
            self.dldoneflag = Event()
            self.dlrawserver = multihandler.newRawServer(infohash,self.dldoneflag)
            self.lmvodeventcallback = lmvodeventcallback
    
            if pstate is not None:
                self.hashcheckfrac = pstate['dlstate']['progress']
            else:
                self.hashcheckfrac = 0.0
    
            self.peerid = createPeerID()
            
            # LOGGING
            event_reporter = get_status_holder("LivingLab")
            event_reporter.create_and_add_event("peerid", [self.b64_infohash, b64encode(self.peerid)])
            
            #print >>sys.stderr,time.asctime(),'-', "SingleDownload: __init__: My peer ID is",`peerid`
    
            self.dow = BT1Download(self.hashcheckprogressfunc,
                            self.finishedfunc,
                            self.fatalerrorfunc, 
                            self.nonfatalerrorfunc,
                            self.logerrorfunc,
                            self.dldoneflag,
                            kvconfig,
                            metainfo, 
                            infohash,
                            self.peerid,
                            self.dlrawserver,
                            get_extip_func,
                            listenport,
                            videoanalyserpath
                            )
        
            file = self.dow.saveAs(self.save_as)
            #if DEBUG:
            #    print >>sys.stderr,time.asctime(),'-', "SingleDownload: dow.saveAs returned",file
            
            # Set local filename in vodfileindex
            if vodfileindex is not None:
                # Ric: for SVC the index is a list of indexes
                index = vodfileindex['index']
                if type(index) == ListType:
                    svc = len(index) > 1
                else:
                    svc = False
                
                if svc:
                    outpathindex = self.dow.get_dest(index[0])
                else:
                    if index == -1:
                        index = 0
                    outpathindex = self.dow.get_dest(index)

                vodfileindex['outpath'] = outpathindex
                self.videoinfo = vodfileindex
                if 'live' in metainfo['info']:
                    authparams = metainfo['info']['live']
                else:
                    authparams = None
                if svc:
                    self.videostatus = SVCVideoStatus(metainfo['info']['piece length'],self.dow.files,vodfileindex,authparams)
                else:
                    self.videostatus = VideoStatus(metainfo['info']['piece length'],self.dow.files,vodfileindex,authparams)
                self.videoinfo['status'] = self.videostatus
                self.dow.set_videoinfo(vodfileindex,self.videostatus)

            #if DEBUG:
            #    print >>sys.stderr,time.asctime(),'-', "SingleDownload: setting vodfileindex",vodfileindex
            
            # RePEX: Start in RePEX mode
            if kvconfig['initialdlstatus'] == DLSTATUS_REPEXING:
                if pstate is not None and pstate.has_key('dlstate'):
                    swarmcache = pstate['dlstate'].get('swarmcache',{})
                else:
                    swarmcache = {}
                self.repexer = RePEXer(self.infohash, swarmcache)
            else:
                self.repexer = None
            
            if pstate is None:
                resumedata = None
            else:
                # Restarting download
                resumedata=pstate['engineresumedata']
            self._hashcheckfunc = self.dow.initFiles(resumedata=resumedata)

            
        except Exception,e:
            self.fatalerrorfunc(e)
Example #4
0
def create_my_peer_id(my_listen_port):
    myid = createPeerID()
    myid = myid[:14] + pack('<H', my_listen_port) + myid[16:]
    return myid
    def __init__(self,
                 infohash,
                 metainfo,
                 kvconfig,
                 multihandler,
                 get_extip_func,
                 listenport,
                 videoanalyserpath,
                 vodfileindex,
                 set_error_func,
                 pstate,
                 lmvodeventcallback,
                 lmhashcheckcompletecallback,
                 peer_type="-",
                 is_supporter_seed=False,
                 supporter_ips=[]):
        #SmoothIT_
        self.is_supporter_seed = is_supporter_seed
        print >> sys.stderr, "SingleDownload: Supporter Ips=%s" % supporter_ips
        self.supporter_ips = supporter_ips
        #_SmoothIT
        self.dow = None
        self.set_error_func = set_error_func
        self.videoinfo = None
        self.videostatus = None
        self.lmvodeventcallback = lmvodeventcallback
        self.lmhashcheckcompletecallback = lmhashcheckcompletecallback
        self.logmsgs = []
        self._hashcheckfunc = None
        self._getstatsfunc = None
        self.infohash = infohash
        self.b64_infohash = b64encode(infohash)
        try:
            self.dldoneflag = Event()
            self.dlrawserver = multihandler.newRawServer(
                infohash, self.dldoneflag)
            self.lmvodeventcallback = lmvodeventcallback

            if pstate is not None:
                self.hashcheckfrac = pstate['dlstate']['progress']
            else:
                self.hashcheckfrac = 0.0

            self.peerid = createPeerID("-" + peer_type + "-")

            # LOGGING
            from BaseLib.Core.Statistics.StatusReporter import get_reporter_instance
            event_reporter = get_reporter_instance()
            event_reporter.add_event(self.b64_infohash,
                                     "peerid:%s" % b64encode(self.peerid))

            #print >>sys.stderr,"SingleDownload: __init__: My peer ID is",`peerid`

            self.dow = BT1Download(self.hashcheckprogressfunc,
                                   self.finishedfunc, self.fatalerrorfunc,
                                   self.nonfatalerrorfunc, self.logerrorfunc,
                                   self.dldoneflag, kvconfig, metainfo,
                                   infohash, self.peerid, self.dlrawserver,
                                   get_extip_func, listenport,
                                   videoanalyserpath)

            self.filename = file = self.dow.saveAs(self.save_as)
            #if DEBUG:
            #    print >>sys.stderr,"SingleDownload: dow.saveAs returned",file

            # Set local filename in vodfileindex
            if vodfileindex is not None:
                # Ric: for SVC the index is a list of indexes
                index = vodfileindex['index']
                if type(index) == ListType:
                    svc = len(index) > 1
                else:
                    svc = False

                if svc:
                    outpathindex = self.dow.get_dest(index[0])
                else:
                    if index == -1:
                        index = 0
                    outpathindex = self.dow.get_dest(index)

                vodfileindex['outpath'] = outpathindex
                self.videoinfo = vodfileindex
                if 'live' in metainfo['info']:
                    authparams = metainfo['info']['live']
                else:
                    authparams = None
                if svc:
                    self.videostatus = SVCVideoStatus(
                        metainfo['info']['piece length'], self.dow.files,
                        vodfileindex, authparams)
                else:
                    self.videostatus = VideoStatus(
                        metainfo['info']['piece length'], self.dow.files,
                        vodfileindex, authparams)
                self.videoinfo['status'] = self.videostatus
                self.dow.set_videoinfo(vodfileindex, self.videostatus)

            #if DEBUG:
            #    print >>sys.stderr,"SingleDownload: setting vodfileindex",vodfileindex

            # RePEX: Start in RePEX mode
            if kvconfig['initialdlstatus'] == DLSTATUS_REPEXING:
                if pstate is not None and pstate.has_key('dlstate'):
                    swarmcache = pstate['dlstate'].get('swarmcache', {})
                else:
                    swarmcache = {}
                self.repexer = RePEXer(self.infohash, swarmcache)
            else:
                self.repexer = None

            if pstate is None:
                resumedata = None
            else:
                # Restarting download
                resumedata = pstate['engineresumedata']
            self._hashcheckfunc = self.dow.initFiles(resumedata=resumedata)

        except Exception, e:
            self.fatalerrorfunc(e)