(1 . 3)(1 . 5)
143 import binascii
144 import logging
145 import time
146 from broadcast import Broadcast
147 from direct import Direct
(14 . 6)(16 . 7)
149 ts = time.time()
150 if message['command'] == BROADCAST:
151 m = Broadcast(message, self.state)
152 assert(m.message_hash == message['message_hash'])
153 elif message['command'] == DIRECT:
154 m = Direct(message, self.state)
155 else:
(33 . 25)(36 . 13)
157 return True
158 return False
159
160 def has(self, message_hash):
161 for value in self.buffer.values():
162 for message in value:
163 if message_hash == message.message_hash:
164 return True
165 return False
166
167 def dequeue_and_order_mature_messages(self):
168 current_time = time.time()
169 sorted_messages = sorted(self.buffer.keys())
170 mature_messages = []
171 for timestamp in sorted_messages:
172 if timestamp < current_time - int(self.state.get_knob('order_buffer_expiration_seconds')):
173 if isinstance(self.buffer[timestamp], list):
174 if len(self.buffer[timestamp]) > 0:
175 for message in self.buffer[timestamp]:
176 mature_messages.append(message)
177 del self.buffer[timestamp]
178 else:
179 mature_messages.append(self.buffer[timestamp])
180 del self.buffer[timestamp]
181 for message in self.buffer[timestamp]:
182 mature_messages.append(message)
183 del self.buffer[timestamp]
184 return sorted(mature_messages, key=lambda m: m.timestamp)