Example #1
0
 def start(self, from_, to, n):
     self._ended = False
     self.conv.send(cbor.dumps([
         0,
         [cbor.VarList(from_), to, n]
     ]))
     yield from self._receive_stream(n)
Example #2
0
 def __call__(self, from_, to):
     self.conv.send(cbor.dumps([cbor.VarList(from_), [to] if to else []]))
     tag, data = cbor.loads(self.conv.receive())  # sum type MsgHeaders
     if tag == 1:  # NoHeaders
         print('no headers', data)
         return []
     return [DecodedBlockHeader(item) for item in data]
Example #3
0
def handle_get_headers(node, conv):
    'Peer wants some block headers from us.'
    store = node.store
    limit = config.CHAIN['block']['recoveryHeadersMessage']
    while True:
        checkpoints, tip = cbor.loads(conv.receive())
        tip = tip[0] if tip else None

        if node.retriever.recovering():
            conv.send(cbor.dumps((1, b'server node is in recovery mode')))
            continue

        headers = None
        if not checkpoints:
            # return single header
            headers = [store.blockheader(tip) if tip else store.tip()]
        else:
            # TODO filter in mainchain.
            # get most recent checkpoint
            checkpoint = max(checkpoints,
                             key=lambda k: store.blockheader(k).slot())
            count = 0
            headers = []
            for h in store.iter_header_hash(checkpoint):
                count += 1
                if count > limit:
                    break
                headers.append(store.blockheader(h))

        if headers:
            conv.send(
                cbor.dumps((0, cbor.VarList(hdr.data for hdr in headers))))
        else:
            conv.send(cbor.dumps((1, b'loaded empty headers')))
Example #4
0
def pack_addr_payload(path, hdpass):
    'packHDAddressAttr'
    plaintext = cbor.dumps(cbor.VarList(path))
    return bytes(
        CHACHA20_POLY1305(hdpass, 'python').seal(b'serokellfore', plaintext,
                                                 b''))