SSU2: Enhance PeerTestState logging

avoid dup previous charlies on list
This commit is contained in:
zzz
2022-12-15 15:05:10 -05:00
parent af5456b846
commit 21c7ad4a89

View File

@@ -106,6 +106,12 @@ class PeerTestState {
public InetAddress getBobIP() { return _bob.getRemoteIPAddress(); }
public InetAddress getCharlieIP() { return _charlieIP; }
/**
* SSU2 only, null for SSU1.
* @since 0.9.57
*/
public Hash getCharlieHash() { return _charlieHash; }
/**
* @param hash SSU2 only, null for SSU1
* @since 0.9.54
@@ -113,7 +119,7 @@ class PeerTestState {
public void setCharlie(InetAddress ip, int port, Hash hash) {
_charlieIP = ip;
_charliePort = port;
if (_charlieHash != null && _previousCharlies != null)
if (_charlieHash != null && _previousCharlies != null && !_charlieHash.equals(hash))
_previousCharlies.add(_charlieHash);
_charlieHash = hash;
}
@@ -215,10 +221,13 @@ class PeerTestState {
.append(" as ").append(_ourRole.toString());
if (_aliceIP != null) {
buf.append("; Alice: ");
if (_ourRole == Role.ALICE)
if (_ourRole == Role.ALICE) {
buf.append("me");
else
} else {
buf.append(_aliceIP).append(':').append(_alicePort);
if (_aliceHash != null)
buf.append(' ').append(_aliceHash.toBase64().substring(0, 6));
}
}
if (_aliceIPFromCharlie != null)
buf.append(" (fromCharlie ").append(_aliceIPFromCharlie).append(':').append(_alicePortFromCharlie).append(')');
@@ -228,10 +237,13 @@ class PeerTestState {
buf.append(" Bob: me");
if (_charlieIP != null) {
buf.append(" Charlie: ");
if (_ourRole == Role.CHARLIE)
if (_ourRole == Role.CHARLIE) {
buf.append("me");
else
} else {
buf.append(_charlieIP).append(':').append(_charliePort);
if (_charlieHash != null)
buf.append(' ').append(_charlieHash.toBase64().substring(0, 6));
}
if (_previousCharlies != null && !_previousCharlies.isEmpty())
buf.append(" previous: ").append(_previousCharlies);
}