Skip to content

Commit

Permalink
fix mixed mode status reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ab77 committed Dec 6, 2023
1 parent ce510c1 commit 2778de9
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions unzoner/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ def main():
if s_msg[idx] in magic_lines:
started[idx] = True
starting[idx] = False
try:
log_server_stats(status=started)
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
log_server_stats(status=started)

if not started[idx] and not starting[idx]:
if i == 1: # at the beginning of the cycle
Expand Down Expand Up @@ -197,25 +193,11 @@ def main():
if DEVICE_TYPE == 3 and connected: # test if double-vpn is up
try:
shell_check_output_cmd('ip link | grep {}'.format(TUN_IFACE)) # raises exception if tunnel is down
geo_result = get_geo_location()
assert geo_result, '{}: double-vpn not ready'.format(this)
print('double-vpn-geo: {}'.format(geo_result))
log_server_stats(status=started) # server up only if double-vpn is up
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()

try:
log_server_stats() # force server down if double-vpn is down
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
except:
log_server_stats() # force server down if double-vpn is down
else:
try:
log_server_stats(status=started)
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
log_server_stats(status=started)

s_status_line = 'server-status: cycle={} started={} starting={} s_pid={} s_conns={} AF={} hostAPd={} UPNP={}'.format(
i,
Expand Down Expand Up @@ -382,11 +364,7 @@ def main():
if c_msg in magic_lines:
connected = True
connecting = False
try:
log_client_stats(status=connected, country=c_country)
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
log_client_stats(status=connected, country=c_country)

if DEVICE_TYPE == 5:
try:
Expand Down Expand Up @@ -468,6 +446,7 @@ def main():
geo_result = get_geo_location()
assert geo_result, '{}: client tunnel down'.format(this)
print('client-vpn-geo: {}'.format(geo_result))
if DEVICE_TYPE == 3: log_server_stats(status=started) # server up only if client-vpn is up
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
Expand All @@ -476,13 +455,9 @@ def main():
c_proc.terminate()
while c_proc.poll() is None: sleep(LOOP_TIMER)
c_pid = None
if DEVICE_TYPE == 3: log_server_stats() # force server down if clienv-vpn is down

try:
log_client_stats(status=connected, country=c_country)
except Exception as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()

log_client_stats(status=connected, country=c_country)
w_clnts = get_stations()
c_status_line = 'client-status: cycle={} connected={} connecting={} c_proto={} c_pid={} w_clnts={} AF={} hostAPd={} UPNP={}'.format(
i,
Expand Down

0 comments on commit 2778de9

Please sign in to comment.