def lengthLimitExceeded(self, length): """ This is called when a remote tries to send a massive string. Quite likely that's because it sends the prefix in little endian (rather than network) byte order. """ log.info("Length limit exceeded (%d bytes)." % (length, )) Int32StringReceiver.lengthLimitExceeded(self, length)
def lengthLimitExceeded(self, length): """ This is called when a remote tries to send a massive string. Quite likely that's because it sends the prefix in little endian (rather than network) byte order. """ log.info("Length limit exceeded (%d bytes)." % (length,)) Int32StringReceiver.lengthLimitExceeded(self, length)
def dataReceived(self, recd): if self.state == "HANDSHAKE": self.recvd = self.recvd + recd #self.logger.debug("Received data in state %s: %s", self.state, repr(self.recvd)) if len(self.recvd) >= 1: if self.preamble_size == 0: pstrlen = ord(self.recvd[0]) self.preamble_size = pstrlen + 49 if len(self.recvd) >= self.preamble_size and self.preamble_size != 0: preamble = self.recvd[0:self.preamble_size] self.recvd = self.recvd[self.preamble_size:] self.handle_HANDSHAKE(preamble) self.state = "ACTIVE" else: Int32StringReceiver.dataReceived(self,recd)
def test_onion_transport(): """ integration test for onion transport """ chutney_control_port = os.environ.get('CHUTNEY_CONTROL_PORT') if chutney_control_port is None: print "CHUTNEY_CONTROL_PORT not set, aborting test" return params = SphinxParams(max_hops=5, payload_size=1024) sphinx_packet_size = params.get_sphinx_forward_size() transport_factory = create_transport_factory(sphinx_packet_size, chutney_control_port) transport = yield transport_factory.build_transport() received_d = defer.Deferred() received_buffer = [] def packet_received(packet): print "packet received of len %s" % len(packet) received_buffer.append(packet) received_d.callback(None) protocol = FakeMixProtocol(packet_received) yield protocol.make_connection(transport) onion_host, onion_port = transport.addr tor_endpoint = transport.tor.stream_via(onion_host, onion_port) send_message_protocol = Int32StringReceiver() remote_mix_protocol = yield endpoints.connectProtocol( tor_endpoint, send_message_protocol) message = b"A" * sphinx_packet_size remote_mix_protocol.sendString(message) remote_mix_protocol.transport.loseConnection() yield received_d assert received_buffer[0] == message
def test_onion_datagram_proxy(): received_buffer = [] received_d = defer.Deferred() def received(data): received_buffer.append(data) received_d.callback(None) received_size = 10 proxy_factory = OnionDatagramProxyFactory(received) protocol = proxy_factory.buildProtocol(123) packet = b"A" * received_size protocol.stringReceived(packet) assert received_buffer[0] == packet service_port = yield txtorcon.util.available_tcp_port(reactor) service_endpoint_desc = "tcp:interface=127.0.0.1:%s" % service_port service_endpoint = endpoints.serverFromString(reactor, service_endpoint_desc) yield service_endpoint.listen(proxy_factory) client_endpoint_desc = "tcp:127.0.0.1:%s" % service_port client_endpoint = endpoints.clientFromString(reactor, client_endpoint_desc) client_protocol = Int32StringReceiver() yield endpoints.connectProtocol(client_endpoint, client_protocol) client_protocol.sendString(packet) print "BEFORE CLOSE" client_protocol.transport.loseConnection() yield received_d assert received_buffer[0] == packet
def lengthLimitExceeded(self, length): print("LENGTH LIMIT EXCEEDED {0}".format(length)) Int32StringReceiver.lengthLimitExceeded(self, length)
def __init__(self): Int32StringReceiver.__init__(self)
def lengthLimitExceeded(self, length): print('LENGTH LIMIT EXCEEDED {0}'.format(length)) Int32StringReceiver.lengthLimitExceeded(self, length)