MCPcopy Create free account
hub / github.com/apenwarr/sshuttle / onaccept

Function onaccept

client.py:180–211  ·  view source on GitHub ↗
(listener, mux, handlers)

Source from the content-addressed store, hash-verified

178
179
180def onaccept(listener, mux, handlers):
181 global _extra_fd
182 try:
183 sock,srcip = listener.accept()
184 except socket.error, e:
185 if e.args[0] in [errno.EMFILE, errno.ENFILE]:
186 debug1('Rejected incoming connection: too many open files!\n')
187 # free up an fd so we can eat the connection
188 os.close(_extra_fd)
189 try:
190 sock,srcip = listener.accept()
191 sock.close()
192 finally:
193 _extra_fd = os.open('/dev/null', os.O_RDONLY)
194 return
195 else:
196 raise
197 dstip = original_dst(sock)
198 debug1('Accept: %s:%r -> %s:%r.\n' % (srcip[0],srcip[1],
199 dstip[0],dstip[1]))
200 if dstip[1] == listener.getsockname()[1] and islocal(dstip[0]):
201 debug1("-- ignored: that's my address!\n")
202 sock.close()
203 return
204 chan = mux.next_channel()
205 if not chan:
206 log('warning: too many open channels. Discarded connection.\n')
207 sock.close()
208 return
209 mux.send(chan, ssnet.CMD_CONNECT, '%s,%s' % dstip)
210 outwrap = MuxWrapper(mux, chan)
211 handlers.append(Proxy(SockWrapper(sock, sock), outwrap))
212
213
214dnsreqs = {}

Callers 1

_mainFunction · 0.85

Calls 9

MuxWrapperClass · 0.90
ProxyClass · 0.90
SockWrapperClass · 0.90
debug1Function · 0.85
original_dstFunction · 0.85
islocalFunction · 0.85
logFunction · 0.85
next_channelMethod · 0.80
sendMethod · 0.80

Tested by

no test coverage detected