def __init__(self, bare_message, sender_id):
     orig_header, orig_data = bft_msgs.unpack_reply(bare_message)
     self.common_header = CommonReplyHeader(orig_header.req_seq_num)
     rsi_loc = orig_header.length - orig_header.rsi_length
     self.rsi_data = orig_data[rsi_loc:]
     self.common_data = orig_data[:rsi_loc]
     self.sender_id = sender_id
     self.primary_id = orig_header.primary_id
Exemple #2
0
 def test_unpack_reply(self):
     msg = b'hello'
     primary_id = 0
     req_seq_num = 1
     packed = bft_msgs.pack_reply(primary_id, req_seq_num, msg)
     (header, unpacked_msg) = bft_msgs.unpack_reply(packed)
     self.assertEqual(primary_id, header.primary_id)
     self.assertEqual(req_seq_num, header.req_seq_num)
     self.assertEqual(msg, unpacked_msg)
Exemple #3
0
 def test_unpack_reply(self):
     msg = b'hello'
     primary_id = 0
     req_seq_num = 1
     result = 1
     rsi_length = 5
     packed = bft_msgs.pack_reply(primary_id, req_seq_num, msg, result, rsi_length)
     (header, unpacked_msg) = bft_msgs.unpack_reply(packed)
     self.assertEqual(primary_id, header.primary_id)
     self.assertEqual(req_seq_num, header.req_seq_num)
     self.assertEqual(result, header.result)
     self.assertEqual(rsi_length, header.rsi_length)
     self.assertEqual(msg, unpacked_msg)
Exemple #4
0
 async def recv(self, cancel_scope):
     """
     Receive reply messages until a quorum is achieved or the enclosing
     cancel_scope times out.
     """
     while True:
         data, sender = await self.sock.recvfrom(self.config.max_msg_size)
         header, reply = bft_msgs.unpack_reply(data)
         if self.valid_reply(header):
             self.replies[sender] = (header, reply)
         if self.has_quorum():
             # This cancel will propagate upward and gracefully terminate all
             # coroutines. self.reply will get set in self.has_quorum()
             cancel_scope.cancel()