Commit 75d9997b authored by Hiro's avatar Hiro 🏄
Browse files

Edit tests and fix style

parent aad730bc
Pipeline #37886 passed with stage
in 1 minute and 34 seconds
......@@ -176,11 +176,7 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
/* Already parsed more recent server descriptor from this relay. */
return;
}
int bandwidthRate = descriptor.getBandwidthRate();
int bandwidthBurst = descriptor.getBandwidthBurst();
int observedBandwidth = descriptor.getBandwidthObserved();
int advertisedBandwidth = Math.min(bandwidthRate,
Math.min(bandwidthBurst, observedBandwidth));
detailsStatus.setDescPublished(descriptor.getPublishedMillis());
detailsStatus.setLastRestarted(calculateLastRestartedMillis(descriptor));
......@@ -200,10 +196,14 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
);
}
}
int bandwidthRate = descriptor.getBandwidthRate();
int bandwidthBurst = descriptor.getBandwidthBurst();
int observedBandwidth = descriptor.getBandwidthObserved();
detailsStatus.setBandwidthRate(bandwidthRate);
detailsStatus.setBandwidthBurst(bandwidthBurst);
detailsStatus.setObservedBandwidth(observedBandwidth);
int advertisedBandwidth = Math.min(bandwidthRate,
Math.min(bandwidthBurst, observedBandwidth));
detailsStatus.setAdvertisedBandwidth(advertisedBandwidth);
long overloadGeneralTimestamp = descriptor.getOverloadGeneralTimestamp();
detailsStatus.setOverloadGeneralTimestamp(overloadGeneralTimestamp);
......@@ -361,9 +361,6 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
/* Already parsed more recent server descriptor from this bridge. */
return;
}
int advertisedBandwidth = Math.min(descriptor.getBandwidthRate(),
Math.min(descriptor.getBandwidthBurst(),
descriptor.getBandwidthObserved()));
detailsStatus.setDescPublished(descriptor.getPublishedMillis());
detailsStatus.setLastRestarted(calculateLastRestartedMillis(descriptor));
......@@ -387,7 +384,9 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
);
}
}
int advertisedBandwidth = Math.min(descriptor.getBandwidthRate(),
Math.min(descriptor.getBandwidthBurst(),
descriptor.getBandwidthObserved()));
detailsStatus.setAdvertisedBandwidth(advertisedBandwidth);
long overloadGeneralTimestamp = descriptor.getOverloadGeneralTimestamp();
detailsStatus.setOverloadGeneralTimestamp(overloadGeneralTimestamp);
......@@ -899,7 +898,8 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
this.rdnsVerifiedLookupResults.put(fingerprint, verifiedHostNames);
}
if (null != unverifiedHostNames) {
this.rdnsUnverifiedLookupResults.put(fingerprint, unverifiedHostNames);
this.rdnsUnverifiedLookupResults.put(fingerprint,
unverifiedHostNames);
}
}
}
......
......@@ -9,11 +9,11 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.torproject.descriptor.BridgePoolAssignment;
import org.torproject.descriptor.BridgeNetworkStatus;
import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParser;
import org.torproject.descriptor.DescriptorSourceFactory;
import org.torproject.descriptor.ServerDescriptor;
import org.torproject.metrics.onionoo.docs.DateTimeHelper;
import org.torproject.metrics.onionoo.docs.DetailsStatus;
import org.torproject.metrics.onionoo.docs.DocumentStoreFactory;
import org.torproject.metrics.onionoo.docs.DummyDocumentStore;
......@@ -123,9 +123,10 @@ public class NodeDetailsStatusUpdaterTest {
assertEquals(3, this.docStore.storedDocuments.size());
DetailsStatus dd = this.docStore.getDocument(DetailsStatus.class, FPB);
assertNotNull(dd);
assertEquals((long) dd.getDescPublished() - 113883000,
assertEquals((long) dd.getDescPublished() - UPTIME_MILLIS,
(long) dd.getLastRestarted());
dd.setFirstSeenMillis(dd.getLastRestarted());
long firstRestarted = dd.getLastRestarted();
this.docStore.store(dd, FPB);
/*
......@@ -134,7 +135,7 @@ public class NodeDetailsStatusUpdaterTest {
* published timestamp. The first_seen field is still equal to the previous
* uptime value.
*/
long lastRestarted = dd.getLastRestarted();
final long lastRestarted = dd.getLastRestarted();
descString = BRIDGE1_RESTARTED + BRIDGES_STATUSES;
for (Descriptor desc : dp.parseDescriptors(descString.getBytes(),
new File("dummy"), "dummy")) {
......@@ -146,7 +147,7 @@ public class NodeDetailsStatusUpdaterTest {
assertEquals((long) dd.getDescPublished(), (long) dd.getLastRestarted());
assertEquals((long) lastRestarted, (long) dd.getFirstSeenMillis());
descString = BRIDGE1_UPDATED;
descString = BRIDGE1_UPDATED1 + BRIDGE1_UPDATED2;
for (Descriptor desc : dp.parseDescriptors(descString.getBytes(),
new File("dummy"), "dummy")) {
assertTrue(desc.getClass().getName(), desc instanceof ServerDescriptor);
......@@ -155,6 +156,15 @@ public class NodeDetailsStatusUpdaterTest {
dd = this.docStore.getDocument(DetailsStatus.class, FPB);
assertNotNull(dd);
String firstSeen = DateTimeHelper.format(
uptimeStatus.getBridgeHistory().first().getStartMillis());
assertEquals(firstSeen, DateTimeHelper.format(dd.getFirstSeenMillis()));
/*
* If the last_restarted field is less then the last_seen field then
* our fix should be applied and the first_seen field be equal to the Uptime
* status first value.
*/
assertEquals((long)
uptimeStatus.getBridgeHistory().first().getStartMillis(),
(long) dd.getFirstSeenMillis());
......@@ -168,87 +178,107 @@ public class NodeDetailsStatusUpdaterTest {
+ "2D8C27AA9C2FEC3EC468D7ABE9C3EDCA3C86610A moat "
+ "transport=obfs4 ip=4 blocklist=ru\n";
private static final String UPTIME = "b 2022-03-17-21 864000";
private static final String UPTIME = "b 2021-12-04-16 3646";
private static final long UPTIME_MILLIS = 28383000L;
private static final String BRIDGES_STATUSES = "@type bridge-network-status "
+ "1.2\n"
+ "published 2022-03-19 08:12:11\n"
+ "flag-thresholds stable-uptime=1990924 stable-mtbf=3896250 "
+ "fast-speed=57000 guard-wfu=98.000% guard-tk=691200 "
+ "guard-bw-inc-exits=3409000 guard-bw-exc-exits=3412000 "
private static final String BRIDGES_STATUSES =
"@type bridge-network-status 1.2\n"
+ "published 2022-02-14 15:25:07\n"
+ "flag-thresholds stable-uptime=2163586 stable-mtbf=2335321 "
+ "fast-speed=58000 guard-wfu=98.000% guard-tk=691200 "
+ "guard-bw-inc-exits=3739000 guard-bw-exc-exits=3746000 "
+ "enough-mtbf=1 ignoring-advertised-bws=0\n"
+ "fingerprint BA44A889E64B93FAA2B114E02C2A279A8555C533\n"
+ "r cybergroot01 LYwnqpwv7D7EaNer6cPtyjyGYQo "
+ "x6XBQBBfnXIioM4LoD6bWpXqoFk 2022-03-17 08:42:16 10.245.66.84 55284 0\n"
+ "a [fd9f:2e19:3bcf::c2:91ab]:55284\n"
+ "s Running V2Dir Valid\n"
+ "w Bandwidth=2381\n"
+ "p reject 1-65535";
private static final String BRIDGE1_RESTARTED = "@type bridge-server-"
+ "descriptor 1.2\n"
+ "router DockerObfs4Bridge 10.136.176.127 50451 0 0\n"
+ "master-key-ed25519 J6M6MmuZ2joRKaihSB1LDym+WiuUeId8+9nvtI1Sd1M\n"
+ "platform Tor 0.4.6.10 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1 HSDir=2 HSIntro=4-5 "
+ "HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Padding=2 Relay=1-3\n"
+ "published 2022-03-18 08:10:11\n"
+ "fingerprint BA44A889E64B93FAA2B114E02C2A279A8555C533\n";
private static final String BRIDGE1_RESTARTED =
"@type bridge-server-descriptor 1.2\n"
+ "router cybergroot01 10.149.116.99 49348 0 0\n"
+ "master-key-ed25519 MkcNLtC9gN29vT1qgTugyn63EJMZ9epEG9MjQPeKtYI\n"
+ "platform Tor 0.3.5.16 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=1-2 HSDir=1-2 HSIntro=3-4 "
+ "HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Relay=1-2\n"
+ "published 2022-02-14 14:10:54\n"
+ "fingerprint 2D8C 27AA 9C2F EC3E C468 D7AB E9C3 EDCA 3C86 610A\n"
+ "uptime 0\n"
+ "bandwidth 1073741824 1073741824 81352\n"
+ "extra-info-digest 29ECA238A04F0D00E941B2CC430393604430B7D4 "
+ "X0jHhL7ygWblKzjoTGMG4Eikz8Sqo2X9eIbrKzVANNw\n"
+ "bandwidth 1073741824 1073741824 6128640\n"
+ "extra-info-digest 3C05293BB26F9B4BEAE2BA3B2E5FEBDCAA199217 "
+ "8BmrMbUIezoSU+M4M7owmn26ye6rnnJ9RAW5wSJ/EU8\n"
+ "hidden-service-dir\n"
+ "contact somebody\n"
+ "bridge-distribution-request any\n"
+ "ntor-onion-key kysCjXGfMAx6AdejV2r34d59atkXFkvLNT/9ADcd73M\n"
+ "ntor-onion-key IFhTimxfUuIJC7lIB3OCVPROHIp3iwT9QVPBmzQVwhU=\n"
+ "reject *:*\n"
+ "tunnelled-dir-server\n"
+ "router-digest-sha256 t+rUo6bm75/Qywapm5TTTnY2HGmxZqFAI1/ON2IxNP4\n"
+ "router-digest 78E7EDA527387064BB4410FC8BAED6DA0902BFE3\n";
private static final String BRIDGE1_UPDATED = "@type bridge-server-"
+ "descriptor 1.2\n"
+ "router DockerObfs4Bridge 10.136.176.127 50451 0 0\n"
+ "master-key-ed25519 J6M6MmuZ2joRKaihSB1LDym+WiuUeId8+9nvtI1Sd1M\n"
+ "platform Tor 0.4.6.10 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1 HSDir=2 HSIntro=4-5 "
+ "router-digest-sha256 HcqOJTo3qy969SnXGHKwBp0Z7JwSSf6cm1GNoHKfiB0\n"
+ "router-digest BDAD66C00286AC2CBFB374B4CBFD92430F861B34\n";
private static final String BRIDGE1_UPDATED1 =
"@type bridge-server-descriptor 1.2\n"
+ "router cybergroot01 10.149.116.99 49348 0 0\n"
+ "master-key-ed25519 MkcNLtC9gN29vT1qgTugyn63EJMZ9epEG9MjQPeKtYI\n"
+ "or-address [fd9f:2e19:3bcf::78:f76a]:49348\n"
+ "platform Tor 0.4.5.10 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1 HSDir=1-2 HSIntro=3-5 "
+ "HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Padding=2 Relay=1-3\n"
+ "published 2022-03-20 08:07:11\n"
+ "published 2022-02-14 19:53:43\n"
+ "fingerprint 2D8C 27AA 9C2F EC3E C468 D7AB E9C3 EDCA 3C86 610A\n"
+ "uptime 864000\n"
+ "bandwidth 1073741824 1073741824 81352\n"
+ "extra-info-digest 29ECA238A04F0D00E941B2CC430393604430B7D4 "
+ "X0jHhL7ygWblKzjoTGMG4Eikz8Sqo2X9eIbrKzVANNw\n"
+ "uptime 17463\n"
+ "bandwidth 1073741824 1073741824 6128640\n"
+ "extra-info-digest 0830594A40E6ACF7D821FEF93DC29282CE94D602 "
+ "pCSztW8CymCiUWR6jybymjKw4DgdDvOJC8WPYUeEh58\n"
+ "hidden-service-dir\n"
+ "contact somebody\n"
+ "bridge-distribution-request any\n"
+ "ntor-onion-key kysCjXGfMAx6AdejV2r34d59atkXFkvLNT/9ADcd73M\n"
+ "ntor-onion-key IFhTimxfUuIJC7lIB3OCVPROHIp3iwT9QVPBmzQVwhU=\n"
+ "reject *:*\n"
+ "tunnelled-dir-server\n"
+ "router-digest-sha256 t+rUo6bm75/Qywapm5TTTnY2HGmxZqFAI1/ON2IxNP4\n"
+ "router-digest 78E7EDA527387064BB4410FC8BAED6DA0902BFE3\n";
+ "router-digest-sha256 Bho7Zt0Ov1Ee22w3C3Dy7cuxEaYbHab985hgfZuOwvI\n"
+ "router-digest 5B044C41BE8DE4E9984534E0A03C85039FB7C1F5\n";
private static final String BRIDGE1 = "@type bridge-server-descriptor 1.2\n"
+ "router DockerObfs4Bridge 10.136.176.127 50451 0 0\n"
+ "master-key-ed25519 J6M6MmuZ2joRKaihSB1LDym+WiuUeId8+9nvtI1Sd1M\n"
+ "platform Tor 0.4.6.10 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1 HSDir=2 HSIntro=4-5 "
private static final String BRIDGE1_UPDATED2 =
"@type bridge-server-descriptor 1.2\n"
+ "router cybergroot01 10.149.116.99 49348 0 0\n"
+ "master-key-ed25519 MkcNLtC9gN29vT1qgTugyn63EJMZ9epEG9MjQPeKtYI\n"
+ "or-address [fd9f:2e19:3bcf::78:f76a]:49348\n"
+ "platform Tor 0.4.5.10 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=2 FlowCtrl=1 HSDir=1-2 HSIntro=3-5 "
+ "HSRend=1-2 Link=1-5 LinkAuth=1,3 Microdesc=1-2 Padding=2 Relay=1-3\n"
+ "published 2022-03-17 08:07:11\n"
+ "published 2022-02-14 22:55:43\n"
+ "fingerprint 2D8C 27AA 9C2F EC3E C468 D7AB E9C3 EDCA 3C86 610A\n"
+ "uptime 70500\n"
+ "bandwidth 1073741824 1073741824 6128640\n"
+ "extra-info-digest 9BFCBE75FB8BFF0117737AC98FFAEF43CDD090A1 "
+ "isXSjKhx5J6+zCSsR0BY3RfAqLqBPXtfKHXS8Ib3a4A\n"
+ "hidden-service-dir\n"
+ "contact somebody\n"
+ "bridge-distribution-request any\n"
+ "ntor-onion-key IFhTimxfUuIJC7lIB3OCVPROHIp3iwT9QVPBmzQVwhU=\n"
+ "reject *:*\n"
+ "tunnelled-dir-server\n"
+ "router-digest-sha256 c6bRS258BG41lxh6bp9E8cWJJ3tjyEBumMPhd23+ums\n"
+ "router-digest 78330E30A608F1FF6619F8D5DF9448E273F1289A\n";
private static final String BRIDGE1 = "@type bridge-server-descriptor 1.2\n"
+ "router cybergroot01 10.149.116.99 49348 0 0\n"
+ "master-key-ed25519 MkcNLtC9gN29vT1qgTugyn63EJMZ9epEG9MjQPeKtYI\n"
+ "platform Tor 0.3.5.16 on Linux\n"
+ "proto Cons=1-2 Desc=1-2 DirCache=1-2 HSDir=1-2 HSIntro=3-4 HSRend=1-2 "
+ "Link=1-5 LinkAuth=1,3 Microdesc=1-2 Relay=1-2\n"
+ "published 2022-02-14 12:44:30\n"
+ "fingerprint 2D8C 27AA 9C2F EC3E C468 D7AB E9C3 EDCA 3C86 610A\n"
+ "uptime 113883\n"
+ "bandwidth 1073741824 1073741824 81352\n"
+ "extra-info-digest 29ECA238A04F0D00E941B2CC430393604430B7D4 "
+ "X0jHhL7ygWblKzjoTGMG4Eikz8Sqo2X9eIbrKzVANNw\n"
+ "uptime 28383\n"
+ "bandwidth 1073741824 1073741824 6129658\n"
+ "extra-info-digest 19C25DE4462851AF5714C5569D16BE73FB9AFAB2 "
+ "5jzavIsijHBWF5gc343AOOWD3juemG67Bcmw5h1T4Wc\n"
+ "hidden-service-dir\n"
+ "contact somebody\n"
+ "bridge-distribution-request any\n"
+ "ntor-onion-key kysCjXGfMAx6AdejV2r34d59atkXFkvLNT/9ADcd73M\n"
+ "ntor-onion-key IFhTimxfUuIJC7lIB3OCVPROHIp3iwT9QVPBmzQVwhU=\n"
+ "reject *:*\n"
+ "tunnelled-dir-server\n"
+ "router-digest-sha256 t+rUo6bm75/Qywapm5TTTnY2HGmxZqFAI1/ON2IxNP4\n"
+ "router-digest 78E7EDA527387064BB4410FC8BAED6DA0902BFE3\n";
+ "router-digest-sha256 o19jeSXaJU8xQa489vJNjydUjcFwLazPkI7Rc0qTvew\n"
+ "router-digest FF142536297451B5B968139E11472C4E1DF581DE\n";
private static final String RELAY1 = "@type server-descriptor 1.0\n"
+ "router impedance 84.201.150.89 443 0 0\n"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment