blob: 64977a16be67e69365955bbc28271bb50f90319d (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package com.wireguard.config;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.Observable;
import com.android.databinding.library.baseAdapters.BR;
/**
* Represents the configuration for a WireGuard peer (a [Peer] block).
*/
public class Peer extends BaseObservable implements Observable {
private String allowedIPs;
private String endpoint;
private String persistentKeepalive;
private String publicKey;
@Bindable
public String getAllowedIPs() {
return allowedIPs;
}
@Bindable
public String getEndpoint() {
return endpoint;
}
@Bindable
public String getPersistentKeepalive() {
return persistentKeepalive;
}
@Bindable
public String getPublicKey() {
return publicKey;
}
public void parseFrom(String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ALLOWED_IPS)
allowedIPs = key.parseFrom(line);
else if (key == Attribute.ENDPOINT)
endpoint = key.parseFrom(line);
else if (key == Attribute.PERSISTENT_KEEPALIVE)
persistentKeepalive = key.parseFrom(line);
else if (key == Attribute.PUBLIC_KEY)
publicKey = key.parseFrom(line);
}
public void setAllowedIPs(String allowedIPs) {
this.allowedIPs = allowedIPs;
notifyPropertyChanged(BR.allowedIPs);
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
notifyPropertyChanged(BR.endpoint);
}
public void setPersistentKeepalive(String persistentKeepalive) {
this.persistentKeepalive = persistentKeepalive;
notifyPropertyChanged(BR.persistentKeepalive);
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
notifyPropertyChanged(BR.publicKey);
}
public String toString() {
final StringBuilder sb = new StringBuilder().append("[Peer]\n");
if (allowedIPs != null)
sb.append(Attribute.ALLOWED_IPS.composeWith(allowedIPs));
if (endpoint != null)
sb.append(Attribute.ENDPOINT.composeWith(endpoint));
if (persistentKeepalive != null)
sb.append(Attribute.PERSISTENT_KEEPALIVE.composeWith(persistentKeepalive));
if (publicKey != null)
sb.append(Attribute.PUBLIC_KEY.composeWith(publicKey));
return sb.toString();
}
}
|