tor-commits
Threads by month
- ----- 2025 -----
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
December 2015
- 18 participants
- 1281 discussions

[webwml/staging] make bitcoin background-color to a bit darker color
by nima@torproject.org 26 Dec '15
by nima@torproject.org 26 Dec '15
26 Dec '15
commit c4ca8729548eec5e15421b644a5cbfe4612b2507
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sat Dec 19 18:05:40 2015 +0800
make bitcoin background-color to a bit darker color
---
css/donate-style.css | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/css/donate-style.css b/css/donate-style.css
index ce8e43f..ce99bfd 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -256,7 +256,7 @@ blockquote footer{
padding-top: 10px;
padding-left: 30px;
padding-right: 30px;
- background-color: #F6F6F6;
+ background-color: #F5F5F5;
}
#bitpayDonation > .well > .form-group {
margin-right: 0;
1
0
commit 17db344b6dce8625090e3a21f2dc05d4a69106b4
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sat Dec 19 17:34:14 2015 +0800
fix logo's width
---
css/donate-style.css | 1 +
1 file changed, 1 insertion(+)
diff --git a/css/donate-style.css b/css/donate-style.css
index b5ccaf5..ce8e43f 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -129,6 +129,7 @@ html {
}
.logo{
height: 81px;
+ width: auto;
}
.donation{
text-align: center;
1
0
commit 305e0ef752fb874ad566f4eabc072ae5c9f31619
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sun Dec 20 07:27:13 2015 +0800
make get-in-touch section responsive
---
css/donate-style.css | 10 ++++++++++
donate/en/donate.wml | 4 ++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/css/donate-style.css b/css/donate-style.css
index 741d3c5..1bd0eea 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -339,6 +339,16 @@ footer.footer{
.dsmall{
padding: 0 5%;
}
+ .title {
+ min-height: auto;
+ margin: 20px 8% 0;
+ border-right: none;
+ border-bottom: 2px solid #3D855B;
+ padding: 0 0 10px;
+ }
+ .detail {
+ margin: 10px 0 20px;
+ }
}
@media (max-width: 659px) {
diff --git a/donate/en/donate.wml b/donate/en/donate.wml
index 68b3e36..4d00b5c 100644
--- a/donate/en/donate.wml
+++ b/donate/en/donate.wml
@@ -271,10 +271,10 @@
<div class="get-in-touch">
<div class="container">
<div class="row">
- <div class="col-xs-4">
+ <div class="col-sm-4">
<h3 class="title"><strong>Get in touch.</strong></h3>
</div>
- <div class="col-xs-8">
+ <div class="col-sm-8">
<p class="detail">Contact us at donations(a)torproject.org for more donation details.</p>
</div>
</div>
1
0

[webwml/staging] reduce margins of donate section on smaller devices
by nima@torproject.org 26 Dec '15
by nima@torproject.org 26 Dec '15
26 Dec '15
commit bc3c20f63d2af87060159f71dda7c51492607d6c
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sun Dec 20 08:34:44 2015 +0800
reduce margins of donate section on smaller devices
---
css/donate-style.css | 9 +++++++++
donate/en/donate.wml | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/css/donate-style.css b/css/donate-style.css
index 7eb4ff0..8e1532f 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -195,6 +195,9 @@ input[type=number] {
color: red;
display: none;
}
+#donate > .btn-group {
+ margin-bottom: 30px;
+}
.quote-section{
background-color:#67467D;
padding: 20px 0;
@@ -337,6 +340,12 @@ footer.footer{
blockquote::before {
display: none;
}
+ .combined-input {
+ margin: 0 15px 15px 15px;
+ }
+ #donate > .btn-group {
+ margin-bottom: 15px;
+ }
#bitpayDonation > .well {
margin-bottom: 30px;
}
diff --git a/donate/en/donate.wml b/donate/en/donate.wml
index ae70b18..06d8289 100644
--- a/donate/en/donate.wml
+++ b/donate/en/donate.wml
@@ -63,7 +63,7 @@
</div>
</div>
- <div class="btn-group btn-group-lg" role="group" style="margin-bottom: 30px;">
+ <div class="btn-group btn-group-lg" role="group">
<div style="padding-bottom:5px;" class="col-xs-6">
<button value="10" id="amount10" name="amnt" type="button" class="btn btn-default btn-lg btn-block amnt-btn">$10</button>
</div>
1
0
commit 3042b1fcc5f50bd28f00cb3b4e876d106a4c8ce7
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sun Dec 20 06:53:59 2015 +0800
make even-more section responsive
---
css/donate-style.css | 8 +++++++-
donate/en/donate.wml | 8 ++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/css/donate-style.css b/css/donate-style.css
index f080dac..741d3c5 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -278,7 +278,7 @@ blockquote footer{
background-color: #FAFAFA;
}
.dsmall{
- padding: 0 100px;
+ padding: 0 8%;
}
.other-ways-img{
width: 100%;
@@ -336,6 +336,9 @@ footer.footer{
blockquote::before {
display: none;
}
+ .dsmall{
+ padding: 0 5%;
+ }
}
@media (max-width: 659px) {
@@ -420,6 +423,9 @@ footer.footer{
.img-section{
width: 35%;
}
+ .dsmall{
+ padding: 0 3%;
+ }
footer.footer {
margin-bottom: 0px;
}
diff --git a/donate/en/donate.wml b/donate/en/donate.wml
index e9225dd..68b3e36 100644
--- a/donate/en/donate.wml
+++ b/donate/en/donate.wml
@@ -240,21 +240,21 @@
</div><!-- row-eqheight -->
- <div class="col-sm-12 even-more">
+ <div class="col-xs-12 even-more">
- <div class="dsmall col-sm-4">
+ <div class="dsmall col-xs-4">
<a href="../donate/donate-amazon.html.en">
<img class="img-responsive img-thumbnail other-ways-img" src="$(IMGROOT)/amazon.jpg">
</a>
</div>
- <div class="dsmall col-sm-4">
+ <div class="dsmall col-xs-4">
<a href="https://smile.amazon.com/ch/20-8096820">
<img class="img-responsive img-thumbnail other-ways-img" src="$(IMGROOT)/amazon-smile.jpg">
</a>
</div>
- <div class="dsmall col-sm-4">
+ <div class="dsmall col-xs-4">
<a id="dwolla"></a>
<a href="https://smile.amazon.com/ch/20-8096820">
<img class="img-responsive img-thumbnail other-ways-img" src="$(IMGROOT)/dwolla.jpg">
1
0

[webwml/staging] add other ways to danate section to the bottom of the main donate page
by nima@torproject.org 26 Dec '15
by nima@torproject.org 26 Dec '15
26 Dec '15
commit 90803ed6ef6d070c6127680605208f1ad3a00b8f
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sat Dec 19 15:29:50 2015 +0800
add other ways to danate section to the bottom of the main donate page
---
donate/en/donate.wml | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 168 insertions(+)
diff --git a/donate/en/donate.wml b/donate/en/donate.wml
index 44d6432..02140ba 100644
--- a/donate/en/donate.wml
+++ b/donate/en/donate.wml
@@ -113,6 +113,174 @@
</div><!-- row -->
</div><!-- container -->
</div><!-- paypal-donate -->
+
+ <div id="other-ways-section">
+ <div class="container-fluid">
+ <div id="maincol">
+ <div class="hundred toptwenty">
+
+ <div class="row-eqheight">
+
+ <!-- BEGIN BITCOIN -->
+ <div class="col-sm-6 bitcoin">
+ <a id="bitcoin"></a>
+ <h3><strong>Bitcoins</strong></h3>
+ <p>In order to comply with US 501(c)(3) non-profit regulations, our Bitcoin transaction limit is currently $10,000 USD per day.
+ If you wish to avoid transaction limits, please consider a direct Bitcoin donation to
+ <a href="https://www.torservers.net/donate.html#cryptocurrencies">Torservers.net</a>,
+ <a href="http://noisetor.net/#bitcoin">NoiseTor</a>,
+ <a href="https://www.oniontip.com/">OnionTip</a>,
+ or <a href="https://tails.boum.org/contribute/how/donate/#bitcoin">Tails</a>.
+ </p>
+ <p>If this transaction limit is not an issue for you, please complete the form below:</p>
+ <form id="bitpayDonation" class="form" action="https://bitpay.com/checkout" method="post" onsubmit="return bp.validateMobileCheckoutForm($('#bitpayDonation'));">
+ <input name="action" type="hidden" value="checkout">
+ <fieldset class="phone-form well form-horizontal" style="margin-top: 5px;">
+ <div class="form-group">
+ <label for="bitcoinEmail" class="input-group control-label" style="padding:0;">Email address</label>
+ <input id="bitcoinEmail" name="orderID" type="email" class="form-control" placeholder="Email address (optional)" maxlength="50" autocapitalize="off" autocorrect="off">
+ </div>
+
+ <div class="form-group row">
+ <label for="bitcoinAmount" class="input-group control-label">Amount</label>
+ <div class="col-sm-8" style="padding:0;">
+ <input name="price" type="number" class="form-control" id="bitcoinAmount" value="43.00" placeholder="Amount" maxlength="10" min="5">
+ </div>
+
+ <div class="col-sm-4" style="padding:0;">
+ <select name="currency" value="" class="form-control">
+ <option value="USD" selected="selected">USD</option>
+ <option value="BTC">BTC</option>
+ <option value="EUR">EUR</option>
+ <option value="GBP">GBP</option>
+ <option value="AUD">AUD</option>
+ <option value="BGN">BGN</option>
+ <option value="BRL">BRL</option>
+ <option value="CAD">CAD</option>
+ <option value="CHF">CHF</option>
+ <option value="CNY">CNY</option>
+ <option value="CZK">CZK</option>
+ <option value="DKK">DKK</option>
+ <option value="HKD">HKD</option>
+ <option value="HRK">HRK</option>
+ <option value="HUF">HUF</option>
+ <option value="IDR">IDR</option>
+ <option value="ILS">ILS</option>
+ <option value="INR">INR</option>
+ <option value="JPY">JPY</option>
+ <option value="KRW">KRW</option>
+ <option value="LTL">LTL</option>
+ <option value="LVL">LVL</option>
+ <option value="MXN">MXN</option>
+ <option value="MYR">MYR</option>
+ <option value="NOK">NOK</option>
+ <option value="NZD">NZD</option>
+ <option value="PHP">PHP</option>
+ <option value="PLN">PLN</option>
+ <option value="RON">RON</option>
+ <option value="RUB">RUB</option>
+ <option value="SEK">SEK</option>
+ <option value="SGD">SGD</option>
+ <option value="THB">THB</option>
+ <option value="TRY">TRY</option>
+ <option value="ZAR">ZAR</option>
+ </select>
+ </div>
+
+ </div>
+ <br>
+ <input type="hidden" name="data" value="iH+sCoKQo5J52hkEzWcMi8+PRt78/89lcSU9GnapWfWL6thyubtDCahTUqa2JTlj6RQrQySkZAoFvK05yifMwfx5V87JJuoaDlHUsZR9ppzkklmzHpKJ4TG5M0zNVcKfNBfyopdfTFbzpOXM2FDppqmU7njsRUF1EZPa0K7SIxpv4lNKSPn1PyjVKVxjnpFE0AZ1Qa75VwZnS+rBNNfwxPsgSz+Oa2Twe226FmJJrLtPuBteFfHAIWh6QS5JnpOn4ScMFph0zjixutmunMAjKw==">
+ <div style="margin: auto; width: 100%; text-align: center">
+ <input name="submit" src="https://www.torproject.org/images/bitpay-donate-md.png" type="image" style="width: auto" alt="BitPay" border="0">
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ <!-- END BITCOIN -->
+
+
+
+
+
+ <div class="col-sm-6 check-eutransfer">
+
+ <!-- BEGIN CHECK -->
+ <a id="cash"></a>
+ <h4><strong>Check or Money Order</strong></h4>
+ <p>You can send checks or money orders to:</p>
+ <p>The Tor Project, Inc<br>
+ 7 Temple Street, Suite A<br>
+ Cambridge, MA 02139-2403 USA
+ </p>
+ <!-- END CHECK -->
+
+ <!-- BEGIN TRANSFER -->
+ <a id="eubanks"></a>
+ <h4 style="margin-top:20px;"><strong>European Bank Transfer</strong></h4>
+ <p>For European bank transfers, we have an arrangement with
+ the Renewable Freedom Foundation to provide
+ <a href="http://www.solicitorsjournal.com/news/private-client/charities/gifts-foreig…">tax-deductible</a>
+ donations for Europeans. (They don't actually pass the money
+ through to us, but rather we trust them to spend it in Tor's
+ interest.) They will issue a donation receipt <a
+ href="https://renewablefreedom.org/contact/">upon request</a>. The
+ account information is as follows:
+ </p>
+ <p>Renewable Freedom Foundation<br>
+ IBAN: DE17721500000053693701<br>
+ BIC: BYLADEM1ING<br>
+ Sparkasse Ingolstadt<br>
+ Rathausplatz 6<br>
+ 85049 Ingolstadt<br>
+ </p>
+ <!-- END TRANSFER -->
+
+ </div><!-- check-eutransfer -->
+
+ </div><!-- row-eqheight -->
+
+
+ <div class="col-sm-12 even-more">
+
+ <div class="dsmall col-sm-4">
+ <a href="../donate/donate-amazon.html.en">
+ <img class="img-responsive img-thumbnail other-ways-img" src="../images/amazon.jpg">
+ </a>
+ </div>
+
+ <div class="dsmall col-sm-4">
+ <a href="https://smile.amazon.com/ch/20-8096820">
+ <img class="img-responsive img-thumbnail other-ways-img" src="../images/amazon-smile.jpg">
+ </a>
+ </div>
+
+ <div class="dsmall col-sm-4">
+ <a id="dwolla"></a>
+ <a href="https://smile.amazon.com/ch/20-8096820">
+ <img class="img-responsive img-thumbnail other-ways-img" src="../images/dwolla.jpg">
+ </a>
+ </div>
+ </div>
+
+ </div> <!-- hundred toptwenty -->
+ </div> <!-- maincol row -->
+ </div> <!-- fluid-container -->
+
+ </div><!-- other-ways-section -->
+
+ <div class="get-in-touch">
+ <div class="container">
+ <div class="row">
+ <div class="col-xs-4">
+ <h3 class="title"><strong>Get in touch.</strong></h3>
+ </div>
+ <div class="col-xs-8">
+ <p class="detail">Contact us at donations(a)torproject.org for more donation details.</p>
+ </div>
+ </div>
+ </div>
+ </div>
+
</div><!-- donation -->
1
0
commit 42c993148b2fa9431086b3d141546056dd67e9a4
Author: MehrabKamrani <mk.zizou(a)gmail.com>
Date: Sun Dec 20 08:19:52 2015 +0800
make perks section responsive
---
css/donate-style.css | 4 ++++
donate/en/donate.wml | 6 +++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/css/donate-style.css b/css/donate-style.css
index 1bd0eea..7eb4ff0 100644
--- a/css/donate-style.css
+++ b/css/donate-style.css
@@ -147,6 +147,7 @@ html {
}
.no-padding{
padding: 0;
+ margin-bottom: 20px;
}
.half-opacity{
opacity: 0.5;
@@ -336,6 +337,9 @@ footer.footer{
blockquote::before {
display: none;
}
+ #bitpayDonation > .well {
+ margin-bottom: 30px;
+ }
.dsmall{
padding: 0 5%;
}
diff --git a/donate/en/donate.wml b/donate/en/donate.wml
index 4d00b5c..ae70b18 100644
--- a/donate/en/donate.wml
+++ b/donate/en/donate.wml
@@ -41,9 +41,9 @@
</noscript>
<h4 style="text-align:left; padding-top:10px;"><b>Perks</b></h4>
- <div class="col-sm-4 no-padding"><img id="stickers" class="img-responsive half-opacity" src="$(IMGROOT)/swag-stickers-lg.png" alt="stickers"></div>
- <div class="col-sm-4 no-padding"><img id="tshirt" class="img-responsive half-opacity" src="$(IMGROOT)/swag-tees-lg.png" alt="tshirt"></div>
- <div class="col-sm-4 no-padding"><img id="hoody" class="img-responsive half-opacity" src="$(IMGROOT)/swag-hoody-lg.png" alt="hoody"></div>
+ <div class="col-xs-4 no-padding"><img id="stickers" class="img-responsive half-opacity" src="$(IMGROOT)/swag-stickers-lg.png" alt="stickers"></div>
+ <div class="col-xs-4 no-padding"><img id="tshirt" class="img-responsive half-opacity" src="$(IMGROOT)/swag-tees-lg.png" alt="tshirt"></div>
+ <div class="col-xs-4 no-padding"><img id="hoody" class="img-responsive half-opacity" src="$(IMGROOT)/swag-hoody-lg.png" alt="hoody"></div>
</div>
<div class="donate-section col-sm-5">
1
0
commit 5b73e0eb9afe09b0f9e73773b4310644de987837
Author: iwakeh <iwakeh(a)users.ourproject.org>
Date: Tue Dec 22 22:00:00 2015 +0000
task-17824 addendum.
---
.../descriptor/impl/DirSourceEntryImpl.java | 35 +++--
.../impl/DirectoryKeyCertificateImpl.java | 53 ++++----
.../descriptor/impl/DirectorySignatureImpl.java | 41 +++---
.../descriptor/impl/DownloadCoordinatorImpl.java | 75 ++++++-----
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 62 ++++-----
.../descriptor/impl/MicrodescriptorImpl.java | 72 +++++-----
.../descriptor/impl/NetworkStatusEntryImpl.java | 25 ++--
.../descriptor/impl/NetworkStatusImpl.java | 27 ++--
.../torproject/descriptor/impl/ParseHelper.java | 12 ++
.../descriptor/impl/RelayDirectoryImpl.java | 64 +++++----
.../descriptor/impl/RelayNetworkStatusImpl.java | 61 +++++----
.../impl/RelayNetworkStatusVoteImpl.java | 14 +-
.../descriptor/impl/ServerDescriptorImpl.java | 137 ++++++++++----------
13 files changed, 377 insertions(+), 301 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
index 3a59d5b..3ea0179 100644
--- a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
@@ -80,25 +80,34 @@ public class DirSourceEntryImpl implements DirSourceEntry {
boolean skipCrypto = false;
while (s.hasNext()) {
String line = s.next();
- if (line.startsWith("dir-source")) {
+ String[] parts = line.split(" ");
+ switch (parts[0]) {
+ case "dir-source":
this.parseDirSourceLine(line);
- } else if (line.startsWith("contact")) {
+ break;
+ case "contact":
this.parseContactLine(line);
- } else if (line.startsWith("vote-digest")) {
+ break;
+ case "vote-digest":
this.parseVoteDigestLine(line);
- } else if (line.startsWith("-----BEGIN")) {
+ break;
+ case "-----BEGIN":
skipCrypto = true;
- } else if (line.startsWith("-----END")) {
+ break;
+ case "-----END":
skipCrypto = false;
- } else if (!skipCrypto) {
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in dir-source entry.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (!skipCrypto) {
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in dir-source entry.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 2b7d3ea..1039bbd 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -98,33 +98,34 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
this.parseDirKeyCertificationLine(line, parts);
nextCrypto = "dir-key-certification";
break;
+ case "-----BEGIN":
+ crypto = new StringBuilder();
+ crypto.append(line).append("\n");
+ break;
+ case "-----END":
+ crypto.append(line).append("\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ switch (nextCrypto) {
+ case "dir-identity-key":
+ this.dirIdentityKey = cryptoString;
+ break;
+ case "dir-signing-key":
+ this.dirSigningKey = cryptoString;
+ break;
+ case "dir-key-crosscert":
+ this.dirKeyCrosscert = cryptoString;
+ break;
+ case "dir-key-certification":
+ this.dirKeyCertification = cryptoString;
+ break;
+ default:
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in directory key certificate.");
+ }
+ nextCrypto = "";
default:
- if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line).append("\n");
- String cryptoString = crypto.toString();
- crypto = null;
- switch (nextCrypto) {
- case "dir-identity-key":
- this.dirIdentityKey = cryptoString;
- break;
- case "dir-signing-key":
- this.dirSigningKey = cryptoString;
- break;
- case "dir-key-crosscert":
- this.dirKeyCrosscert = cryptoString;
- break;
- case "dir-key-certification":
- this.dirKeyCertification = cryptoString;
- break;
- default:
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in directory key certificate.");
- }
- nextCrypto = "";
- } else if (crypto != null) {
+ if (crypto != null) {
crypto.append(line).append("\n");
} else {
if (this.failUnrecognizedDescriptorLines) {
diff --git a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
index 8cf6589..18de918 100644
--- a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
@@ -40,13 +40,19 @@ public class DirectorySignatureImpl implements DirectorySignature {
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
- if (line.startsWith("directory-signature ")) {
- String[] parts = line.split(" ", -1);
+ String[] parts = line.split(" ", -1);
+ String keyword = parts[0];
+ switch (keyword) {
+ case "directory-signature":
int algorithmOffset = 0;
- if (parts.length == 4) {
+ switch (parts.length) {
+ case 4:
this.algorithm = parts[1];
algorithmOffset = 1;
- } else if (parts.length != 3) {
+ break;
+ case 3:
+ break;
+ default:
throw new DescriptorParseException("Illegal line '" + line
+ "'.");
}
@@ -54,25 +60,30 @@ public class DirectorySignatureImpl implements DirectorySignature {
parts[1 + algorithmOffset]);
this.signingKeyDigest = ParseHelper.parseTwentyByteHexString(
line, parts[2 + algorithmOffset]);
- } else if (line.startsWith("-----BEGIN")) {
+ break;
+ case "-----BEGIN":
crypto = new StringBuilder();
crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
+ break;
+ case "-----END":
crypto.append(line).append("\n");
String cryptoString = crypto.toString();
crypto = null;
this.signature = cryptoString;
- } else if (crypto != null) {
- crypto.append(line).append("\n");
- } else {
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in dir-source entry.");
+ break;
+ default:
+ if (crypto != null) {
+ crypto.append(line).append("\n");
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in dir-source entry.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java b/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
index e95f9da..6a73090 100644
--- a/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
+++ b/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
@@ -203,48 +203,51 @@ public class DownloadCoordinatorImpl implements DownloadCoordinator {
if (response.getException() != null) {
this.runningDirectories.remove(nickname);
}
- if (response.getDescriptorType().equals("consensus")) {
- this.requestingConsensuses.remove(nickname);
- if (response.getResponseCode() == 200 &&
- response.getDescriptors() != null) {
- if (this.includeCurrentReferencedVotes) {
- /* TODO Only add votes if the consensus is not older than one
- * hour. Or does that make no sense? */
- for (Descriptor parsedDescriptor : response.getDescriptors()) {
- if (!(parsedDescriptor instanceof
- RelayNetworkStatusConsensus)) {
- continue;
- }
- RelayNetworkStatusConsensus parsedConsensus =
- (RelayNetworkStatusConsensus) parsedDescriptor;
- for (DirSourceEntry dirSource :
- parsedConsensus.getDirSourceEntries().values()) {
- String identity = dirSource.getIdentity();
- if (!this.missingVotes.contains(identity)) {
- boolean alreadyRequested = false;
- for (Set<String> requestedBefore :
- this.requestedVotes.values()) {
- if (requestedBefore.contains(identity)) {
- alreadyRequested = true;
- break;
+ switch (response.getDescriptorType()) {
+ case "consensus":
+ this.requestingConsensuses.remove(nickname);
+ if (response.getResponseCode() == 200 &&
+ response.getDescriptors() != null) {
+ if (this.includeCurrentReferencedVotes) {
+ /* TODO Only add votes if the consensus is not older than one
+ * hour. Or does that make no sense? */
+ for (Descriptor parsedDescriptor :
+ response.getDescriptors()) {
+ if (!(parsedDescriptor instanceof
+ RelayNetworkStatusConsensus)) {
+ continue;
+ }
+ RelayNetworkStatusConsensus parsedConsensus =
+ (RelayNetworkStatusConsensus) parsedDescriptor;
+ for (DirSourceEntry dirSource :
+ parsedConsensus.getDirSourceEntries().values()) {
+ String identity = dirSource.getIdentity();
+ if (!this.missingVotes.contains(identity)) {
+ boolean alreadyRequested = false;
+ for (Set<String> requestedBefore :
+ this.requestedVotes.values()) {
+ if (requestedBefore.contains(identity)) {
+ alreadyRequested = true;
+ break;
+ }
+ }
+ if (!alreadyRequested) {
+ this.missingVotes.add(identity);
}
- }
- if (!alreadyRequested) {
- this.missingVotes.add(identity);
}
}
}
+ /* TODO Later, add referenced server descriptors. */
}
- /* TODO Later, add referenced server descriptors. */
+ } else {
+ this.missingConsensus = true;
+ }
+ break;
+ case "vote":
+ String requestedVote = requestingVotes.remove(nickname);
+ if (response.getResponseCode() != 200) {
+ this.missingVotes.add(requestedVote);
}
- } else {
- this.missingConsensus = true;
- }
- } else if (response.getDescriptorType().equals("vote")) {
- String requestedVote = requestingVotes.remove(nickname);
- if (response.getResponseCode() != 200) {
- this.missingVotes.add(requestedVote);
- }
}
if (response.getRequestEnd() != 0L) {
this.descriptorQueue.add(response);
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 4fcf4c9..3255bd9 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -238,40 +238,42 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
case "router-digest-sha256":
this.parseRouterDigestSha256Line(line, lineNoOpt, partsNoOpt);
break;
- default:
- if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<>();
- cryptoLines.add(line);
- } else if (line.startsWith("-----END")) {
- cryptoLines.add(line);
- StringBuilder sb = new StringBuilder();
- for (String cryptoLine : cryptoLines) {
- sb.append("\n").append(cryptoLine);
- }
- String cryptoString = sb.toString().substring(1);
- switch (nextCrypto) {
- case "router-signature":
- this.routerSignature = cryptoString;
- break;
- case "identity-ed25519":
- this.identityEd25519 = cryptoString;
- this.parseIdentityEd25519CryptoBlock(cryptoString);
- break;
- default:
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block '" + cryptoString + "' in extra-info "
- + "descriptor.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
- }
- this.unrecognizedLines.addAll(cryptoLines);
+ case "-----BEGIN":
+ cryptoLines = new ArrayList<>();
+ cryptoLines.add(line);
+ break;
+ case "-----END":
+ cryptoLines.add(line);
+ StringBuilder sb = new StringBuilder();
+ for (String cryptoLine : cryptoLines) {
+ sb.append("\n").append(cryptoLine);
+ }
+ String cryptoString = sb.toString().substring(1);
+ switch (nextCrypto) {
+ case "router-signature":
+ this.routerSignature = cryptoString;
+ break;
+ case "identity-ed25519":
+ this.identityEd25519 = cryptoString;
+ this.parseIdentityEd25519CryptoBlock(cryptoString);
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block '" + cryptoString + "' in extra-info "
+ + "descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
}
+ this.unrecognizedLines.addAll(cryptoLines);
}
cryptoLines = null;
nextCrypto = "";
- } else if (cryptoLines != null) {
+ }
+ break;
+ default:
+ if (cryptoLines != null) {
cryptoLines.add(line);
} else {
ParseHelper.parseKeyword(line, partsNoOpt[0]);
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index d303fa0..cf8f3e6 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -89,22 +89,24 @@ public class MicrodescriptorImpl extends DescriptorImpl
case "id":
this.parseIdLine(line, parts);
break;
+ case "-----BEGIN":
+ crypto = new StringBuilder();
+ crypto.append(line).append("\n");
+ break;
+ case "-----END":
+ crypto.append(line).append("\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("onion-key")) {
+ this.onionKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in microdescriptor.");
+ }
+ nextCrypto = "";
+ break;
default:
- if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line).append("\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("onion-key")) {
- this.onionKey = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in microdescriptor.");
- }
- nextCrypto = "";
- } else if (crypto != null) {
+ if (crypto != null) {
crypto.append(line).append("\n");
} else {
ParseHelper.parseKeyword(line, parts[0]);
@@ -191,15 +193,20 @@ public class MicrodescriptorImpl extends DescriptorImpl
boolean isValid = true;
if (parts.length != 3) {
isValid = false;
- } else if (!parts[1].equals("accept") && !parts[1].equals("reject")) {
- isValid = false;
- } else {
- String[] ports = parts[2].split(",", -1);
- for (int i = 0; i < ports.length; i++) {
- if (ports[i].length() < 1) {
- isValid = false;
- break;
+ } else {
+ switch (parts[1]) {
+ case "accept":
+ case "reject":
+ String[] ports = parts[2].split(",", -1);
+ for (int i = 0; i < ports.length; i++) {
+ if (ports[i].length() < 1) {
+ isValid = false;
+ break;
+ }
}
+ break;
+ default:
+ isValid = false;
}
}
if (!isValid) {
@@ -211,14 +218,19 @@ public class MicrodescriptorImpl extends DescriptorImpl
throws DescriptorParseException {
if (parts.length != 3) {
throw new DescriptorParseException("Illegal line '" + line + "'.");
- } else if ("ed25519".equals(parts[1])) {
- ParseHelper.parseThirtyTwoByteBase64String(line, parts[2]);
- this.ed25519Identity = parts[2];
- } else if ("rsa1024".equals(parts[1])) {
- ParseHelper.parseTwentyByteBase64String(line, parts[2]);
- this.rsa1024Identity = parts[2];
} else {
- throw new DescriptorParseException("Illegal line '" + line + "'.");
+ switch (parts[1]) {
+ case "ed25519":
+ ParseHelper.parseThirtyTwoByteBase64String(line, parts[2]);
+ this.ed25519Identity = parts[2];
+ break;
+ case "rsa1024":
+ ParseHelper.parseTwentyByteBase64String(line, parts[2]);
+ this.rsa1024Identity = parts[2];
+ break;
+ default:
+ throw new DescriptorParseException("Illegal line '" + line + "'.");
+ }
}
}
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index c5f0704..a17973e 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -213,18 +213,23 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
boolean isValid = true;
if (parts.length != 3) {
isValid = false;
- } else if (!parts[1].equals("accept") && !parts[1].equals("reject")) {
- isValid = false;
} else {
- this.defaultPolicy = parts[1];
- this.portList = parts[2];
- String[] ports = parts[2].split(",", -1);
- for (int i = 0; i < ports.length; i++) {
- if (ports[i].length() < 1) {
- isValid = false;
- break;
+ switch (parts[1]) {
+ case "accept":
+ case "reject":
+ this.defaultPolicy = parts[1];
+ this.portList = parts[2];
+ String[] ports = parts[2].split(",", -1);
+ for (int i = 0; i < ports.length; i++) {
+ if (ports[i].length() < 1) {
+ isValid = false;
+ break;
+ }
+ }
+ break;
+ default:
+ isValid = false;
}
- }
}
if (!isValid) {
throw new DescriptorParseException("Illegal line '" + line + "'.");
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
index a9c2483..9a950cf 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
@@ -177,19 +177,22 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
protected String[] parseClientOrServerVersions(String line,
String[] parts) throws DescriptorParseException {
String[] result = null;
- if (parts.length > 2) {
- throw new DescriptorParseException("Illegal versions line '" + line
- + "'.");
- } else if (parts.length == 2) {
- result = parts[1].split(",", -1);
- for (String version : result) {
- if (version.length() < 1) {
- throw new DescriptorParseException("Illegal versions line '"
- + line + "'.");
+ switch (parts.length) {
+ case 1:
+ result = new String[0];
+ break;
+ case 2:
+ result = parts[1].split(",", -1);
+ for (String version : result) {
+ if (version.length() < 1) {
+ throw new DescriptorParseException("Illegal versions line '"
+ + line + "'.");
+ }
}
- }
- } else if (parts.length == 1) {
- result = new String[0];
+ break;
+ default:
+ throw new DescriptorParseException("Illegal versions line '" + line
+ + "'.");
}
return result;
}
diff --git a/src/org/torproject/descriptor/impl/ParseHelper.java b/src/org/torproject/descriptor/impl/ParseHelper.java
index 43a44d1..6ae549b 100644
--- a/src/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/org/torproject/descriptor/impl/ParseHelper.java
@@ -263,6 +263,18 @@ public class ParseHelper {
return nickname;
}
+ public static boolean parseBoolean(String b, String line)
+ throws DescriptorParseException {
+ switch (b) {
+ case "1":
+ return true;
+ case "0":
+ return false;
+ default:
+ throw new DescriptorParseException("Illegal line '" + line + "'.");
+ }
+ }
+
private static Pattern twentyByteBase64Pattern =
Pattern.compile("^[0-9a-zA-Z+/]{27}$");
public static String parseTwentyByteBase64String(String line,
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index ac17f54..873326d 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -227,23 +227,25 @@ public class RelayDirectoryImpl extends DescriptorImpl
case "router-status":
routerStatusLine = line;
break;
+ case "-----BEGIN":
+ crypto = new StringBuilder();
+ crypto.append(line).append("\n");
+ break;
+ case "-----END":
+ crypto.append(line).append("\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("dir-signing-key") &&
+ this.dirSigningKey == null) {
+ this.dirSigningKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in v1 directory.");
+ }
+ nextCrypto = "";
+ break;
default:
- if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line).append("\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("dir-signing-key") &&
- this.dirSigningKey == null) {
- this.dirSigningKey = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in v1 directory.");
- }
- nextCrypto = "";
- } else if (crypto != null) {
+ if (crypto != null) {
crypto.append(line).append("\n");
} else {
if (this.failUnrecognizedDescriptorLines) {
@@ -313,13 +315,16 @@ public class RelayDirectoryImpl extends DescriptorImpl
line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
- if (keyword.equals("directory-signature")) {
+ switch (keyword) {
+ case "directory-signature":
this.parseDirectorySignatureLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "directory-signature";
- } else if (line.startsWith("-----BEGIN")) {
+ break;
+ case "-----BEGIN":
crypto = new StringBuilder();
crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
+ break;
+ case "-----END":
crypto.append(line).append("\n");
String cryptoString = crypto.toString();
crypto = null;
@@ -330,16 +335,19 @@ public class RelayDirectoryImpl extends DescriptorImpl
+ "block in v2 network status.");
}
nextCrypto = "";
- } else if (crypto != null) {
- crypto.append(line).append("\n");
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in v2 network status.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (crypto != null) {
+ crypto.append(line).append("\n");
+ } else if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in v2 network status.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 7788040..9ac3284 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -126,22 +126,23 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
case "dir-options":
this.parseDirOptionsLine(line, parts);
break;
+ case "-----BEGIN":
+ crypto = new StringBuilder();
+ crypto.append(line).append("\n");
+ break;
+ case "-----END":
+ crypto.append(line).append("\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("dir-signing-key")) {
+ this.dirSigningKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in v2 network status.");
+ }
+ nextCrypto = "";
default:
- if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line).append("\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("dir-signing-key")) {
- this.dirSigningKey = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in v2 network status.");
- }
- nextCrypto = "";
- } else if (crypto != null) {
+ if (crypto != null) {
crypto.append(line).append("\n");
} else if (this.failUnrecognizedDescriptorLines) {
throw new DescriptorParseException("Unrecognized line '" + line
@@ -172,13 +173,16 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("directory-signature")) {
+ switch (keyword) {
+ case "directory-signature":
this.parseDirectorySignatureLine(line, parts);
nextCrypto = "directory-signature";
- } else if (line.startsWith("-----BEGIN")) {
+ break;
+ case "-----BEGIN":
crypto = new StringBuilder();
crypto.append(line).append("\n");
- } else if (line.startsWith("-----END")) {
+ break;
+ case "-----END":
crypto.append(line).append("\n");
String cryptoString = crypto.toString();
crypto = null;
@@ -189,16 +193,19 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
+ "block in v2 network status.");
}
nextCrypto = "";
- } else if (crypto != null) {
- crypto.append(line).append("\n");
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in v2 network status.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (crypto != null) {
+ crypto.append(line).append("\n");
+ } else if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in v2 network status.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index d74ef65..c16a9f9 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -148,12 +148,14 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
case "dir-key-crosscert":
case "dir-key-certification":
break;
+ case "-----BEGIN":
+ skipCrypto = true;
+ break;
+ case "-----END":
+ skipCrypto = false;
+ break;
default:
- if (line.startsWith("-----BEGIN")) {
- skipCrypto = true;
- } else if (line.startsWith("-----END")) {
- skipCrypto = false;
- } else if (!skipCrypto) {
+ if (!skipCrypto) {
if (this.failUnrecognizedDescriptorLines) {
throw new DescriptorParseException("Unrecognized line '"
+ line + "' in vote.");
@@ -313,6 +315,8 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
case "ignoring-advertised-bws":
this.ignoringAdvertisedBws = Integer.parseInt(e.getValue());
break;
+ default:
+ // empty
}
}
} catch (NumberFormatException ex) {
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 84ad2a1..8b6e983 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -171,51 +171,53 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
this.parseNtorOnionKeyCrosscert(line, lineNoOpt, partsNoOpt);
nextCrypto = "ntor-onion-key-crosscert";
break;
- default:
- if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<>();
- cryptoLines.add(line);
- } else if (line.startsWith("-----END")) {
- cryptoLines.add(line);
- StringBuilder sb = new StringBuilder();
- for (String cryptoLine : cryptoLines) {
- sb.append("\n").append(cryptoLine);
- }
- String cryptoString = sb.toString().substring(1);
- switch (nextCrypto) {
- case "onion-key":
- this.onionKey = cryptoString;
- break;
- case "signing-key":
- this.signingKey = cryptoString;
- break;
- case "router-signature":
- this.routerSignature = cryptoString;
- break;
- case "identity-ed25519":
- this.identityEd25519 = cryptoString;
- this.parseIdentityEd25519CryptoBlock(cryptoString);
- break;
- case "onion-key-crosscert":
- this.onionKeyCrosscert = cryptoString;
- break;
- case "ntor-onion-key-crosscert":
- this.ntorOnionKeyCrosscert = cryptoString;
- break;
- default:
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block '" + cryptoString + "' in server descriptor.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
- }
- this.unrecognizedLines.addAll(cryptoLines);
+ case "-----BEGIN":
+ cryptoLines = new ArrayList<>();
+ cryptoLines.add(line);
+ break;
+ case "-----END":
+ cryptoLines.add(line);
+ StringBuilder sb = new StringBuilder();
+ for (String cryptoLine : cryptoLines) {
+ sb.append("\n").append(cryptoLine);
+ }
+ String cryptoString = sb.toString().substring(1);
+ switch (nextCrypto) {
+ case "onion-key":
+ this.onionKey = cryptoString;
+ break;
+ case "signing-key":
+ this.signingKey = cryptoString;
+ break;
+ case "router-signature":
+ this.routerSignature = cryptoString;
+ break;
+ case "identity-ed25519":
+ this.identityEd25519 = cryptoString;
+ this.parseIdentityEd25519CryptoBlock(cryptoString);
+ break;
+ case "onion-key-crosscert":
+ this.onionKeyCrosscert = cryptoString;
+ break;
+ case "ntor-onion-key-crosscert":
+ this.ntorOnionKeyCrosscert = cryptoString;
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block '" + cryptoString + "' in server descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
}
+ this.unrecognizedLines.addAll(cryptoLines);
}
- cryptoLines = null;
- nextCrypto = "";
- } else if (cryptoLines != null) {
+ }
+ cryptoLines = null;
+ nextCrypto = "";
+ break;
+ default:
+ if (cryptoLines != null) {
cryptoLines.add(line);
} else {
ParseHelper.parseKeyword(line, partsNoOpt[0]);
@@ -317,13 +319,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
if (partsNoOpt.length != 2) {
throw new DescriptorParseException("Illegal line '" + line + "'.");
}
- if (partsNoOpt[1].equals("1")) {
- this.hibernating = true;
- } else if (partsNoOpt[1].equals("0")) {
- this.hibernating = false;
- } else {
- throw new DescriptorParseException("Illegal line '" + line + "'.");
- }
+ this.hibernating = ParseHelper.parseBoolean(partsNoOpt[1], line);
}
private void parseUptimeLine(String line, String lineNoOpt,
@@ -438,13 +434,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
if (partsNoOpt.length != 2) {
throw new DescriptorParseException("Illegal line '" + line + "'.");
}
- if (partsNoOpt[1].equals("1")) {
- this.usesEnhancedDnsLogic = true;
- } else if (partsNoOpt[1].equals("0")) {
- this.usesEnhancedDnsLogic = false;
- } else {
- throw new DescriptorParseException("Illegal line '" + line + "'.");
- }
+ this.usesEnhancedDnsLogic = ParseHelper.parseBoolean(partsNoOpt[1], line);
}
private void parseCachesExtraInfoLine(String line, String lineNoOpt,
@@ -490,10 +480,15 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
String[] partsNoOpt) throws DescriptorParseException {
int linkIndex = -1, circuitIndex = -1;
for (int i = 1; i < partsNoOpt.length; i++) {
- if (partsNoOpt[i].equals("Link")) {
+ switch (partsNoOpt[i]) {
+ case "Link":
linkIndex = i;
- } else if (partsNoOpt[i].equals("Circuit")) {
+ break;
+ case "Circuit":
circuitIndex = i;
+ break;
+ default:
+ // empty
}
}
if (linkIndex < 0 || circuitIndex < 0 || circuitIndex < linkIndex) {
@@ -555,19 +550,23 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
boolean isValid = true;
if (partsNoOpt.length != 3) {
isValid = false;
- } else if (!partsNoOpt[1].equals("accept") &&
- !partsNoOpt[1].equals("reject")) {
- isValid = false;
} else {
- this.ipv6DefaultPolicy = partsNoOpt[1];
- this.ipv6PortList = partsNoOpt[2];
- String[] ports = partsNoOpt[2].split(",", -1);
- for (int i = 0; i < ports.length; i++) {
- if (ports[i].length() < 1) {
- isValid = false;
+ switch (partsNoOpt[1]) {
+ case "accept":
+ case "reject":
+ this.ipv6DefaultPolicy = partsNoOpt[1];
+ this.ipv6PortList = partsNoOpt[2];
+ String[] ports = partsNoOpt[2].split(",", -1);
+ for (int i = 0; i < ports.length; i++) {
+ if (ports[i].length() < 1) {
+ isValid = false;
+ break;
+ }
+ }
break;
+ default:
+ isValid = false;
}
- }
}
if (!isValid) {
throw new DescriptorParseException("Illegal line '" + line + "'.");
1
0

[metrics-lib/master] Use Java 7's diamond operator wherever possible.
by karsten@torproject.org 25 Dec '15
by karsten@torproject.org 25 Dec '15
25 Dec '15
commit ce18717907b502dfbc87f4b8567652ffe10fefe5
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Dec 22 11:42:15 2015 +0100
Use Java 7's diamond operator wherever possible.
In many cases, the compiler will now infer which parameter types a new
object shall have, which allows us to make our code less verbose.
Suggested by iwakeh, implements #17823.
---
.../descriptor/impl/BandwidthHistoryImpl.java | 2 +-
.../descriptor/impl/BlockingIteratorImpl.java | 2 +-
.../impl/BridgeExtraInfoDescriptorImpl.java | 3 +-
.../descriptor/impl/BridgeNetworkStatusImpl.java | 2 +-
.../descriptor/impl/BridgePoolAssignmentImpl.java | 10 +++---
.../impl/BridgeServerDescriptorImpl.java | 3 +-
.../descriptor/impl/DescriptorCollectorImpl.java | 13 ++++----
.../descriptor/impl/DescriptorDownloaderImpl.java | 6 ++--
.../descriptor/impl/DescriptorFileImpl.java | 2 +-
.../torproject/descriptor/impl/DescriptorImpl.java | 13 ++++----
.../descriptor/impl/DescriptorReaderImpl.java | 21 ++++++-------
.../descriptor/impl/DirSourceEntryImpl.java | 6 ++--
.../impl/DirectoryKeyCertificateImpl.java | 9 +++---
.../descriptor/impl/DirectorySignatureImpl.java | 2 +-
.../descriptor/impl/DownloadCoordinatorImpl.java | 16 +++++-----
.../descriptor/impl/ExitListEntryImpl.java | 2 +-
.../torproject/descriptor/impl/ExitListImpl.java | 6 ++--
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 32 ++++++++++----------
.../descriptor/impl/MicrodescriptorImpl.java | 13 ++++----
.../descriptor/impl/NetworkStatusEntryImpl.java | 20 ++++++------
.../descriptor/impl/NetworkStatusImpl.java | 21 ++++++-------
.../torproject/descriptor/impl/ParseHelper.java | 13 ++++----
.../descriptor/impl/RelayDirectoryImpl.java | 31 +++++++++----------
.../impl/RelayExtraInfoDescriptorImpl.java | 3 +-
.../impl/RelayNetworkStatusConsensusImpl.java | 18 +++++------
.../descriptor/impl/RelayNetworkStatusImpl.java | 13 ++++----
.../impl/RelayNetworkStatusVoteImpl.java | 15 +++++----
.../descriptor/impl/RelayServerDescriptorImpl.java | 3 +-
.../descriptor/impl/ServerDescriptorImpl.java | 18 +++++------
.../descriptor/impl/TorperfResultImpl.java | 12 ++++----
.../descriptor/impl/BridgeNetworkStatusTest.java | 2 +-
.../descriptor/impl/ConsensusBuilder.java | 6 ++--
.../impl/ExtraInfoDescriptorImplTest.java | 2 +-
.../impl/RelayNetworkStatusConsensusImplTest.java | 10 +++---
.../impl/RelayNetworkStatusVoteImplTest.java | 6 ++--
.../descriptor/impl/ServerDescriptorImplTest.java | 6 ++--
36 files changed, 170 insertions(+), 192 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
index 136a6d7..0023b88 100644
--- a/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
+++ b/src/org/torproject/descriptor/impl/BandwidthHistoryImpl.java
@@ -82,7 +82,7 @@ public class BandwidthHistoryImpl implements BandwidthHistory {
private long[] bandwidthValues;
public SortedMap<Long, Long> getBandwidthValues() {
- SortedMap<Long, Long> result = new TreeMap<Long, Long>();
+ SortedMap<Long, Long> result = new TreeMap<>();
if (this.bandwidthValues != null) {
long endMillis = this.historyEndMillis;
for (int i = this.bandwidthValues.length - 1; i >= 0; i--) {
diff --git a/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java b/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
index aee669f..b4ea525 100644
--- a/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
+++ b/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
@@ -13,7 +13,7 @@ import java.util.Queue;
public class BlockingIteratorImpl<T> implements Iterator<T> {
/* Queue containing produced elemnts waiting for consumers. */
- private Queue<T> queue = new LinkedList<T>();
+ private Queue<T> queue = new LinkedList<>();
/* Maximum number of elements in queue. */
private int maxQueueSize = 100;
diff --git a/src/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java
index daacfba..15d40d8 100644
--- a/src/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java
@@ -15,8 +15,7 @@ public class BridgeExtraInfoDescriptorImpl
protected static List<ExtraInfoDescriptor> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<ExtraInfoDescriptor> parsedDescriptors =
- new ArrayList<ExtraInfoDescriptor>();
+ List<ExtraInfoDescriptor> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"extra-info ");
diff --git a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
index bddf5ab..d5e6d8f 100644
--- a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
@@ -82,7 +82,7 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
+ "' in bridge network status.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
diff --git a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
index 01dc7b0..06270bc 100644
--- a/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
@@ -21,8 +21,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
protected static List<BridgePoolAssignment> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<BridgePoolAssignment> parsedDescriptors =
- new ArrayList<BridgePoolAssignment>();
+ List<BridgePoolAssignment> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"bridge-pool-assignment ");
@@ -40,7 +39,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
throws DescriptorParseException {
super(descriptorBytes, failUnrecognizedDescriptorLines, false);
this.parseDescriptorBytes();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList(
new String[] { "bridge-pool-assignment" }));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
this.checkFirstKeyword("bridge-pool-assignment");
@@ -90,10 +89,9 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
return this.publishedMillis;
}
- private SortedMap<String, String> entries =
- new TreeMap<String, String>();
+ private SortedMap<String, String> entries = new TreeMap<>();
public SortedMap<String, String> getEntries() {
- return new TreeMap<String, String>(this.entries);
+ return new TreeMap<>(this.entries);
}
}
diff --git a/src/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java
index 0dec458..eb2b933 100644
--- a/src/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java
@@ -15,8 +15,7 @@ public class BridgeServerDescriptorImpl extends ServerDescriptorImpl
protected static List<ServerDescriptor> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<ServerDescriptor> parsedDescriptors =
- new ArrayList<ServerDescriptor>();
+ List<ServerDescriptor> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"router ");
diff --git a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
index 8b5f2ca..49c7995 100644
--- a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
@@ -49,8 +49,8 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
this.statLocalDirectory(localDirectory);
SortedMap<String, String> fetchedDirectoryListings =
this.fetchRemoteDirectories(collecTorBaseUrl, remoteDirectories);
- SortedSet<String> parsedDirectories = new TreeSet<String>();
- SortedMap<String, Long> remoteFiles = new TreeMap<String, Long>();
+ SortedSet<String> parsedDirectories = new TreeSet<>();
+ SortedMap<String, Long> remoteFiles = new TreeMap<>();
for (Map.Entry<String, String> e :
fetchedDirectoryListings.entrySet()) {
String remoteDirectory = e.getKey();
@@ -73,11 +73,11 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
SortedMap<String, Long> statLocalDirectory(
File localDirectory) {
- SortedMap<String, Long> localFiles = new TreeMap<String, Long>();
+ SortedMap<String, Long> localFiles = new TreeMap<>();
if (!localDirectory.exists()) {
return localFiles;
}
- Stack<File> files = new Stack<File>();
+ Stack<File> files = new Stack<>();
files.add(localDirectory);
while (!files.isEmpty()) {
File file = files.pop();
@@ -94,8 +94,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
SortedMap<String, String> fetchRemoteDirectories(
String collecTorBaseUrl, String[] remoteDirectories) {
- SortedMap<String, String> fetchedDirectoryListings =
- new TreeMap<String, String>();
+ SortedMap<String, String> fetchedDirectoryListings = new TreeMap<>();
for (String remoteDirectory : remoteDirectories) {
String remoteDirectoryWithSlashAtBeginAndEnd =
(remoteDirectory.startsWith("/") ? "" : "/") + remoteDirectory
@@ -145,7 +144,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
SortedMap<String, Long> parseDirectoryListing(
String remoteDirectory, String directoryListing) {
- SortedMap<String, Long> remoteFiles = new TreeMap<String, Long>();
+ SortedMap<String, Long> remoteFiles = new TreeMap<>();
DateFormat dateTimeFormat = ParseHelper.getDateFormat(
"dd-MMM-yyyy HH:mm");
try {
diff --git a/src/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java b/src/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java
index 490b1ac..aaac8f8 100644
--- a/src/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java
@@ -17,7 +17,7 @@ public class DescriptorDownloaderImpl
private boolean hasStartedDownloading = false;
private SortedMap<String, DirectoryDownloader> directoryAuthorities =
- new TreeMap<String, DirectoryDownloader>();
+ new TreeMap<>();
public void addDirectoryAuthority(String nickname, String ip,
int dirPort) {
if (this.hasStartedDownloading) {
@@ -31,7 +31,7 @@ public class DescriptorDownloaderImpl
}
private SortedMap<String, DirectoryDownloader> directoryMirrors =
- new TreeMap<String, DirectoryDownloader>();
+ new TreeMap<>();
public void addDirectoryMirror(String nickname, String ip,
int dirPort) {
if (this.hasStartedDownloading) {
@@ -99,7 +99,7 @@ public class DescriptorDownloaderImpl
this.includeCurrentReferencedVotes = true;
}
- private Set<String> downloadVotes = new HashSet<String>();
+ private Set<String> downloadVotes = new HashSet<>();
public void setIncludeCurrentVote(String fingerprint) {
if (this.hasStartedDownloading) {
throw new IllegalStateException("Reconfiguration is not permitted "
diff --git a/src/org/torproject/descriptor/impl/DescriptorFileImpl.java b/src/org/torproject/descriptor/impl/DescriptorFileImpl.java
index 440426d..b683e7f 100644
--- a/src/org/torproject/descriptor/impl/DescriptorFileImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorFileImpl.java
@@ -57,7 +57,7 @@ public class DescriptorFileImpl implements DescriptorFile {
}
public List<Descriptor> getDescriptors() {
return this.descriptors == null ? new ArrayList<Descriptor>() :
- new ArrayList<Descriptor>(this.descriptors);
+ new ArrayList<>(this.descriptors);
}
private Exception exception;
diff --git a/src/org/torproject/descriptor/impl/DescriptorImpl.java b/src/org/torproject/descriptor/impl/DescriptorImpl.java
index 4e639a4..e7a3f0e 100644
--- a/src/org/torproject/descriptor/impl/DescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorImpl.java
@@ -19,7 +19,7 @@ public abstract class DescriptorImpl implements Descriptor {
byte[] rawDescriptorBytes, String fileName,
boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<Descriptor> parsedDescriptors = new ArrayList<Descriptor>();
+ List<Descriptor> parsedDescriptors = new ArrayList<>();
if (rawDescriptorBytes == null) {
return parsedDescriptors;
}
@@ -114,7 +114,7 @@ public abstract class DescriptorImpl implements Descriptor {
protected static List<byte[]> splitRawDescriptorBytes(
byte[] rawDescriptorBytes, String startToken) {
- List<byte[]> rawDescriptors = new ArrayList<byte[]>();
+ List<byte[]> rawDescriptors = new ArrayList<>();
String splitToken = "\n" + startToken;
String ascii;
try {
@@ -168,7 +168,7 @@ public abstract class DescriptorImpl implements Descriptor {
protected List<String> unrecognizedLines;
public List<String> getUnrecognizedLines() {
return this.unrecognizedLines == null ? new ArrayList<String>() :
- new ArrayList<String>(this.unrecognizedLines);
+ new ArrayList<>(this.unrecognizedLines);
}
protected DescriptorImpl(byte[] rawDescriptorBytes,
@@ -182,7 +182,7 @@ public abstract class DescriptorImpl implements Descriptor {
}
/* Parse annotation lines from the descriptor bytes. */
- private List<String> annotations = new ArrayList<String>();
+ private List<String> annotations = new ArrayList<>();
private void cutOffAnnotations(byte[] rawDescriptorBytes)
throws DescriptorParseException {
String ascii = new String(rawDescriptorBytes);
@@ -206,13 +206,12 @@ public abstract class DescriptorImpl implements Descriptor {
}
}
public List<String> getAnnotations() {
- return new ArrayList<String>(this.annotations);
+ return new ArrayList<>(this.annotations);
}
/* Count parsed keywords for consistency checks by subclasses. */
private String firstKeyword, lastKeyword;
- private Map<String, Integer> parsedKeywords =
- new HashMap<String, Integer>();
+ private Map<String, Integer> parsedKeywords = new HashMap<>();
private void countKeywords(byte[] rawDescriptorBytes,
boolean blankLinesAllowed) throws DescriptorParseException {
if (rawDescriptorBytes.length == 0) {
diff --git a/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java
index e47c2a7..454c526 100644
--- a/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorReaderImpl.java
@@ -34,7 +34,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
private boolean hasStartedReading = false;
- private List<File> directories = new ArrayList<File>();
+ private List<File> directories = new ArrayList<>();
public void addDirectory(File directory) {
if (this.hasStartedReading) {
throw new IllegalStateException("Reconfiguration is not permitted "
@@ -43,7 +43,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
this.directories.add(directory);
}
- private List<File> tarballs = new ArrayList<File>();
+ private List<File> tarballs = new ArrayList<>();
public void addTarball(File tarball) {
if (this.hasStartedReading) {
throw new IllegalStateException("Reconfiguration is not permitted "
@@ -75,7 +75,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
throw new IllegalStateException("Operation is not permitted before "
+ "finishing to read.");
}
- return new TreeMap<String, Long>(this.reader.excludedFilesAfter);
+ return new TreeMap<>(this.reader.excludedFilesAfter);
}
public SortedMap<String, Long> getParsedFiles() {
@@ -83,7 +83,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
throw new IllegalStateException("Operation is not permitted before "
+ "finishing to read.");
}
- return new TreeMap<String, Long>(this.reader.parsedFilesAfter);
+ return new TreeMap<>(this.reader.parsedFilesAfter);
}
private boolean failUnrecognizedDescriptorLines = false;
@@ -128,10 +128,9 @@ public class DescriptorReaderImpl implements DescriptorReader {
private List<File> tarballs;
private BlockingIteratorImpl<DescriptorFile> descriptorQueue;
private File historyFile;
- private SortedMap<String, Long>
- excludedFilesBefore = new TreeMap<String, Long>(),
- excludedFilesAfter = new TreeMap<String, Long>(),
- parsedFilesAfter = new TreeMap<String, Long>();
+ private SortedMap<String, Long> excludedFilesBefore = new TreeMap<>(),
+ excludedFilesAfter = new TreeMap<>(),
+ parsedFilesAfter = new TreeMap<>();
private DescriptorParser descriptorParser;
private boolean hasFinishedReading = false;
private DescriptorReaderRunnable(List<File> directories,
@@ -205,7 +204,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
}
BufferedWriter bw = new BufferedWriter(new FileWriter(
this.historyFile));
- SortedMap<String, Long> newHistory = new TreeMap<String, Long>();
+ SortedMap<String, Long> newHistory = new TreeMap<>();
newHistory.putAll(this.excludedFilesAfter);
newHistory.putAll(this.parsedFilesAfter);
for (Map.Entry<String, Long> e : newHistory.entrySet()) {
@@ -224,7 +223,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
if (!directory.exists() || !directory.isDirectory()) {
continue;
}
- Stack<File> files = new Stack<File>();
+ Stack<File> files = new Stack<>();
files.add(directory);
boolean abortReading = false;
while (!abortReading && !files.isEmpty()) {
@@ -265,7 +264,7 @@ public class DescriptorReaderImpl implements DescriptorReader {
}
}
private void readTarballs() {
- List<File> files = new ArrayList<File>(this.tarballs);
+ List<File> files = new ArrayList<>(this.tarballs);
boolean abortReading = false;
while (!abortReading && !files.isEmpty()) {
File tarball = files.remove(0);
diff --git a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
index 5b65789..3a59d5b 100644
--- a/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/DirSourceEntryImpl.java
@@ -39,10 +39,10 @@ public class DirSourceEntryImpl implements DirSourceEntry {
private SortedSet<String> exactlyOnceKeywords, atMostOnceKeywords;
private void initializeKeywords() {
- this.exactlyOnceKeywords = new TreeSet<String>();
+ this.exactlyOnceKeywords = new TreeSet<>();
this.exactlyOnceKeywords.add("dir-source");
this.exactlyOnceKeywords.add("vote-digest");
- this.atMostOnceKeywords = new TreeSet<String>();
+ this.atMostOnceKeywords = new TreeSet<>();
this.atMostOnceKeywords.add("contact");
}
@@ -96,7 +96,7 @@ public class DirSourceEntryImpl implements DirSourceEntry {
+ line + "' in dir-source entry.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 4a2f39c..152ffeb 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -25,8 +25,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
protected static List<DirectoryKeyCertificate> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<DirectoryKeyCertificate> parsedDescriptors =
- new ArrayList<DirectoryKeyCertificate>();
+ List<DirectoryKeyCertificate> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DirectoryKeyCertificateImpl.splitRawDescriptorBytes(
descriptorsBytes, "dir-key-certificate-version ");
@@ -45,12 +44,12 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
super(rawDescriptorBytes, failUnrecognizedDescriptorLines, false);
this.parseDescriptorBytes();
this.calculateDigest();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"dir-key-certificate-version,fingerprint,dir-identity-key,"
+ "dir-key-published,dir-key-expires,dir-signing-key,"
+ "dir-key-certification").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"dir-address,dir-key-crosscert").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("dir-key-certificate-version");
@@ -117,7 +116,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
+ line + "' in directory key certificate.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
diff --git a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
index 4e56006..27e9cc9 100644
--- a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
@@ -70,7 +70,7 @@ public class DirectorySignatureImpl implements DirectorySignature {
+ line + "' in dir-source entry.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
diff --git a/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java b/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
index 067c38c..e95f9da 100644
--- a/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
+++ b/src/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java
@@ -20,7 +20,7 @@ import org.torproject.descriptor.RelayNetworkStatusConsensus;
public class DownloadCoordinatorImpl implements DownloadCoordinator {
private BlockingIteratorImpl<DescriptorRequest> descriptorQueue =
- new BlockingIteratorImpl<DescriptorRequest>();
+ new BlockingIteratorImpl<>();
protected Iterator<DescriptorRequest> getDescriptorQueue() {
return this.descriptorQueue;
}
@@ -45,7 +45,7 @@ public class DownloadCoordinatorImpl implements DownloadCoordinator {
long globalTimeoutMillis, boolean failUnrecognizedDescriptorLines) {
this.directoryAuthorities = directoryAuthorities;
this.directoryMirrors = directoryMirrors;
- this.runningDirectories = new TreeSet<String>();
+ this.runningDirectories = new TreeSet<>();
this.runningDirectories.addAll(directoryAuthorities.keySet());
this.runningDirectories.addAll(directoryMirrors.keySet());
this.missingConsensus = downloadConsensus;
@@ -120,24 +120,22 @@ public class DownloadCoordinatorImpl implements DownloadCoordinator {
/* Which directories are currently attempting to download the
* consensus? */
- private Set<String> requestingConsensuses = new HashSet<String>();
+ private Set<String> requestingConsensuses = new HashSet<>();
/* Which directories have attempted to download the consensus so far,
* including those directories that are currently attempting it? */
- private Set<String> requestedConsensuses = new HashSet<String>();
+ private Set<String> requestedConsensuses = new HashSet<>();
/* Which votes are we currently missing? */
- private Set<String> missingVotes = new HashSet<String>();
+ private Set<String> missingVotes = new HashSet<>();
/* Which vote (map value) is a given directory (map key) currently
* attempting to download? */
- private Map<String, String> requestingVotes =
- new HashMap<String, String>();
+ private Map<String, String> requestingVotes = new HashMap<>();
/* Which votes (map value) has a given directory (map key) attempted or
* is currently attempting to download? */
- private Map<String, Set<String>> requestedVotes =
- new HashMap<String, Set<String>>();
+ private Map<String, Set<String>> requestedVotes = new HashMap<>();
private boolean hasFinishedDownloading = false;
diff --git a/src/org/torproject/descriptor/impl/ExitListEntryImpl.java b/src/org/torproject/descriptor/impl/ExitListEntryImpl.java
index e899bcf..6d00bf4 100644
--- a/src/org/torproject/descriptor/impl/ExitListEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/ExitListEntryImpl.java
@@ -68,7 +68,7 @@ public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry {
private SortedSet<String> keywordCountingSet;
private void initializeKeywords() {
- this.keywordCountingSet = new TreeSet<String>();
+ this.keywordCountingSet = new TreeSet<>();
this.keywordCountingSet.add("ExitNode");
this.keywordCountingSet.add("Published");
this.keywordCountingSet.add("LastStatus");
diff --git a/src/org/torproject/descriptor/impl/ExitListImpl.java b/src/org/torproject/descriptor/impl/ExitListImpl.java
index 730217e..33003df 100644
--- a/src/org/torproject/descriptor/impl/ExitListImpl.java
+++ b/src/org/torproject/descriptor/impl/ExitListImpl.java
@@ -94,7 +94,7 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
+ line + "' in exit list.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -114,7 +114,7 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
getAndClearUnrecognizedLines();
if (unrecognizedExitListEntryLines != null) {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(unrecognizedExitListEntryLines);
}
@@ -133,7 +133,7 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
private Set<ExitList.Entry> exitListEntries = new HashSet<>();
public Set<ExitList.Entry> getEntries() {
- return new HashSet<ExitList.Entry>(this.exitListEntries);
+ return new HashSet<>(this.exitListEntries);
}
}
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index ef0c82c..ff8df51 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -34,27 +34,27 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
this.parseDescriptorBytes();
this.calculateDigest();
this.calculateDigestSha256();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"extra-info,published").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> dirreqStatsKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> dirreqStatsKeywords = new HashSet<>(Arrays.asList((
"dirreq-stats-end,dirreq-v2-ips,dirreq-v3-ips,dirreq-v2-reqs,"
+ "dirreq-v3-reqs,dirreq-v2-share,dirreq-v3-share,dirreq-v2-resp,"
+ "dirreq-v3-resp,dirreq-v2-direct-dl,dirreq-v3-direct-dl,"
+ "dirreq-v2-tunneled-dl,dirreq-v3-tunneled-dl,").split(",")));
- Set<String> entryStatsKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> entryStatsKeywords = new HashSet<>(Arrays.asList(
"entry-stats-end,entry-ips".split(",")));
- Set<String> cellStatsKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> cellStatsKeywords = new HashSet<>(Arrays.asList((
"cell-stats-end,cell-processed-cells,cell-queued-cells,"
+ "cell-time-in-queue,cell-circuits-per-decile").split(",")));
- Set<String> connBiDirectStatsKeywords = new HashSet<String>(
+ Set<String> connBiDirectStatsKeywords = new HashSet<>(
Arrays.asList("conn-bi-direct".split(",")));
- Set<String> exitStatsKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exitStatsKeywords = new HashSet<>(Arrays.asList((
"exit-stats-end,exit-kibibytes-written,exit-kibibytes-read,"
+ "exit-streams-opened").split(",")));
- Set<String> bridgeStatsKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> bridgeStatsKeywords = new HashSet<>(Arrays.asList(
"bridge-stats-end,bridge-stats-ips".split(",")));
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"identity-ed25519,master-key-ed25519,read-history,write-history,"
+ "dirreq-read-history,dirreq-write-history,geoip-db-digest,"
+ "router-sig-ed25519,router-signature,router-digest-sha256,"
@@ -189,7 +189,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
} else if (keyword.equals("router-digest-sha256")) {
this.parseRouterDigestSha256Line(line, lineNoOpt, partsNoOpt);
} else if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<String>();
+ cryptoLines = new ArrayList<>();
cryptoLines.add(line);
} else if (line.startsWith("-----END")) {
cryptoLines.add(line);
@@ -208,7 +208,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
+ "block '" + cryptoString + "' in extra-info descriptor.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(cryptoLines);
}
@@ -223,7 +223,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
+ line + "' in extra-info descriptor.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -1047,19 +1047,19 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
private SortedMap<String, Long> exitKibibytesWritten;
public SortedMap<String, Long> getExitKibibytesWritten() {
return this.exitKibibytesWritten == null ? null :
- new TreeMap<String, Long>(this.exitKibibytesWritten);
+ new TreeMap<>(this.exitKibibytesWritten);
}
private SortedMap<String, Long> exitKibibytesRead;
public SortedMap<String, Long> getExitKibibytesRead() {
return this.exitKibibytesRead == null ? null :
- new TreeMap<String, Long>(this.exitKibibytesRead);
+ new TreeMap<>(this.exitKibibytesRead);
}
private SortedMap<String, Long> exitStreamsOpened;
public SortedMap<String, Long> getExitStreamsOpened() {
return this.exitStreamsOpened == null ? null :
- new TreeMap<String, Long>(this.exitStreamsOpened);
+ new TreeMap<>(this.exitStreamsOpened);
}
private long geoipStartTimeMillis = -1L;
@@ -1101,9 +1101,9 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
this.bridgeIpTransports);
}
- private List<String> transports = new ArrayList<String>();
+ private List<String> transports = new ArrayList<>();
public List<String> getTransports() {
- return new ArrayList<String>(this.transports);
+ return new ArrayList<>(this.transports);
}
private long hidservStatsEndMillis = -1L;
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index 1987659..3e7f466 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -24,8 +24,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
protected static List<Microdescriptor> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<Microdescriptor> parsedDescriptors =
- new ArrayList<Microdescriptor>();
+ List<Microdescriptor> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"onion-key\n");
@@ -44,10 +43,10 @@ public class MicrodescriptorImpl extends DescriptorImpl
super(descriptorBytes, failUnrecognizedDescriptorLines, false);
this.parseDescriptorBytes();
this.calculateDigest();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList(
"onion-key".split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"ntor-onion-key,family,p,p6,id").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("onion-key");
@@ -105,7 +104,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
+ line + "' in microdescriptor.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -253,9 +252,9 @@ public class MicrodescriptorImpl extends DescriptorImpl
return this.ntorOnionKey;
}
- private List<String> orAddresses = new ArrayList<String>();
+ private List<String> orAddresses = new ArrayList<>();
public List<String> getOrAddresses() {
- return new ArrayList<String>(this.orAddresses);
+ return new ArrayList<>(this.orAddresses);
}
private String[] familyEntries;
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 94575c6..4f2b69b 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -48,7 +48,7 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
private SortedSet<String> atMostOnceKeywords;
private void initializeKeywords() {
- this.atMostOnceKeywords = new TreeSet<String>();
+ this.atMostOnceKeywords = new TreeSet<>();
this.atMostOnceKeywords.add("s");
this.atMostOnceKeywords.add("v");
this.atMostOnceKeywords.add("w");
@@ -98,7 +98,7 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
+ "' in status entry.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -142,10 +142,8 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
this.orAddresses.add(parts[1]);
}
- private static Map<String, Integer> flagIndexes =
- new HashMap<String, Integer>();
- private static Map<Integer, String> flagStrings =
- new HashMap<Integer, String>();
+ private static Map<String, Integer> flagIndexes = new HashMap<>();
+ private static Map<Integer, String> flagStrings = new HashMap<>();
private void parseSLine(String line, String[] parts)
throws DescriptorParseException {
@@ -226,7 +224,7 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
private void parseMLine(String line, String[] parts)
throws DescriptorParseException {
if (this.microdescriptorDigests == null) {
- this.microdescriptorDigests = new HashSet<String>();
+ this.microdescriptorDigests = new HashSet<>();
}
if (parts.length == 2) {
this.microdescriptorDigests.add(
@@ -293,17 +291,17 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
private Set<String> microdescriptorDigests;
public Set<String> getMicrodescriptorDigests() {
return this.microdescriptorDigests == null ? null :
- new HashSet<String>(this.microdescriptorDigests);
+ new HashSet<>(this.microdescriptorDigests);
}
- private List<String> orAddresses = new ArrayList<String>();
+ private List<String> orAddresses = new ArrayList<>();
public List<String> getOrAddresses() {
- return new ArrayList<String>(this.orAddresses);
+ return new ArrayList<>(this.orAddresses);
}
private BitSet flags;
public SortedSet<String> getFlags() {
- SortedSet<String> result = new TreeSet<String>();
+ SortedSet<String> result = new TreeSet<>();
if (this.flags != null) {
for (int i = this.flags.nextSetBit(0); i >= 0;
i = this.flags.nextSetBit(i + 1)) {
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
index 9f92b47..a9c2483 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusImpl.java
@@ -134,7 +134,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
private List<byte[]> splitByKeyword(String descriptorString,
String keyword, int start, int end) {
- List<byte[]> splitParts = new ArrayList<byte[]>();
+ List<byte[]> splitParts = new ArrayList<>();
int from = start;
while (from < end) {
int to = descriptorString.indexOf("\n" + keyword + " ", from);
@@ -168,7 +168,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
getAndClearUnrecognizedLines();
if (unrecognizedDirSourceLines != null) {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(unrecognizedDirSourceLines);
}
@@ -203,7 +203,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
getAndClearUnrecognizedLines();
if (unrecognizedStatusEntryLines != null) {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(unrecognizedStatusEntryLines);
}
@@ -215,8 +215,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
protected void parseDirectorySignature(byte[] directorySignatureBytes)
throws DescriptorParseException {
if (this.directorySignatures == null) {
- this.directorySignatures = new TreeMap<String,
- DirectorySignature>();
+ this.directorySignatures = new TreeMap<>();
}
DirectorySignatureImpl signature = new DirectorySignatureImpl(
directorySignatureBytes, failUnrecognizedDescriptorLines);
@@ -225,22 +224,22 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
getAndClearUnrecognizedLines();
if (unrecognizedStatusEntryLines != null) {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(unrecognizedStatusEntryLines);
}
}
protected SortedMap<String, DirSourceEntry> dirSourceEntries =
- new TreeMap<String, DirSourceEntry>();
+ new TreeMap<>();
public SortedMap<String, DirSourceEntry> getDirSourceEntries() {
- return new TreeMap<String, DirSourceEntry>(this.dirSourceEntries);
+ return new TreeMap<>(this.dirSourceEntries);
}
protected SortedMap<String, NetworkStatusEntry> statusEntries =
- new TreeMap<String, NetworkStatusEntry>();
+ new TreeMap<>();
public SortedMap<String, NetworkStatusEntry> getStatusEntries() {
- return new TreeMap<String, NetworkStatusEntry>(this.statusEntries);
+ return new TreeMap<>(this.statusEntries);
}
public boolean containsStatusEntry(String fingerprint) {
return this.statusEntries.containsKey(fingerprint);
@@ -252,7 +251,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
protected SortedMap<String, DirectorySignature> directorySignatures;
public SortedMap<String, DirectorySignature> getDirectorySignatures() {
return this.directorySignatures == null ? null :
- new TreeMap<String, DirectorySignature>(this.directorySignatures);
+ new TreeMap<>(this.directorySignatures);
}
}
diff --git a/src/org/torproject/descriptor/impl/ParseHelper.java b/src/org/torproject/descriptor/impl/ParseHelper.java
index 15de5ee..43a44d1 100644
--- a/src/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/org/torproject/descriptor/impl/ParseHelper.java
@@ -146,7 +146,7 @@ public class ParseHelper {
return super.get();
}
protected Map<String, DateFormat> initialValue() {
- return new HashMap<String, DateFormat>();
+ return new HashMap<>();
}
public void remove() {
super.remove();
@@ -221,7 +221,7 @@ public class ParseHelper {
public static SortedMap<String, String> parseKeyValueStringPairs(
String line, String[] parts, int startIndex, String separatorString)
throws DescriptorParseException {
- SortedMap<String, String> result = new TreeMap<String, String>();
+ SortedMap<String, String> result = new TreeMap<>();
for (int i = startIndex; i < parts.length; i++) {
String pair = parts[i];
String[] pairParts = pair.split(separatorString);
@@ -237,7 +237,7 @@ public class ParseHelper {
public static SortedMap<String, Integer> parseKeyValueIntegerPairs(
String line, String[] parts, int startIndex, String separatorString)
throws DescriptorParseException {
- SortedMap<String, Integer> result = new TreeMap<String, Integer>();
+ SortedMap<String, Integer> result = new TreeMap<>();
SortedMap<String, String> keyValueStringPairs =
ParseHelper.parseKeyValueStringPairs(line, parts, startIndex,
separatorString);
@@ -292,8 +292,7 @@ public class ParseHelper {
}
private static Map<Integer, Pattern>
- commaSeparatedKeyValueListPatterns =
- new HashMap<Integer, Pattern>();
+ commaSeparatedKeyValueListPatterns = new HashMap<>();
public static String parseCommaSeparatedKeyIntegerValueList(
String line, String[] partsNoOpt, int index, int keyLength)
throws DescriptorParseException {
@@ -331,7 +330,7 @@ public class ParseHelper {
convertCommaSeparatedKeyIntegerValueList(String validatedString) {
SortedMap<String, Integer> result = null;
if (validatedString != null) {
- result = new TreeMap<String, Integer>();
+ result = new TreeMap<>();
if (validatedString.contains("=")) {
for (String listElement : validatedString.split(",", -1)) {
String[] keyAndValue = listElement.split("=");
@@ -346,7 +345,7 @@ public class ParseHelper {
parseCommaSeparatedKeyLongValueList(String line,
String[] partsNoOpt, int index, int keyLength)
throws DescriptorParseException {
- SortedMap<String, Long> result = new TreeMap<String, Long>();
+ SortedMap<String, Long> result = new TreeMap<>();
if (partsNoOpt.length < index) {
throw new DescriptorParseException("Line '" + line + "' does not "
+ "contain a key-value list at index " + index + ".");
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index e613c88..0b82328 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -27,8 +27,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
protected static List<RelayDirectory> parseDirectories(
byte[] directoriesBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<RelayDirectory> parsedDirectories =
- new ArrayList<RelayDirectory>();
+ List<RelayDirectory> parsedDirectories = new ArrayList<>();
List<byte[]> splitDirectoriesBytes =
DescriptorImpl.splitRawDescriptorBytes(directoriesBytes,
"signed-directory\n");
@@ -47,11 +46,11 @@ public class RelayDirectoryImpl extends DescriptorImpl
super(directoryBytes, failUnrecognizedDescriptorLines, true);
this.splitAndParseParts(rawDescriptorBytes);
this.calculateDigest();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"signed-directory,recommended-software,"
+ "directory-signature").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList(
"dir-signing-key,running-routers,router-status".split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("signed-directory");
@@ -161,7 +160,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
private List<byte[]> splitByKeyword(String descriptorString,
String keyword, int start, int end) {
- List<byte[]> splitParts = new ArrayList<byte[]>();
+ List<byte[]> splitParts = new ArrayList<>();
int from = start;
while (from < end) {
int to = descriptorString.indexOf("\n" + keyword + " ", from);
@@ -244,7 +243,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
+ line + "' in v1 directory.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -329,7 +328,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
+ "' in v2 network status.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -374,7 +373,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
private void parseRecommendedSoftwareLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
- List<String> result = new ArrayList<String>();
+ List<String> result = new ArrayList<>();
if (partsNoOpt.length > 2) {
throw new DescriptorParseException("Illegal versions line '" + line
+ "'.");
@@ -485,7 +484,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
private List<String> recommendedSoftware;
public List<String> getRecommendedSoftware() {
return this.recommendedSoftware == null ? null :
- new ArrayList<String>(this.recommendedSoftware);
+ new ArrayList<>(this.recommendedSoftware);
}
private String directorySignature;
@@ -493,22 +492,20 @@ public class RelayDirectoryImpl extends DescriptorImpl
return this.directorySignature;
}
- private List<RouterStatusEntry> statusEntries =
- new ArrayList<RouterStatusEntry>();
+ private List<RouterStatusEntry> statusEntries = new ArrayList<>();
public List<RouterStatusEntry> getRouterStatusEntries() {
- return new ArrayList<RouterStatusEntry>(this.statusEntries);
+ return new ArrayList<>(this.statusEntries);
}
- private List<ServerDescriptor> serverDescriptors =
- new ArrayList<ServerDescriptor>();
+ private List<ServerDescriptor> serverDescriptors = new ArrayList<>();
public List<ServerDescriptor> getServerDescriptors() {
- return new ArrayList<ServerDescriptor>(this.serverDescriptors);
+ return new ArrayList<>(this.serverDescriptors);
}
private List<Exception> serverDescriptorParseExceptions =
- new ArrayList<Exception>();
+ new ArrayList<>();
public List<Exception> getServerDescriptorParseExceptions() {
- return new ArrayList<Exception>(this.serverDescriptorParseExceptions);
+ return new ArrayList<>(this.serverDescriptorParseExceptions);
}
private String nickname;
diff --git a/src/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java
index 5ff0e04..73d4dfa 100644
--- a/src/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java
@@ -15,8 +15,7 @@ public class RelayExtraInfoDescriptorImpl
protected static List<ExtraInfoDescriptor> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<ExtraInfoDescriptor> parsedDescriptors =
- new ArrayList<ExtraInfoDescriptor>();
+ List<ExtraInfoDescriptor> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"extra-info ");
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index 0b3c53a..d92718c 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -29,7 +29,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
byte[] consensusesBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
List<RelayNetworkStatusConsensus> parsedConsensuses =
- new ArrayList<RelayNetworkStatusConsensus>();
+ new ArrayList<>();
List<byte[]> splitConsensusBytes =
DescriptorImpl.splitRawDescriptorBytes(consensusesBytes,
"network-status-version 3");
@@ -46,11 +46,11 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
super(consensusBytes, failUnrecognizedDescriptorLines, true, false);
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"vote-status,consensus-method,valid-after,fresh-until,"
+ "valid-until,voting-delay,known-flags").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"client-versions,server-versions,params,directory-footer,"
+ "bandwidth-weights").split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
@@ -122,7 +122,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
+ "' in consensus.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -140,7 +140,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
getAndClearUnrecognizedLines();
if (unrecognizedStatusEntryLines != null) {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(unrecognizedStatusEntryLines);
}
@@ -161,7 +161,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
+ "' in consensus.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -341,19 +341,19 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
private String[] knownFlags;
public SortedSet<String> getKnownFlags() {
- return new TreeSet<String>(Arrays.asList(this.knownFlags));
+ return new TreeSet<>(Arrays.asList(this.knownFlags));
}
private SortedMap<String, Integer> consensusParams;
public SortedMap<String, Integer> getConsensusParams() {
return this.consensusParams == null ? null:
- new TreeMap<String, Integer>(this.consensusParams);
+ new TreeMap<>(this.consensusParams);
}
private SortedMap<String, Integer> bandwidthWeights;
public SortedMap<String, Integer> getBandwidthWeights() {
return this.bandwidthWeights == null ? null :
- new TreeMap<String, Integer>(this.bandwidthWeights);
+ new TreeMap<>(this.bandwidthWeights);
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 6faeee0..c2735e7 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -27,8 +27,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
protected static List<RelayNetworkStatus> parseStatuses(
byte[] statusesBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<RelayNetworkStatus> parsedStatuses =
- new ArrayList<RelayNetworkStatus>();
+ List<RelayNetworkStatus> parsedStatuses = new ArrayList<>();
List<byte[]> splitStatusBytes =
DescriptorImpl.splitRawDescriptorBytes(statusesBytes,
"network-status-version 2");
@@ -44,11 +43,11 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
super(statusBytes, failUnrecognizedDescriptorLines, false, true);
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"network-status-version,dir-source,fingerprint,contact,"
+ "dir-signing-key,published").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList(
"dir-options,client-versions,server-versions".split(",")));
this.checkAtMostOnceKeywords(atMostOnceKeywords);
this.checkFirstKeyword("network-status-version");
@@ -138,7 +137,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
+ "' in v2 network status.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -185,7 +184,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
+ "' in v2 network status.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -336,7 +335,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
private String[] dirOptions;
public SortedSet<String> getDirOptions() {
- return new TreeSet<String>(Arrays.asList(this.dirOptions));
+ return new TreeSet<>(Arrays.asList(this.dirOptions));
}
private String nickname;
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index 410c2f1..b8f0412 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -24,8 +24,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
protected static List<RelayNetworkStatusVote> parseVotes(
byte[] votesBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<RelayNetworkStatusVote> parsedVotes =
- new ArrayList<RelayNetworkStatusVote>();
+ List<RelayNetworkStatusVote> parsedVotes = new ArrayList<>();
List<byte[]> splitVotesBytes =
DescriptorImpl.splitRawDescriptorBytes(votesBytes,
"network-status-version 3");
@@ -42,14 +41,14 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
super(voteBytes, failUnrecognizedDescriptorLines, false, false);
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList((
"vote-status,consensus-methods,published,valid-after,fresh-until,"
+ "valid-until,voting-delay,known-flags,dir-source,"
+ "dir-key-certificate-version,fingerprint,dir-key-published,"
+ "dir-key-expires,dir-identity-key,dir-signing-key,"
+ "dir-key-certification,directory-signature").split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"client-versions,server-versions,flag-thresholds,params,contact,"
+ "legacy-key,dir-key-crosscert,dir-address,directory-footer").
split(",")));
@@ -136,7 +135,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
+ line + "' in vote.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -385,7 +384,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
+ line + "' in vote.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -502,7 +501,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
private String[] knownFlags;
public SortedSet<String> getKnownFlags() {
- return new TreeSet<String>(Arrays.asList(this.knownFlags));
+ return new TreeSet<>(Arrays.asList(this.knownFlags));
}
private long stableUptime;
@@ -553,7 +552,7 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
private SortedMap<String, Integer> consensusParams;
public SortedMap<String, Integer> getConsensusParams() {
return this.consensusParams == null ? null:
- new TreeMap<String, Integer>(this.consensusParams);
+ new TreeMap<>(this.consensusParams);
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java
index 174c541..4957072 100644
--- a/src/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java
@@ -15,8 +15,7 @@ public class RelayServerDescriptorImpl extends ServerDescriptorImpl
protected static List<ServerDescriptor> parseDescriptors(
byte[] descriptorsBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
- List<ServerDescriptor> parsedDescriptors =
- new ArrayList<ServerDescriptor>();
+ List<ServerDescriptor> parsedDescriptors = new ArrayList<>();
List<byte[]> splitDescriptorsBytes =
DescriptorImpl.splitRawDescriptorBytes(descriptorsBytes,
"router ");
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 1484866..ddca784 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -29,10 +29,10 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
this.parseDescriptorBytes();
this.calculateDigest();
this.calculateDigestSha256();
- Set<String> exactlyOnceKeywords = new HashSet<String>(Arrays.asList(
+ Set<String> exactlyOnceKeywords = new HashSet<>(Arrays.asList(
"router,bandwidth,published".split(",")));
this.checkExactlyOnceKeywords(exactlyOnceKeywords);
- Set<String> atMostOnceKeywords = new HashSet<String>(Arrays.asList((
+ Set<String> atMostOnceKeywords = new HashSet<>(Arrays.asList((
"identity-ed25519,master-key-ed25519,platform,fingerprint,"
+ "hibernating,uptime,contact,family,read-history,write-history,"
+ "eventdns,caches-extra-info,extra-info-digest,"
@@ -138,7 +138,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
this.parseNtorOnionKeyCrosscert(line, lineNoOpt, partsNoOpt);
nextCrypto = "ntor-onion-key-crosscert";
} else if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<String>();
+ cryptoLines = new ArrayList<>();
cryptoLines.add(line);
} else if (line.startsWith("-----END")) {
cryptoLines.add(line);
@@ -165,7 +165,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
+ "block '" + cryptoString + "' in server descriptor.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.addAll(cryptoLines);
}
@@ -180,7 +180,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
+ line + "' in server descriptor.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -705,9 +705,9 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
return this.dirPort;
}
- private List<String> orAddresses = new ArrayList<String>();
+ private List<String> orAddresses = new ArrayList<>();
public List<String> getOrAddresses() {
- return new ArrayList<String>(this.orAddresses);
+ return new ArrayList<>(this.orAddresses);
}
private int bandwidthRate;
@@ -760,9 +760,9 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
return this.signingKey;
}
- private List<String> exitPolicyLines = new ArrayList<String>();
+ private List<String> exitPolicyLines = new ArrayList<>();
public List<String> getExitPolicyLines() {
- return new ArrayList<String>(this.exitPolicyLines);
+ return new ArrayList<>(this.exitPolicyLines);
}
private String routerSignature;
diff --git a/src/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/org/torproject/descriptor/impl/TorperfResultImpl.java
index 6da985f..aad8e32 100644
--- a/src/org/torproject/descriptor/impl/TorperfResultImpl.java
+++ b/src/org/torproject/descriptor/impl/TorperfResultImpl.java
@@ -24,7 +24,7 @@ public class TorperfResultImpl extends DescriptorImpl
if (rawDescriptorBytes.length == 0) {
throw new DescriptorParseException("Descriptor is empty.");
}
- List<Descriptor> parsedDescriptors = new ArrayList<Descriptor>();
+ List<Descriptor> parsedDescriptors = new ArrayList<>();
String descriptorString = new String(rawDescriptorBytes);
Scanner s = new Scanner(descriptorString).useDelimiter("\n");
String typeAnnotation = "";
@@ -130,7 +130,7 @@ public class TorperfResultImpl extends DescriptorImpl
+ "' in line '" + line + "'.");
} else {
if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<String>();
+ this.unrecognizedLines = new ArrayList<>();
}
this.unrecognizedLines.add(line);
}
@@ -138,8 +138,8 @@ public class TorperfResultImpl extends DescriptorImpl
this.checkAllRequiredKeysParsed(line);
}
- private Set<String> parsedKeys = new HashSet<String>();
- private Set<String> requiredKeys = new HashSet<String>(Arrays.asList(
+ private Set<String> parsedKeys = new HashSet<>();
+ private Set<String> requiredKeys = new HashSet<>(Arrays.asList(
("SOURCE,FILESIZE,START,SOCKET,CONNECT,NEGOTIATE,REQUEST,RESPONSE,"
+ "DATAREQUEST,DATARESPONSE,DATACOMPLETE,WRITEBYTES,READBYTES").
split(",")));
@@ -244,7 +244,7 @@ public class TorperfResultImpl extends DescriptorImpl
}
}
- private Set<String> unparsedPercentiles = new HashSet<String>(
+ private Set<String> unparsedPercentiles = new HashSet<>(
Arrays.asList("10,20,30,40,50,60,70,80,90".split(",")));
private void parseDataPercentile(String value, String keyValue,
String line) throws DescriptorParseException {
@@ -431,7 +431,7 @@ public class TorperfResultImpl extends DescriptorImpl
if (this.dataDeciles == null) {
return null;
}
- SortedMap<Integer, Long> result = new TreeMap<Integer, Long>();
+ SortedMap<Integer, Long> result = new TreeMap<>();
for (int i = 0; i < dataDeciles.length; i++) {
if (dataDeciles[i] > 0L) {
result.put(10 * (i + 1), dataDeciles[i]);
diff --git a/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java b/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
index c8e95bf..d0e4cb7 100644
--- a/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
+++ b/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
@@ -51,7 +51,7 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
- private List<String> statusEntries = new ArrayList<String>();
+ private List<String> statusEntries = new ArrayList<>();
private String unrecognizedHeaderLine = null;
protected static BridgeNetworkStatus
createWithUnrecognizedHeaderLine(String line,
diff --git a/test/org/torproject/descriptor/impl/ConsensusBuilder.java b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
index 9d72e1e..470523d 100644
--- a/test/org/torproject/descriptor/impl/ConsensusBuilder.java
+++ b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
@@ -106,8 +106,8 @@ public class ConsensusBuilder {
cb.paramsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
- List<String> dirSources = new ArrayList<String>();
- List<String> statusEntries = new ArrayList<String>();
+ List<String> dirSources = new ArrayList<>();
+ List<String> statusEntries = new ArrayList<>();
private String directoryFooterLine = "directory-footer";
protected void setDirectoryFooterLine(String line) {
this.directoryFooterLine = line;
@@ -133,7 +133,7 @@ public class ConsensusBuilder {
cb.bandwidthWeightsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
- private List<String> directorySignatures = new ArrayList<String>();
+ private List<String> directorySignatures = new ArrayList<>();
protected void addDirectorySignature(String directorySignatureString) {
this.directorySignatures.add(directorySignatureString);
}
diff --git a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index 55e0578..33540dc 100644
--- a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -1577,7 +1577,7 @@ public class ExtraInfoDescriptorImplTest {
String unrecognizedLine = "unrecognized-line 1";
ExtraInfoDescriptor descriptor = DescriptorBuilder.
createWithUnrecognizedLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 0707d55..1875774 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -1121,7 +1121,7 @@ public class RelayNetworkStatusConsensusImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusConsensus consensus = ConsensusBuilder.
createWithUnrecognizedHeaderLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
}
@@ -1140,7 +1140,7 @@ public class RelayNetworkStatusConsensusImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusConsensus consensus = ConsensusBuilder.
createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
}
@@ -1159,7 +1159,7 @@ public class RelayNetworkStatusConsensusImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusConsensus consensus = ConsensusBuilder.
createWithUnrecognizedStatusEntryLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
}
@@ -1178,7 +1178,7 @@ public class RelayNetworkStatusConsensusImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusConsensus consensus = ConsensusBuilder.
createWithUnrecognizedFooterLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
}
@@ -1198,7 +1198,7 @@ public class RelayNetworkStatusConsensusImplTest {
RelayNetworkStatusConsensus consensus = ConsensusBuilder.
createWithUnrecognizedDirectorySignatureLine(unrecognizedLine,
false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
}
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 46688d6..34e7721 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -1150,7 +1150,7 @@ public class RelayNetworkStatusVoteImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusVote vote = VoteBuilder.
createWithUnrecognizedHeaderLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
}
@@ -1169,7 +1169,7 @@ public class RelayNetworkStatusVoteImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusVote vote = VoteBuilder.
createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
}
@@ -1187,7 +1187,7 @@ public class RelayNetworkStatusVoteImplTest {
String unrecognizedLine = "unrecognized-line 1";
RelayNetworkStatusVote vote = VoteBuilder.
createWithUnrecognizedFooterLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
}
diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index 56f1419..41be8ea 100644
--- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -1358,14 +1358,14 @@ public class ServerDescriptorImplTest {
String unrecognizedLine = "unrecognized-line 1";
ServerDescriptor descriptor = DescriptorBuilder.
createWithUnrecognizedLine(unrecognizedLine, false);
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
@Test()
public void testSomeOtherKey() throws DescriptorParseException {
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add("some-other-key");
unrecognizedLines.add("-----BEGIN RSA PUBLIC KEY-----");
unrecognizedLines.add("MIGJAoGBAKM+iiHhO6eHsvd6Xjws9z9EQB1V/Bpuy5ciGJ"
@@ -1387,7 +1387,7 @@ public class ServerDescriptorImplTest {
@Test()
public void testUnrecognizedCryptoBlockNoKeyword()
throws DescriptorParseException {
- List<String> unrecognizedLines = new ArrayList<String>();
+ List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add("-----BEGIN RSA PUBLIC KEY-----");
unrecognizedLines.add("MIGJAoGBAKM+iiHhO6eHsvd6Xjws9z9EQB1V/Bpuy5ciGJ"
+ "1U4V9SeiKooSo5BpPL");
1
0

[metrics-lib/master] Use Java 7's switch-on-String wherever possible.
by karsten@torproject.org 25 Dec '15
by karsten@torproject.org 25 Dec '15
25 Dec '15
commit 2b4d7732f65a8d030f7b747ed9931e5541956332
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Dec 22 12:55:44 2015 +0100
Use Java 7's switch-on-String wherever possible.
Rather than writing chained if-else statements with String comparison
for equals(), we can now switch on a String instance.
Suggested by iwakeh, implements #17824.
---
.../descriptor/DescriptorSourceFactory.java | 13 +-
.../descriptor/impl/BridgeNetworkStatusImpl.java | 51 +++--
.../impl/DirectoryKeyCertificateImpl.java | 95 ++++----
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 228 ++++++++++++--------
.../descriptor/impl/MicrodescriptorImpl.java | 74 ++++---
.../descriptor/impl/NetworkStatusEntryImpl.java | 38 ++--
.../descriptor/impl/RelayDirectoryImpl.java | 75 ++++---
.../impl/RelayNetworkStatusConsensusImpl.java | 73 ++++---
.../descriptor/impl/RelayNetworkStatusImpl.java | 80 ++++---
.../impl/RelayNetworkStatusVoteImpl.java | 127 +++++++----
.../descriptor/impl/ServerDescriptorImpl.java | 199 ++++++++++-------
.../descriptor/impl/TorperfResultImpl.java | 87 +++++---
12 files changed, 700 insertions(+), 440 deletions(-)
diff --git a/src/org/torproject/descriptor/DescriptorSourceFactory.java b/src/org/torproject/descriptor/DescriptorSourceFactory.java
index 49fcdc6..8bab13e 100644
--- a/src/org/torproject/descriptor/DescriptorSourceFactory.java
+++ b/src/org/torproject/descriptor/DescriptorSourceFactory.java
@@ -53,14 +53,19 @@ public final class DescriptorSourceFactory {
Object object;
String clazzName = null;
try {
- if (PARSER_PROPERTY.equals(type)) {
+ switch (type) {
+ case PARSER_PROPERTY:
clazzName = System.getProperty(type, PARSER_DEFAULT);
- } else if (LOADER_PROPERTY.equals(type)) {
+ break;
+ case LOADER_PROPERTY:
clazzName = System.getProperty(type, LOADER_DEFAULT);
- } else if (READER_PROPERTY.equals(type)) {
+ break;
+ case READER_PROPERTY:
clazzName = System.getProperty(type, READER_DEFAULT);
- } else if (COLLECTOR_PROPERTY.equals(type)) {
+ break;
+ case COLLECTOR_PROPERTY:
clazzName = System.getProperty(type, COLLECTOR_DEFAULT);
+ break;
}
object = ClassLoader.getSystemClassLoader().loadClass(clazzName).
newInstance();
diff --git a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
index d5e6d8f..fcc9b64 100644
--- a/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
@@ -73,18 +73,23 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("published")) {
+ switch (keyword) {
+ case "published":
this.parsePublishedLine(line, parts);
- } else if (keyword.equals("flag-thresholds")) {
+ break;
+ case "flag-thresholds":
this.parseFlagThresholdsLine(line, parts);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in bridge network status.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in bridge network status.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
@@ -105,27 +110,37 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
ParseHelper.parseKeyValueStringPairs(line, parts, 1, "=");
try {
for (Map.Entry<String, String> e : flagThresholds.entrySet()) {
- if (e.getKey().equals("stable-uptime")) {
+ switch (e.getKey()) {
+ case "stable-uptime":
this.stableUptime = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("stable-mtbf")) {
+ break;
+ case "stable-mtbf":
this.stableMtbf = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("fast-speed")) {
+ break;
+ case "fast-speed":
this.fastBandwidth = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-wfu")) {
+ break;
+ case "guard-wfu":
this.guardWfu = Double.parseDouble(e.getValue().
replaceAll("%", ""));
- } else if (e.getKey().equals("guard-tk")) {
+ break;
+ case "guard-tk":
this.guardTk = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-bw-inc-exits")) {
+ break;
+ case "guard-bw-inc-exits":
this.guardBandwidthIncludingExits =
Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-bw-exc-exits")) {
+ break;
+ case "guard-bw-exc-exits":
this.guardBandwidthExcludingExits =
Long.parseLong(e.getValue());
- } else if (e.getKey().equals("enough-mtbf")) {
+ break;
+ case "enough-mtbf":
this.enoughMtbfInfo = Integer.parseInt(e.getValue());
- } else if (e.getKey().equals("ignoring-advertised-bws")) {
+ break;
+ case "ignoring-advertised-bws":
this.ignoringAdvertisedBws = Integer.parseInt(e.getValue());
+ break;
}
}
} catch (NumberFormatException ex) {
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 152ffeb..fcbf3f7 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -60,65 +60,82 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
private void parseDescriptorBytes() throws DescriptorParseException {
Scanner s = new Scanner(new String(this.rawDescriptorBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("dir-key-certificate-version")) {
+ switch (keyword) {
+ case "dir-key-certificate-version":
this.parseDirKeyCertificateVersionLine(line, parts);
- } else if (keyword.equals("dir-address")) {
+ break;
+ case "dir-address":
this.parseDirAddressLine(line, parts);
- } else if (keyword.equals("fingerprint")) {
+ break;
+ case "fingerprint":
this.parseFingerprintLine(line, parts);
- } else if (keyword.equals("dir-identity-key")) {
+ break;
+ case "dir-identity-key":
this.parseDirIdentityKeyLine(line, parts);
nextCrypto = "dir-identity-key";
- } else if (keyword.equals("dir-key-published")) {
+ break;
+ case "dir-key-published":
this.parseDirKeyPublishedLine(line, parts);
- } else if (keyword.equals("dir-key-expires")) {
+ break;
+ case "dir-key-expires":
this.parseDirKeyExpiresLine(line, parts);
- } else if (keyword.equals("dir-signing-key")) {
+ break;
+ case "dir-signing-key":
this.parseDirSigningKeyLine(line, parts);
nextCrypto = "dir-signing-key";
- } else if (keyword.equals("dir-key-crosscert")) {
+ break;
+ case "dir-key-crosscert":
this.parseDirKeyCrosscertLine(line, parts);
nextCrypto = "dir-key-crosscert";
- } else if (keyword.equals("dir-key-certification")) {
+ break;
+ case "dir-key-certification":
this.parseDirKeyCertificationLine(line, parts);
nextCrypto = "dir-key-certification";
- } else if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line + "\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line + "\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("dir-identity-key")) {
- this.dirIdentityKey = cryptoString;
- } else if (nextCrypto.equals("dir-signing-key")) {
- this.dirSigningKey = cryptoString;
- } else if (nextCrypto.equals("dir-key-crosscert")) {
- this.dirKeyCrosscert = cryptoString;
- } else if (nextCrypto.equals("dir-key-certification")) {
- this.dirKeyCertification = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in directory key certificate.");
- }
- nextCrypto = null;
- } else if (crypto != null) {
- crypto.append(line + "\n");
- } else {
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in directory key certificate.");
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ crypto = new StringBuilder();
+ crypto.append(line + "\n");
+ } else if (line.startsWith("-----END")) {
+ crypto.append(line + "\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ switch (nextCrypto) {
+ case "dir-identity-key":
+ this.dirIdentityKey = cryptoString;
+ break;
+ case "dir-signing-key":
+ this.dirSigningKey = cryptoString;
+ break;
+ case "dir-key-crosscert":
+ this.dirKeyCrosscert = cryptoString;
+ break;
+ case "dir-key-certification":
+ this.dirKeyCertification = cryptoString;
+ break;
+ default:
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in directory key certificate.");
+ }
+ nextCrypto = "";
+ } else if (crypto != null) {
+ crypto.append(line + "\n");
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in directory key certificate.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index ff8df51..36ff269 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -79,7 +79,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseDescriptorBytes() throws DescriptorParseException {
Scanner s = new Scanner(new String(this.rawDescriptorBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
List<String> cryptoLines = null;
while (s.hasNext()) {
String line = s.next();
@@ -87,145 +87,203 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
- if (keyword.equals("extra-info")) {
+ switch (keyword) {
+ case "extra-info":
this.parseExtraInfoLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("published")) {
+ break;
+ case "published":
this.parsePublishedLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("read-history")) {
+ break;
+ case "read-history":
this.parseReadHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("write-history")) {
+ break;
+ case "write-history":
this.parseWriteHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("geoip-db-digest")) {
+ break;
+ case "geoip-db-digest":
this.parseGeoipDbDigestLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("geoip6-db-digest")) {
+ break;
+ case "geoip6-db-digest":
this.parseGeoip6DbDigestLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("geoip-start-time")) {
+ break;
+ case "geoip-start-time":
this.parseGeoipStartTimeLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("geoip-client-origins")) {
+ break;
+ case "geoip-client-origins":
this.parseGeoipClientOriginsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-stats-end")) {
+ break;
+ case "dirreq-stats-end":
this.parseDirreqStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-ips")) {
+ break;
+ case "dirreq-v2-ips":
this.parseDirreqV2IpsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-ips")) {
+ break;
+ case "dirreq-v3-ips":
this.parseDirreqV3IpsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-reqs")) {
+ break;
+ case "dirreq-v2-reqs":
this.parseDirreqV2ReqsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-reqs")) {
+ break;
+ case "dirreq-v3-reqs":
this.parseDirreqV3ReqsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-share")) {
+ break;
+ case "dirreq-v2-share":
this.parseDirreqV2ShareLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-share")) {
+ break;
+ case "dirreq-v3-share":
this.parseDirreqV3ShareLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-resp")) {
+ break;
+ case "dirreq-v2-resp":
this.parseDirreqV2RespLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-resp")) {
+ break;
+ case "dirreq-v3-resp":
this.parseDirreqV3RespLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-direct-dl")) {
+ break;
+ case "dirreq-v2-direct-dl":
this.parseDirreqV2DirectDlLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-direct-dl")) {
+ break;
+ case "dirreq-v3-direct-dl":
this.parseDirreqV3DirectDlLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v2-tunneled-dl")) {
+ break;
+ case "dirreq-v2-tunneled-dl":
this.parseDirreqV2TunneledDlLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-v3-tunneled-dl")) {
+ break;
+ case "dirreq-v3-tunneled-dl":
this.parseDirreqV3TunneledDlLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-read-history")) {
+ break;
+ case "dirreq-read-history":
this.parseDirreqReadHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dirreq-write-history")) {
+ break;
+ case "dirreq-write-history":
this.parseDirreqWriteHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("entry-stats-end")) {
+ break;
+ case "entry-stats-end":
this.parseEntryStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("entry-ips")) {
+ break;
+ case "entry-ips":
this.parseEntryIpsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("cell-stats-end")) {
+ break;
+ case "cell-stats-end":
this.parseCellStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("cell-processed-cells")) {
+ break;
+ case "cell-processed-cells":
this.parseCellProcessedCellsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("cell-queued-cells")) {
+ break;
+ case "cell-queued-cells":
this.parseCellQueuedCellsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("cell-time-in-queue")) {
+ break;
+ case "cell-time-in-queue":
this.parseCellTimeInQueueLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("cell-circuits-per-decile")) {
+ break;
+ case "cell-circuits-per-decile":
this.parseCellCircuitsPerDecileLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("conn-bi-direct")) {
+ break;
+ case "conn-bi-direct":
this.parseConnBiDirectLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("exit-stats-end")) {
+ break;
+ case "exit-stats-end":
this.parseExitStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("exit-kibibytes-written")) {
+ break;
+ case "exit-kibibytes-written":
this.parseExitKibibytesWrittenLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("exit-kibibytes-read")) {
+ break;
+ case "exit-kibibytes-read":
this.parseExitKibibytesReadLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("exit-streams-opened")) {
+ break;
+ case "exit-streams-opened":
this.parseExitStreamsOpenedLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("bridge-stats-end")) {
+ break;
+ case "bridge-stats-end":
this.parseBridgeStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("bridge-ips")) {
+ break;
+ case "bridge-ips":
this.parseBridgeStatsIpsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("bridge-ip-versions")) {
+ break;
+ case "bridge-ip-versions":
this.parseBridgeIpVersionsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("bridge-ip-transports")) {
+ break;
+ case "bridge-ip-transports":
this.parseBridgeIpTransportsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("transport")) {
+ break;
+ case "transport":
this.parseTransportLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("hidserv-stats-end")) {
+ break;
+ case "hidserv-stats-end":
this.parseHidservStatsEndLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("hidserv-rend-relayed-cells")) {
+ break;
+ case "hidserv-rend-relayed-cells":
this.parseHidservRendRelayedCellsLine(line, lineNoOpt,
partsNoOpt);
- } else if (keyword.equals("hidserv-dir-onions-seen")) {
+ break;
+ case "hidserv-dir-onions-seen":
this.parseHidservDirOnionsSeenLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("identity-ed25519")) {
+ break;
+ case "identity-ed25519":
this.parseIdentityEd25519Line(line, lineNoOpt, partsNoOpt);
nextCrypto = "identity-ed25519";
- } else if (keyword.equals("master-key-ed25519")) {
+ break;
+ case "master-key-ed25519":
this.parseMasterKeyEd25519Line(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-sig-ed25519")) {
+ break;
+ case "router-sig-ed25519":
this.parseRouterSigEd25519Line(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-signature")) {
+ break;
+ case "router-signature":
this.parseRouterSignatureLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "router-signature";
- } else if (keyword.equals("router-digest")) {
+ break;
+ case "router-digest":
this.parseRouterDigestLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-digest-sha256")) {
+ break;
+ case "router-digest-sha256":
this.parseRouterDigestSha256Line(line, lineNoOpt, partsNoOpt);
- } else if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<>();
- cryptoLines.add(line);
- } else if (line.startsWith("-----END")) {
- cryptoLines.add(line);
- StringBuilder sb = new StringBuilder();
- for (String cryptoLine : cryptoLines) {
- sb.append("\n" + cryptoLine);
- }
- String cryptoString = sb.toString().substring(1);
- if ("router-signature".equals(nextCrypto)) {
- this.routerSignature = cryptoString;
- } else if ("identity-ed25519".equals(nextCrypto)) {
- this.identityEd25519 = cryptoString;
- this.parseIdentityEd25519CryptoBlock(cryptoString);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block '" + cryptoString + "' in extra-info descriptor.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ cryptoLines = new ArrayList<>();
+ cryptoLines.add(line);
+ } else if (line.startsWith("-----END")) {
+ cryptoLines.add(line);
+ StringBuilder sb = new StringBuilder();
+ for (String cryptoLine : cryptoLines) {
+ sb.append("\n" + cryptoLine);
}
- this.unrecognizedLines.addAll(cryptoLines);
- }
- cryptoLines = null;
- nextCrypto = null;
- } else if (cryptoLines != null) {
- cryptoLines.add(line);
- } else {
- ParseHelper.parseKeyword(line, partsNoOpt[0]);
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in extra-info descriptor.");
+ String cryptoString = sb.toString().substring(1);
+ switch (nextCrypto) {
+ case "router-signature":
+ this.routerSignature = cryptoString;
+ break;
+ case "identity-ed25519":
+ this.identityEd25519 = cryptoString;
+ this.parseIdentityEd25519CryptoBlock(cryptoString);
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block '" + cryptoString + "' in extra-info "
+ + "descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.addAll(cryptoLines);
+ }
+ }
+ cryptoLines = null;
+ nextCrypto = "";
+ } else if (cryptoLines != null) {
+ cryptoLines.add(line);
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ ParseHelper.parseKeyword(line, partsNoOpt[0]);
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in extra-info descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index 3e7f466..a70493d 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -57,7 +57,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
private void parseDescriptorBytes() throws DescriptorParseException {
Scanner s = new Scanner(new String(this.rawDescriptorBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
@@ -66,47 +66,57 @@ public class MicrodescriptorImpl extends DescriptorImpl
}
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("onion-key")) {
+ switch (keyword) {
+ case "onion-key":
this.parseOnionKeyLine(line, parts);
nextCrypto = "onion-key";
- } else if (keyword.equals("ntor-onion-key")) {
+ break;
+ case "ntor-onion-key":
this.parseNtorOnionKeyLine(line, parts);
- } else if (keyword.equals("a")) {
+ break;
+ case "a":
this.parseALine(line, parts);
- } else if (keyword.equals("family")) {
+ break;
+ case "family":
this.parseFamilyLine(line, parts);
- } else if (keyword.equals("p")) {
+ break;
+ case "p":
this.parsePLine(line, parts);
- } else if (keyword.equals("p6")) {
+ break;
+ case "p6":
this.parseP6Line(line, parts);
- } else if (keyword.equals("id")) {
+ break;
+ case "id":
this.parseIdLine(line, parts);
- } else if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line + "\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line + "\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("onion-key")) {
- this.onionKey = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in microdescriptor.");
- }
- nextCrypto = null;
- } else if (crypto != null) {
- crypto.append(line + "\n");
- } else {
- ParseHelper.parseKeyword(line, parts[0]);
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in microdescriptor.");
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ crypto = new StringBuilder();
+ crypto.append(line + "\n");
+ } else if (line.startsWith("-----END")) {
+ crypto.append(line + "\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("onion-key")) {
+ this.onionKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in microdescriptor.");
+ }
+ nextCrypto = "";
+ } else if (crypto != null) {
+ crypto.append(line + "\n");
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ ParseHelper.parseKeyword(line, parts[0]);
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in microdescriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index 4f2b69b..c5f0704 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -79,28 +79,38 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
String[] parts = !line.startsWith("opt ") ? line.split("[ \t]+") :
line.substring("opt ".length()).split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("a")) {
+ switch (keyword) {
+ case "a":
this.parseALine(line, parts);
- } else if (keyword.equals("s")) {
+ break;
+ case "s":
this.parseSLine(line, parts);
- } else if (keyword.equals("v")) {
+ break;
+ case "v":
this.parseVLine(line, parts);
- } else if (keyword.equals("w")) {
+ break;
+ case "w":
this.parseWLine(line, parts);
- } else if (keyword.equals("p")) {
+ break;
+ case "p":
this.parsePLine(line, parts);
- } else if (keyword.equals("m")) {
+ break;
+ case "m":
this.parseMLine(line, parts);
- } else if (keyword.equals("id")) {
+ break;
+ case "id":
this.parseIdLine(line, parts);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in status entry.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in status entry.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 0b82328..4d583aa 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -189,7 +189,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
private void parseHeader(byte[] headerBytes)
throws DescriptorParseException {
Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
- String publishedLine = null, nextCrypto = null,
+ String publishedLine = null, nextCrypto = "",
runningRoutersLine = null, routerStatusLine = null;
StringBuilder crypto = null;
while (s.hasNext()) {
@@ -201,9 +201,11 @@ public class RelayDirectoryImpl extends DescriptorImpl
line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
- if (keyword.equals("signed-directory")) {
+ switch (keyword) {
+ case "signed-directory":
this.parseSignedDirectoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("published")) {
+ break;
+ case "published":
if (publishedLine != null) {
throw new DescriptorParseException("Keyword 'published' is "
+ "contained more than once, but must be contained exactly "
@@ -211,41 +213,48 @@ public class RelayDirectoryImpl extends DescriptorImpl
} else {
publishedLine = line;
}
- } else if (keyword.equals("dir-signing-key")) {
+ break;
+ case "dir-signing-key":
this.parseDirSigningKeyLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "dir-signing-key";
- } else if (keyword.equals("recommended-software")) {
+ break;
+ case "recommended-software":
this.parseRecommendedSoftwareLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("running-routers")) {
+ break;
+ case "running-routers":
runningRoutersLine = line;
- } else if (keyword.equals("router-status")) {
+ break;
+ case "router-status":
routerStatusLine = line;
- } else if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line + "\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line + "\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("dir-signing-key") &&
- this.dirSigningKey == null) {
- this.dirSigningKey = cryptoString;
- } else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in v1 directory.");
- }
- nextCrypto = null;
- } else if (crypto != null) {
- crypto.append(line + "\n");
- } else {
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in v1 directory.");
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ crypto = new StringBuilder();
+ crypto.append(line + "\n");
+ } else if (line.startsWith("-----END")) {
+ crypto.append(line + "\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("dir-signing-key") &&
+ this.dirSigningKey == null) {
+ this.dirSigningKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in v1 directory.");
+ }
+ nextCrypto = "";
+ } else if (crypto != null) {
+ crypto.append(line + "\n");
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in v1 directory.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
@@ -296,7 +305,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
throws DescriptorParseException {
Scanner s = new Scanner(new String(directorySignatureBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
@@ -320,7 +329,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
throw new DescriptorParseException("Unrecognized crypto "
+ "block in v2 network status.");
}
- nextCrypto = null;
+ nextCrypto = "";
} else if (crypto != null) {
crypto.append(line + "\n");
} else if (this.failUnrecognizedDescriptorLines) {
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index d92718c..13b9142 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -95,36 +95,50 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("network-status-version")) {
+ switch (keyword) {
+ case "network-status-version":
this.parseNetworkStatusVersionLine(line, parts);
- } else if (keyword.equals("vote-status")) {
+ break;
+ case "vote-status":
this.parseVoteStatusLine(line, parts);
- } else if (keyword.equals("consensus-method")) {
+ break;
+ case "consensus-method":
this.parseConsensusMethodLine(line, parts);
- } else if (keyword.equals("valid-after")) {
+ break;
+ case "valid-after":
this.parseValidAfterLine(line, parts);
- } else if (keyword.equals("fresh-until")) {
+ break;
+ case "fresh-until":
this.parseFreshUntilLine(line, parts);
- } else if (keyword.equals("valid-until")) {
+ break;
+ case "valid-until":
this.parseValidUntilLine(line, parts);
- } else if (keyword.equals("voting-delay")) {
+ break;
+ case "voting-delay":
this.parseVotingDelayLine(line, parts);
- } else if (keyword.equals("client-versions")) {
+ break;
+ case "client-versions":
this.parseClientVersionsLine(line, parts);
- } else if (keyword.equals("server-versions")) {
+ break;
+ case "server-versions":
this.parseServerVersionsLine(line, parts);
- } else if (keyword.equals("known-flags")) {
+ break;
+ case "known-flags":
this.parseKnownFlagsLine(line, parts);
- } else if (keyword.equals("params")) {
+ break;
+ case "params":
this.parseParamsLine(line, parts);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in consensus.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in consensus.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
@@ -153,17 +167,22 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("directory-footer")) {
- } else if (keyword.equals("bandwidth-weights")) {
+ switch (keyword) {
+ case "directory-footer":
+ break;
+ case "bandwidth-weights":
this.parseBandwidthWeightsLine(line, parts);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in consensus.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in consensus.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index c2735e7..a10ed7a 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -88,7 +88,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
protected void parseHeader(byte[] headerBytes)
throws DescriptorParseException {
Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
@@ -97,49 +97,61 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
}
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("network-status-version")) {
+ switch (keyword) {
+ case "network-status-version":
this.parseNetworkStatusVersionLine(line, parts);
- } else if (keyword.equals("dir-source")) {
+ break;
+ case "dir-source":
this.parseDirSourceLine(line, parts);
- } else if (keyword.equals("fingerprint")) {
+ break;
+ case "fingerprint":
this.parseFingerprintLine(line, parts);
- } else if (keyword.equals("contact")) {
+ break;
+ case "contact":
this.parseContactLine(line, parts);
- } else if (keyword.equals("dir-signing-key")) {
+ break;
+ case "dir-signing-key":
this.parseDirSigningKeyLine(line, parts);
nextCrypto = "dir-signing-key";
- } else if (keyword.equals("client-versions")) {
+ break;
+ case "client-versions":
this.parseClientVersionsLine(line, parts);
- } else if (keyword.equals("server-versions")) {
+ break;
+ case "server-versions":
this.parseServerVersionsLine(line, parts);
- } else if (keyword.equals("published")) {
+ break;
+ case "published":
this.parsePublishedLine(line, parts);
- } else if (keyword.equals("dir-options")) {
+ break;
+ case "dir-options":
this.parseDirOptionsLine(line, parts);
- } else if (line.startsWith("-----BEGIN")) {
- crypto = new StringBuilder();
- crypto.append(line + "\n");
- } else if (line.startsWith("-----END")) {
- crypto.append(line + "\n");
- String cryptoString = crypto.toString();
- crypto = null;
- if (nextCrypto.equals("dir-signing-key")) {
- this.dirSigningKey = cryptoString;
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ crypto = new StringBuilder();
+ crypto.append(line + "\n");
+ } else if (line.startsWith("-----END")) {
+ crypto.append(line + "\n");
+ String cryptoString = crypto.toString();
+ crypto = null;
+ if (nextCrypto.equals("dir-signing-key")) {
+ this.dirSigningKey = cryptoString;
+ } else {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block in v2 network status.");
+ }
+ nextCrypto = "";
+ } else if (crypto != null) {
+ crypto.append(line + "\n");
+ } else if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '" + line
+ + "' in v2 network status.");
} else {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block in v2 network status.");
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- nextCrypto = null;
- } else if (crypto != null) {
- crypto.append(line + "\n");
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '" + line
- + "' in v2 network status.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
- }
- this.unrecognizedLines.add(line);
}
}
}
@@ -154,7 +166,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
throws DescriptorParseException {
Scanner s = new Scanner(new String(directorySignatureBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
StringBuilder crypto = null;
while (s.hasNext()) {
String line = s.next();
@@ -176,7 +188,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
throw new DescriptorParseException("Unrecognized crypto "
+ "block in v2 network status.");
}
- nextCrypto = null;
+ nextCrypto = "";
} else if (crypto != null) {
crypto.append(line + "\n");
} else if (this.failUnrecognizedDescriptorLines) {
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index b8f0412..d74ef65 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -79,65 +79,90 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
String line = s.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
- if (keyword.equals("network-status-version")) {
+ switch (keyword) {
+ case "network-status-version":
this.parseNetworkStatusVersionLine(line, parts);
- } else if (keyword.equals("vote-status")) {
+ break;
+ case "vote-status":
this.parseVoteStatusLine(line, parts);
- } else if (keyword.equals("consensus-methods")) {
+ break;
+ case "consensus-methods":
this.parseConsensusMethodsLine(line, parts);
- } else if (keyword.equals("published")) {
+ break;
+ case "published":
this.parsePublishedLine(line, parts);
- } else if (keyword.equals("valid-after")) {
+ break;
+ case "valid-after":
this.parseValidAfterLine(line, parts);
- } else if (keyword.equals("fresh-until")) {
+ break;
+ case "fresh-until":
this.parseFreshUntilLine(line, parts);
- } else if (keyword.equals("valid-until")) {
+ break;
+ case "valid-until":
this.parseValidUntilLine(line, parts);
- } else if (keyword.equals("voting-delay")) {
+ break;
+ case "voting-delay":
this.parseVotingDelayLine(line, parts);
- } else if (keyword.equals("client-versions")) {
+ break;
+ case "client-versions":
this.parseClientVersionsLine(line, parts);
- } else if (keyword.equals("server-versions")) {
+ break;
+ case "server-versions":
this.parseServerVersionsLine(line, parts);
- } else if (keyword.equals("known-flags")) {
+ break;
+ case "known-flags":
this.parseKnownFlagsLine(line, parts);
- } else if (keyword.equals("flag-thresholds")) {
+ break;
+ case "flag-thresholds":
this.parseFlagThresholdsLine(line, parts);
- } else if (keyword.equals("params")) {
+ break;
+ case "params":
this.parseParamsLine(line, parts);
- } else if (keyword.equals("dir-source")) {
+ break;
+ case "dir-source":
this.parseDirSourceLine(line, parts);
- } else if (keyword.equals("contact")) {
+ break;
+ case "contact":
this.parseContactLine(line, parts);
- } else if (keyword.equals("dir-key-certificate-version")) {
+ break;
+ case "dir-key-certificate-version":
this.parseDirKeyCertificateVersionLine(line, parts);
- } else if (keyword.equals("dir-address")) {
+ break;
+ case "dir-address":
this.parseDirAddressLine(line, parts);
- } else if (keyword.equals("fingerprint")) {
+ break;
+ case "fingerprint":
this.parseFingerprintLine(line, parts);
- } else if (keyword.equals("legacy-dir-key")) {
+ break;
+ case "legacy-dir-key":
this.parseLegacyDirKeyLine(line, parts);
- } else if (keyword.equals("dir-key-published")) {
+ break;
+ case "dir-key-published":
this.parseDirKeyPublished(line, parts);
- } else if (keyword.equals("dir-key-expires")) {
+ break;
+ case "dir-key-expires":
this.parseDirKeyExpiresLine(line, parts);
- } else if (keyword.equals("dir-identity-key") ||
- keyword.equals("dir-signing-key") ||
- keyword.equals("dir-key-crosscert") ||
- keyword.equals("dir-key-certification")) {
- } else if (line.startsWith("-----BEGIN")) {
- skipCrypto = true;
- } else if (line.startsWith("-----END")) {
- skipCrypto = false;
- } else if (!skipCrypto) {
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in vote.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ case "dir-identity-key":
+ case "dir-signing-key":
+ case "dir-key-crosscert":
+ case "dir-key-certification":
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ skipCrypto = true;
+ } else if (line.startsWith("-----END")) {
+ skipCrypto = false;
+ } else if (!skipCrypto) {
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in vote.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
@@ -257,27 +282,37 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
ParseHelper.parseKeyValueStringPairs(line, parts, 1, "=");
try {
for (Map.Entry<String, String> e : flagThresholds.entrySet()) {
- if (e.getKey().equals("stable-uptime")) {
+ switch (e.getKey()) {
+ case "stable-uptime":
this.stableUptime = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("stable-mtbf")) {
+ break;
+ case "stable-mtbf":
this.stableMtbf = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("fast-speed")) {
+ break;
+ case "fast-speed":
this.fastBandwidth = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-wfu")) {
+ break;
+ case "guard-wfu":
this.guardWfu = Double.parseDouble(e.getValue().
replaceAll("%", ""));
- } else if (e.getKey().equals("guard-tk")) {
+ break;
+ case "guard-tk":
this.guardTk = Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-bw-inc-exits")) {
+ break;
+ case "guard-bw-inc-exits":
this.guardBandwidthIncludingExits =
Long.parseLong(e.getValue());
- } else if (e.getKey().equals("guard-bw-exc-exits")) {
+ break;
+ case "guard-bw-exc-exits":
this.guardBandwidthExcludingExits =
Long.parseLong(e.getValue());
- } else if (e.getKey().equals("enough-mtbf")) {
+ break;
+ case "enough-mtbf":
this.enoughMtbfInfo = Integer.parseInt(e.getValue());
- } else if (e.getKey().equals("ignoring-advertised-bws")) {
+ break;
+ case "ignoring-advertised-bws":
this.ignoringAdvertisedBws = Integer.parseInt(e.getValue());
+ break;
}
}
} catch (NumberFormatException ex) {
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index ddca784..4ed311e 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -54,7 +54,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
private void parseDescriptorBytes() throws DescriptorParseException {
Scanner s = new Scanner(new String(this.rawDescriptorBytes)).
useDelimiter("\n");
- String nextCrypto = null;
+ String nextCrypto = "";
List<String> cryptoLines = null;
while (s.hasNext()) {
String line = s.next();
@@ -65,124 +65,169 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
String keyword = partsNoOpt[0];
- if (keyword.equals("router")) {
+ switch (keyword) {
+ case "router":
this.parseRouterLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("or-address")) {
+ break;
+ case "or-address":
this.parseOrAddressLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("bandwidth")) {
+ break;
+ case "bandwidth":
this.parseBandwidthLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("platform")) {
+ break;
+ case "platform":
this.parsePlatformLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("published")) {
+ break;
+ case "published":
this.parsePublishedLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("fingerprint")) {
+ break;
+ case "fingerprint":
this.parseFingerprintLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("hibernating")) {
+ break;
+ case "hibernating":
this.parseHibernatingLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("uptime")) {
+ break;
+ case "uptime":
this.parseUptimeLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("onion-key")) {
+ break;
+ case "onion-key":
this.parseOnionKeyLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "onion-key";
- } else if (keyword.equals("signing-key")) {
+ break;
+ case "signing-key":
this.parseSigningKeyLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "signing-key";
- } else if (keyword.equals("accept")) {
+ break;
+ case "accept":
this.parseAcceptLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("reject")) {
+ break;
+ case "reject":
this.parseRejectLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-signature")) {
+ break;
+ case "router-signature":
this.parseRouterSignatureLine(line, lineNoOpt, partsNoOpt);
nextCrypto = "router-signature";
- } else if (keyword.equals("contact")) {
+ break;
+ case "contact":
this.parseContactLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("family")) {
+ break;
+ case "family":
this.parseFamilyLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("read-history")) {
+ break;
+ case "read-history":
this.parseReadHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("write-history")) {
+ break;
+ case "write-history":
this.parseWriteHistoryLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("eventdns")) {
+ break;
+ case "eventdns":
this.parseEventdnsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("caches-extra-info")) {
+ break;
+ case "caches-extra-info":
this.parseCachesExtraInfoLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("extra-info-digest")) {
+ break;
+ case "extra-info-digest":
this.parseExtraInfoDigestLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("hidden-service-dir")) {
+ break;
+ case "hidden-service-dir":
this.parseHiddenServiceDirLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("protocols")) {
+ break;
+ case "protocols":
this.parseProtocolsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("allow-single-hop-exits")) {
+ break;
+ case "allow-single-hop-exits":
this.parseAllowSingleHopExitsLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("dircacheport")) {
+ break;
+ case "dircacheport":
this.parseDircacheportLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-digest")) {
+ break;
+ case "router-digest":
this.parseRouterDigestLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-digest-sha256")) {
+ break;
+ case "router-digest-sha256":
this.parseRouterDigestSha256Line(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("ipv6-policy")) {
+ break;
+ case "ipv6-policy":
this.parseIpv6PolicyLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("ntor-onion-key")) {
+ break;
+ case "ntor-onion-key":
this.parseNtorOnionKeyLine(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("identity-ed25519")) {
+ break;
+ case "identity-ed25519":
this.parseIdentityEd25519Line(line, lineNoOpt, partsNoOpt);
nextCrypto = "identity-ed25519";
- } else if (keyword.equals("master-key-ed25519")) {
+ break;
+ case "master-key-ed25519":
this.parseMasterKeyEd25519Line(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("router-sig-ed25519")) {
+ break;
+ case "router-sig-ed25519":
this.parseRouterSigEd25519Line(line, lineNoOpt, partsNoOpt);
- } else if (keyword.equals("onion-key-crosscert")) {
+ break;
+ case "onion-key-crosscert":
this.parseOnionKeyCrosscert(line, lineNoOpt, partsNoOpt);
nextCrypto = "onion-key-crosscert";
- } else if (keyword.equals("ntor-onion-key-crosscert")) {
+ break;
+ case "ntor-onion-key-crosscert":
this.parseNtorOnionKeyCrosscert(line, lineNoOpt, partsNoOpt);
nextCrypto = "ntor-onion-key-crosscert";
- } else if (line.startsWith("-----BEGIN")) {
- cryptoLines = new ArrayList<>();
- cryptoLines.add(line);
- } else if (line.startsWith("-----END")) {
- cryptoLines.add(line);
- StringBuilder sb = new StringBuilder();
- for (String cryptoLine : cryptoLines) {
- sb.append("\n" + cryptoLine);
- }
- String cryptoString = sb.toString().substring(1);
- if ("onion-key".equals(nextCrypto)) {
- this.onionKey = cryptoString;
- } else if ("signing-key".equals(nextCrypto)) {
- this.signingKey = cryptoString;
- } else if ("router-signature".equals(nextCrypto)) {
- this.routerSignature = cryptoString;
- } else if ("identity-ed25519".equals(nextCrypto)) {
- this.identityEd25519 = cryptoString;
- this.parseIdentityEd25519CryptoBlock(cryptoString);
- } else if ("onion-key-crosscert".equals(nextCrypto)) {
- this.onionKeyCrosscert = cryptoString;
- } else if ("ntor-onion-key-crosscert".equals(nextCrypto)) {
- this.ntorOnionKeyCrosscert = cryptoString;
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized crypto "
- + "block '" + cryptoString + "' in server descriptor.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (line.startsWith("-----BEGIN")) {
+ cryptoLines = new ArrayList<>();
+ cryptoLines.add(line);
+ } else if (line.startsWith("-----END")) {
+ cryptoLines.add(line);
+ StringBuilder sb = new StringBuilder();
+ for (String cryptoLine : cryptoLines) {
+ sb.append("\n" + cryptoLine);
}
- this.unrecognizedLines.addAll(cryptoLines);
- }
- cryptoLines = null;
- nextCrypto = null;
- } else if (cryptoLines != null) {
- cryptoLines.add(line);
- } else {
- ParseHelper.parseKeyword(line, partsNoOpt[0]);
- if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized line '"
- + line + "' in server descriptor.");
+ String cryptoString = sb.toString().substring(1);
+ switch (nextCrypto) {
+ case "onion-key":
+ this.onionKey = cryptoString;
+ break;
+ case "signing-key":
+ this.signingKey = cryptoString;
+ break;
+ case "router-signature":
+ this.routerSignature = cryptoString;
+ break;
+ case "identity-ed25519":
+ this.identityEd25519 = cryptoString;
+ this.parseIdentityEd25519CryptoBlock(cryptoString);
+ break;
+ case "onion-key-crosscert":
+ this.onionKeyCrosscert = cryptoString;
+ break;
+ case "ntor-onion-key-crosscert":
+ this.ntorOnionKeyCrosscert = cryptoString;
+ break;
+ default:
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized crypto "
+ + "block '" + cryptoString + "' in server descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.addAll(cryptoLines);
+ }
+ }
+ cryptoLines = null;
+ nextCrypto = "";
+ } else if (cryptoLines != null) {
+ cryptoLines.add(line);
} else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ ParseHelper.parseKeyword(line, partsNoOpt[0]);
+ if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized line '"
+ + line + "' in server descriptor.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
}
diff --git a/src/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/org/torproject/descriptor/impl/TorperfResultImpl.java
index aad8e32..26e0e4a 100644
--- a/src/org/torproject/descriptor/impl/TorperfResultImpl.java
+++ b/src/org/torproject/descriptor/impl/TorperfResultImpl.java
@@ -79,60 +79,85 @@ public class TorperfResultImpl extends DescriptorImpl
String key = keyValueParts[0];
this.markKeyAsParsed(key, line);
String value = keyValueParts[1];
- if (key.equals("SOURCE")) {
+ switch (key) {
+ case "SOURCE":
this.parseSource(value, keyValue, line);
- } else if (key.equals("FILESIZE")) {
+ break;
+ case "FILESIZE":
this.parseFileSize(value, keyValue, line);
- } else if (key.equals("START")) {
+ break;
+ case "START":
this.parseStart(value, keyValue, line);
- } else if (key.equals("SOCKET")) {
+ break;
+ case "SOCKET":
this.parseSocket(value, keyValue, line);
- } else if (key.equals("CONNECT")) {
+ break;
+ case "CONNECT":
this.parseConnect(value, keyValue, line);
- } else if (key.equals("NEGOTIATE")) {
+ break;
+ case "NEGOTIATE":
this.parseNegotiate(value, keyValue, line);
- } else if (key.equals("REQUEST")) {
+ break;
+ case "REQUEST":
this.parseRequest(value, keyValue, line);
- } else if (key.equals("RESPONSE")) {
+ break;
+ case "RESPONSE":
this.parseResponse(value, keyValue, line);
- } else if (key.equals("DATAREQUEST")) {
+ break;
+ case "DATAREQUEST":
this.parseDataRequest(value, keyValue, line);
- } else if (key.equals("DATARESPONSE")) {
+ break;
+ case "DATARESPONSE":
this.parseDataResponse(value, keyValue, line);
- } else if (key.equals("DATACOMPLETE")) {
+ break;
+ case "DATACOMPLETE":
this.parseDataComplete(value, keyValue, line);
- } else if (key.equals("WRITEBYTES")) {
+ break;
+ case "WRITEBYTES":
this.parseWriteBytes(value, keyValue, line);
- } else if (key.equals("READBYTES")) {
+ break;
+ case "READBYTES":
this.parseReadBytes(value, keyValue, line);
- } else if (key.equals("DIDTIMEOUT")) {
+ break;
+ case "DIDTIMEOUT":
this.parseDidTimeout(value, keyValue, line);
- } else if (key.startsWith("DATAPERC")) {
- this.parseDataPercentile(value, keyValue, line);
- } else if (key.equals("LAUNCH")) {
+ break;
+ case "LAUNCH":
this.parseLaunch(value, keyValue, line);
- } else if (key.equals("USED_AT")) {
+ break;
+ case "USED_AT":
this.parseUsedAt(value, keyValue, line);
- } else if (key.equals("PATH")) {
+ break;
+ case "PATH":
this.parsePath(value, keyValue, line);
- } else if (key.equals("BUILDTIMES")) {
+ break;
+ case "BUILDTIMES":
this.parseBuildTimes(value, keyValue, line);
- } else if (key.equals("TIMEOUT")) {
+ break;
+ case "TIMEOUT":
this.parseTimeout(value, keyValue, line);
- } else if (key.equals("QUANTILE")) {
+ break;
+ case "QUANTILE":
this.parseQuantile(value, keyValue, line);
- } else if (key.equals("CIRC_ID")) {
+ break;
+ case "CIRC_ID":
this.parseCircId(value, keyValue, line);
- } else if (key.equals("USED_BY")) {
+ break;
+ case "USED_BY":
this.parseUsedBy(value, keyValue, line);
- } else if (this.failUnrecognizedDescriptorLines) {
- throw new DescriptorParseException("Unrecognized key '" + key
- + "' in line '" + line + "'.");
- } else {
- if (this.unrecognizedLines == null) {
- this.unrecognizedLines = new ArrayList<>();
+ break;
+ default:
+ if (key.startsWith("DATAPERC")) {
+ this.parseDataPercentile(value, keyValue, line);
+ } else if (this.failUnrecognizedDescriptorLines) {
+ throw new DescriptorParseException("Unrecognized key '" + key
+ + "' in line '" + line + "'.");
+ } else {
+ if (this.unrecognizedLines == null) {
+ this.unrecognizedLines = new ArrayList<>();
+ }
+ this.unrecognizedLines.add(line);
}
- this.unrecognizedLines.add(line);
}
}
this.checkAllRequiredKeysParsed(line);
1
0