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

Function hw_main

sshuttle/hostwatch.py:209–250  ·  view source on GitHub ↗
(seed_hosts, auto_hosts)

Source from the content-addressed store, hash-verified

207
208
209def hw_main(seed_hosts, auto_hosts):
210 helpers.logprefix = 'HH: '
211
212 debug1('Starting hostwatch with Python version %s'
213 % platform.python_version())
214
215 for h in seed_hosts:
216 check_host(h)
217
218 if auto_hosts:
219 read_host_cache()
220 _enqueue(_check_etc_hosts)
221 _enqueue(_check_netstat)
222 check_host('localhost')
223 check_host(socket.gethostname())
224
225 while 1:
226 now = time.time()
227 # For each item in the queue
228 for t, last_polled in list(queue.items()):
229 (op, args) = t
230 if not _stdin_still_ok(0):
231 break
232
233 # Determine if we need to run.
234 maxtime = POLL_TIME
235 # netstat runs more often than other jobs
236 if op == _check_netstat:
237 maxtime = NETSTAT_POLL_TIME
238
239 # Check if this jobs needs to run.
240 if now - last_polled > maxtime:
241 queue[t] = time.time()
242 op(*args)
243 try:
244 sys.stdout.flush()
245 except IOError:
246 break
247
248 # FIXME: use a smarter timeout based on oldest last_polled
249 if not _stdin_still_ok(1): # sleeps for up to 1 second
250 break

Callers

nothing calls this directly

Calls 6

debug1Function · 0.90
check_hostFunction · 0.85
read_host_cacheFunction · 0.85
_enqueueFunction · 0.85
_stdin_still_okFunction · 0.85
flushMethod · 0.80

Tested by

no test coverage detected