tunnel: use record class where possible
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
58ec110360
commit
353679801e
@ -21,31 +21,7 @@ import androidx.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
@NonNullForAll
|
@NonNullForAll
|
||||||
public class Statistics {
|
public class Statistics {
|
||||||
|
public record PeerStats(long rxBytes, long txBytes, long latestHandshakeEpochMillis) { }
|
||||||
// TODO: switch to Java Record class once R8 supports desugaring those.
|
|
||||||
public final class PeerStats {
|
|
||||||
public final long rxBytes, txBytes, latestHandshakeEpochMillis;
|
|
||||||
|
|
||||||
PeerStats(final long rxBytes, final long txBytes, final long latestHandshakeEpochMillis) {
|
|
||||||
this.rxBytes = rxBytes;
|
|
||||||
this.txBytes = txBytes;
|
|
||||||
this.latestHandshakeEpochMillis = latestHandshakeEpochMillis;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean equals(final Object o) {
|
|
||||||
if (this == o)
|
|
||||||
return true;
|
|
||||||
if (o == null || getClass() != o.getClass())
|
|
||||||
return false;
|
|
||||||
final PeerStats stats = (PeerStats) o;
|
|
||||||
return rxBytes == stats.rxBytes && txBytes == stats.txBytes && latestHandshakeEpochMillis == stats.latestHandshakeEpochMillis;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public int hashCode() {
|
|
||||||
return Objects.hash(rxBytes, txBytes, latestHandshakeEpochMillis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<Key, PeerStats> stats = new HashMap<>();
|
private final Map<Key, PeerStats> stats = new HashMap<>();
|
||||||
private long lastTouched = SystemClock.elapsedRealtime();
|
private long lastTouched = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
@ -85,7 +61,7 @@ public class Statistics {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public PeerStats peer(final Key peer) {
|
public PeerStats peer(final Key peer) {
|
||||||
return this.stats.get(peer);
|
return stats.get(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user