Commit 563f762c authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Fix two NullPointerExceptions.

There's a relay running an alternate Tor version that produces
descriptors without "uptime" line, and the directory authorities don't
include a "v" line for that relay, likely because its platform string
does not include the magic word "Tor".

Fixes #24012.
parent da9fe314
# Changes in version 4.2-1.6.1 - 2017-10-2?
* Medium changes
- Fix two NullPointerExceptions caused by accessing optional parts
of relay server descriptors and consensuses without checking
first whether they're available or not.
# Changes in version 4.2-1.6.0 - 2017-10-09
* Medium changes
......
......@@ -45,7 +45,8 @@ public class DetailsStatus extends Document {
private String last_restarted;
public void setLastRestarted(Long lastRestarted) {
this.last_restarted = DateTimeHelper.format(lastRestarted);
this.last_restarted = null == lastRestarted ? null
: DateTimeHelper.format(lastRestarted);
}
public Long getLastRestarted() {
......
......@@ -324,7 +324,8 @@ public class NodeStatus extends Document {
private String version;
public void setVersion(String version) {
this.version = version.substring(version.lastIndexOf(" ") + 1);
this.version = null == version ? null
: version.substring(version.lastIndexOf(" ") + 1);
}
public String getVersion() {
......
......@@ -158,15 +158,13 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
/* Already parsed more recent server descriptor from this relay. */
return;
}
long lastRestartedMillis = descriptor.getPublishedMillis()
- descriptor.getUptime() * DateTimeHelper.ONE_SECOND;
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(lastRestartedMillis);
detailsStatus.setLastRestarted(calculateLastRestartedMillis(descriptor));
detailsStatus.setBandwidthRate(bandwidthRate);
detailsStatus.setBandwidthBurst(bandwidthBurst);
detailsStatus.setObservedBandwidth(observedBandwidth);
......@@ -204,6 +202,15 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
this.documentStore.store(detailsStatus, fingerprint);
}
private Long calculateLastRestartedMillis(ServerDescriptor descriptor) {
Long lastRestartedMillis = null;
if (null != descriptor.getUptime()) {
lastRestartedMillis = descriptor.getPublishedMillis()
- descriptor.getUptime() * DateTimeHelper.ONE_SECOND;
}
return lastRestartedMillis;
}
private Map<String, Map<String, Long>> exitListEntries = new HashMap<>();
private void processExitList(ExitList exitList) {
......@@ -318,13 +325,11 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
/* Already parsed more recent server descriptor from this bridge. */
return;
}
long lastRestartedMillis = descriptor.getPublishedMillis()
- descriptor.getUptime() * DateTimeHelper.ONE_SECOND;
int advertisedBandwidth = Math.min(descriptor.getBandwidthRate(),
Math.min(descriptor.getBandwidthBurst(),
descriptor.getBandwidthObserved()));
detailsStatus.setDescPublished(descriptor.getPublishedMillis());
detailsStatus.setLastRestarted(lastRestartedMillis);
detailsStatus.setLastRestarted(calculateLastRestartedMillis(descriptor));
detailsStatus.setAdvertisedBandwidth(advertisedBandwidth);
detailsStatus.setPlatform(descriptor.getPlatform());
this.documentStore.store(detailsStatus, fingerprint);
......
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