var socks_test_server = null; var socks_listen_port = -1;
function getAvailableBytes(input) { var len = 0;
try {
len = input.available();
} catch (e) {}
return len;
}
function runScriptSubprocess(script, args) { var ds = new DirectoryService(); var bin = ds.get("XREExeF", Ci.nsIFile); if (!bin.exists()) {
do_throw("Can't find xpcshell binary");
}
var file = do_get_file(script); var proc = new Process(bin); var procArgs = [file.path].concat(args);
proc.run(false, procArgs, procArgs.length);
return proc;
}
function buf2ip(buf) { if (buf.length == 16) { var ip =
((buf[0] << 4) | buf[1]).toString(16) + ":" +
((buf[2] << 4) | buf[3]).toString(16) + ":" +
((buf[4] << 4) | buf[5]).toString(16) + ":" +
((buf[6] << 4) | buf[7]).toString(16) + ":" +
((buf[8] << 4) | buf[9]).toString(16) + ":" +
((buf[10] << 4) | buf[11]).toString(16) + ":" +
((buf[12] << 4) | buf[13]).toString(16) + ":" +
((buf[14] << 4) | buf[15]).toString(16); for (var i = 8; i >= 2; i--) { var re = new RegExp("(^|:)(0(:|$)){" + i + "}"); var shortip = ip.replace(re, "::"); if (shortip != ip) { return shortip;
}
} return ip;
} return buf.join(".");
}
function buf2int(buf) { var n = 0;
for (var i in buf) {
n |= buf[i] << ((buf.length - i - 1) * 8);
}
return n;
}
function buf2str(buf) { return String.fromCharCode.apply(null, buf);
}
var bin = new BinaryInputStream(input); var data = bin.readByteArray(len); this.inbuf = this.inbuf.concat(data);
switch (this.state) { case STATE_WAIT_GREETING: this.checkSocksGreeting(); break; case STATE_WAIT_SOCKS4_REQUEST: this.checkSocks4Request(); break; case STATE_WAIT_SOCKS4_USERNAME: this.checkSocks4Username(); break; case STATE_WAIT_SOCKS4_HOSTNAME: this.checkSocks4Hostname(); break; case STATE_WAIT_SOCKS5_GREETING: this.checkSocks5Greeting(); break; case STATE_WAIT_SOCKS5_REQUEST: this.checkSocks5Request(); break; case STATE_WAIT_PONG: this.checkPong(); break; default:
do_throw("server: read in invalid state!");
}
this.waitRead(input);
},
onOutputStreamReady(output) { var len = output.write(this.outbuf, this.outbuf.length); if (len != this.outbuf.length) { this.outbuf = this.outbuf.substring(len); this.waitWrite(output);
} else { this.outbuf = String();
}
},
var atype = this.inbuf[3]; var len; var name = false;
switch (atype) { case 0x01:
len = 4; break; case 0x03:
len = this.inbuf[4];
name = true; break; case 0x04:
len = 16; break; default:
do_throw("Unknown address type " + atype);
}
if (name) { if (this.inbuf.length < 4 + len + 1 + 2) { return;
}
let buf = this.inbuf.slice(5, 5 + len); this.dest_name = buf2str(buf);
len += 1;
} else { if (this.inbuf.length < 4 + len + 2) { return;
}
this.dest_addr = this.inbuf.slice(4, 4 + len);
}
len += 4; this.dest_port = this.inbuf.slice(len, len + 2); this.inbuf = this.inbuf.slice(len + 2); this.sendSocks5Response();
},
sendSocks5Response() { if (this.dest_addr.length == 16) { // send a successful response with the address, [::1]:80 this.outbuf += "\x05\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x80";
} else { // send a successful response with the address, 127.0.0.1:80 this.outbuf += "\x05\x00\x00\x01\x7f\x00\x00\x01\x00\x80";
} this.sendPing();
},
function SocksTestServer() { this.listener = ServerSocket(-1, true, -1);
socks_listen_port = this.listener.port;
print("server: listening on", socks_listen_port); this.listener.asyncListen(this); this.test_cases = []; this.client_connections = []; this.client_subprocess = null; // port is used as the ID for test cases this.test_port_id = 8000; this.tests_completed = 0;
}
SocksTestServer.prototype = {
addTestCase(test) {
test.finished = false;
test.port = this.test_port_id++; this.test_cases.push(test);
},
pickTest(id) { for (var i in this.test_cases) { var test = this.test_cases[i]; if (test.port == id) { this.tests_completed++; return test;
}
}
do_throw("No test case with id " + id); returnnull;
},
testCompleted(client) { var port_id = buf2int(client.dest_port); var test = this.pickTest(port_id);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.