summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/pluggableTransports/models/HoppingConfig.java
blob: 96b8c4606ff17a20fb8f620325b07dde50c1cbae (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
67
68
69
package se.leap.bitmaskclient.pluggableTransports.models;

import androidx.annotation.NonNull;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import se.leap.bitmaskclient.base.models.Transport;

public class HoppingConfig {

    /**
     * Enabled       bool     `json:"enabled"`
     * 	Remotes       []string `json:"remotes"`
     * 	Obfs4Certs    []string `json:"obfs4_certs"`
     * 	PortSeed      int64    `json:"port_seed"`
     * 	PortCount     uint     `json:"port_count"`
     * 	MinHopSeconds uint     `json:"min_hop_seconds"`
     * 	HopJitter     uint     `json:"hop_jitter"`
     * }
     */

    final boolean enabled;
    final String proxyAddr;
    final String[] remotes;
    final String[] obfs4Certs;
    final int portSeed;
    final int portCount;
    final int minHopSeconds;
    final int hopJitter;

    public HoppingConfig(boolean enabled,
                         String proxyAddr,
                         Obfs4Options options,
                         int minHopSeconds,
                         int hopJitter) {
        this.enabled = enabled;
        this.proxyAddr = proxyAddr;
        Transport transport = options.transport;
        Transport.Endpoint[] endpoints = transport.getOptions().getEndpoints();
        if (endpoints == null) {
            // only port hopping, we assume the gateway IP as hopping PT's IP
            this.remotes = new String[]{ options.bridgeIP };
            this.obfs4Certs = new String[] { transport.getOptions().getCert() };
        } else {
            // port+ip hopping
            this.remotes = new String[endpoints.length];
            this.obfs4Certs = new String[endpoints.length];
            for (int i = 0; i < remotes.length; i++) {
                remotes[i] = endpoints[i].getIp();
                obfs4Certs[i] = endpoints[i].getCert();
            }
        }
        this.portSeed = transport.getOptions().getPortSeed();
        this.portCount = transport.getOptions().getPortCount();
        this.minHopSeconds = minHopSeconds;
        this.hopJitter = hopJitter;
    }

    @NonNull
    @Override
    public String toString() {
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();
       return gson.toJson(this);
    }
}