Created
August 20, 2011 02:17
-
-
Save baversjo/1158511 to your computer and use it in GitHub Desktop.
error output issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KernelConnector(LineReceiver): | |
def __init__(self,app): | |
self.app = app | |
self.disconnectDef = None | |
def connectionMade(self): | |
self.factory.app.handleKernelConnected(self) | |
def lineReceived(self,line): | |
print 'got line:',line | |
values = line.split(";") | |
try: | |
action = values[0] | |
protocol = values[1] | |
dest_addr = values[2] | |
dest_port = values[3] | |
pid = values[4] | |
except: | |
self._write(['0']) | |
else: | |
self.app.requestTunnel({ | |
'dest_addr':dest_addr, | |
'dest_port':dest_port, | |
'protocol':protocol | |
}).addCallback(self._write) | |
def _write(self,data): | |
if data['error']: | |
self.transport.write(';'.join([str(data['error']),'-1'])) | |
else: | |
self.transport.write(';'.join(['0',str(data['proxy_port'])])) | |
def disconnect(self): | |
self.transport.loseConnection() | |
self.disconnectDef = defer.Deferred() | |
return self.disconnectDef | |
def connectionLost(self,arg2): | |
if self.disconnectDef: | |
self.disconnectDef.callback(True) | |
class KernelConnectorFactory(ClientFactory): | |
def __init__(self,app): | |
self.app = app | |
def buildProtocol(self, addr): | |
protocol = KernelConnector(self.app) | |
protocol.factory = self | |
return protocol | |
#app init: | |
self.kernelFactory = KernelConnectorFactory(self) | |
#kernel connected: | |
def handleKernelConnected(self,connectedKernel): | |
self.kernelConnected = True | |
self.kernel = connectedKernel | |
if not self.kernelInitDef.called: | |
self.kernelInitDef.callback(True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
network_test | |
TestProxy | |
test_data ... [OK] | |
test_host_disconnect ... [OK] | |
test_kernel_protocol ... [ERROR] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2011-08-20 04:16:42+0200 [-] Log opened. | |
2011-08-20 04:16:42+0200 [-] --> network_test.TestProxy.test_data <-- | |
2011-08-20 04:16:42+0200 [-] twisted.internet.protocol.Factory starting on 8052 | |
2011-08-20 04:16:42+0200 [-] Starting factory <twisted.internet.protocol.Factory instance at 0x10e6b7950> | |
2011-08-20 04:16:42+0200 [-] Starting factory <client.ProxyClientFactory instance at 0x10e6b7b90> | |
2011-08-20 04:16:42+0200 [-] client.TCPForwardFactory starting on 8008 | |
2011-08-20 04:16:42+0200 [-] Starting factory <client.TCPForwardFactory instance at 0x10e6b7e18> | |
2011-08-20 04:16:42+0200 [-] Starting factory <client.KernelConnectorFactory instance at 0x10e6c5098> | |
2011-08-20 04:16:42+0200 [-] (TCP Port 8052 Closed) | |
2011-08-20 04:16:42+0200 [-] Stopping factory <twisted.internet.protocol.Factory instance at 0x10e6b7950> | |
2011-08-20 04:16:42+0200 [-] (TCP Port 8008 Closed) | |
2011-08-20 04:16:42+0200 [-] Stopping factory <client.TCPForwardFactory instance at 0x10e6b7e18> | |
2011-08-20 04:16:42+0200 [KernelConnector,client] Stopping factory <client.KernelConnectorFactory instance at 0x10e6c5098> | |
2011-08-20 04:16:42+0200 [Proxy,client] Stopping factory <client.ProxyClientFactory instance at 0x10e6b7b90> | |
2011-08-20 04:16:42+0200 [-] Main loop terminated. | |
2011-08-20 04:16:42+0200 [-] --> network_test.TestProxy.test_host_disconnect <-- | |
2011-08-20 04:16:42+0200 [-] twisted.internet.protocol.Factory starting on 8052 | |
2011-08-20 04:16:42+0200 [-] Starting factory <twisted.internet.protocol.Factory instance at 0x10e581998> | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.ProxyClientFactory instance at 0x10e6e65a8> | |
2011-08-20 04:16:43+0200 [-] client.TCPForwardFactory starting on 8008 | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.TCPForwardFactory instance at 0x10e6e52d8> | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.KernelConnectorFactory instance at 0x10e6e5368> | |
2011-08-20 04:16:43+0200 [-] (TCP Port 8052 Closed) | |
2011-08-20 04:16:43+0200 [-] Stopping factory <twisted.internet.protocol.Factory instance at 0x10e581998> | |
2011-08-20 04:16:43+0200 [KernelConnector,client] Stopping factory <client.KernelConnectorFactory instance at 0x10e6e5368> | |
2011-08-20 04:16:43+0200 [Proxy,client] Stopping factory <client.ProxyClientFactory instance at 0x10e6e65a8> | |
2011-08-20 04:16:43+0200 [-] (TCP Port 8008 Closed) | |
2011-08-20 04:16:43+0200 [-] Stopping factory <client.TCPForwardFactory instance at 0x10e6e52d8> | |
2011-08-20 04:16:43+0200 [-] Main loop terminated. | |
2011-08-20 04:16:43+0200 [-] --> network_test.TestProxy.test_kernel_protocol <-- | |
2011-08-20 04:16:43+0200 [-] twisted.internet.protocol.Factory starting on 8052 | |
2011-08-20 04:16:43+0200 [-] Starting factory <twisted.internet.protocol.Factory instance at 0x10e5a98c0> | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.ProxyClientFactory instance at 0x10e5aacb0> | |
2011-08-20 04:16:43+0200 [-] client.TCPForwardFactory starting on 8008 | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.TCPForwardFactory instance at 0x10e6f53f8> | |
2011-08-20 04:16:43+0200 [-] Starting factory <client.KernelConnectorFactory instance at 0x10e6f5ab8> | |
2011-08-20 04:16:43+0200 [-] (TCP Port 8052 Closed) | |
2011-08-20 04:16:43+0200 [-] Stopping factory <twisted.internet.protocol.Factory instance at 0x10e5a98c0> | |
2011-08-20 04:16:43+0200 [-] (TCP Port 8008 Closed) | |
2011-08-20 04:16:43+0200 [-] Stopping factory <client.TCPForwardFactory instance at 0x10e6f53f8> | |
2011-08-20 04:16:43+0200 [Proxy,client] Stopping factory <client.ProxyClientFactory instance at 0x10e5aacb0> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_kernel_protocol(self): | |
d = defer.Deferred() | |
d.addErrback(log.err) | |
times = 0 | |
def gotData(data): | |
print 'got data:',data | |
times += 1 | |
data = data.rstrip().split(';') | |
if data[0] == '0': | |
assert int(data[1]) > 1 | |
elif int(data[0]) > 0: | |
assert data[1] == '-1' | |
if times == 2: | |
d.callback(True) | |
else: | |
d.errback(Exception('Got error on first message')) | |
self.kernelProto = self.app.kernelFactory.buildProtocol(('127.0.0.1',0)) | |
self.kernelTr = CustomStringTransport(gotData) | |
#anything after this line will fail: | |
self.kernelProto.makeConnection(self.kernelTr) | |
qwe;qwe | |
self.kernelProto.fake = True | |
#send two messages to client, one will pass and one will fail | |
self.kernelProto.dataReceived("connect;tcp;localhost;8052;1337\r\n") | |
self.kernelProto.dataReceived("connect;tcp;localhost;9999;1337\r\n") | |
return d | |
#A subclass I use | |
class CustomStringTransport(proto_helpers.StringTransport): | |
def __init__(self, cb,hostAddress=None, peerAddress=None): | |
self.cb = cb | |
proto_helpers.StringTransport.__init__(self,hostAddress,peerAddress) | |
def write(self,data): | |
self.cb(data) | |
proto_helpers.StringTransport.write(self,data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment