def test_dumpb_empty_message(self): """ The empty string is encoded as "0:,". """ packet = dumpb("") self.assertEqual(bytes([0x30, 0x3a, 0x2c]), packet)
def test_dumpb_empty_message(self): """ The empty string is encoded as "0:,". """ packet = dumpb("") self.assertEqual(bytes([0x30, 0x3a, 0x2c]), packet)
def __call__(self, token=None): token = token or self.token while True: try: job = yield from self.down.get() poa, msg = self.hop(token, job, policy="udp") if job.header.via is not None: # User-defined route hop = next(Flow.find( token, application=job.header.via.application, policy="udp"), None) poa = Flow.inspect(hop) if poa is None: warnings.warn("Message expired.") continue if msg is not None: remote_addr = (poa.addr, poa.port) data = Assembly.dumps(msg) packet = dumpb(data) self.transport.sendto(packet, remote_addr) else: warnings.warn("No message from hop.") except concurrent.futures.CancelledError: break except Exception as e: warnings.warn(repr(getattr(e, "args", e) or e)) continue
def __call__(self, token=None): token = token or self.token while True: try: job = yield from self.down.get() poa, msg = self.hop(token, job, policy="udp") if job.header.via is not None: # User-defined route hop = next( Flow.find(token, application=job.header.via.application, policy="udp"), None) poa = Flow.inspect(hop) if poa is None: warnings.warn("Message expired.") continue if msg is not None: remote_addr = (poa.addr, poa.port) data = Assembly.dumps(msg) packet = dumpb(data) self.transport.sendto(packet, remote_addr) else: warnings.warn("No message from hop.") except concurrent.futures.CancelledError: break except Exception as e: warnings.warn(repr(getattr(e, "args", e) or e)) continue
def test_dumpb_full_message(self): """ The string "hello world!" is encoded as <31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,". """ packet = dumpb("hello world!") self.assertEqual( bytes([ 0x31, 0x32, 0x3a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x2c ]), packet)
def test_dumpb_full_message(self): """ The string "hello world!" is encoded as <31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>, i.e., "12:hello world!,". """ packet = dumpb("hello world!") self.assertEqual(bytes([ 0x31, 0x32, 0x3a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x2c ]), packet)
def datagram_received(self, data, addr): """ Routing only. Provides no upward service. """ packet = self.decoder.send(data) if packet is None: return (None, None) msg = Assembly.loads(packet) poa, msg = self.hop(self.token, msg, policy="udp") if poa is not None: remote_addr = (poa.addr, poa.port) data = Assembly.dumps(msg) packet = dumpb(data) self.transport.sendto(packet, remote_addr) return (poa, msg)
def datagram_received(self, data, addr): """ Routing only. Provides no upward service. """ packet = self.decoder.send(data) if packet is None: return (None, None) msg = Assembly.loads(packet) poa, msg = self.hop(self.token, msg, policy="udp") if poa is not None: remote_addr = (poa.addr, poa.port) data = Assembly.dumps(msg) packet = dumpb(data) self.transport.sendto(packet, remote_addr) return (poa, msg)