summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/ObfsVpnClient.java
blob: 692108815e7fc8b63f9e11d8bea36bbcb7446982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package se.leap.bitmaskclient.pluggableTransports;

import android.util.Log;

import java.util.Observable;
import java.util.Observer;

import client.Client_;
import de.blinkt.openvpn.core.ConnectionStatus;
import se.leap.bitmaskclient.eip.EipStatus;

public class ObfsVpnClient implements Observer {

    public static final String SOCKS_PORT = "4430";
    public static final String SOCKS_IP = "127.0.0.1";

    private static final String TAG = ObfsVpnClient.class.getSimpleName();
    private boolean noNetwork;
    // TODO: implement error signaling go->java
    private boolean isErrorHandling;

    private final client.Client_ obfsVpnClient;
    private final Object LOCK = new Object();

    public ObfsVpnClient(Obfs4Options options) {
        obfsVpnClient = new Client_(options.udp, SOCKS_IP+":"+SOCKS_PORT, options.cert);
    }

    public void start() {
        synchronized (LOCK) {
            Log.d(TAG, "aquired LOCK");
            new Thread(obfsVpnClient::start).start();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Log.d(TAG, "returning LOCK after 500 ms");
        }
    }

    public void stop() {
        synchronized (LOCK) {
            Log.d(TAG, "stopping obfsVpnClient...");
            obfsVpnClient.stop();
        }
    }

    @Override
    public void update(Observable observable, Object arg) {
        if (observable instanceof EipStatus) {
            EipStatus status = (EipStatus) observable;
            //This doesn't do anything yet, since the error handling is still missing
            if (status.getLevel() == ConnectionStatus.LEVEL_NONETWORK) {
                noNetwork = true;
            } else {
                noNetwork = false;
                if (isErrorHandling) {
                    isErrorHandling = false;
                    stop();
                    start();
                }
            }
        }
    }
}