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 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(): 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 = os.path.expanduser(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(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 repeatsRequest(client: Client, count: int) -> Client: """ Client sends count number of requests for each operation. Different requestIds will be generated for the same operation. :param client: the client to make faulty :param count: the number of requests to send for each operation. :return: the faulty client """ def evilSubmit(self, *operations: Mapping) -> List[Request]: requests = [] logger.debug( "EVIL: client creates {} requests for each operation".format(count)) for op in operations: for _ in range(count): request = self.createRequest(op) self.send(request) requests.append(request) return requests client.submit = types.MethodType(evilSubmit, client) return client
def repeatsRequest(client: Client, count: int) -> Client: """ Client sends count number of requests for each operation. Different requestIds will be generated for the same operation. :param client: the client to make faulty :param count: the number of requests to send for each operation. :return: the faulty client """ def evilSubmit(self, *operations: Mapping) -> List[Request]: requests = [] logger.debug( "EVIL: client creates {} requests for each operation".format( count)) for op in operations: for _ in range(count): request = self.createRequest(op) self.send(request) requests.append(request) return requests client.submit = types.MethodType(evilSubmit, client) return client
def sendRandomRequests(client: Client, count: int): ops = [randomOperation() for _ in range(count)] return client.submit(*ops)
def sendRandomRequest(client: Client): return client.submit(randomOperation())[0]
node.clientAuthNr.addClient(*idAndKey) """ We give the client a little time to connect """ looper.runFor(3) """ Create a simple message. """ msg = {'life_answer': 42} """ And submit it to the pool. """ request, = client.submit(msg) """ 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))