Skip to content

Commit

Permalink
fix client-vpn reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
ab77 committed Dec 3, 2023
1 parent 1767215 commit 8497f01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
3 changes: 0 additions & 3 deletions unzoner/.balena/balena.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ build-variables:
# FIXME: https://sources.debian.org/patches/sniproxy/0.6.0-2/
- BUILD_SNIPROXY_VERSION=0.6.0
- BUILD_SNIPROXY=0
# project abandoned http://wanproxy.org/)
- BUILD_WANPROXY_VERSION=0.8.0
- BUILD_WANPROXY=0
# https://nuitka.net/
- COMPILE_CODE=1
# (e.g.) dig +short us.{{ DNS_SUB_DOMAIN }}.{{ DNS_DOMAIN }}
Expand Down
23 changes: 4 additions & 19 deletions unzoner/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ ARG BUILD_OPENVPN
ARG BUILD_OPENVPN_VERSION
ARG BUILD_SNIPROXY
ARG BUILD_SNIPROXY_VERSION
ARG BUILD_WANPROXY
ARG BUILD_WANPROXY_VERSION
ARG COMPILE_CODE
ARG DNS_SUB_DOMAIN

Expand Down Expand Up @@ -73,10 +71,7 @@ RUN if [ "$BUILD_OPENSSL" = '1' ]; then \

# https://stackoverflow.com/a/39006247/1559300
RUN if [ "$BUILD_OPENVPN" = '1' ]; then \
set -x; (wget --retry-on-host-error --retry-connrefused --waitretry=2 -q \
https://swupdate.openvpn.org/community/releases/openvpn-$BUILD_OPENVPN_VERSION.tar.gz \
|| curl --fail --retry 3 https://swupdate.openvpn.org/community/releases/openvpn-$BUILD_OPENVPN_VERSION.tar.gz \
-o openvpn-$BUILD_OPENVPN_VERSION.tar.gz) \
set -x; curl --retry 3 -sFo openvpn-$BUILD_OPENVPN_VERSION.tar.gz https://swupdate.openvpn.org/community/releases/openvpn-$BUILD_OPENVPN_VERSION.tar.gz \
&& tar -xvf openvpn-$BUILD_OPENVPN_VERSION.tar.gz && cd openvpn-$BUILD_OPENVPN_VERSION \
&& if [ "$BUILD_OPENSSL" = '1' ]; then CFLAGS='-I/usr/local/ssl/include -Wl,-rpath=/usr/local/ssl/lib -Wl,-rpath=/usr/local/ssl/lib64 -L/usr/local/ssl/lib -L/usr/local/ssl/lib64' ./configure; else ./configure; fi \
&& make -j $(nproc) && make check && make install \
Expand All @@ -92,23 +87,13 @@ RUN if [ "$BUILD_SNIPROXY" = '1' ]; then \
&& make install; fi

RUN if [ "$BUILD_BIRD" = '1' ]; then \
wget --retry-on-host-error --retry-connrefused --waitretry=2 -q \
https://bird.network.cz/download/bird-$BUILD_BIRD_VERSION.tar.gz \
curl --retry 3 -sFo bird-$BUILD_BIRD_VERSION.tar.gz https://bird.network.cz/download/bird-$BUILD_BIRD_VERSION.tar.gz \
&& tar -xvf bird-$BUILD_BIRD_VERSION.tar.gz && cd bird-$BUILD_BIRD_VERSION \
&& mkdir -p tools/ \
&& wget --retry-on-host-error --retry-connrefused --waitretry=2 -qO tools/config.guess \
'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' \
&& wget --retry-on-host-error --retry-connrefused --waitretry=2 -qO tools/config.sub \
'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' \
&& curl --retry 3 -sFo tools/config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' \
&& curl --retry 3 -sFo tools/config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' \
&& autoreconf && ./configure && make -j $(nproc) && make install; fi

RUN if [ "$BUILD_WANPROXY" = '1' ]; then \
wget --retry-on-host-error --retry-connrefused --waitretry=2 -q \
http://wanproxy.org/releases/wanproxy-$BUILD_WANPROXY_VERSION.tar.gz \
&& tar zxf wanproxy-$BUILD_WANPROXY_VERSION.tar.gz \
&& cd wanproxy-$BUILD_WANPROXY_VERSION/programs/wanproxy \
&& make && cp wanproxy /usr/local/sbin; fi

WORKDIR /root

ENV VIRTUAL_ENV=/root/venv3
Expand Down
30 changes: 16 additions & 14 deletions unzoner/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def main():
except (IndexError, TypeError, AttributeError):
pass

if not connected and not connecting:
if not connected and not connecting: # connect client-vpn
if i == 1:
connecting = True
log('vpn-client-state: cycle={} connecting={} family={}'.format(
Expand All @@ -410,7 +410,10 @@ def main():
family=AF
)
c_pid = c_proc.pid
connected = True
connecting = False
except AssertionError as e:
connected = False
connecting = False
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
Expand Down Expand Up @@ -456,19 +459,18 @@ def main():
))

if i % LOOP_CYCLE == 0: # at the end of the cycle
if not connected and connecting: # if client-vpn still connecting, kill and restart
try:
shell_check_output_cmd('ip link | grep {}'.format(TUN_IFACE))
geo_result = get_geo_location()
assert geo_result, '{}: client tunnel down'.format(this)
print('client-vpn-geo: {}'.format(geo_result))
except AssertionError as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
connected = False
connecting = False
c_proc.terminate()
c_pid = None
try:
shell_check_output_cmd('ip link | grep {}'.format(TUN_IFACE))
geo_result = get_geo_location()
assert geo_result, '{}: client tunnel down'.format(this)
print('client-vpn-geo: {}'.format(geo_result))
except AssertionError as e:
print('exception-handler in {}: {}'.format(this, repr(e)))
if DEBUG: print_exc()
connected = False
connecting = False
c_proc.terminate()
c_pid = None

try:
log_client_stats(status=connected, country=c_country)
Expand Down
2 changes: 1 addition & 1 deletion unzoner/src/tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function finish() {
trap finish EXIT

function install_venv() {
python3.9 -m venv src/tests/venv
python3 -m venv src/tests/venv

export PATH="$(pwd)/src/tests/venv/bin:${PATH}"

Expand Down

0 comments on commit 8497f01

Please sign in to comment.