Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | const CC = Components.Constructor; |
michael@0 | 2 | const Cc = Components.classes; |
michael@0 | 3 | const Ci = Components.interfaces; |
michael@0 | 4 | |
michael@0 | 5 | const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", |
michael@0 | 6 | "nsIBinaryInputStream", |
michael@0 | 7 | "setInputStream"); |
michael@0 | 8 | const ProtocolProxyService = CC("@mozilla.org/network/protocol-proxy-service;1", |
michael@0 | 9 | "nsIProtocolProxyService"); |
michael@0 | 10 | var sts = Cc["@mozilla.org/network/socket-transport-service;1"] |
michael@0 | 11 | .getService(Ci.nsISocketTransportService); |
michael@0 | 12 | |
michael@0 | 13 | function launchConnection(socks_vers, socks_port, dest_host, dest_port, dns) |
michael@0 | 14 | { |
michael@0 | 15 | var pi_flags = 0; |
michael@0 | 16 | if (dns == 'remote') |
michael@0 | 17 | pi_flags = Ci.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST; |
michael@0 | 18 | |
michael@0 | 19 | var pps = new ProtocolProxyService(); |
michael@0 | 20 | var pi = pps.newProxyInfo(socks_vers, 'localhost', socks_port, |
michael@0 | 21 | pi_flags, -1, null); |
michael@0 | 22 | var trans = sts.createTransport(null, 0, dest_host, dest_port, pi); |
michael@0 | 23 | var input = trans.openInputStream(Ci.nsITransport.OPEN_BLOCKING,0,0); |
michael@0 | 24 | var output = trans.openOutputStream(Ci.nsITransport.OPEN_BLOCKING,0,0); |
michael@0 | 25 | var bin = new BinaryInputStream(input); |
michael@0 | 26 | var data = bin.readBytes(5); |
michael@0 | 27 | if (data == 'PING!') { |
michael@0 | 28 | print('client: got ping, sending pong.'); |
michael@0 | 29 | output.write('PONG!', 5); |
michael@0 | 30 | } else { |
michael@0 | 31 | print('client: wrong data from server:', data); |
michael@0 | 32 | output.write('Error: wrong data received.', 27); |
michael@0 | 33 | } |
michael@0 | 34 | output.close(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | for each (var arg in arguments) { |
michael@0 | 38 | print('client: running test', arg); |
michael@0 | 39 | test = arg.split('|'); |
michael@0 | 40 | launchConnection(test[0], parseInt(test[1]), test[2], |
michael@0 | 41 | parseInt(test[3]), test[4]); |
michael@0 | 42 | } |