def recvAck(self, res): curr_exec = self.current_execution curr_exec.ack_resps.append(res) if len(curr_exec.ack_resps) == len(self.global_config['shards']): aggrR = self.cosi.aggr_response(curr_exec.ack_resps) self.current_execution.block.cosign = tuple((curr_exec.sch_challenge, aggrR)) msg = self.msg_mgr.create_decision_msg(self.current_execution.final_decision, self.current_execution.block) Messenger.get().send(msg, (self.global_config["client"]["ip_addr"], self.global_config["client"]["port"])) Messenger.get().broadcast(msg, self.global_config['shards'])
def recvEndTransaction(self, req, txn_id, ts, rw_set_list, updates): if self.current_execution: self.req_q.appendleft(req) return txns = [Transaction(rw_set) for rw_set in rw_set_list] self.pending_block = self.bch.createBlock(ts, txns, {}) self.current_execution = CurrentExecution(self.pending_block) msg = self.msg_mgr.create_get_vote_msg(self.pending_block, updates) Messenger.get().broadcast(msg, self.global_config['shards'])
def recvGetVote(self, req, block, updates): if self.current_execution and self.current_execution.block.bid != block.bid: self.req_q.append(req) return self.current_execution = CurrentExecution( block ) if self.current_execution is None else self.current_execution self.current_execution.updates = updates msg = self.msg_mgr.create_vote_msg(self.shard_i, 'commit') Messenger.get().send(msg, req['addr'])
def recvGetVote(self, req, block, updates): if self.current_execution and self.current_execution.block.bid != block.bid: self.req_q.append(req) return self.current_execution = CurrentExecution(block) if self.current_execution is None else self.current_execution for k, new_v in updates: if k in self.mht.kv_map: self.mht.update(k, new_v) sch_commitment = self.cosi.commitment() msg = self.msg_mgr.create_vote_msg(self.shard_i, 'commit', self.mht.getRoot(), sch_commitment) Messenger.get().send(msg, req['addr'])
def recvVote(self, v): self.current_execution.vote_list.append(v) if len(self.current_execution.vote_list) == len( self.global_config['shards']): final_decision = 'commit' for vote in self.current_execution.vote_list: if vote['decision'] == 'abort': final_decision = 'abort' self.current_execution.final_decision = final_decision msg = self.msg_mgr.create_decision_msg(final_decision, self.pending_block) Messenger.get().send(msg, (self.global_config["client"]["ip_addr"], self.global_config["client"]["port"])) Messenger.get().broadcast(msg, self.global_config['shards'])
def recvVote(self, v): self.current_execution.vote_list.append(v) if len(self.current_execution.vote_list) == len(self.global_config['shards']): final_decision = 'commit' sch_commits = [] for vote in self.current_execution.vote_list: self.current_execution.block.roots[vote['sender_id']] = vote['root'] sch_commits.append(vote['sch_commitment']) if vote['decision'] != 'commit': final_decision = 'abort' self.current_execution.final_decision = final_decision sch_challenge = self.cosi.challenge(str(self.current_execution.block), sch_commits) self.current_execution.sch_challenge = sch_challenge msg = self.msg_mgr.create_prepare_msg(final_decision, self.current_execution.block, sch_challenge) Messenger.get().broadcast(msg, self.global_config['shards'])
class Agent: def __init__(self, sendPort, homePort): self.ToSend = Queue.Queue() self.messenger = Messenger(homePort, sendPort, IP='127.0.0.1') self.other = sendPort self.home = homePort def GatherInput(self): while True: IP = '127.0.0.1' port = input("Target IP? ") msg = raw_input("Message? ") send = message.Message(msg, type='test', keepAlive='1', MLen=1024, port=self.home) self.ToSend.put(((IP, port), send)) def Start(self): self.messenger.StartListening() t = Thread(target=self.runLoop) # Thread t.daemon = True t.start() l = Thread(target=self.GatherInput) l.start() def runLoop(self): """ Perform actions and handle messages when received. If an interesting message pops, open a new connection and reply to it. """ while True: if not self.ToSend.empty(): print(self.ToSend.qsize()) (target, msg) = self.ToSend.get() self.messenger.SendMessage(target[0], target[1], msg) if not self.messenger.empty(): (sender, a) = self.messenger.get() print a if a.text == "exit": break if a.text == "echo": self.messenger.SendMessage(sender[0], sender[1], "echo") print "Ended run"
def performTransaction(self): self.cntr += 1 txn = self.createTxn() msg = self.msg_mgr.create_end_transaction_msg(txn) Messenger.get().send(msg, (self.global_config['shards'][0]['ip_addr'], self.global_config['shards'][0]['port']))
def recvPrepare(self, req, body): block = pickle.loads(body['block']) sch_challenge = body['ch'] sch_response = self.cosi.response(sch_challenge) msg = self.msg_mgr.create_ack_msg(sch_response) Messenger.get().send(msg, req['addr'])