def run_node(): cliNodeReg = OrderedDict([ ('AlphaC', ('127.0.0.1', 8002)), ('BetaC', ('127.0.0.1', 8004)), ('GammaC', ('127.0.0.1', 8006)), ('DeltaC', ('127.0.0.1', 8008))]) with Looper(debug=False) as looper: # Nodes persist keys when bootstrapping to other nodes and reconnecting # using an ephemeral temporary directory when proving a concept is a # nice way to keep things clean. with TemporaryDirectory() as tmpdir: clientName = 'Joe' # this seed is used by the signer to deterministically generate # a signature verification key that is shared out of band with the # consensus pool seed = b'a 32 byte super secret seed.....' assert len(seed) == 32 signer = SimpleSigner(clientName, seed) assert signer.verkey == b'cffbb88a142be2f62d1b408818e21a2f' \ b'887c4442ae035a260d4cc2ec28ae24d6' client_address = ('127.0.0.1', 8000) client = Client(clientName, cliNodeReg, ha=client_address, signer=signer, basedirpath=tmpdir) looper.add(client) # give the client time to connect looper.runFor(3) # a simple message msg = {'life_answer': 42} # submit the request to the pool request, = client.submit(msg) # allow time for the request to be executed looper.runFor(3) reply, status = client.getReply(request.reqId) print('') print('Reply: {}\n'.format(reply)) print('Status: {}\n'.format(status))
def run_node(): cliNodeReg = OrderedDict([('AlphaC', ('127.0.0.1', 8002)), ('BetaC', ('127.0.0.1', 8004)), ('GammaC', ('127.0.0.1', 8006)), ('DeltaC', ('127.0.0.1', 8008))]) with Looper(debug=False) as looper: # Nodes persist keys when bootstrapping to other nodes and reconnecting # using an ephemeral temporary directory when proving a concept is a # nice way to keep things clean. with SafeTemporaryDirectory() as tmpdir: clientName = 'Joe' # this seed is used by the signer to deterministically generate # a signature verification key that is shared out of band with the # consensus pool seed = b'a 32 byte super secret seed.....' assert len(seed) == 32 signer = SimpleSigner(clientName, seed) assert signer.verkey == b'cffbb88a142be2f62d1b408818e21a2f' \ b'887c4442ae035a260d4cc2ec28ae24d6' client_address = ('127.0.0.1', 8000) client = Client(clientName, cliNodeReg, ha=client_address, signer=signer, basedirpath=tmpdir) looper.add(client) # give the client time to connect looper.runFor(3) # a simple message msg = {'life_answer': 42} # submit the request to the pool request, = client.submit_DEPRECATED(msg) # allow time for the request to be executed looper.runFor(3) reply, status = client.getReply(request.reqId) print('') print('Reply: {}\n'.format(reply)) print('Status: {}\n'.format(status))
def check_sufficient_replies_received(client: Client, identifier, request_id): reply, _ = client.getReply(identifier, request_id) full_request_id = "({}:{})".format(identifier, request_id) if reply is not None: logger.debug("got confirmed reply for {}: {}".format( full_request_id, reply)) return reply all_replies = getRepliesFromClientInbox(client.inBox, request_id) logger.debug("there are {} replies for request {}, " "but expected at-least {}, " "or one with valid proof: ".format(len(all_replies), full_request_id, client.quorums.reply.value, all_replies)) raise AssertionError( "There is no proved reply and no " "quorum achieved for request {}".format(full_request_id))
def run_node(): with Looper(debug=False) as looper: # Nodes persist keys when bootstrapping to other nodes and reconnecting # using an ephemeral temporary directory when proving a concept is a # nice way to keep things clean. config = getConfig() basedirpath = config.baseDir cliNodeReg = {k: v[0] for k, v in config.cliNodeReg.items()} clientName = 'Alice' # this seed is used by the signer to deterministically generate # a signature verification key that is shared out of band with the # consensus pool seed = b'22222222222222222222222222222222' assert len(seed) == 32 signer = SimpleSigner(clientName, seed) client_address = ('0.0.0.0', 9700) client = Client(clientName, cliNodeReg, ha=client_address, signer=signer, basedirpath=basedirpath) looper.add(client) # give the client time to connect looper.runFor(3) # a simple message msg = {'life_answer': 42} # submit the request to the pool request, = client.submit_DEPRECATED(msg) # allow time for the request to be executed looper.runFor(3) reply, status = client.getReply(request.reqId) print('') print('Reply: {}\n'.format(reply)) print('Status: {}\n'.format(status))
Before sending this message to the pool, the message needs to be signed first with a key from the wallet """ request = wallet.signOp(msg, identifier=wallet.defaultId) """ And submit the request to the pool. """ client.submitReqs(request) """ Allow some time for the request to be executed. """ looper.runFor(3) """ Let's get the reply. """ reply, status = client.getReply(request.reqId) """ Check the reply and see if consensus has been reached. """ print("Reply: {}\n".format(reply)) print("Status: {}\n".format(status)) """ See the reply details of a request. """ client.showReplyDetails(request.reqId) """ As we are using 4 nodes, we have an f-value of 1, which means that consensus can be still achieved with one faulty node. In this example, we're going to cause Beta to be malicious, altering a client's request before propagating to other nodes. """
request = wallet.signOp(msg, identifier=wallet.defaultId) """ And submit the request to the pool. """ client.submitReqs(request) """ Allow some time for the request to be executed. """ looper.runFor(3) """ Let's get the reply. """ reply, status = client.getReply(request.reqId) """ Check the reply and see if consensus has been reached. """ print("Reply: {}\n".format(reply)) print("Status: {}\n".format(status)) """ See the reply details of a request. """ client.showReplyDetails(request.reqId) """ As we are using 4 nodes, we have an f-value of 1, which means that consensus can be still achieved with one faulty node. In this example,