Пример #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
    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
async def do_get_value(host, port, key):
    #print('C: requesting value...')
    msg = json.dumps(make_value_request(key))
    data = await get(url=f'http://{host}/value/{key}', port=port, body=msg)
    req = http_data_create(data)
    #print('C: value retrieved:')
    #print('{}'.format(req.body))
    return req.body
Пример #4
0
    def run(self):
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect('tcp://127.0.0.1:8080')

        for i in range(100):
            msg = json.dumps(make_value_request(hexlify(urandom(32)).decode()))
            req.send(msg.encode())
            print("C: received: {}".format(req.recv()))

        req.close()
        context.term()
Пример #5
0
    def run(self):
        context = zmq.Context.instance()
        req = context.socket(zmq.REQ)
        req.connect('tcp://127.0.0.1:8080')

        #man_file = '7e725dae613062ae5dd26799c9baa8a6d19e3126'
        man_file = '69f4075cbceb77d49cf643422884b0ed96e3af39'
        msg = json.dumps(make_manifest_request(man_file))
        req.send(msg.encode())

        res = req.recv().decode()
        #print('C: received: {}'.format(res))

        js = json.loads(res)
        manifest = js['body']

        data = b''

        #get each chunk described in the manifest
        for line in manifest.split('\n'):
            if len(line) < 1:
                continue
            msg = json.dumps(make_value_request(line))
            req.send(msg.encode())

            res = req.recv().decode()
            js = json.loads(res)
            #print('C: received: {}'.format(js['header']))

            data += base64.b64decode(js['body'].encode())

        print('C: writing file...')
        with open('video.mp4', 'wb') as w:
            w.write(data)

        req.close()
        context.term()
Пример #6
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()
Пример #7
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()