(latency_control, latency_buffer_size, auto_hosts, to_nameserver,
auto_nets)
| 285 | |
| 286 | |
| 287 | def main(latency_control, latency_buffer_size, auto_hosts, to_nameserver, |
| 288 | auto_nets): |
| 289 | try: |
| 290 | helpers.logprefix = ' s: ' |
| 291 | |
| 292 | debug1('latency control setting = %r' % latency_control) |
| 293 | if latency_buffer_size: |
| 294 | import sshuttle.ssnet as ssnet |
| 295 | ssnet.LATENCY_BUFFER_SIZE = latency_buffer_size |
| 296 | |
| 297 | # synchronization header |
| 298 | sys.stdout.write('\0\0SSHUTTLE0001') |
| 299 | sys.stdout.flush() |
| 300 | |
| 301 | handlers = [] |
| 302 | # get unbuffered stdin and stdout in binary mode. Equivalent to stdin.buffer/stdout.buffer (Only available in Python 3) |
| 303 | r, w = io.FileIO(0, mode='r'), io.FileIO(1, mode='w') |
| 304 | if sys.platform == 'win32': |
| 305 | def _deferred_exit(): |
| 306 | time.sleep(1) # give enough time to write logs to stderr |
| 307 | os._exit(23) |
| 308 | shim = SocketRWShim(r, w, on_end=_deferred_exit) |
| 309 | mux = Mux(*shim.makefiles()) |
| 310 | else: |
| 311 | mux = Mux(r, w) |
| 312 | handlers.append(mux) |
| 313 | |
| 314 | debug1('auto-nets:' + str(auto_nets)) |
| 315 | if auto_nets: |
| 316 | routes = list(list_routes()) |
| 317 | debug1('available routes:') |
| 318 | for r in routes: |
| 319 | debug1(' %d/%s/%d' % r) |
| 320 | else: |
| 321 | routes = [] |
| 322 | |
| 323 | routepkt = '' |
| 324 | for r in routes: |
| 325 | routepkt += '%d,%s,%d\n' % r |
| 326 | mux.send(0, ssnet.CMD_ROUTES, b(routepkt)) |
| 327 | |
| 328 | hw = Hostwatch() |
| 329 | hw.leftover = b('') |
| 330 | |
| 331 | def hostwatch_ready(sock): |
| 332 | assert hw.pid |
| 333 | content = hw.sock.recv(4096) |
| 334 | if content: |
| 335 | lines = (hw.leftover + content).split(b('\n')) |
| 336 | if lines[-1]: |
| 337 | # no terminating newline: entry isn't complete yet! |
| 338 | hw.leftover = lines.pop() |
| 339 | lines.append(b('')) |
| 340 | else: |
| 341 | hw.leftover = b('') |
| 342 | mux.send(0, ssnet.CMD_HOST_LIST, b('\n').join(lines)) |
| 343 | else: |
| 344 | raise Fatal('hostwatch process died') |
no test coverage detected