MCPcopy Index your code
hub / github.com/sshuttle/sshuttle / onaccept_tcp

Function onaccept_tcp

sshuttle/client.py:497–531  ·  view source on GitHub ↗
(listener, method, mux, handlers)

Source from the content-addressed store, hash-verified

495
496
497def onaccept_tcp(listener, method, mux, handlers):
498 global _extra_fd
499 try:
500 sock, srcip = listener.accept()
501 except socket.error as e:
502 if e.args[0] in [errno.EMFILE, errno.ENFILE]:
503 debug1('Rejected incoming connection: too many open files!')
504 # free up an fd so we can eat the connection
505 os.close(_extra_fd)
506 try:
507 sock, srcip = listener.accept()
508 sock.close()
509 finally:
510 _extra_fd = os.open(os.devnull, os.O_RDONLY)
511 return
512 else:
513 raise
514
515 dstip = method.get_tcp_dstip(sock)
516 debug1('Accept TCP: %s:%r -> %s:%r.' % (srcip[0], srcip[1],
517 dstip[0], dstip[1]))
518 if dstip[1] == sock.getsockname()[1] and islocal(dstip[0], sock.family):
519 debug1("-- ignored: that's my address!")
520 sock.close()
521 return
522 chan = mux.next_channel()
523 if not chan:
524 log('warning: too many open channels. Discarded connection.')
525 sock.close()
526 return
527 mux.send(chan, ssnet.CMD_TCP_CONNECT, b'%d,%s,%d' %
528 (sock.family, dstip[0].encode("ASCII"), dstip[1]))
529 outwrap = MuxWrapper(mux, chan)
530 handlers.append(Proxy(SockWrapper(sock, sock), outwrap))
531 expire_connections(time.time(), mux)
532
533
534def udp_done(chan, data, method, sock, dstip):

Callers

nothing calls this directly

Calls 11

debug1Function · 0.90
islocalFunction · 0.90
logFunction · 0.90
MuxWrapperClass · 0.90
ProxyClass · 0.90
SockWrapperClass · 0.90
expire_connectionsFunction · 0.85
closeMethod · 0.80
next_channelMethod · 0.80
get_tcp_dstipMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected