コード例 #1
0
    def get_value(self, key):
        """
        attempts to retrieve a chunk with the specified key value
        """
        #setup zmq connection
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect(self.PROTOCOL + self.ADDRESS + ':' + self.PORT)

        print('C: geting chunk...')
        msg = json.dumps(make_value_request(key))
        req.send(msg.encode())

        res = req.recv().decode()

        print('C: chunk retrieved...')

        js = json.loads(res)

        data = b64dec(js['body'])

        #check to make sure there was content
        if data is not b'':
            fi = Filer()
            fi.write_chunk(data, key)
            print('C: wrote chunk...')
        else:
            print('C: chunk has no data...')

        #terminate connection
        req.close()
        context.term()
コード例 #2
0
ファイル: client.py プロジェクト: xevrem/csdm
    def get_value(self, key):
        """
        attempts to retrieve a chunk with the specified key value
        """
        #setup zmq connection
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect(self.PROTOCOL + self.ADDRESS + ':' + self.PORT)

        print('C: geting chunk...')
        msg = json.dumps(make_value_request(key))
        req.send(msg.encode())

        res = req.recv().decode()

        print('C: chunk retrieved...')

        js = json.loads(res)

        data = b64dec(js['body'])

        #check to make sure there was content
        if data is not b'':
            fi = Filer()
            fi.write_chunk(data, key)
            print('C: wrote chunk...')
        else:
            print('C: chunk has no data...')

        #terminate connection
        req.close()
        context.term()
コード例 #3
0
    def retrieve(self, key, passphrase):
        """
        attempts to retrieve and re-assemble a file with a given manifest key
        """
        #setup zmq connection
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect(self.PROTOCOL + self.ADDRESS + ':' + self.PORT)

        #if manifest doesnt exist locally, request it
        if not os.path.exists(MANIFESTDIR + key):
            print('C: requesting manifest for {}'.format(key))
            msg = json.dumps(make_manifest_request(key))
            req.send(msg.encode())

            res = req.recv().decode()
            js = json.loads(res)

            #read in the manifest
            manifest = json.loads(js['body'])

            #store manifest locally
            with open(MANIFESTDIR + key, 'wb') as f:
                f.write(js['body'].encode())
        else:
            with open(MANIFESTDIR + key, 'r') as f:
                manifest = json.loads(f.read())

        print('C: manifest retrieved...')

        #print(manifest)

        #setup the eccpgp object
        epgp = ECCPGP()
        epgp.generate(passphrase)

        #decrypt the manifest
        manenc = manifest['manifest']
        mandec = epgp.raw_dec(b64dec(manenc), passphrase.encode())
        manifest['manifest'] = json.loads(mandec.decode())

        data = b''

        #get each chunk described in the manifest
        print('C: retrieving chunks...')
        fi = Filer()
        for chunk in manifest['manifest']:
            msg = json.dumps(make_value_request(chunk))
            req.send(msg.encode())

            res = req.recv().decode()
            js = json.loads(res)

            data = b64dec(js['body'])

            fi.write_chunk(data, chunk)
            #with open(CHUNKDIR+chunk, 'wb') as w:
            #    w.write(data)

        print('C: chunks saved...')

        #terminate connection
        req.close()
        context.term()
コード例 #4
0
ファイル: client.py プロジェクト: xevrem/csdm
    def retrieve(self, key, passphrase):
        """
        attempts to retrieve and re-assemble a file with a given manifest key
        """
        #setup zmq connection
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect(self.PROTOCOL + self.ADDRESS + ':' + self.PORT)

        #if manifest doesnt exist locally, request it
        if not os.path.exists(MANIFESTDIR+key):
            print('C: requesting manifest for {}'.format(key))
            msg = json.dumps(make_manifest_request(key))
            req.send(msg.encode())

            res = req.recv().decode()
            js = json.loads(res)

            #read in the manifest
            manifest = json.loads(js['body'])

            #store manifest locally
            with open(MANIFESTDIR+key, 'wb') as f:
                f.write(js['body'].encode())
        else:
            with open(MANIFESTDIR+key,'r') as f:
                manifest = json.loads(f.read())

        print('C: manifest retrieved...')

        #print(manifest)

        #setup the eccpgp object
        epgp = ECCPGP()
        epgp.generate(passphrase)

        #decrypt the manifest
        manenc = manifest['manifest']
        mandec = epgp.raw_dec(b64dec(manenc), passphrase.encode())
        manifest['manifest'] = json.loads(mandec.decode())

        data = b''

        #get each chunk described in the manifest
        print('C: retrieving chunks...')
        fi = Filer()
        for chunk in manifest['manifest']:
            msg = json.dumps(make_value_request(chunk))
            req.send(msg.encode())

            res = req.recv().decode()
            js = json.loads(res)

            data = b64dec(js['body'])

            fi.write_chunk(data, chunk)
            #with open(CHUNKDIR+chunk, 'wb') as w:
            #    w.write(data)

        print('C: chunks saved...')

        #terminate connection
        req.close()
        context.term()