MCPcopy
hub / github.com/sshuttle/sshuttle / _main

Function _main

sshuttle/client.py:591–805  ·  view source on GitHub ↗
(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
          python, latency_control, latency_buffer_size,
          dns_listener, seed_hosts, auto_hosts, auto_nets, daemon,
          to_nameserver, add_cmd_delimiter, remote_shell)

Source from the content-addressed store, hash-verified

589
590
591def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
592 python, latency_control, latency_buffer_size,
593 dns_listener, seed_hosts, auto_hosts, auto_nets, daemon,
594 to_nameserver, add_cmd_delimiter, remote_shell):
595
596 helpers.logprefix = 'c : '
597 debug1('Starting client with Python version %s'
598 % platform.python_version())
599
600 method = fw.method
601
602 handlers = []
603 debug1('Connecting to server...')
604
605 try:
606 (serverproc, rfile, wfile) = ssh.connect(
607 ssh_cmd, remotename, python,
608 stderr=ssyslog._p and ssyslog._p.stdin,
609 add_cmd_delimiter=add_cmd_delimiter,
610 remote_shell=remote_shell,
611 options=dict(latency_control=latency_control,
612 latency_buffer_size=latency_buffer_size,
613 auto_hosts=auto_hosts,
614 to_nameserver=to_nameserver,
615 auto_nets=auto_nets))
616 except socket.error as e:
617 if e.args[0] == errno.EPIPE:
618 debug3('Error: EPIPE: ' + repr(e))
619 raise Fatal("SSH connection lost: broken pipe (server may have terminated unexpectedly)")
620 else:
621 raise
622 mux = Mux(rfile, wfile)
623 handlers.append(mux)
624
625 expected = b'SSHUTTLE0001'
626 try:
627 v = 'x'
628 while v and v != b'\0':
629 v = rfile.read(1)
630 v = 'x'
631 while v and v != b'\0':
632 v = rfile.read(1)
633 initstring = rfile.read(len(expected))
634 except socket.error as e:
635 if e.args[0] == errno.ECONNRESET:
636 debug3('Error: ECONNRESET ' + repr(e))
637 raise Fatal("failed to establish ssh session (2)")
638 else:
639 raise
640
641 # Returns None if process is still running (or returns exit code)
642 rv = serverproc.poll()
643 if rv is not None:
644 errmsg = "server died with error code %d\n" % rv
645
646 # Our fatal exceptions return exit code 99
647 if rv == 99:
648 errmsg += "This error code likely means that python started and " \

Callers 1

mainFunction · 0.85

Calls 11

sendMethod · 0.95
check_fullnessMethod · 0.95
debug1Function · 0.90
debug3Function · 0.90
FatalClass · 0.90
MuxClass · 0.90
logFunction · 0.90
daemonizeFunction · 0.85
check_ssh_aliveFunction · 0.85
flushMethod · 0.80
add_handlerMethod · 0.80

Tested by

no test coverage detected