Esempio n. 1
0
 def tearDown(self):
     TestAsServer.tearDown(self)
     time.sleep(1)
     try:
         shutil.rmtree(self.scandir)
     except:
         pass
Esempio n. 2
0
 def tearDown(self):
     TestAsServer.tearDown(self)
     time.sleep(1)
     try:
         shutil.rmtree(self.scandir)
     except:
         pass
Esempio n. 3
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = os.path.join(os.getcwdu(),"dest")

        try:
            shutil.rmtree(self.destdir)
        except:
            pass
        os.mkdir(self.destdir)
        
        # Create tree with 6 chunks
        self.chunks = []
        for i in range(0,6+1):
            chunk = chr(i) * 1024
            self.chunks.append(chunk)
            
        self.hashes = {}
        self.hashes[(7,7)] = '\x00' * 20
        for i in range(0,6+1):
            hash = sha(self.chunks[i]).digest()
            self.hashes[(i,i)] = hash
        self.hashes[(0,1)] = sha(self.hashes[(0,0)]+self.hashes[(1,1)]).digest()
        self.hashes[(2,3)] = sha(self.hashes[(2,2)]+self.hashes[(3,3)]).digest()
        self.hashes[(4,5)] = sha(self.hashes[(4,4)]+self.hashes[(5,5)]).digest()
        self.hashes[(6,7)] = sha(self.hashes[(6,6)]+self.hashes[(7,7)]).digest()
        
        self.hashes[(0,3)] = sha(self.hashes[(0,1)]+self.hashes[(2,3)]).digest()
        self.hashes[(4,7)] = sha(self.hashes[(4,5)]+self.hashes[(6,7)]).digest()
        
        self.hashes[(0,7)] = sha(self.hashes[(0,3)]+self.hashes[(4,7)]).digest()
Esempio n. 4
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        #self.cmdport = None
        self.httpport = None
        self.scandir = "seeder2"
        self.progress = True

        self.setUpScanDir()

        try:
            shutil.rmtree(self.scandir)
        except:
            pass
        os.mkdir(self.scandir)

        # Create content
        for i in range(len(self.filelist)):
            fn = self.filelist[i][0]
            s = self.filelist[i][1]
            f = open(fn, "wb")
            data = '#' * s
            f.write(data)
            f.close()

            # Pre hash check and checkpoint them
            sdef = SwiftDef()
            sdef.add_content(fn)
            sdef.finalize(self.binpath)
            self.filelist[i][2] = sdef.get_id()  # save roothash

        for i in range(len(self.filelist)):
            print >> sys.stderr, "test: Configured from filelist", binascii.hexlify(
                self.filelist[i][2])
Esempio n. 5
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        #self.cmdport = None
        self.httpport = None
        self.scandir = "seeder2"
        self.progress = True
        
        self.setUpScanDir()

        try:
            shutil.rmtree(self.scandir)
        except:
            pass
        os.mkdir(self.scandir)
        
        # Create content
        for i in range(len(self.filelist)):
            fn = self.filelist[i][0]
            s = self.filelist[i][1]
            f = open(fn,"wb")
            data = '#' * s
            f.write(data)
            f.close()
            
            # Pre hash check and checkpoint them
            sdef = SwiftDef()
            sdef.add_content(fn)
            sdef.finalize(self.binpath)
            self.filelist[i][2] = sdef.get_id() # save roothash

        for i in range(len(self.filelist)):
            print >>sys.stderr,"test: Configured from filelist",binascii.hexlify(self.filelist[i][2])
Esempio n. 6
0
 def setUpPostSession(self):
     TestAsServer.setUpPostSession(self)
     
     #CMD = "START tswift:/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n"
     CMD = "START tswift://127.0.0.1:"+str(self.listenport)+"/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n"
     self.cmdsock.send(CMD)
     
     self.urlprefix = "http://127.0.0.1:"+str(self.httpport)+"/"+binascii.hexlify(self.swarmid)
Esempio n. 7
0
    def tearDown(self):
        # Wait 30+ second such  that zerostate cleanup code gets covered.
        time.sleep(self.exitwait)

        TestAsServer.tearDown(self)
        try:
            shutil.rmtree(self.zerosdir)
        except:
            print_exc()
Esempio n. 8
0
 def tearDown(self):
     # Wait 30+ second such  that zerostate cleanup code gets covered.
     time.sleep(self.exitwait)
     
     TestAsServer.tearDown(self)
     try:
         shutil.rmtree(self.zerosdir)
     except:
         print_exc()
Esempio n. 9
0
 def tearDown(self):
     TestAsServer.tearDown(self)
     try:
         os.remove(self.livesourceinput)
     except:
         pass
     try:
         os.remove(self.filename)
     except:
         pass
Esempio n. 10
0
 def tearDown(self):
     TestAsServer.tearDown(self)
     try:
         os.remove(self.livesourceinput)
     except:
         pass
     try:
         os.remove(self.filename)
     except:
         pass
Esempio n. 11
0
    def setUpPostSession(self):
        TestAsServer.setUpPostSession(self)

        #CMD = "START tswift:/"+binascii.hexlify(self.swarmid)+" "+self.destdir+"\r\n"
        CMD = "START tswift://127.0.0.1:" + str(
            self.listenport) + "/" + binascii.hexlify(
                self.swarmid) + " " + self.destdir + "\r\n"
        self.cmdsock.send(CMD)

        self.urlprefix = "http://127.0.0.1:" + str(
            self.httpport) + "/" + binascii.hexlify(self.swarmid)
Esempio n. 12
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.cond = Condition()

        self.peer1port = 1234
        self.peer1 = UDPListener(self, self.peer1port)
        self.peer1.start()

        self.destdir = "."

        self.udpsendport = random.randint(14001, 14999)  #

        time.sleep(2)  # let server threads start
Esempio n. 13
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        
        self.cond = Condition()
        
        self.peer1port = 1234
        self.peer1 = UDPListener(self,self.peer1port)
        self.peer1.start()

        self.destdir = "."
        
        self.udpsendport = random.randint(14001,14999) #

        time.sleep(2) # let server threads start
Esempio n. 14
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = '.'

        f = open("liveinput.dat", "wb")
        self.nchunks = 1017
        for i in range(0, self.nchunks):
            data = chr((ord('a') + i) % 256) * 1024
            f.write(data)
        f.close()

        self.livesourceinput = "liveinput.dat"
        self.filename = "storage.dat"
Esempio n. 15
0
    def setUpPostSession(self):
        TestAsServer.setUpPostSession(self)

        f = open(self.urlfilename, "rb")
        swarmurl = f.read()
        f.close()
        swarmurl = swarmurl.strip()
        idx = swarmurl.find("/")
        if idx == -1:
            self.assertFalse(True)
        else:
            liveswarmidhex = swarmurl[idx + 1:]
            print >> sys.stderr, "test: SwarmID <" + liveswarmidhex + ">"
            self.liveswarmid = binascii.unhexlify(liveswarmidhex)
Esempio n. 16
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = '.'

        f = open("liveinput.dat","wb")
        self.nchunks = 1017
        for i in range(0,self.nchunks):
            data = chr((ord('a')+i)%256) * 1024
            f.write(data)
        f.close()

        self.livesourceinput = "liveinput.dat"
        self.filename = "storage.dat"
Esempio n. 17
0
    def setUpPostSession(self):
        TestAsServer.setUpPostSession(self)

        f = open(self.urlfilename,"rb")
        swarmurl = f.read()
        f.close()
        swarmurl = swarmurl.strip()
        idx = swarmurl.find("/")
        if idx == -1:
            self.assertFalse(True)
        else:
            liveswarmidhex = swarmurl[idx+1:]
            print >>sys.stderr,"test: SwarmID <"+liveswarmidhex+">"
            self.liveswarmid = binascii.unhexlify(liveswarmidhex)
Esempio n. 18
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = '.'

        f = open("liveinput.dat", "wb")
        self.nchunks = 1017
        for i in range(0, self.nchunks):
            data = chr((ord('0') + i) % 256) * 1024
            f.write(data)
        f.close()

        self.livesourceinput = "liveinput.dat"
        self.filename = "storage.dat"

        self.urlfilename = "swarm.url"
        self.livesigalg = ord(POPT_LSA_ECDSAP256SHA256)

        self.debug = True
Esempio n. 19
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = '.'

        f = open("liveinput.dat","wb")
        self.nchunks = 1017
        for i in range(0,self.nchunks):
            data = chr((ord('0')+i)%256) * 1024
            f.write(data)
        f.close()

        self.livesourceinput = "liveinput.dat"
        self.filename = "storage.dat"

        self.urlfilename = "swarm.url"
        self.livesigalg = ord(POPT_LSA_ECDSAP256SHA256)

        self.debug = True
Esempio n. 20
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        self.destdir = tempfile.mkdtemp()

        print >> sys.stderr, "test: destdir is", self.destdir

        self.setUpFileList()

        idx = self.filelist[0][0].find("/")
        specprefix = self.filelist[0][0][0:idx]

        prefixdir = os.path.join(self.destdir, specprefix)
        os.mkdir(prefixdir)

        sdef = SwiftDef()

        # Create content
        for fn, s in self.filelist:
            osfn = fn.replace("/", os.sep)
            fullpath = os.path.join(self.destdir, osfn)
            f = open(fullpath, "wb")
            data = fn[len(specprefix) + 1] * s
            f.write(data)
            f.close()

            sdef.add_content(fullpath, fn)

        self.specfn = sdef.finalize(self.binpath, destdir=self.destdir)
        f = open(self.specfn, "rb")
        self.spec = f.read()
        f.close()

        self.swarmid = sdef.get_id()
        print >> sys.stderr, "test: setUpPreSession: roothash is", binascii.hexlify(
            self.swarmid)

        self.mfdestfn = os.path.join(self.destdir,
                                     binascii.hexlify(self.swarmid))
        shutil.copyfile(self.specfn, self.mfdestfn)
        shutil.copyfile(self.specfn + ".mhash", self.mfdestfn + ".mhash")
        shutil.copyfile(self.specfn + ".mbinmap", self.mfdestfn + ".mbinmap")
Esempio n. 21
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        self.httpport = None
        self.zerosdir = os.path.join(os.getcwd(), "zeros2")
        self.exitwait = 36
        self.progress = True

        self.setUpZerosDir()

        try:
            shutil.rmtree(self.zerosdir)
        except:
            pass
        os.mkdir(self.zerosdir)

        # Create content
        for i in range(len(self.filelist)):
            fn = self.filelist[i][0]
            s = self.filelist[i][1]
            f = open(fn, "wb")
            data = '#' * s
            f.write(data)
            f.close()

            # Pre hash check and checkpoint them
            sdef = SwiftDef()
            sdef.add_content(fn)
            sdef.finalize(self.binpath)
            self.filelist[i][2] = sdef.get_id()  # save roothash

        # Hack: now copy to <roothash>[.mhash|.mbinmap] files such that zerostate works
        for i in range(len(self.filelist)):
            print >> sys.stderr, "test: Configuring", binascii.hexlify(
                self.filelist[i][2])
            srcfile = self.filelist[i][0]
            dstfile = os.path.join(self.zerosdir,
                                   binascii.hexlify(self.filelist[i][2]))
            shutil.copyfile(srcfile, dstfile)
            shutil.copyfile(srcfile + ".mhash", dstfile + ".mhash")
            shutil.copyfile(srcfile + ".mbinmap", dstfile + ".mbinmap")
Esempio n. 22
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        self.destdir = tempfile.mkdtemp()
        
        print >>sys.stderr,"test: destdir is",self.destdir
        
        self.setUpFileList()
        
        idx = self.filelist[0][0].find("/")
        specprefix = self.filelist[0][0][0:idx]
        
        prefixdir = os.path.join(self.destdir,specprefix)
        os.mkdir(prefixdir)

        sdef = SwiftDef()
        
        # Create content
        for fn,s in self.filelist:
            osfn = fn.replace("/",os.sep)
            fullpath = os.path.join(self.destdir,osfn)
            f = open(fullpath,"wb")
            data = fn[len(specprefix)+1] * s
            f.write(data)
            f.close()
            
            sdef.add_content(fullpath,fn)

        self.specfn = sdef.finalize(self.binpath,destdir=self.destdir)
        f = open(self.specfn,"rb")
        self.spec = f.read()
        f.close()
        
        self.swarmid = sdef.get_id()
        print >>sys.stderr,"test: setUpPreSession: roothash is",binascii.hexlify(self.swarmid)
        
        self.mfdestfn = os.path.join(self.destdir,binascii.hexlify(self.swarmid))
        shutil.copyfile(self.specfn,self.mfdestfn)
        shutil.copyfile(self.specfn+".mhash",self.mfdestfn+".mhash")
        shutil.copyfile(self.specfn+".mbinmap",self.mfdestfn+".mbinmap")
Esempio n. 23
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)
        self.httpport = None
        self.zerosdir = os.path.join(os.getcwd(),"zeros2")
        self.exitwait = 36
        self.progress = True
        
        self.setUpZerosDir()

        try:
            shutil.rmtree(self.zerosdir)
        except:
            pass
        os.mkdir(self.zerosdir)
        
        # Create content
        for i in range(len(self.filelist)):
            fn = self.filelist[i][0]
            s = self.filelist[i][1]
            f = open(fn,"wb")
            data = '#' * s
            f.write(data)
            f.close()
            
            # Pre hash check and checkpoint them
            sdef = SwiftDef()
            sdef.add_content(fn)
            sdef.finalize(self.binpath)
            self.filelist[i][2] = sdef.get_id() # save roothash

        # Hack: now copy to <roothash>[.mhash|.mbinmap] files such that zerostate works
        for i in range(len(self.filelist)):
            print >>sys.stderr,"test: Configuring",binascii.hexlify(self.filelist[i][2])
            srcfile = self.filelist[i][0]
            dstfile = os.path.join(self.zerosdir,binascii.hexlify(self.filelist[i][2]))
            shutil.copyfile(srcfile,dstfile)
            shutil.copyfile(srcfile+".mhash",dstfile+".mhash")
            shutil.copyfile(srcfile+".mbinmap",dstfile+".mbinmap")
Esempio n. 24
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.destdir = os.path.join(os.getcwdu(), "dest")

        try:
            shutil.rmtree(self.destdir)
        except:
            pass
        os.mkdir(self.destdir)

        # Create tree with 6 chunks
        self.chunks = []
        for i in range(0, 6 + 1):
            chunk = chr(i) * 1024
            self.chunks.append(chunk)

        self.hashes = {}
        self.hashes[(7, 7)] = '\x00' * 20
        for i in range(0, 6 + 1):
            hash = sha(self.chunks[i]).digest()
            self.hashes[(i, i)] = hash
        self.hashes[(0, 1)] = sha(self.hashes[(0, 0)] +
                                  self.hashes[(1, 1)]).digest()
        self.hashes[(2, 3)] = sha(self.hashes[(2, 2)] +
                                  self.hashes[(3, 3)]).digest()
        self.hashes[(4, 5)] = sha(self.hashes[(4, 4)] +
                                  self.hashes[(5, 5)]).digest()
        self.hashes[(6, 7)] = sha(self.hashes[(6, 6)] +
                                  self.hashes[(7, 7)]).digest()

        self.hashes[(0, 3)] = sha(self.hashes[(0, 1)] +
                                  self.hashes[(2, 3)]).digest()
        self.hashes[(4, 7)] = sha(self.hashes[(4, 5)] +
                                  self.hashes[(6, 7)]).digest()

        self.hashes[(0, 7)] = sha(self.hashes[(0, 3)] +
                                  self.hashes[(4, 7)]).digest()
Esempio n. 25
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.statshttpport = 8091
Esempio n. 26
0
 def setUpPostSession(self):
     TestAsServer.setUpPostSession(self)
Esempio n. 27
0
 def tearDown(self):
     TestAsServer.tearDown(self)
Esempio n. 28
0
 def setUpPostSession(self):
     TestAsServer.setUpPostSession(self)
Esempio n. 29
0
    def setUpPreSession(self):
        TestAsServer.setUpPreSession(self)

        self.statshttpport = 8091
Esempio n. 30
0
    def setUpPostSession(self):
        TestAsServer.setUpPostSession(self)

        time.sleep(2)
Esempio n. 31
0
 def tearDown(self):
     TestAsServer.tearDown(self)
Esempio n. 32
0
 def setUpPostSession(self):
     TestAsServer.setUpPostSession(self)
     
     time.sleep(2)