diff options
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt b/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt index abc81998..80b32fd5 100644 --- a/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt +++ b/ui/src/main/java/com/wireguard/android/viewmodel/PeerDetail.kt @@ -4,25 +4,37 @@ import android.util.Log import androidx.databinding.BaseObservable import androidx.databinding.Bindable import androidx.databinding.Observable +import androidx.databinding.ObservableList +import androidx.databinding.ObservableArrayList import com.wireguard.android.BR import com.wireguard.config.InetEndpoint +import com.wireguard.config.InetNetwork import com.wireguard.config.Peer +import com.wireguard.crypto.Key; import java.util.Optional; +import kotlin.collections.LinkedHashSet + class PeerDetail : BaseObservable { - var peer: Peer + var peer: Peer? private var owner: ConfigDetail? = null @get:Bindable + var publicKey: Key + + @get:Bindable + var allowedIps: ObservableList<InetNetwork> = ObservableArrayList<InetNetwork>() + + @get:Bindable var endpoint: Optional<InetEndpoint> = Optional.empty() get() { if (!field.isEmpty()) { return field } else { - return peer.endpoint + return Optional.ofNullable(peer?.endpoint?.get()) } } @@ -32,8 +44,20 @@ class PeerDetail : BaseObservable { notifyPropertyChanged(BR.endpoint) } + @get:Bindable + var persistentKeepalive: Optional<Int> = Optional.empty() + constructor(other: Peer) { peer = other + publicKey = other.getPublicKey() + allowedIps.addAll(other.getAllowedIps()) + endpoint = other.getEndpoint(); + persistentKeepalive = other.getPersistentKeepalive() + } + + constructor(publicKey: Key) { + peer = null + this.publicKey = publicKey } fun bind(owner: ConfigDetail) { @@ -45,6 +69,16 @@ class PeerDetail : BaseObservable { super.addOnPropertyChangedCallback(callback) } + /** + * Converts the {@code Peer} into a string suitable for debugging purposes. The {@code Peer} is + * identified by its public key and (if known) its endpoint. + * + * @return a concise single-line identifier for the {@code Peer} + */ + override fun toString(): String { + return "(Peer " + publicKey.toBase64() + ")" + } + companion object { private const val TAG = "WireGuard/PeerDetail" } |