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
January 2017
- 22 participants
- 1796 discussions

[torspec/master] Start a new guard-spec.txt as a copy of prop271.
by nickm@torproject.org 31 Jan '17
by nickm@torproject.org 31 Jan '17
31 Jan '17
commit 6fddd69ec0671f1b83294c1a4f15d281368aea86
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Jan 31 12:46:28 2017 -0500
Start a new guard-spec.txt as a copy of prop271.
Remove the old guard section of path-spec, now that guard-spec is
separate.
---
guard-spec.txt | 818 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
path-spec.txt | 123 +--------
2 files changed, 824 insertions(+), 117 deletions(-)
diff --git a/guard-spec.txt b/guard-spec.txt
new file mode 100644
index 0000000..59c66b8
--- /dev/null
+++ b/guard-spec.txt
@@ -0,0 +1,818 @@
+ Tor Guard Specification
+
+ Isis Lovecruft
+ George Kadianakis
+ Ola Bini
+ Nick Mathewson
+
+1. Introduction and motivation
+
+ Tor uses entry guards to prevent an attacker who controls some
+ fraction of the network from observing a fraction of every user's
+ traffic. If users chose their entries and exits uniformly at
+ random from the list of servers every time they build a circuit,
+ then an adversary who had (k/N) of the network would deanonymize
+ F=(k/N)^2 of all circuits... and after a given user had built C
+ circuits, the attacker would see them at least once with
+ probability 1-(1-F)^C. With large C, the attacker would get a
+ sample of every user's traffic with probability 1.
+
+ To prevent this from happening, Tor clients choose a small number
+ of guard nodes (currently 3). These guard nodes are the only
+ nodes that the client will connect to directly. If they are not
+ compromised, the user's paths are not compromised.
+
+ This proposal outlines Tor's current guard selection algorithm,
+ which tries to meet the following goals:
+
+ - Heuristics and algorithms for determining how and which guards
+ are chosen should be kept as simple and easy to understand as
+ possible.
+
+ - Clients in censored regions or who are behind a fascist
+ firewall who connect to the Tor network should not experience
+ any significant disadvantage in terms of reachability or
+ usability.
+
+ - Tor should make a best attempt at discovering the most
+ appropriate behaviour, with as little user input and
+ configuration as possible.
+
+ - Tor clients should discover usable guards without too much
+ delay.
+
+ - Tor clients should resist (to the extent possible) attacks
+ that try to force them onto compromised guards.
+
+
+2. State instances
+
+ In the algorithm below, we describe a set of persistent and
+ non-persistent state variables. These variables should be
+ treated as an object, of which multiple instances can exist.
+
+ In particular, we specify the use of three particular instances:
+
+ A. UseBridges
+
+ If UseBridges is set, then we replace the {GUARDS} set in
+ [Sec:GUARDS] below with the list of list of configured
+ bridges. We maintain a separate persistent instance of
+ {SAMPLED_GUARDS} and {CONFIRMED_GUARDS} and other derived
+ values for the UseBridges case.
+
+ In this case, we impose no upper limit on the sample size.
+
+ B. EntryNodes / ExcludeNodes / Reachable*Addresses /
+ FascistFirewall / ClientUseIPv4=0
+
+ If one of the above options is set, and UseBridges is not,
+ then we compare the fraction of usable guards in the consensus
+ to the total number of guards in the consensus.
+
+ If this fraction is less than {MEANINGFUL_RESTRICTION_FRAC},
+ we use a separate instance of the state.
+
+ (While Tor is running, we do not change back and forth between
+ the separate instance of the state and the default instance
+ unless the fraction of usable guards is 5% higher than, or 5%
+ lower than, {MEANINGFUL_RESTRICTION_FRAC}. This prevents us
+ from flapping back and forth between instances if we happen to
+ hit {MEANINGFUL_RESTRICTION_FRAC} exactly.
+
+ If this fraction is less than {EXTREME_RESTRICTION_FRAC}, we use a
+ separate instance of the state, and warn the user.
+
+ [TODO: should we have a different instance for each set of heavily
+ restricted options?]
+
+ C. Default
+
+ If neither of the above variant-state instances is used,
+ we use a default instance.
+
+3. Circuit Creation, Entry Guard Selection (1000 foot view)
+
+ A circuit in Tor is a path through the network connecting a client to
+ its destination. At a high-level, a three-hop exit circuit will look
+ like this:
+
+ Client <-> Entry Guard <-> Middle Node <-> Exit Node <-> Destination
+
+ Entry guards are the only nodes which a client will connect to
+ directly, Exit relays are the nodes by which traffic exists the
+ Tor network in order to connect to an external destination.
+
+ 3.1 Path selection
+
+ For any circuit, at least one entry guard and middle node(s) are
+ required. An exit node is required if traffic will exit the Tor
+ network. Depending on its configuration, a relay listed in a
+ consensus could be used for any of these roles. However, this
+ proposal defines how entry guards specifically should be selected and
+ managed, as opposed to middle or exit nodes.
+
+ 3.1.1 Entry guard selection
+
+ At a high level, a relay listed in a consensus will move through the
+ following states in the process from initial selection to eventual
+ usage as an entry guard:
+
+ relays listed in consensus
+ |
+ sampled
+ | |
+ confirmed filtered
+ | | |
+ primary usable_filtered
+
+ Relays listed in the latest consensus can be sampled for guard usage
+ if they have the "Guard" flag. Sampling is random but weighted by
+ bandwidth.
+
+ Once a path is built and a circuit established using this guard, it
+ is marked as confirmed. Until this point, guards are first sampled
+ and then filtered based on information such as our current
+ configuration (see SAMPLED and FILTERED sections) and later marked as
+ usable_filtered if the guard is not primary but can be reached.
+
+ It is always preferable to use a primary guard when building a new
+ circuit in order to reduce guard churn; only on failure to connect to
+ existing primary guards will new guards be used.
+
+ 3.1.2 Middle and exit node selection
+
+ Middle nodes are selected at random from relays listed in the
+ latest consensus, weighted by bandwidth. Exit nodes are chosen
+ similarly but restricted to relays with an exit policy.
+
+ 3.2 Circuit Building
+
+ Once a path is chosen, Tor will use this path to build a new circuit.
+
+ If the circuit is built successfully, it either can be used
+ immediately or wait for a better guard, depending on whether other
+ circuits already exist with higher-priority guards.
+
+ If at any point the circuit fails, the guard is marked as
+ unreachable, the circuit is closed, and waiting circuits are updated.
+
+4. The algorithm.
+
+4.0. The guards listed in the current consensus. [Section:GUARDS]
+
+ By {set:GUARDS} we mean the set of all guards in the current
+ consensus that are usable for all circuits and directory
+ requests. (They must have the flags: Stable, Fast, V2Dir, Guard.)
+
+ **Rationale**
+
+ We require all guards to have the flags that we potentially need
+ from any guard, so that all guards are usable for all circuits.
+
+4.1. The Sampled Guard Set. [Section:SAMPLED]
+
+ We maintain a set, {set:SAMPLED_GUARDS}, that persists across
+ invocations of Tor. It is an unordered subset of the nodes that
+ we have seen listed as a guard in the consensus at some point.
+ For each such guard, we record persistently:
+
+ - {pvar:ADDED_ON_DATE}: The date on which it was added to
+ sampled_guards.
+
+ We base this value on RAND(now, {GUARD_LIFETIME}/10). See
+ Appendix [RANDOM] below.
+
+ - {pvar:ADDED_BY_VERSION}: The version of Tor that added it to
+ sampled_guards.
+
+ - {pvar:IS_LISTED}: Whether it was listed as a usable Guard in
+ the _most recent_ consensus we have seen.
+
+ - {pvar:FIRST_UNLISTED_AT}: If IS_LISTED is false, the publication date
+ of the earliest consensus in which this guard was listed such that we
+ have not seen it listed in any later consensus. Otherwise "None."
+ We randomize this, based on
+ RAND(added_at_time, {REMOVE_UNLISTED_GUARDS_AFTER} / 5)
+
+ For each guard in {SAMPLED_GUARDS}, we also record this data,
+ non-persistently:
+
+ - {tvar:last_tried_connect}: A 'last tried to connect at'
+ time. Default 'never'.
+
+ - {tvar:is_reachable}: an "is reachable" tristate, with
+ possible values { <state:yes>, <state:no>, <state:maybe> }.
+ Default '<maybe>.'
+
+ [Note: "yes" is not strictly necessary, but I'm
+ making it distinct from "maybe" anyway, to make our
+ logic clearer. A guard is "maybe" reachable if it's
+ worth trying. A guard is "yes" reachable if we tried
+ it and succeeded.]
+
+ - {tvar:failing_since}: The first time when we failed to
+ connect to this guard. Defaults to "never". Reset to
+ "never" when we successfully connect to this guard.
+
+ - {tvar:is_pending} A "pending" flag. This indicates that we
+ are trying to build an exploratory circuit through the
+ guard, and we don't know whether it will succeed.
+
+ We require that {SAMPLED_GUARDS} contain at least
+ {MIN_FILTERED_SAMPLE} guards from the consensus (if possible),
+ but not more than {MAX_SAMPLE_THRESHOLD} of the number of guards
+ in the consensus, and not more then {MAX_SAMPLE_SIZE} in total.
+ (But if the maximum would be smaller than {MIN_FILTERED_SAMPLE}, we
+ set the maximum at {MIN_FILTERED_SAMPLE}.)
+
+ To add a new guard to {SAMPLED_GUARDS}, pick an entry at random
+ from ({GUARDS} - {SAMPLED_GUARDS}), weighted by bandwidth.
+
+ We remove an entry from {SAMPLED_GUARDS} if:
+
+ * We have a live consensus, and {IS_LISTED} is false, and
+ {FIRST_UNLISTED_AT} is over {REMOVE_UNLISTED_GUARDS_AFTER}
+ days in the past.
+
+ OR
+
+ * We have a live consensus, and {ADDED_ON_DATE} is over
+ {GUARD_LIFETIME} ago, *and* {CONFIRMED_ON_DATE} is either
+ "never", or over {GUARD_CONFIRMED_MIN_LIFETIME} ago.
+
+ Note that {SAMPLED_GUARDS} does not depend on our configuration.
+ It is possible that we can't actually connect to any of these
+ guards.
+
+ **Rationale**
+
+ The {SAMPLED_GUARDS} set is meant to limit the total number of
+ guards that a client will connect to in a given period. The
+ upper limit on its size prevents us from considering too many
+ guards.
+
+ The first expiration mechanism is there so that our
+ {SAMPLED_GUARDS} list does not accumulate so many dead
+ guards that we cannot add new ones.
+
+ The second expiration mechanism makes us rotate our guards slowly
+ over time.
+
+
+4.2. The Usable Sample [Section:FILTERED]
+
+ We maintain another set, {set:FILTERED_GUARDS}, that does not
+ persist. It is derived from:
+ - {SAMPLED_GUARDS}
+ - our current configuration,
+ - the path bias information.
+
+ A guard is a member of {set:FILTERED_GUARDS} if and only if all
+ of the following are true:
+
+ - It is a member of {SAMPLED_GUARDS}, with {IS_LISTED} set to
+ true.
+ - It is not disabled because of path bias issues.
+ - It is not disabled because of ReachableAddress police,
+ the ClientUseIPv4 setting, the ClientUseIPv6 setting,
+ the FascistFirewall setting, or some other
+ option that prevents using some addresses.
+ - It is not disabled because of ExcludeNodes.
+ - It is a bridge if UseBridges is true; or it is not a
+ bridge if UseBridges is false.
+ - Is included in EntryNodes if EntryNodes is set and
+ UseBridges is not. (But see 2.B above).
+
+ We have an additional subset, {set:USABLE_FILTERED_GUARDS}, which
+ is defined to be the subset of {FILTERED_GUARDS} where
+ {is_reachable} is <yes> or <maybe>.
+
+ We try to maintain a requirement that {USABLE_FILTERED_GUARDS}
+ contain at least {MIN_FILTERED_SAMPLE} elements:
+
+ Whenever we are going to sample from {USABLE_FILTERED_GUARDS},
+ and it contains fewer than {MIN_FILTERED_SAMPLE} elements, we
+ add new elements to {SAMPLED_GUARDS} until one of the following
+ is true:
+
+ * {USABLE_FILTERED_GUARDS} is large enough,
+ OR
+ * {SAMPLED_GUARDS} is at its maximum size.
+
+
+ ** Rationale **
+
+ These filters are applied _after_ sampling: if we applied them
+ before the sampling, then our sample would reflect the set of
+ filtering restrictions that we had in the past.
+
+4.3. The confirmed-guard list. [Section:CONFIRMED]
+
+ [formerly USED_GUARDS]
+
+ We maintain a persistent ordered list, {list:CONFIRMED_GUARDS}.
+ It contains guards that we have used before, in our preference
+ order of using them. It is a subset of {SAMPLED_GUARDS}. For
+ each guard in this list, we store persistently:
+
+ - {pvar:IDENTITY} Its fingerprint
+
+ - {pvar:CONFIRMED_ON_DATE} When we added this guard to
+ {CONFIRMED_GUARDS}.
+
+ Randomized as RAND(now, {GUARD_LIFETIME}/10).
+
+ We add new members to {CONFIRMED_GUARDS} when we mark a circuit
+ built through a guard as "for user traffic."
+
+ Whenever we remove a member from {SAMPLED_GUARDS}, we also remove
+ it from {CONFIRMED_GUARDS}.
+
+ [Note: You can also regard the {CONFIRMED_GUARDS} list as a
+ total ordering defined over a subset of {SAMPLED_GUARDS}.]
+
+ Definition: we call Guard A "higher priority" than another Guard B
+ if, when A and B are both reachable, we would rather use A. We
+ define priority as follows:
+
+ * Every guard in {CONFIRMED_GUARDS} has a higher priority
+ than every guard not in {CONFIRMED_GUARDS}.
+
+ * Among guards in {CONFIRMED_GUARDS}, the one appearing earlier
+ on the {CONFIRMED_GUARDS} list has a higher priority.
+
+ * Among guards that do not appear in {CONFIRMED_GUARDS},
+ {is_pending}==true guards have higher priority.
+
+ * Among those, the guard with earlier {last_tried_connect} time
+ have higher priority.
+
+ * Finally, among guards that do not appear in
+ {CONFIRMED_GUARDS} with {is_pending==false}, all have equal
+ priority.
+
+ ** Rationale **
+
+ We add elements to this ordering when we have actually used them
+ for building a usable circuit. We could mark them at some other
+ time (such as when we attempt to connect to them, or when we
+ actually connect to them), but this approach keeps us from
+ committing to a guard before we actually use it for sensitive
+ traffic.
+
+4.4. The Primary guards [Section:PRIMARY]
+
+ We keep a run-time non-persistent ordered list of
+ {list:PRIMARY_GUARDS}. It is a subset of {FILTERED_GUARDS}. It
+ contains {N_PRIMARY_GUARDS} elements.
+
+ To compute primary guards, take the ordered intersection of
+ {CONFIRMED_GUARDS} and {FILTERED_GUARDS}, and take the first
+ {N_PRIMARY_GUARDS} elements. If there are fewer than
+ {N_PRIMARY_GUARDS} elements, add additional elements to
+ PRIMARY_GUARDS chosen _uniformly_ at random from
+ ({FILTERED_GUARDS} - {CONFIRMED_GUARDS}).
+
+ Once an element has been added to {PRIMARY_GUARDS}, we do not remove it
+ until it is replaced by some element from {CONFIRMED_GUARDS}. Confirmed
+ elements always proceed unconfirmed ones in the {PRIMARY_GUARDS} list.
+
+ Note that {PRIMARY_GUARDS} do not have to be in
+ {USABLE_FILTERED_GUARDS}: they might be unreachable.
+
+ ** Rationale **
+
+ These guards are treated differently from other guards. If one of
+ them is usable, then we use it right away. For other guards
+ {FILTERED_GUARDS}, if it's usable, then before using it we might
+ first double-check whether perhaps one of the primary guards is
+ usable after all.
+
+4.5. Retrying guards. [Section:RETRYING]
+
+ (We run this process as frequently as needed. It can be done once
+ a second, or just-in-time.)
+
+ If a primary sampled guard's {is_reachable} status is <no>, then
+ we decide whether to update its {is_reachable} status to <maybe>
+ based on its {last_tried_connect} time, its {failing_since} time,
+ and the {PRIMARY_GUARDS_RETRY_SCHED} schedule.
+
+ If a non-primary sampled guard's {is_reachable} status is <no>, then
+ we decide whether to update its {is_reachable} status to <maybe>
+ based on its {last_tried_connect} time, its {failing_since} time,
+ and the {GUARDS_RETRY_SCHED} schedule.
+
+ ** Rationale **
+
+ An observation that a guard has been 'unreachable' only lasts for
+ a given amount of time, since we can't infer that it's unreachable
+ now from the fact that it was unreachable a few minutes ago.
+
+4.6. Selecting guards for circuits. [Section:SELECTING]
+
+ Every origin circuit is now in one of these states:
+ <state:usable_on_completion>,
+ <state:usable_if_no_better_guard>,
+ <state:waiting_for_better_guard>, or
+ <state:complete>.
+
+ You may only attach streams to <complete> circuits.
+ (Additionally, you may only send RENDEZVOUS cells, ESTABLISH_INTRO
+ cells, and INTRODUCE cells on <complete> circuits.)
+
+ The per-circuit state machine is:
+
+ New circuits are <usable_on_completion> or
+ <usable_if_no_better_guard>.
+
+ A <usable_on_completion> circuit may become <complete>, or may
+ fail.
+
+ A <usable_if_no_better_guard> circuit may become
+ <usable_on_completion>; may become <waiting_for_better_guard>; or may
+ fail.
+
+ A <waiting_for_better_guard> circuit will become <complete>, or will
+ be closed, or will fail.
+
+ A <complete> circuit remains <complete> until it fails or is
+ closed.
+
+ Each of these transitions is described below.
+
+ We keep, as global transient state:
+
+ * {tvar:last_time_on_internet} -- the last time at which we
+ successfully used a circuit or connected to a guard. At
+ startup we set this to "infinitely far in the past."
+
+ When we want to build a circuit, and we need to pick a guard:
+
+ * If any entry in PRIMARY_GUARDS has {is_reachable} status of
+ <maybe> or <yes>, return the first such guard. The circuit is
+ <usable_on_completion>.
+
+ [Note: We do not use {is_pending} on primary guards, since we
+ are willing to try to build multiple circuits through them
+ before we know for sure whether they work, and since we will
+ not use any non-primary guards until we are sure that the
+ primary guards are all down. (XX is this good?)]
+
+ * Otherwise, if the ordered intersection of {CONFIRMED_GUARDS}
+ and {USABLE_FILTERED_GUARDS} is nonempty, return the first
+ entry in that intersection that has {is_pending} set to
+ false. Set its value of {is_pending} to true. The circuit
+ is now <usable_if_no_better_guard>. (If all entries have
+ {is_pending} true, pick the first one.)
+
+ * Otherwise, if there is no such entry, select a member at
+ random from {USABLE_FILTERED_GUARDS}. Set its {is_pending}
+ field to true. The circuit is <usable_if_no_better_guard>.
+
+ We update the {last_tried_connect} time for the guard to 'now.'
+
+ In some cases (for example, when we need a certain directory feature,
+ or when we need to avoid using a certain exit as a guard), we need to
+ restrict the guards that we use for a single circuit. When this happens, we
+ remember the restrictions that applied when choosing the guard for
+ that circuit, since we will need them later (see [UPDATE_WAITING].).
+
+ ** Rationale **
+
+ We're getting to the core of the algorithm here. Our main goals are to
+ make sure that
+ 1. If it's possible to use a primary guard, we do.
+ 2. We probably use the first primary guard.
+
+ So we only try non-primary guards if we're pretty sure that all
+ the primary guards are down, and we only try a given primary guard
+ if the earlier primary guards seem down.
+
+ When we _do_ try non-primary guards, however, we only build one
+ circuit through each, to give it a chance to succeed or fail. If
+ ever such a circuit succeeds, we don't use it until we're pretty
+ sure that it's the best guard we're getting. (see below).
+
+ [XXX timeout.]
+
+4.7. When a circuit fails. [Section:ON_FAIL]
+
+ When a circuit fails in a way that makes us conclude that a guard
+ is not reachable, we take the following steps:
+
+ * We set the guard's {is_reachable} status to <no>. If it had
+ {is_pending} set to true, we make it non-pending.
+
+ * We close the circuit, of course. (This removes it from
+ consideration by the algorithm in [UPDATE_WAITING].)
+
+ * Update the list of waiting circuits. (See [UPDATE_WAITING]
+ below.)
+
+ [Note: the existing Tor logic will cause us to create more
+ circuits in response to some of these steps; and also see
+ [ON_CONSENSUS].]
+
+ ** Rationale **
+
+ See [SELECTING] above for rationale.
+
+4.8. When a circuit succeeds [Section:ON_SUCCESS]
+
+ When a circuit succeeds in a way that makes us conclude that a
+ guard _was_ reachable, we take these steps:
+
+ * We set its {is_reachable} status to <yes>.
+ * We set its {failing_since} to "never".
+ * If the guard was {is_pending}, we clear the {is_pending} flag.
+ * If the guard was not a member of {CONFIRMED_GUARDS}, we add
+ it to the end of {CONFIRMED_GUARDS}.
+
+ * If this circuit was <usable_on_completion>, this circuit is
+ now <complete>. You may attach streams to this circuit,
+ and use it for hidden services.
+
+ * If this circuit was <usable_if_no_better_guard>, it is now
+ <waiting_for retry>. You may not yet attach streams to it.
+ Then check whether the {last_time_on_internet} is more than
+ {INTERNET_LIKELY_DOWN_INTERVAL} seconds ago:
+
+ * If it is, then mark all {PRIMARY_GUARDS} as "maybe"
+ reachable.
+
+ * If it is not, update the list of waiting circuits. (See
+ [UPDATE_WAITING] below)
+
+ [Note: the existing Tor logic will cause us to create more
+ circuits in response to some of these steps; and see
+ [ON_CONSENSUS].]
+
+ ** Rationale **
+
+ See [SELECTING] above for rationale.
+
+4.9. Updating the list of waiting circuits [Section:UPDATE_WAITING]
+
+ We run this procedure whenever it's possible that a
+ <waiting_for_better_guard> circuit might be ready to be called
+ <complete>.
+
+ * If any circuit C1 is <waiting_for_better_guard>, AND:
+ * All primary guards have reachable status of <no>.
+ * There is no circuit C2 that "blocks" C1.
+ Then, upgrade C1 to <complete>.
+
+ Definition: In the algorithm above, C2 "blocks" C1 if:
+ * C2 obeys all the restrictions that C1 had to obey, AND
+ * C2 has higher priority than C1, AND
+ * Either C2 is <complete>, or C2 is <waiting_for_better_guard>,
+ or C2 has been <usable_if_no_better_guard> for no more than
+ {NONPRIMARY_GUARD_CONNECT_TIMEOUT} seconds.
+
+ We run this procedure periodically:
+
+ * If any circuit stays is <waiting_for_better_guard>
+ for more than {NONPRIMARY_GUARD_IDLE_TIMEOUT} seconds,
+ time it out.
+
+ **Rationale**
+
+ If we open a connection to a guard, we might want to use it
+ immediately (if we're sure that it's the best we can do), or we
+ might want to wait a little while to see if some other circuit
+ which we like better will finish.
+
+
+ When we mark a circuit <complete>, we don't close the
+ lower-priority circuits immediately: we might decide to use
+ them after all if the <complete> circuit goes down before
+ {NONPRIMARY_GUARD_IDLE_TIMEOUT} seconds.
+
+4.10. Whenever we get a new consensus. [Section:ON_CONSENSUS]
+
+ We update {GUARDS}.
+
+ For every guard in {SAMPLED_GUARDS}, we update {IS_LISTED} and
+ {FIRST_UNLISTED_AT}.
+
+ [**] We remove entries from {SAMPLED_GUARDS} if appropriate,
+ according to the sampled-guards expiration rules. If they were
+ in {CONFIRMED_GUARDS}, we also remove them from
+ {CONFIRMED_GUARDS}.
+
+ We recompute {FILTERED_GUARDS}, and everything that derives from
+ it, including {USABLE_FILTERED_GUARDS}, and {PRIMARY_GUARDS}.
+
+ (Whenever one of the configuration options that affects the
+ filter is updated, we repeat the process above, starting at the
+ [**] line.)
+
+4.11. Deciding whether to generate a new circuit.
+ [Section:NEW_CIRCUIT_NEEDED]
+
+ In current Tor, we generate a new circuit when we don't have
+ enough circuits either built or in-progress to handle a given
+ stream, or an expected stream.
+
+ For the purpose of this rule, we say that <waiting_for_better_guard>
+ circuits are neither built nor in-progress; that <complete>
+ circuits are built; and that the other states are in-progress.
+
+A. Appendices
+
+A.1. Parameters with suggested values. [Section:PARAM_VALS]
+
+ (All suggested values chosen arbitrarily)
+
+ {param:MAX_SAMPLE_THRESHOLD} -- 20%
+
+ {param:MAX_SAMPLE_SIZE} -- 60
+
+ {param:GUARD_LIFETIME} -- 120 days
+
+ {param:REMOVE_UNLISTED_GUARDS_AFTER} -- 20 days
+ [previously ENTRY_GUARD_REMOVE_AFTER]
+
+ {param:MIN_FILTERED_SAMPLE} -- 20
+
+ {param:N_PRIMARY_GUARDS} -- 3
+
+ {param:PRIMARY_GUARDS_RETRY_SCHED}
+ -- every 30 minutes for the first 6 hours.
+ -- every 2 hours for the next 3.75 days.
+ -- every 4 hours for the next 3 days.
+ -- every 9 hours thereafter.
+
+ {param:GUARDS_RETRY_SCHED} -- 1 hour
+ -- every hour for the first 6 hours.
+ -- every 4 hours for the next 3.75 days.
+ -- every 18 hours for the next 3 days.
+ -- every 36 hours thereafter.
+
+ {param:INTERNET_LIKELY_DOWN_INTERVAL} -- 10 minutes
+
+ {param:NONPRIMARY_GUARD_CONNECT_TIMEOUT} -- 15 seconds
+
+ {param:NONPRIMARY_GUARD_IDLE_TIMEOUT} -- 10 minutes
+
+ {param:MEANINGFUL_RESTRICTION_FRAC} -- .2
+
+ {param:EXTREME_RESTRICTION_FRAC} -- .01
+
+ {param:GUARD_CONFIRMED_MIN_LIFETIME} -- 60 days
+
+A.2. Random values [Section:RANDOM]
+
+ Frequently, we want to randomize the expiration time of something
+ so that it's not easy for an observer to match it to its start
+ time. We do this by randomizing its start date a little, so that
+ we only need to remember a fixed expiration interval.
+
+ By RAND(now, INTERVAL) we mean a time between now and INTERVAL in
+ the past, chosen uniformly at random.
+
+
+A.3. Why not a sliding scale of primaryness? [Section:CVP]
+
+ At one meeting, I floated the idea of having "primaryness" be a
+ continuous variable rather than a boolean.
+
+ I'm no longer sure this is a great idea, but I'll try to outline
+ how it might work.
+
+ To begin with: being "primary" gives it a few different traits:
+
+ 1) We retry primary guards more frequently. [Section:RETRYING]
+
+ 2) We don't even _try_ building circuits through
+ lower-priority guards until we're pretty sure that the
+ higher-priority primary guards are down. (With non-primary
+ guards, on the other hand, we launch exploratory circuits
+ which we plan not to use if higher-priority guards
+ succeed.) [Section:SELECTING]
+
+ 3) We retry them all one more time if a circuit succeeds after
+ the net has been down for a while. [Section:ON_SUCCESS]
+
+ We could make each of the above traits continuous:
+
+ 1) We could make the interval at which a guard is retried
+ depend continuously on its position in CONFIRMED_GUARDS.
+
+ 2) We could change the number of guards we test in parallel
+ based on their position in CONFIRMED_GUARDS.
+
+ 3) We could change the rule for how long the higher-priority
+ guards need to have been down before we call a
+ <usable_if_no_better_guard> circuit <complete> based on a
+ possible network-down condition. For example, we could
+ retry the first guard if we tried it more than 10 seconds
+ ago, the second if we tried it more than 20 seconds ago,
+ etc.
+
+ I am pretty sure, however, that if these are worth doing, they
+ need more analysis! Here's why:
+
+ * They all have the potential to leak more information about a
+ guard's exact position on the list. Is that safe? Is there
+ any way to exploit that? I don't think we know.
+
+ * They all seem like changes which it would be relatively
+ simple to make to the code after we implement the simpler
+ version of the algorithm described above.
+
+A.3. Controller changes
+
+ We will add to control-spec.txt a new possible circuit state, GUARD_WAIT,
+ that can be given as part of circuit events and GETINFO responses about
+ circuits. A circuit is in the GUARD_WAIT state when it is fully built,
+ but we will not use it because a circuit with a better guard might
+ become built too.
+
+A.4. Persistent state format
+
+ The persistent state format doesn't need to be part of this
+ proposal, since different implementations can do it
+ differently. Nonetheless, here's the one Tor uses:
+
+ The "state" file contains one Guard entry for each sampled guard
+ in each instance of the guard state (see section 2). The value
+ of this Guard entry is a set of space-separated K=V entries,
+ where K contains any nonspace character except =, and V contains
+ any nonspace characters.
+
+ Implementations must retain any unrecognized K=V entries for a
+ sampled guard when the regenerate the state file.
+
+ The order of K=V entries is not allowed to matter.
+
+ Recognized fields (values of K) are:
+
+ "in" -- the name of the guard state instance that this
+ sampled guard is in. If a sampled guard is in two guard
+ states instances, it appears twice, with a different "in"
+ field each time. Required.
+
+ "rsa_id" -- the RSA id digest for this guard, encoded in
+ hex. Required.
+
+ "bridge_addr" -- If the guard is a bridge, its configured
+ address and OR port. Optional.
+
+ "nickname" -- the guard's nickname, if any. Optional.
+
+ "sampled_on" -- the date when the guard was sampled. Required.
+
+ "sampled_by" -- the Tor version that sampled this guard.
+ Optional.
+
+ "unlisted_since" -- the date since which the guard has been
+ unlisted. Optional.
+
+ "listed" -- 0 if the guard is not listed ; 1 if it is. Required.
+
+ "confirmed_on" -- date when the guard was
+ confirmed. Optional.
+
+ "confirmed_idx" -- position of the guard in the confirmed
+ list. Optional.
+
+ "pb_use_attempts", "pb_use_successes", "pb_circ_attempts",
+ "pb_circ_successes", "pb_successful_circuits_closed",
+ "pb_collapsed_circuits", "pb_unusable_circuits",
+ "pb_timeouts" -- state for the circuit path bias algorithm,
+ given in decimal fractions. Optional.
+
+ All dates here are given as a (spaceless) ISO8601 combined date
+ and time in UTC (e.g., 2016-11-29T19:39:31).
+
+
+TODO. Still non-addressed issues [Section:TODO]
+
+ Simulate to answer: Will this work in a dystopic world?
+
+ Simulate actual behavior.
+
+ For all lifetimes: instead of storing the "this began at" time,
+ store the "remove this at" time, slightly randomized.
+
+ Clarify that when you get a <complete> circuit, you might need to
+ relaunch circuits through that same guard immediately, if they
+ are circuits that have to be independent.
+
+
+ Fix all items marked XX or TODO.
+
+ "Directory guards" -- do they matter?
+
+ Suggestion: require that all guards support downloads via BEGINDIR.
+ We don't need to worry about directory guards for relays, since we
+ aren't trying to prevent relay enumeration.
+
+ IP version preferenes via ClientPreferIPv6ORPort
+
+ Suggestion: Treat it as a preference when adding to
+ {CONFIRMED_GUARDS}, but not otherwise.
+
diff --git a/path-spec.txt b/path-spec.txt
index 47dae3b..ceb6c77 100644
--- a/path-spec.txt
+++ b/path-spec.txt
@@ -554,123 +554,12 @@ of their choices.
5. Guard nodes
- We use Guard nodes (also called "helper nodes" in the literature) to
- prevent certain profiling attacks. Here's the risk: if we choose entry and
- exit nodes at random, and an attacker controls C out of N relays
- (ignoring bandwidth), then the
- attacker will control the entry and exit node of any given circuit with
- probability (C/N)^2. But as we make many different circuits over time,
- then the probability that the attacker will see a sample of about (C/N)^2
- of our traffic goes to 1. Since statistical sampling works, the attacker
- can be sure of learning a profile of our behavior.
-
- If, on the other hand, we picked an entry node and held it fixed, we would
- have probability C/N of choosing a bad entry and being profiled, and
- probability (N-C)/N of choosing a good entry and not being profiled.
-
- When guard nodes are enabled, Tor maintains an ordered list of entry nodes
- as our chosen guards, and stores this list persistently to disk. If a Guard
- node becomes unusable, rather than replacing it, Tor adds new guards to the
- end of the list. When choosing the first hop of a circuit, Tor
- chooses at
- random from among the first NumEntryGuards (default 3) usable guards on the
- list. If there are not at least 2 usable guards on the list, Tor adds
- routers until there are, or until there are no more usable routers to add.
-
- A guard is unusable if any of the following hold:
- - it is not marked as a Guard by the networkstatuses,
- - it is not marked Valid (and the user hasn't set AllowInvalid entry)
- - it is not marked Running
- - Tor couldn't reach it the last time it tried to connect
-
- A guard is unusable for a particular circuit if any of the rules for path
- selection in 2.2 are not met. In particular, if the circuit is "fast"
- and the guard is not Fast, or if the circuit is "stable" and the guard is
- not Stable, or if the guard has already been chosen as the exit node in
- that circuit, Tor can't use it as a guard node for that circuit.
-
- If the guard is excluded because of its status in the networkstatuses for
- over 30 days, Tor removes it from the list entirely, preserving order.
-
- If Tor fails to connect to an otherwise usable guard, it retries
- periodically: every hour for six hours, every 4 hours for 3 days, every
- 18 hours for a week, and every 36 hours thereafter. Additionally, Tor
- retries unreachable guards the first time it adds a new guard to the list,
- since it is possible that the old guards were only marked as unreachable
- because the network was unreachable or down.
-
- Tor does not add a guard persistently to the list until the first time we
- have connected to it successfully.
-
-5.1. Guard selection algorithm
-
- If configured to use entry guards, and the circuit's purpose is not marked
- for testing, then a random entry guard from the persisted state (as
- mentioned earlier in §5) will be chosen (provided there is already some
- persisted state storing previously chosen guard nodes).
-
- Otherwise, if any the above conditions are not satisfied, then a new entry
- guard node will be chosen for that circuit. The algorithm is as follows:
-
- - EXCLUDED_NODES is a list of nodes which, for some reason, are not
- acceptable for use as an entry guard.
-
- 1. If an exit node has been chosen for the circuit:
-
- 1.a. Then that exit is added to EXCLUDED_NODES (and thus will not be
- used as the entry guard).
-
- 2. If running behind a fascist firewall (e.g. outgoing connections are
- only permitted to ports 80 and/or 443):
-
- 2.a. For all known routers in the network (as given in the
- networkstatus document), a router is added to the list of
- EXCLUDED_NODES iff it does not advertise the ability to be reached
- via the ports allowed through the fascist firewall.
-
- 3. Add any entry guards currently in volatile storage, as well as all
- nodes within their families, to EXCLUDED_NODES.
-
- 4. Determine which of the following flags should apply to the selection of
- an entry guard:
-
- * CRN_NEED_UPTIME: the router can only be chosen as an entry guard
- iff has been available for at least some minimum uptime.
- * CRN_NEED_CAPACITY: potentially suitable routers are weighted by
- their advertised bandwidth capacity.
- * CRN_ALLOW_INVALID: also consider using routers which have been
- marked as invalid.
- * CRN_NEED_GUARD: only consider routers which have the Guard flag.
- * CRN_NEED_DESC: only consider routers for which we have enough
- information to be used to build a circuit.
-
- Additionally, if configured to allow nodes marked as invalid AND to
- specifically allow entry guards which have been marked as invalid, then
- the CRN_ALLOW_INVALID flag will be set. Lastly, the CRN_NEED_GUARD and
- CRN_NEED_DESC flags are always applied, regardless of configuration.
-
- 5. If configured to exclude routers which allow single-hop circuits, then
- the list of known routers is traversed, and all routers which permit
- single-hop circuits are added to EXCLUDED_NODES.
-
- 6. If we are an OR, add ourselves (and our family) to EXCLUDED_NODES.
-
- 7. The list of potential routers is weighted according to the bandwidth
- weights from the consensus (cf. §5.1.1), and then a random selection is
- chosen with respect to those weights.
-
- 7.a. If we've made a choice now, the algorithm finishes.
- 7.b. Otherwise, continue to step #8.
-
- 8. We couldn't find a suitable guard, so now we try much harder by
- discarding the CRN_NEED_UPTIME, CRN_NEED_CAPACITY, and CRN_NEED_GUARD
- selection flags. This effectively means we'll use nearly any router,
- except for ones already in EXCLUDED_LIST.
-
- [XXX Does this mean we even include BadExits and other misbehaving
- nodes? This sounds bad. —isis]
-
-5.1.1. How consensus bandwidth weights factor into entry guard selection
+ We use Guard nodes (also called "helper nodes" in the research
+ literature) to prevent certain profiling attacks. For an overview of
+ our Guard selection algorithm -- which has grown rather complex -- see
+ guard-spec.txt.
+
+5.1. How consensus bandwidth weights factor into entry guard selection
When weighting a list of routers for choosing an entry guard, the following
consensus parameters (from the "bandwidth-weights" line) apply:
1
0
commit cd3dea88f2c4fd5226d284816200d87ce7e734ee
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Jan 31 12:47:32 2017 -0500
Mark proposal 271 as closed
---
proposals/000-index.txt | 4 ++--
proposals/271-another-guard-selection.txt | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/proposals/000-index.txt b/proposals/000-index.txt
index 6eb4e4f..4e400c8 100644
--- a/proposals/000-index.txt
+++ b/proposals/000-index.txt
@@ -191,7 +191,7 @@ Proposals by number:
268 New Guard Selection Behaviour [OBSOLETE]
269 Transitionally secure hybrid handshakes [DRAFT]
270 RebelAlliance: A Post-Quantum Secure Hybrid Handshake Based on NewHope [DRAFT]
-271 Another algorithm for guard selection [FINISHED]
+271 Another algorithm for guard selection [CLOSED]
272 Listed routers should be Valid, Running, and treated as such [FINISHED]
273 Exit relay pinning for web services [DRAFT]
@@ -278,7 +278,6 @@ Proposals by status:
232 Pluggable Transport through SOCKS proxy [in 0.2.6]
235 Stop assigning (and eventually supporting) the Named flag [in 0.2.6, 0.2.7]
260 Rendezvous Single Onion Services
- 271 Another algorithm for guard selection [in 0.3.0.1-alpha]
272 Listed routers should be Valid, Running, and treated as such [in 0.2.9.3-alpha, 0.2.9.4-alpha]
CLOSED:
101 Voting on the Tor Directory System [in 0.2.0.x]
@@ -342,6 +341,7 @@ Proposals by status:
243 Give out HSDir flag only to relays with Stable flag
250 Random Number Generation During Tor Voting
264 Putting version numbers on the Tor subprotocols [in 0.2.9.4-alpha]
+ 271 Another algorithm for guard selection [in 0.3.0.1-alpha]
SUPERSEDED:
112 Bring Back Pathlen Coin Weight
113 Simplifying directory authority administration
diff --git a/proposals/271-another-guard-selection.txt b/proposals/271-another-guard-selection.txt
index b606cc2..f03a7c3 100644
--- a/proposals/271-another-guard-selection.txt
+++ b/proposals/271-another-guard-selection.txt
@@ -3,7 +3,7 @@ Title: Another algorithm for guard selection
Author: Isis Lovecruft, George Kadianakis, Ola Bini, Nick Mathewson
Created: 2016-07-11
Supersedes: 259, 268
-Status: Finished
+Status: Closed
Implemented-In: 0.3.0.1-alpha
0.0. Preliminaries
1
0

31 Jan '17
commit d7bdb1ecaa137d0bdb38b5731c7e5b1a7469728b
Author: Damian Johnson <atagar(a)torproject.org>
Date: Tue Jan 31 09:10:19 2017 -0800
Don't rely on order for test_setconf_event test
With the recent tor push our test_setconf_event fails for me. This is because
our test expected CONF_CHANGED events to come before the SETCONF 'OK' response.
Changing our test to accept either ordering.
---
test/integ/socket/control_message.py | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py
index b873a59..47f77c1 100644
--- a/test/integ/socket/control_message.py
+++ b/test/integ/socket/control_message.py
@@ -159,13 +159,20 @@ class TestControlMessage(unittest.TestCase):
self.assertEqual('250 OK\r\n', setevents_response.raw_content())
self.assertEqual([('250', ' ', 'OK')], setevents_response.content())
- # CONF_CHANGED event will come before the SETCONF 'OK' response
+ # We'll receive both a CONF_CHANGED event and 'OK' response for the
+ # SETCONF, but not necessarily in any specific order.
control_socket.send('SETCONF NodeFamily=%s' % test.mocking.random_fingerprint())
+ msg1 = control_socket.recv()
+ msg2 = control_socket.recv()
+
+ if msg1.content()[0][0] == 650:
+ conf_changed_event, setconf_response = msg1, msg2
+ else:
+ setconf_response, conf_changed_event = msg1, msg2
- conf_changed_event = control_socket.recv()
self.assertTrue(re.match('CONF_CHANGED\nNodeFamily=.*', str(conf_changed_event)))
self.assertTrue(re.match('650-CONF_CHANGED\r\n650-NodeFamily=.*\r\n650 OK', conf_changed_event.raw_content()))
self.assertEqual(('650', '-'), conf_changed_event.content()[0][:2])
- self.assertEqual([('250', ' ', 'OK')], control_socket.recv().content())
+ self.assertEqual([('250', ' ', 'OK')], setconf_response.content())
1
0
commit 1f5eec9375320854904e1bf8360fac828823605c
Author: Damian Johnson <atagar(a)torproject.org>
Date: Tue Jan 31 08:52:35 2017 -0800
Add Ahmia project idea
GSoC project idea from Juha Nurmi.
---
getinvolved/en/volunteer.wml | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/getinvolved/en/volunteer.wml b/getinvolved/en/volunteer.wml
index 37f6879..64b30b1 100644
--- a/getinvolved/en/volunteer.wml
+++ b/getinvolved/en/volunteer.wml
@@ -1114,6 +1114,68 @@ ideas.
</p>
</li>
+ <a id="ahmiaSearch"></a>
+ <li>
+ <b>Ahmia - Hidden Service Search</b>
+ <br>
+ Language: <i>Python, Django</i>
+ <br>
+ Likely Mentors: <i>Juha Nurmi (numes), George (asn)</i>
+ <p>
+ Ahmia is open-source search engine software for Tor hidden service deep
+ dark web sites. You can test the running search engine at ahmia.fi. For
+ more information see our <a
+ href="https://blog.torproject.org/category/tags/ahmiafi">blog post about
+ Ahmia's GSoC2014 development</a>.
+ </p>
+
+ <p>
+ Ahmia is a working search engine that indexes, searches, and catalogs
+ content published on Tor Hidden Services. Furthermore, it is an environment
+ to share meaningful insights, statistics, insights, and news about the Tor
+ network itself. In this context, there is a lot of work to do.
+ </p>
+
+ <p>
+ The Ahmia web service is written using the Django web framework. As a
+ result, the server-side language is Python. On the client-side, most of the
+ pages are plain HTML. There are some pages that require JavaScript, but the
+ search itself works without client-side JavaScript.
+ </p>
+
+ <p>
+ There are several possible directions for this project, including...
+ </p>
+
+ <ol>
+ <li>Automate blacklisting (very important)<br />
+ <ul>
+ <li>Fetch a list of child abuse media sites</li>
+ <li>Remove these sites from the search results</li>
+ </ul>
+ </li>
+ <li>Add hidden services funtion (very important)<br />
+ <ul>
+ <li>You can add onions using HTML form</li>
+ <li>Call the crawler immidiately when a new site is added</li>
+ </ul>
+ </li>
+ <li>Elasticsearch<br />
+ <ul>
+ <li>Must be updated to 5.X.X sooner or later</li>
+ <li>Adjust the settings</li>
+ <li>Automatically remove data older than, for instance, 90 days</li>
+ </ul>
+ </li>
+ <li>Maintainance<br />
+ <ul>
+ <li>Update all software dependencies</li>
+ <li>Automate crash recovery for Tor, Elasticsearch and crawler</li>
+ </ul>
+ </li>
+ </ol>
+ </li>
+
<!--
<a id=""></a>
<li>
1
0
commit a500e95ed37a8749098e0f8616e0b5f83bf1c90b
Author: Damian Johnson <atagar(a)torproject.org>
Date: Tue Jan 31 08:49:28 2017 -0800
Add Tor Browser project ideas
Couple GSoC project ideas from Tom Ritter.
---
getinvolved/en/volunteer.wml | 44 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/getinvolved/en/volunteer.wml b/getinvolved/en/volunteer.wml
index 8604881..37f6879 100644
--- a/getinvolved/en/volunteer.wml
+++ b/getinvolved/en/volunteer.wml
@@ -422,8 +422,9 @@ meetings around the world.</li>
<p>
<b>Project Ideas:</b><br />
- <i><a href="#panopticlick">Panopticlick</a></i><br />
<i><a href="#feedbackExtension">Feedback Extension for Tor Browser</a></i><br />
+ <i><a href="#torBrowserCrashReport">Crash Reporter for Tor Browser</a></i><br />
+ <i><a href="#fasterTorBrowser">Make Tor Browser Faster</a></i>
</p>
<a id="project-httpseverywhere"></a>
@@ -1056,7 +1057,6 @@ ideas.
<br>
Likely Mentors: <i>Nima (mrphs)</i>, <i>Sukhbir (sukhe)</i>
<p>
-
Design and implement an extension for Tor Browser that can be used to gather
end-user UI/UX feedback on an opt-in basis. While the design and
implementation is left as an exercise for the applicant (and also serves as
@@ -1066,16 +1066,54 @@ ideas.
</p>
<p>
-
Please propose the extension design in a way that the information is strictly
on an opt-in basis and scrubs any information that can be used to identify a
user, and also come up with a way to send the gathered information to a
central server, whether to an onion address (if the user has Tor running), or
otherwise. To start with, we are looking to gather only text as part of the
feedback process.
+ </p>
+ </li>
+ <a id="torBrowserCrashReport"></a>
+ <li>
+ <b>Crash Reporter for Tor Browser</b>
+ <br>
+ Likely Mentors: <i>Tom Ritter (tjr)</i>, <i>Georg (GeKo)</i>
+ <p>
+ Currently Tor Browser disables the Crash Reporter. We would like to
+ build it reproducible, enable it, and configure it to report crashes
+ containing non-detailed and impersonal information to Tor, on a .onion
+ submission platform that would allow us to view and explore the
+ crashes.
+ </p>
+
+ <p>
+ The project will entail enabling the Crash Report on Tor Browser and
+ creating a backend to receive reports from it. Once created, the crash
+ reporter data will be analyzed and modified to fit Tor's requirements
+ for personal data collection. As time permits, we will update the
+ build system to ensure the crash reporter is built reproducibly and
+ add data analysis tools for the crash report database to visualize top
+ crashers and similar statistics.
+ </p>
+ </li>
+
+ <a id="fasterTorBrowser"></a>
+ <li>
+ <b>Make Tor Browser Faster</b>
+ <br>
+ Likely Mentors: <i>Tom Ritter (tjr)</i>, <i>Georg (GeKo)</i>
+ <p>
+ This project will enable and take advantage of HTTP/2, the Alt-Srv
+ header, and tor's new single hop .onion mode to enable websites to
+ transparently move their traffic to a .onion address. In addition to
+ improvements in security, we will benchmark page load and paint times
+ under normal HTTP/1.1, HTTP/2, and when taking advantage of features
+ such as Server Push.
</p>
</li>
+
<!--
<a id=""></a>
<li>
1
0

[metrics-lib/master] Avoid deleting extraneous local descriptor files.
by karsten@torproject.org 31 Jan '17
by karsten@torproject.org 31 Jan '17
31 Jan '17
commit 8d09f56568652bc9104901ca4f27e170f8aa9316
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Jan 31 15:58:05 2017 +0100
Avoid deleting extraneous local descriptor files.
DescriptorIndexCollector deletes descriptor files from a previous or
concurrent collect run if it doesn't collect those files itself. This
is unexpected behavior and differs from what DescriptorCollectorImpl
does.
Fixes #20525.
---
CHANGELOG.md | 2 ++
.../descriptor/index/DescriptorIndexCollector.java | 19 ++++++++++++-------
.../index/DescriptorIndexCollectorTest.java | 6 ++++--
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22586d2..afaa1e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@
- Unify the build process by adding git-submodule metrics-base in
src/build and removing all centralized parts of the build
process.
+ - Avoid deleting extraneous local descriptor files when collecting
+ descriptors from CollecTor.
# Changes in version 1.5.0 - 2016-10-19
diff --git a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
index a6a5fe8..68b6591 100644
--- a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
+++ b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
@@ -87,7 +87,8 @@ public class DescriptorIndexCollector implements DescriptorCollector {
if (deleteExtraneousLocalFiles) {
log.info("Deleting extraneous files from local directory {}.",
localDirectory);
- deleteExtraneousLocalFiles(remoteFiles, localDirectory, localFiles);
+ deleteExtraneousLocalFiles(remoteDirectories, remoteFiles, localDirectory,
+ localFiles);
}
log.info("Finished descriptor collection.");
}
@@ -138,15 +139,19 @@ public class DescriptorIndexCollector implements DescriptorCollector {
return true;
}
- static void deleteExtraneousLocalFiles(
+ static void deleteExtraneousLocalFiles(String[] remoteDirectories,
SortedMap<String, FileNode> remoteFiles,
File localDir, SortedMap<String, Long> locals) {
for (String localPath : locals.keySet()) {
- if (!remoteFiles.containsKey(localPath)) {
- File extraneousLocalFile = new File(localDir, localPath);
- log.debug("Deleting extraneous local file {}.",
- extraneousLocalFile.getAbsolutePath());
- extraneousLocalFile.delete();
+ for (String remoteDirectory : remoteDirectories) {
+ if (localPath.startsWith(remoteDirectory)) {
+ if (!remoteFiles.containsKey(localPath)) {
+ File extraneousLocalFile = new File(localDir, localPath);
+ log.debug("Deleting extraneous local file {}.",
+ extraneousLocalFile.getAbsolutePath());
+ extraneousLocalFile.delete();
+ }
+ }
}
}
}
diff --git a/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java b/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java
index a40e0e3..e2a31b5 100644
--- a/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java
+++ b/src/test/java/org/torproject/descriptor/index/DescriptorIndexCollectorTest.java
@@ -139,6 +139,8 @@ public class DescriptorIndexCollectorTest {
public void testNormalCollectingWithDeletion() throws Exception {
File localFolder = tmpf.newFolder();
makeStructure(localFolder, "1");
+ File nonSyncedDir = makeDirs(localFolder.toString(), "d");
+ makeFiles(nonSyncedDir, "p1");
File remoteDirectory = tmpf.newFolder();
makeStructure(remoteDirectory, "2");
@@ -158,10 +160,10 @@ public class DescriptorIndexCollectorTest {
.collectDescriptors(indexFile.toURL().toString(),
new String[]{"a/b", "a/b/c"}, 1451606400_000L, localFolder, true);
- // verify file addition.
+ // verify file addition, including that the non-synced dir is not touched.
checkContains(true,
DescriptorIndexCollector.statLocalDirectory(localFolder).toString(),
- "a/b/y2", "a/b/x2", "a/b/c/u2");
+ "a/b/y2", "a/b/x2", "a/b/c/u2", "d/p1");
// verify that invalid files weren't fetched.
checkContains(false,
1
0
commit 8258b18aff005fcdb6b44d5dee81ac55fa0b7fa2
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Tue Jan 31 16:26:22 2017 +0100
Add webstats-tb-locale graph.
---
website/etc/categories.json | 1 +
website/etc/metrics.json | 14 ++++++++++++++
website/etc/web.xml | 4 ++++
website/rserve/graphs.R | 33 +++++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+)
diff --git a/website/etc/categories.json b/website/etc/categories.json
index 64b5c1a..134ef44 100644
--- a/website/etc/categories.json
+++ b/website/etc/categories.json
@@ -81,6 +81,7 @@
"description": "The following application statistics are based on the analysis of requests to <code>torproject.org</code> web servers.",
"metrics": [
"webstats-tb",
+ "webstats-tb-locale",
"webstats-tm"
]
}
diff --git a/website/etc/metrics.json b/website/etc/metrics.json
index 2601318..41e2c6f 100644
--- a/website/etc/metrics.json
+++ b/website/etc/metrics.json
@@ -418,6 +418,20 @@
]
},
{
+ "id": "webstats-tb-locale",
+ "title": "Tor Browser downloads by locale",
+ "type": "Graph",
+ "description": "<p>This graph shows absolute numbers of requests to Tor's web servers by request type. It is based on data from <a href=\"https://webstats.torproject.org/\" target=\"_blank\"><code>webstats.torproject.org</code></a> which collects logs from <code>torproject.org</code> web servers and provides them as a stripped-down version of Apache's \"combined\" log format without IP addresses, log times, HTTP parameters, referers, and user agent strings. All shown requests are requests made by the user to download a Tor Browser executable from the Tor website, broken down by requested locale.</p>",
+ "function": "plot_webstats_tb_locale",
+ "parameters": [
+ "start",
+ "end"
+ ],
+ "data": [
+ "webstats"
+ ]
+ },
+ {
"id": "webstats-tm",
"title": "Tor Messenger downloads and updates",
"type": "Graph",
diff --git a/website/etc/web.xml b/website/etc/web.xml
index adfc370..9e42aa5 100644
--- a/website/etc/web.xml
+++ b/website/etc/web.xml
@@ -47,6 +47,7 @@
<url-pattern>/hidserv-rend-relayed-cells.html</url-pattern>
<url-pattern>/hidserv-frac-reporting.html</url-pattern>
<url-pattern>/webstats-tb.html</url-pattern>
+ <url-pattern>/webstats-tb-locale.html</url-pattern>
<url-pattern>/webstats-tm.html</url-pattern>
</servlet-mapping>
@@ -182,6 +183,9 @@
<url-pattern>/webstats-tb.png</url-pattern>
<url-pattern>/webstats-tb.pdf</url-pattern>
<url-pattern>/webstats-tb.svg</url-pattern>
+ <url-pattern>/webstats-tb-locale.png</url-pattern>
+ <url-pattern>/webstats-tb-locale.pdf</url-pattern>
+ <url-pattern>/webstats-tb-locale.svg</url-pattern>
<url-pattern>/webstats-tm.png</url-pattern>
<url-pattern>/webstats-tm.pdf</url-pattern>
<url-pattern>/webstats-tm.svg</url-pattern>
diff --git a/website/rserve/graphs.R b/website/rserve/graphs.R
index e854aff..1b232f4 100644
--- a/website/rserve/graphs.R
+++ b/website/rserve/graphs.R
@@ -1126,6 +1126,39 @@ plot_webstats_tb <- function(start, end, path) {
ggsave(filename = path, width = 8, height = 5, dpi = 72)
}
+plot_webstats_tb_locale <- function(start, end, path) {
+ end <- min(end, as.character(Sys.Date() - 2))
+ d <- read.csv(paste("/srv/metrics.torproject.org/metrics/shared/stats/",
+ "webstats.csv", sep = ""), stringsAsFactors = FALSE)
+ d <- d[d$log_date >= start & d$log_date <= end & d$request_type == 'tbid', ]
+ e <- d
+ e <- aggregate(list(count = e$count), by = list(locale = e$locale), FUN = sum)
+ e <- e[order(e$count, decreasing = TRUE), ]
+ e <- e[1:5, ]
+ d <- aggregate(list(count = d$count), by = list(log_date = as.Date(d$log_date),
+ locale = ifelse(d$locale %in% e$locale, d$locale, '(other)')), FUN = sum)
+ date_breaks <- date_breaks(as.numeric(max(d$log_date) - min(d$log_date)))
+ formatter <- function(x, ...) {
+ format(x, ..., scientific = FALSE, big.mark = ' ') }
+ ggplot(d, aes(x = log_date, y = count, colour = locale)) +
+ geom_point() +
+ geom_line() +
+ expand_limits(y = 0) +
+ scale_x_date(name = paste("\nThe Tor Project - ",
+ "https://metrics.torproject.org/", sep = ""),
+ labels = date_format(date_breaks$format),
+ breaks = date_breaks$major,
+ minor_breaks = date_breaks$minor) +
+ scale_y_continuous(name = 'Requests per day\n', labels = formatter) +
+ scale_colour_hue(name = "Locale",
+ breaks = c(e$locale, "(other)"),
+ labels = c(e$locale, "Other")) +
+ theme(strip.text.y = element_text(angle = 0, hjust = 0, size = rel(1.5)),
+ strip.background = element_rect(fill = NA)) +
+ ggtitle("Tor Browser downloads by locale\n")
+ ggsave(filename = path, width = 8, height = 5, dpi = 72)
+}
+
plot_webstats_tm <- function(start, end, path) {
end <- min(end, as.character(Sys.Date() - 2))
load("/srv/metrics.torproject.org/metrics/shared/RData/webstats-tm.RData")
1
0

31 Jan '17
commit 09a00a2f826233b417066d90dcf5ba9be48b4e13
Merge: cccd3f1 4d83999
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Jan 31 11:09:04 2017 -0500
Merge remote-tracking branch 'public/bug21300'
changes/bug21300 | 6 ++++++
src/or/confparse.c | 22 ++++++++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
1
0
commit 4d83999213712c731b9fdd6eb739f29289ff00d7
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Jan 30 10:09:47 2017 -0500
Make "GETCONF SocksPort" work again
I broke "GETCONF *Port" in 20956, when I made SocksPort a
subordinate option of the virtual option SocksPortLines, so that I
could make SocksPort and __SocksPort provide qthe same
functionality. The problem was that you can't pass a subordinate
option to GETCONF.
So, this patch fixes that by letting you fetch subordinate options.
It won't always be meaningful to consider these options
out-of-context, but that can be the controller-user's
responsibility to check.
Closes ticket 21300.
---
changes/bug21300 | 6 ++++++
src/or/confparse.c | 22 ++++++++++++++++++----
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/changes/bug21300 b/changes/bug21300
new file mode 100644
index 0000000..70cc12a
--- /dev/null
+++ b/changes/bug21300
@@ -0,0 +1,6 @@
+ o Minor features (controller):
+ - The GETCONF command can now query options that may only be meaningful
+ in context-sensitive lists. This allows the controller to query
+ the mixed SocksPort/__SocksPort style options introduced in
+ feature 20956. Implements ticket 21300.
+
diff --git a/src/or/confparse.c b/src/or/confparse.c
index 92a66a4..9e352ac 100644
--- a/src/or/confparse.c
+++ b/src/or/confparse.c
@@ -31,6 +31,8 @@ static int config_parse_msec_interval(const char *s, int *ok);
static int config_parse_interval(const char *s, int *ok);
static void config_reset(const config_format_t *fmt, void *options,
const config_var_t *var, int use_defaults);
+static config_line_t *config_lines_dup_and_filter(const config_line_t *inp,
+ const char *key);
/** Allocate an empty configuration object of a given format type. */
void *
@@ -635,9 +637,22 @@ config_value_needs_escape(const char *value)
config_line_t *
config_lines_dup(const config_line_t *inp)
{
+ return config_lines_dup_and_filter(inp, NULL);
+}
+
+/** Return a newly allocated deep copy of the lines in <b>inp</b>,
+ * but only the ones that match <b>key</b>. */
+static config_line_t *
+config_lines_dup_and_filter(const config_line_t *inp,
+ const char *key)
+{
config_line_t *result = NULL;
config_line_t **next_out = &result;
while (inp) {
+ if (key && strcasecmpstart(inp->key, key)) {
+ inp = inp->next;
+ continue;
+ }
*next_out = tor_malloc_zero(sizeof(config_line_t));
(*next_out)->key = tor_strdup(inp->key);
(*next_out)->value = tor_strdup(inp->value);
@@ -764,11 +779,10 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
tor_free(result);
return NULL;
case CONFIG_TYPE_LINELIST_S:
- log_warn(LD_CONFIG,
- "Can't return context-sensitive '%s' on its own", key);
- tor_free(result->key);
tor_free(result);
- return NULL;
+ result = config_lines_dup_and_filter(*(const config_line_t **)value,
+ key);
+ break;
case CONFIG_TYPE_LINELIST:
case CONFIG_TYPE_LINELIST_V:
tor_free(result->key);
1
0

31 Jan '17
commit c3079ae2ecbed0994273b7986e3cf19160f55153
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Wed Jan 25 11:27:09 2017 +0100
Remove 604 checkstyle complaints.
Resolves #21144.
---
.../descriptor/DescriptorSourceFactory.java | 3 +-
.../descriptor/impl/DescriptorReaderImpl.java | 3 +-
.../descriptor/DescriptorSourceFactoryTest.java | 82 ++---
.../descriptor/DummyCollectorImplementation.java | 15 +
.../descriptor/DummyDownloaderImplementation.java | 15 +
.../descriptor/DummyParserImplementation.java | 15 +
.../descriptor/DummyReaderImplementation.java | 15 +
.../descriptor/benchmark/MeasurePerformance.java | 22 +-
.../descriptor/impl/BridgeNetworkStatusTest.java | 24 +-
.../descriptor/impl/ConsensusBuilder.java | 55 +++-
.../impl/DescriptorCollectorImplTest.java | 5 +-
.../descriptor/impl/DescriptorReaderImplTest.java | 1 +
.../descriptor/impl/ExitListImplTest.java | 10 +-
.../impl/ExtraInfoDescriptorImplTest.java | 231 ++++++++++----
.../descriptor/impl/MicrodescriptorImplTest.java | 16 +-
.../impl/RelayNetworkStatusConsensusImplTest.java | 97 ++++--
.../impl/RelayNetworkStatusImplTest.java | 47 ++-
.../impl/RelayNetworkStatusVoteImplTest.java | 111 +++++--
.../descriptor/impl/ServerDescriptorImplTest.java | 338 ++++++++++++---------
.../descriptor/impl/TorperfResultImplTest.java | 10 +-
20 files changed, 772 insertions(+), 343 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
index efdc5cf..77d8740 100644
--- a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
+++ b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
@@ -34,7 +34,8 @@ import org.slf4j.LoggerFactory;
* descriptor downloader:</p>
*
* <p><code>
- * java -Ddescriptor.downloader=my.special.descriptorimpl.Downloader my.app.Mainclass
+ * java -Ddescriptor.downloader=my.special.descriptorimpl.Downloader \
+ * my.app.Mainclass
* </code></p>
*
* @since 1.0.0
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
index 2cbb6c8..cb14588 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
@@ -36,7 +36,8 @@ import java.util.TreeMap;
public class DescriptorReaderImpl implements DescriptorReader {
- private static Logger log = LoggerFactory.getLogger(DescriptorReaderImpl.class);
+ private static Logger log = LoggerFactory.getLogger(
+ DescriptorReaderImpl.class);
private boolean hasStartedReading = false;
private List<File> directories = new ArrayList<>();
diff --git a/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java b/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
index d8990ac..9e0b5ff 100644
--- a/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
+++ b/src/test/java/org/torproject/descriptor/DescriptorSourceFactoryTest.java
@@ -1,42 +1,46 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor;
-import static org.torproject.descriptor.DescriptorSourceFactory.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.torproject.descriptor.DescriptorSourceFactory.COLLECTOR_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.COLLECTOR_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.DOWNLOADER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.DOWNLOADER_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.PARSER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.PARSER_PROPERTY;
+import static org.torproject.descriptor.DescriptorSourceFactory.READER_DEFAULT;
+import static org.torproject.descriptor.DescriptorSourceFactory.READER_PROPERTY;
-import org.torproject.descriptor.DescriptorCollector;
-import org.torproject.descriptor.DescriptorDownloader;
-import org.torproject.descriptor.DescriptorParser;
-import org.torproject.descriptor.DescriptorReader;
-import org.torproject.descriptor.ImplementationNotAccessibleException;
import org.torproject.descriptor.impl.DescriptorDownloaderImpl;
import org.torproject.descriptor.impl.DescriptorParserImpl;
import org.torproject.descriptor.impl.DescriptorReaderImpl;
import org.torproject.descriptor.index.DescriptorIndexCollector;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.junit.Test;
-import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
public class DescriptorSourceFactoryTest {
- private final static String[] properties = new String[]{
- COLLECTOR_PROPERTY, DOWNLOADER_PROPERTY, PARSER_PROPERTY, READER_PROPERTY};
- private final static String[] defaults = new String[]{
- COLLECTOR_DEFAULT, DOWNLOADER_DEFAULT, PARSER_DEFAULT, READER_DEFAULT};
+ private static final String[] properties = new String[] { COLLECTOR_PROPERTY,
+ DOWNLOADER_PROPERTY, PARSER_PROPERTY, READER_PROPERTY };
+
+ private static final String[] defaults = new String[] { COLLECTOR_DEFAULT,
+ DOWNLOADER_DEFAULT, PARSER_DEFAULT, READER_DEFAULT };
@Test()
public void testDefaults() {
setProperties(defaults);
- DescriptorCollector dc = DescriptorSourceFactory.createDescriptorCollector();
+ DescriptorCollector dc =
+ DescriptorSourceFactory.createDescriptorCollector();
assertTrue(dc instanceof DescriptorIndexCollector);
- DescriptorDownloader dd = DescriptorSourceFactory.createDescriptorDownloader();
+ DescriptorDownloader dd =
+ DescriptorSourceFactory.createDescriptorDownloader();
assertTrue(dd instanceof DescriptorDownloaderImpl);
DescriptorParser dp = DescriptorSourceFactory.createDescriptorParser();
assertTrue(dp instanceof DescriptorParserImpl);
@@ -66,7 +70,7 @@ public class DescriptorSourceFactoryTest {
retrieve.setAccessible(true);
retrieve.invoke(null, "unknown.property");
} catch (InvocationTargetException ite) {
- if(ite.getCause() instanceof ImplementationNotAccessibleException) {
+ if (ite.getCause() instanceof ImplementationNotAccessibleException) {
return;
} else {
fail("Cause was " + ite.getCause()
@@ -79,16 +83,17 @@ public class DescriptorSourceFactoryTest {
@Test()
public void testProperties() {
- setProperties(new String[]{
+ setProperties(new String[] {
"org.torproject.descriptor.DummyCollectorImplementation",
"org.torproject.descriptor.DummyDownloaderImplementation",
"org.torproject.descriptor.DummyParserImplementation",
- "org.torproject.descriptor.DummyReaderImplementation",
- });
- DescriptorCollector dc = DescriptorSourceFactory.createDescriptorCollector();
+ "org.torproject.descriptor.DummyReaderImplementation" });
+ DescriptorCollector dc =
+ DescriptorSourceFactory.createDescriptorCollector();
assertTrue(dc instanceof DummyCollectorImplementation);
assertEquals(1, DummyCollectorImplementation.count);
- DescriptorDownloader dd = DescriptorSourceFactory.createDescriptorDownloader();
+ DescriptorDownloader dd =
+ DescriptorSourceFactory.createDescriptorDownloader();
assertTrue(dd instanceof DummyDownloaderImplementation);
assertEquals(1, DummyDownloaderImplementation.count);
DescriptorParser dp = DescriptorSourceFactory.createDescriptorParser();
@@ -98,33 +103,4 @@ public class DescriptorSourceFactoryTest {
assertTrue(dr instanceof DummyReaderImplementation);
assertEquals(1, DummyReaderImplementation.count);
}
-
-}
-
-class DummyCollectorImplementation extends DescriptorIndexCollector {
- static int count;
- public DummyCollectorImplementation() {
- count++;
- }
-}
-
-class DummyDownloaderImplementation extends DescriptorDownloaderImpl {
- static int count;
- public DummyDownloaderImplementation() {
- count++;
- }
-}
-
-class DummyParserImplementation extends DescriptorParserImpl {
- static int count;
- public DummyParserImplementation() {
- count++;
- }
-}
-
-class DummyReaderImplementation extends DescriptorReaderImpl {
- static int count;
- public DummyReaderImplementation() {
- count++;
- }
}
diff --git a/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java b/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java
new file mode 100644
index 0000000..130a718
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyCollectorImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.index.DescriptorIndexCollector;
+
+class DummyCollectorImplementation extends DescriptorIndexCollector {
+
+ static int count;
+
+ public DummyCollectorImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java b/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java
new file mode 100644
index 0000000..dce3372
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorDownloaderImpl;
+
+class DummyDownloaderImplementation extends DescriptorDownloaderImpl {
+
+ static int count;
+
+ public DummyDownloaderImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyParserImplementation.java b/src/test/java/org/torproject/descriptor/DummyParserImplementation.java
new file mode 100644
index 0000000..42e67c9
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyParserImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorParserImpl;
+
+class DummyParserImplementation extends DescriptorParserImpl {
+
+ static int count;
+
+ public DummyParserImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java b/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java
new file mode 100644
index 0000000..8f74337
--- /dev/null
+++ b/src/test/java/org/torproject/descriptor/DummyReaderImplementation.java
@@ -0,0 +1,15 @@
+/* Copyright 2016--2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.descriptor;
+
+import org.torproject.descriptor.impl.DescriptorReaderImpl;
+
+class DummyReaderImplementation extends DescriptorReaderImpl {
+
+ static int count;
+
+ public DummyReaderImplementation() {
+ count++;
+ }
+}
diff --git a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
index 4c36ae4..a0c923c 100644
--- a/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
+++ b/src/test/java/org/torproject/descriptor/benchmark/MeasurePerformance.java
@@ -1,5 +1,6 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.benchmark;
import org.torproject.descriptor.Descriptor;
@@ -20,7 +21,7 @@ import java.util.SortedMap;
public class MeasurePerformance {
- /* Check if all necessary files are available and then measure
+ /** Check if all necessary files are available and then measure
* performance of some more or less common use cases. */
public static void main(String[] args) {
if (!filesAvailable()) {
@@ -88,8 +89,9 @@ public class MeasurePerformance {
private static void measureAverageAdvertisedBandwidth(
File tarballFileOrDirectory) {
System.out.println("Starting measureAverageAdvertisedBandwidth");
- long startedMillis = System.currentTimeMillis();
- long sumAdvertisedBandwidth = 0, countedServerDescriptors = 0;
+ final long startedMillis = System.currentTimeMillis();
+ long sumAdvertisedBandwidth = 0;
+ long countedServerDescriptors = 0;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFileOrDirectory);
@@ -125,7 +127,7 @@ public class MeasurePerformance {
private static void measureCountriesV3Requests(File tarballFile) {
System.out.println("Starting measureCountriesV3Requests");
- long startedMillis = System.currentTimeMillis();
+ final long startedMillis = System.currentTimeMillis();
Set<String> countries = new HashSet<>();
long countedExtraInfoDescriptors = 0;
DescriptorReader descriptorReader =
@@ -165,9 +167,10 @@ public class MeasurePerformance {
private static void measureAverageRelaysExit(
File tarballFileOrDirectory) {
System.out.println("Starting measureAverageRelaysExit");
- long startedMillis = System.currentTimeMillis();
- long totalRelaysWithExitFlag = 0L, totalRelays = 0L,
- countedConsensuses = 0L;
+ final long startedMillis = System.currentTimeMillis();
+ long totalRelaysWithExitFlag = 0L;
+ long totalRelays = 0L;
+ long countedConsensuses = 0L;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFileOrDirectory);
@@ -212,8 +215,9 @@ public class MeasurePerformance {
File tarballFile) {
System.out.println("Starting "
+ "measureFractionRelaysExit80Microdescriptors");
- long startedMillis = System.currentTimeMillis();
- long totalRelaysWithExitFlag = 0L, countedMicrodescriptors = 0L;
+ final long startedMillis = System.currentTimeMillis();
+ long totalRelaysWithExitFlag = 0L;
+ long countedMicrodescriptors = 0L;
DescriptorReader descriptorReader =
DescriptorSourceFactory.createDescriptorReader();
descriptorReader.addTarball(tarballFile);
diff --git a/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java b/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
index d1a083e..8720d7b 100644
--- a/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
@@ -1,17 +1,19 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
import org.torproject.descriptor.BridgeNetworkStatus;
import org.torproject.descriptor.DescriptorParseException;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
/* Test parsing of bridge network statuses. Some of the parsing code is
* already tested in the consensus/vote-parsing tests. */
public class BridgeNetworkStatusTest {
@@ -19,8 +21,10 @@ public class BridgeNetworkStatusTest {
/* Helper class to build a bridge network status based on default data
* and modifications requested by test methods. */
private static class StatusBuilder {
+
private String fileName = "20151121-173936-"
+ "4A0CCD2DDC7995083D73F5D667100C8A5831F16D";
+
private static BridgeNetworkStatus
createWithFileName(String fileName)
throws DescriptorParseException {
@@ -29,7 +33,9 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private String publishedLine = "published 2015-11-21 17:39:36";
+
private static BridgeNetworkStatus
createWithPublishedLine(String line)
throws DescriptorParseException {
@@ -38,11 +44,13 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private String flagThresholdsLine = "flag-thresholds "
+ "stable-uptime=3105080 stable-mtbf=2450615 fast-speed=55000 "
+ "guard-wfu=98.000% guard-tk=691200 guard-bw-inc-exits=337000 "
+ "guard-bw-exc-exits=339000 enough-mtbf=1 "
+ "ignoring-advertised-bws=0";
+
private static BridgeNetworkStatus
createWithFlagThresholdsLine(String line)
throws DescriptorParseException {
@@ -51,8 +59,11 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
true);
}
+
private List<String> statusEntries = new ArrayList<>();
+
private String unrecognizedHeaderLine = null;
+
protected static BridgeNetworkStatus
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -62,7 +73,9 @@ public class BridgeNetworkStatusTest {
return new BridgeNetworkStatusImpl(sb.buildStatus(), sb.fileName,
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static BridgeNetworkStatus
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -79,12 +92,14 @@ public class BridgeNetworkStatusTest {
+ "10.153.163.200 443 0\ns Fast Running Stable Valid\n"
+ "w Bandwidth=264\np reject 1-65535");
}
+
private byte[] buildStatus() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
this.appendStatusEntries(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.publishedLine != null) {
sb.append(this.publishedLine).append("\n");
@@ -96,6 +111,7 @@ public class BridgeNetworkStatusTest {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
diff --git a/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java b/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
index fccd33b..b765be6 100644
--- a/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
+++ b/src/test/java/org/torproject/descriptor/impl/ConsensusBuilder.java
@@ -1,17 +1,20 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.RelayNetworkStatusConsensus;
+
import java.util.ArrayList;
import java.util.List;
-import org.torproject.descriptor.RelayNetworkStatusConsensus;
-
/* Helper class to build a consensus based on default data and
* modifications requested by test methods. */
public class ConsensusBuilder {
+
String networkStatusVersionLine = "network-status-version 3";
+
protected static RelayNetworkStatusConsensus
createWithNetworkStatusVersionLine(String line)
throws DescriptorParseException {
@@ -19,7 +22,9 @@ public class ConsensusBuilder {
cb.networkStatusVersionLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String voteStatusLine = "vote-status consensus";
+
protected static RelayNetworkStatusConsensus
createWithVoteStatusLine(String line)
throws DescriptorParseException {
@@ -27,7 +32,9 @@ public class ConsensusBuilder {
cb.voteStatusLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String consensusMethodLine = "consensus-method 11";
+
protected static RelayNetworkStatusConsensus
createWithConsensusMethodLine(String line)
throws DescriptorParseException {
@@ -35,7 +42,9 @@ public class ConsensusBuilder {
cb.consensusMethodLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String validAfterLine = "valid-after 2011-11-30 09:00:00";
+
protected static RelayNetworkStatusConsensus
createWithValidAfterLine(String line)
throws DescriptorParseException {
@@ -43,7 +52,9 @@ public class ConsensusBuilder {
cb.validAfterLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String freshUntilLine = "fresh-until 2011-11-30 10:00:00";
+
protected static RelayNetworkStatusConsensus
createWithFreshUntilLine(String line)
throws DescriptorParseException {
@@ -51,7 +62,9 @@ public class ConsensusBuilder {
cb.freshUntilLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String validUntilLine = "valid-until 2011-11-30 12:00:00";
+
protected static RelayNetworkStatusConsensus
createWithValidUntilLine(String line)
throws DescriptorParseException {
@@ -59,7 +72,9 @@ public class ConsensusBuilder {
cb.validUntilLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String votingDelayLine = "voting-delay 300 300";
+
protected static RelayNetworkStatusConsensus
createWithVotingDelayLine(String line)
throws DescriptorParseException {
@@ -67,8 +82,10 @@ public class ConsensusBuilder {
cb.votingDelayLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
String clientVersionsLine = "client-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
protected static RelayNetworkStatusConsensus
createWithClientVersionsLine(String line)
throws DescriptorParseException {
@@ -76,8 +93,10 @@ public class ConsensusBuilder {
cb.clientVersionsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
String serverVersionsLine = "server-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
protected static RelayNetworkStatusConsensus
createWithServerVersionsLine(String line)
throws DescriptorParseException {
@@ -85,7 +104,9 @@ public class ConsensusBuilder {
cb.serverVersionsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String packageLines = null;
+
protected static RelayNetworkStatusConsensus
createWithPackageLines(String lines)
throws DescriptorParseException {
@@ -93,8 +114,10 @@ public class ConsensusBuilder {
cb.packageLines = lines;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String knownFlagsLine = "known-flags Authority BadExit Exit "
+ "Fast Guard HSDir Named Running Stable Unnamed V2Dir Valid";
+
protected static RelayNetworkStatusConsensus
createWithKnownFlagsLine(String line)
throws DescriptorParseException {
@@ -102,11 +125,13 @@ public class ConsensusBuilder {
cb.knownFlagsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String paramsLine = "params "
+ "CircuitPriorityHalflifeMsec=30000 bwauthbestratio=1 "
+ "bwauthcircs=1 bwauthdescbw=0 bwauthkp=10000 bwauthpid=1 "
+ "bwauthtd=5000 bwauthti=50000 bwauthtidecay=5000 cbtnummodes=3 "
+ "cbtquantile=80 circwindow=1000 refuseunknownexits=1";
+
protected static RelayNetworkStatusConsensus
createWithParamsLine(String line)
throws DescriptorParseException {
@@ -114,12 +139,17 @@ public class ConsensusBuilder {
cb.paramsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
List<String> dirSources = new ArrayList<>();
+
List<String> statusEntries = new ArrayList<>();
+
private String directoryFooterLine = "directory-footer";
+
protected void setDirectoryFooterLine(String line) {
this.directoryFooterLine = line;
}
+
protected static RelayNetworkStatusConsensus
createWithDirectoryFooterLine(String line)
throws DescriptorParseException {
@@ -127,13 +157,16 @@ public class ConsensusBuilder {
cb.directoryFooterLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private String bandwidthWeightsLine = "bandwidth-weights Wbd=285 "
+ "Wbe=0 Wbg=0 Wbm=10000 Wdb=10000 Web=10000 Wed=1021 Wee=10000 "
+ "Weg=1021 Wem=10000 Wgb=10000 Wgd=8694 Wgg=10000 Wgm=10000 "
+ "Wmb=10000 Wmd=285 Wme=0 Wmg=0 Wmm=10000";
+
protected void setBandwidthWeightsLine(String line) {
this.bandwidthWeightsLine = line;
}
+
protected static RelayNetworkStatusConsensus
createWithBandwidthWeightsLine(String line)
throws DescriptorParseException {
@@ -141,11 +174,15 @@ public class ConsensusBuilder {
cb.bandwidthWeightsLine = line;
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(), true);
}
+
private List<String> directorySignatures = new ArrayList<>();
+
protected void addDirectorySignature(String directorySignatureString) {
this.directorySignatures.add(directorySignatureString);
}
+
private String unrecognizedHeaderLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -155,7 +192,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirSourceLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedDirSourceLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -165,7 +204,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -175,7 +216,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedFooterLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedFooterLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -185,7 +228,9 @@ public class ConsensusBuilder {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirectorySignatureLine = null;
+
protected static RelayNetworkStatusConsensus
createWithUnrecognizedDirectorySignatureLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -232,6 +277,7 @@ public class ConsensusBuilder {
+ "oQA/qeby7E\n5374pPPL6WwCLJHkKtk21S9oHDmFBdlZq7JWQelWlVM=\n"
+ "-----END SIGNATURE-----");
}
+
protected byte[] buildConsensus() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
@@ -241,6 +287,7 @@ public class ConsensusBuilder {
this.appendDirectorySignatures(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.networkStatusVersionLine != null) {
sb.append(this.networkStatusVersionLine).append("\n");
@@ -282,6 +329,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendDirSources(StringBuilder sb) {
for (String dirSource : this.dirSources) {
sb.append(dirSource).append("\n");
@@ -290,6 +338,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedDirSourceLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
@@ -298,6 +347,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedStatusEntryLine).append("\n");
}
}
+
private void appendFooter(StringBuilder sb) {
if (this.directoryFooterLine != null) {
sb.append(this.directoryFooterLine).append("\n");
@@ -309,6 +359,7 @@ public class ConsensusBuilder {
sb.append(this.unrecognizedFooterLine).append("\n");
}
}
+
private void appendDirectorySignatures(StringBuilder sb) {
for (String directorySignature : this.directorySignatures) {
sb.append(directorySignature).append("\n");
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
index ad34528..45752b2 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
@@ -8,10 +9,10 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.util.SortedMap;
-
import org.junit.Test;
+import java.util.SortedMap;
+
public class DescriptorCollectorImplTest {
private static final String REMOTE_DIRECTORY_CONSENSUSES =
diff --git a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
index 5a418b9..0d3bdcf 100644
--- a/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/DescriptorReaderImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
diff --git a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
index 8bc81f9..916c4df 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExitListImplTest.java
@@ -1,17 +1,19 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.ExitListEntry;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
public class ExitListImplTest {
@Test()
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index fb38c86..096314e 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -1,5 +1,6 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
@@ -7,6 +8,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.BridgeExtraInfoDescriptor;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.ExtraInfoDescriptor;
+import org.torproject.descriptor.RelayExtraInfoDescriptor;
+
+import org.junit.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -14,138 +22,166 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
-import org.junit.Test;
-import org.torproject.descriptor.BridgeExtraInfoDescriptor;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.ExtraInfoDescriptor;
-import org.torproject.descriptor.RelayExtraInfoDescriptor;
-
/* Test parsing of extra-info descriptors. */
public class ExtraInfoDescriptorImplTest {
/* Helper class to build a descriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String extraInfoLine = "extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26";
+
private static ExtraInfoDescriptor createWithExtraInfoLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.extraInfoLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String publishedLine = "published 2012-02-11 09:08:36";
+
private static ExtraInfoDescriptor createWithPublishedLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.publishedLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String writeHistoryLine = "write-history 2012-02-11 09:03:39 "
+ "(900 s) 4713350144,4723824640,4710717440,4572675072";
+
private static ExtraInfoDescriptor createWithWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.writeHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String readHistoryLine = "read-history 2012-02-11 09:03:39 "
+ "(900 s) 4707695616,4699666432,4650004480,4489718784";
+
private static ExtraInfoDescriptor createWithReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.readHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqWriteHistoryLine = "dirreq-write-history "
+ "2012-02-11 09:03:39 (900 s) 81281024,64996352,60625920,"
+ "67922944";
+
private static ExtraInfoDescriptor createWithDirreqWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqWriteHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqReadHistoryLine = "dirreq-read-history "
+ "2012-02-11 09:03:39 (900 s) 17074176,16235520,16005120,"
+ "16209920";
+
private static ExtraInfoDescriptor createWithDirreqReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqReadHistoryLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoipDbDigestLine = null;
+
private static ExtraInfoDescriptor createWithGeoipDbDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoipDbDigestLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoip6DbDigestLine = null;
+
private static ExtraInfoDescriptor createWithGeoip6DbDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoip6DbDigestLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String geoipStatsLines = null;
+
private static ExtraInfoDescriptor createWithGeoipStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.geoipStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String dirreqStatsLines = null;
+
private static ExtraInfoDescriptor createWithDirreqStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.dirreqStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String entryStatsLines = null;
+
private static ExtraInfoDescriptor createWithEntryStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.entryStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String cellStatsLines = null;
+
private static ExtraInfoDescriptor createWithCellStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.cellStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String connBiDirectLine = null;
+
private static ExtraInfoDescriptor createWithConnBiDirectLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.connBiDirectLine = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String exitStatsLines = null;
+
private static ExtraInfoDescriptor createWithExitStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.exitStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String bridgeStatsLines = null;
+
private static ExtraInfoDescriptor createWithBridgeStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.bridgeStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hidservStatsLines = null;
+
private static ExtraInfoDescriptor createWithHidservStatsLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hidservStatsLines = lines;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private String unrecognizedLine = null;
+
private static ExtraInfoDescriptor createWithUnrecognizedLine(
String line, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -154,7 +190,9 @@ public class ExtraInfoDescriptorImplTest {
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private byte[] nonAsciiLineBytes = null;
+
private static ExtraInfoDescriptor createWithNonAsciiLineBytes(
byte[] lineBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -163,20 +201,27 @@ public class ExtraInfoDescriptorImplTest {
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private String routerSignatureLines = "router-signature\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "o4j+kH8UQfjBwepUnr99v0ebN8RpzHJ/lqYsTojXHy9kMr1RNI9IDeSzA7PSqT"
+ "uV\n4PL8QsGtlfwthtIoZpB2srZeyN/mcpA9fa1JXUrt/UN9K/+32Cyaad7h0n"
+ "HE6Xfb\njqpXDpnBpvk4zjmzjjKYnIsUWTnADmu0fo3xTRqXi7g=\n"
+ "-----END SIGNATURE-----";
+
private static ExtraInfoDescriptor createWithRouterSignatureLines(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerSignatureLines = line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
- private String identityEd25519Lines = null,
- masterKeyEd25519Line = null, routerSigEd25519Line = null;
+
+ private String identityEd25519Lines = null;
+
+ private String masterKeyEd25519Line = null;
+
+ private String routerSigEd25519Line = null;
+
private static ExtraInfoDescriptor createWithEd25519Lines(
String identityEd25519Lines, String masterKeyEd25519Line,
String routerSigEd25519Line) throws DescriptorParseException {
@@ -186,6 +231,7 @@ public class ExtraInfoDescriptorImplTest {
db.routerSigEd25519Line = routerSigEd25519Line;
return new RelayExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.extraInfoLine != null) {
@@ -272,8 +318,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of geoip-stats lines based on default
* data and modifications requested by test methods. */
private static class GeoipStatsBuilder {
+
private String geoipStartTimeLine = "geoip-start-time 2012-02-10 "
+ "18:32:51";
+
private static ExtraInfoDescriptor createWithGeoipStartTimeLine(
String line) throws DescriptorParseException {
GeoipStatsBuilder gsb = new GeoipStatsBuilder();
@@ -281,8 +329,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithGeoipStatsLines(
gsb.buildGeoipStatsLines());
}
+
private String geoipClientOriginsLine = "geoip-client-origins "
+ "de=1152,cn=896,us=712,it=504,ru=352,fr=208,gb=208,ir=200";
+
private static ExtraInfoDescriptor createWithGeoipClientOriginsLine(
String line) throws DescriptorParseException {
GeoipStatsBuilder gsb = new GeoipStatsBuilder();
@@ -290,11 +340,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithGeoipStatsLines(
gsb.buildGeoipStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithGeoipStatsLines(
new GeoipStatsBuilder().buildGeoipStatsLines());
}
+
private String buildGeoipStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.geoipStartTimeLine != null) {
@@ -314,8 +366,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of dirreq-stats lines based on default
* data and modifications requested by test methods. */
private static class DirreqStatsBuilder {
+
private String dirreqStatsEndLine = "dirreq-stats-end 2012-02-11 "
+ "00:59:53 (86400 s)";
+
private static ExtraInfoDescriptor createWithDirreqStatsEndLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -323,8 +377,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3IpsLine = "dirreq-v3-ips us=1544,de=1056,"
+ "it=1032,fr=784,es=640,ru=440,br=312,gb=272,kr=224,sy=192";
+
private static ExtraInfoDescriptor createWithDirreqV3IpsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -332,7 +388,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2IpsLine = "dirreq-v2-ips ";
+
private static ExtraInfoDescriptor createWithDirreqV2IpsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -340,8 +398,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3ReqsLine = "dirreq-v3-reqs us=1744,de=1224,"
+ "it=1080,fr=832,es=664,ru=536,br=344,gb=296,kr=272,in=216";
+
private static ExtraInfoDescriptor createWithDirreqV3ReqsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -349,7 +409,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2ReqsLine = "dirreq-v2-reqs ";
+
private static ExtraInfoDescriptor createWithDirreqV2ReqsLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -357,9 +419,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3RespLine = "dirreq-v3-resp ok=10848,"
+ "not-enough-sigs=8,unavailable=0,not-found=0,not-modified=0,"
+ "busy=80";
+
private static ExtraInfoDescriptor createWithDirreqV3RespLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -367,8 +431,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2RespLine = "dirreq-v2-resp ok=0,unavailable=0,"
+ "not-found=1576,not-modified=0,busy=0";
+
private static ExtraInfoDescriptor createWithDirreqV2RespLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -376,7 +442,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2ShareLine = "dirreq-v2-share 0.37%";
+
private static ExtraInfoDescriptor createWithDirreqV2ShareLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -384,7 +452,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3ShareLine = "dirreq-v3-share 0.37%";
+
private static ExtraInfoDescriptor createWithDirreqV3ShareLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -392,10 +462,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3DirectDlLine = "dirreq-v3-direct-dl "
+ "complete=36,timeout=4,running=0,min=7538,d1=20224,d2=28950,"
+ "q1=40969,d3=55786,d4=145813,md=199164,d6=267230,d7=480900,"
+ "q3=481049,d8=531276,d9=778086,max=15079428";
+
private static ExtraInfoDescriptor createWithDirreqV3DirectDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -403,8 +475,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2DirectDlLine = "dirreq-v2-direct-dl "
+ "complete=0,timeout=0,running=0";
+
private static ExtraInfoDescriptor createWithDirreqV2DirectDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -412,10 +486,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV3TunneledDlLine = "dirreq-v3-tunneled-dl "
+ "complete=10608,timeout=204,running=4,min=507,d1=20399,"
+ "d2=27588,q1=29292,d3=30889,d4=40624,md=59967,d6=103333,"
+ "d7=161170,q3=209415,d8=256711,d9=452503,max=23417777";
+
private static ExtraInfoDescriptor createWithDirreqV3TunneledDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -423,8 +499,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private String dirreqV2TunneledDlLine = "dirreq-v2-tunneled-dl "
+ "complete=0,timeout=0,running=0";
+
private static ExtraInfoDescriptor createWithDirreqV2TunneledDlLine(
String line) throws DescriptorParseException {
DirreqStatsBuilder dsb = new DirreqStatsBuilder();
@@ -432,11 +510,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithDirreqStatsLines(
dsb.buildDirreqStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithDirreqStatsLines(
new DirreqStatsBuilder().buildDirreqStatsLines());
}
+
private String buildDirreqStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.dirreqStatsEndLine != null) {
@@ -489,8 +569,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of entry-stats lines based on default
* data and modifications requested by test methods. */
private static class EntryStatsBuilder {
+
private String entryStatsEndLine = "entry-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithEntryStatsEndLine(
String line) throws DescriptorParseException {
EntryStatsBuilder esb = new EntryStatsBuilder();
@@ -498,9 +580,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithEntryStatsLines(
esb.buildEntryStatsLines());
}
+
private String entryIpsLine = "entry-ips ir=25368,us=15744,it=14816,"
+ "de=13256,es=8280,fr=8120,br=5176,sy=4760,ru=4504,sa=4216,"
+ "gb=3152,pl=2928,nl=2208,kr=1856,ca=1792,ua=1272,in=1192";
+
private static ExtraInfoDescriptor createWithEntryIpsLine(
String line) throws DescriptorParseException {
EntryStatsBuilder esb = new EntryStatsBuilder();
@@ -508,11 +592,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithEntryStatsLines(
esb.buildEntryStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithEntryStatsLines(
new EntryStatsBuilder().buildEntryStatsLines());
}
+
private String buildEntryStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.entryStatsEndLine != null) {
@@ -532,8 +618,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of cell-stats lines based on default
* data and modifications requested by test methods. */
private static class CellStatsBuilder {
+
private String cellStatsEndLine = "cell-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithCellStatsEndLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -541,8 +629,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellProcessedCellsLine = "cell-processed-cells "
+ "1441,11,6,4,2,1,1,1,1,1";
+
private static ExtraInfoDescriptor createWithCellProcessedCellsLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -550,8 +640,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellQueuedCellsLine = "cell-queued-cells "
+ "3.29,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00";
+
private static ExtraInfoDescriptor createWithCellQueuedCellsLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -559,8 +651,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellTimeInQueueLine = "cell-time-in-queue "
+ "524,1,1,0,0,25,0,0,0,0";
+
private static ExtraInfoDescriptor createWithCellTimeInQueueLine(
String line) throws DescriptorParseException {
CellStatsBuilder csb = new CellStatsBuilder();
@@ -568,8 +662,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private String cellCircuitsPerDecileLine = "cell-circuits-per-decile "
+ "866";
+
private static ExtraInfoDescriptor
createWithCellCircuitsPerDecileLine(String line)
throws DescriptorParseException {
@@ -578,11 +674,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithCellStatsLines(
csb.buildCellStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithCellStatsLines(
new CellStatsBuilder().buildCellStatsLines());
}
+
private String buildCellStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.cellStatsEndLine != null) {
@@ -611,8 +709,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of exit-stats lines based on default
* data and modifications requested by test methods. */
private static class ExitStatsBuilder {
+
private String exitStatsEndLine = "exit-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithExitStatsEndLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -620,9 +720,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitKibibytesWrittenLine = "exit-kibibytes-written "
+ "25=74647,80=31370,443=20577,49755=23,52563=12,52596=1111,"
+ "57528=4,60912=11,61351=6,64811=3365,other=2592";
+
private static ExtraInfoDescriptor createWithExitKibibytesWrittenLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -630,10 +732,12 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitKibibytesReadLine = "exit-kibibytes-read "
+ "25=35562,80=1254256,443=110279,49755=9396,52563=1911,"
+ "52596=648,57528=1188,60912=1427,61351=1824,64811=14,"
+ "other=3054";
+
private static ExtraInfoDescriptor createWithExitKibibytesReadLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -641,9 +745,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private String exitStreamsOpenedLine = "exit-streams-opened "
+ "25=369748,80=64212,443=151660,49755=4,52563=4,52596=4,57528=4,"
+ "60912=4,61351=4,64811=4,other=1212";
+
private static ExtraInfoDescriptor createWithExitStreamsOpenedLine(
String line) throws DescriptorParseException {
ExitStatsBuilder esb = new ExitStatsBuilder();
@@ -651,11 +757,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithExitStatsLines(
esb.buildExitStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithExitStatsLines(
new ExitStatsBuilder().buildExitStatsLines());
}
+
private String buildExitStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.exitStatsEndLine != null) {
@@ -681,8 +789,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of bridge-stats lines based on default
* data and modifications requested by test methods. */
private static class BridgeStatsBuilder {
+
private String bridgeStatsEndLine = "bridge-stats-end 2012-02-11 "
+ "01:59:39 (86400 s)";
+
private static ExtraInfoDescriptor createWithBridgeStatsEndLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -690,8 +800,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpsLine = "bridge-ips ir=24,sy=16,??=8,cn=8,"
+ "de=8,es=8,fr=8,gb=8,in=8,jp=8,kz=8,nl=8,ua=8,us=8,vn=8,za=8";
+
private static ExtraInfoDescriptor createWithBridgeIpsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -699,7 +811,9 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpVersionsLine = "bridge-ip-versions v4=8,v6=16";
+
private static ExtraInfoDescriptor createWithBridgeIpVersionsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -707,8 +821,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private String bridgeIpTransportsLine = "bridge-ip-transports "
+ "<OR>=8,obfs2=792,obfs3=1728";
+
private static ExtraInfoDescriptor createWithBridgeIpTransportsLine(
String line) throws DescriptorParseException {
BridgeStatsBuilder bsb = new BridgeStatsBuilder();
@@ -716,11 +832,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithBridgeStatsLines(
bsb.buildBridgeStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithBridgeStatsLines(
new BridgeStatsBuilder().buildBridgeStatsLines());
}
+
private String buildBridgeStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.bridgeStatsEndLine != null) {
@@ -746,8 +864,10 @@ public class ExtraInfoDescriptorImplTest {
/* Helper class to build a set of hidserv-stats lines based on default
* data and modifications requested by test methods. */
private static class HidservStatsBuilder {
+
private String hidservStatsEndLine = "hidserv-stats-end 2015-12-03 "
+ "14:26:56 (86400 s)";
+
private static ExtraInfoDescriptor createWithHidservStatsEndLine(
String line) throws DescriptorParseException {
HidservStatsBuilder hsb = new HidservStatsBuilder();
@@ -755,9 +875,11 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private String hidservRendRelayedCellsLine =
"hidserv-rend-relayed-cells 36474281 delta_f=2048 epsilon=0.30 "
+ "bin_size=1024";
+
private static ExtraInfoDescriptor
createWithHidservRendRelayedCellsLine(String line)
throws DescriptorParseException {
@@ -766,8 +888,10 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private String hidservDirOnionsSeenLine = "hidserv-dir-onions-seen "
+ "-3 delta_f=8 epsilon=0.30 bin_size=8";
+
private static ExtraInfoDescriptor createWithHidservDirOnionsSeenLine(
String line) throws DescriptorParseException {
HidservStatsBuilder hsb = new HidservStatsBuilder();
@@ -775,11 +899,13 @@ public class ExtraInfoDescriptorImplTest {
return DescriptorBuilder.createWithHidservStatsLines(
hsb.buildHidservStatsLines());
}
+
private static ExtraInfoDescriptor createWithDefaultLines()
throws DescriptorParseException {
return DescriptorBuilder.createWithHidservStatsLines(
new HidservStatsBuilder().buildHidservStatsLines());
}
+
private String buildHidservStatsLines() {
StringBuilder sb = new StringBuilder();
if (this.hidservStatsEndLine != null) {
@@ -809,11 +935,11 @@ public class ExtraInfoDescriptorImplTest {
descriptor.getFingerprint());
assertEquals(1328951316000L, descriptor.getPublishedMillis());
assertNotNull(descriptor.getWriteHistory());
- assertEquals(1328951019000L, descriptor.getWriteHistory().
- getHistoryEndMillis());
+ assertEquals(1328951019000L, descriptor.getWriteHistory()
+ .getHistoryEndMillis());
assertEquals(900L, descriptor.getWriteHistory().getIntervalLength());
- assertEquals(4572675072L, (long) descriptor.getWriteHistory().
- getBandwidthValues().get(1328951019000L));
+ assertEquals(4572675072L, (long) descriptor.getWriteHistory()
+ .getBandwidthValues().get(1328951019000L));
assertNotNull(descriptor.getReadHistory());
assertNotNull(descriptor.getDirreqWriteHistory());
assertNotNull(descriptor.getDirreqReadHistory());
@@ -826,8 +952,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExtraInfoOpt() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26");
assertEquals("chaoscomputerclub5", descriptor.getNickname());
assertEquals("A9C039A5FD02FCA06303DCFAABE25C5912C63B26",
@@ -837,8 +963,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExtraInfoNicknameTwoSpaces()
throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoLine("opt extra-info chaoscomputerclub5 "
+ "A9C039A5FD02FCA06303DCFAABE25C5912C63B26");
assertEquals("chaoscomputerclub5", descriptor.getNickname());
assertEquals("A9C039A5FD02FCA06303DCFAABE25C5912C63B26",
@@ -899,15 +1025,15 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testPublishedOpt() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-02-11 09:08:36");
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-02-11 09:08:36");
assertEquals(1328951316000L, descriptor.getPublishedMillis());
}
@Test()
public void testPublishedMillis() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-02-11 09:08:36.123");
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-02-11 09:08:36.123");
assertEquals(1328951316000L, descriptor.getPublishedMillis());
}
@@ -977,8 +1103,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoipDbDigestValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithGeoipDbDigestLine("geoip-db-digest "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithGeoipDbDigestLine("geoip-db-digest "
+ "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8");
assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8",
descriptor.getGeoipDbDigest());
@@ -1006,8 +1132,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoip6DbDigestValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithGeoip6DbDigestLine("geoip6-db-digest "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithGeoip6DbDigestLine("geoip6-db-digest "
+ "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8");
assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8",
descriptor.getGeoip6DbDigest());
@@ -1015,8 +1141,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testGeoipStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = GeoipStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = GeoipStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328898771000L, descriptor.getGeoipStartTimeMillis());
SortedMap<String, Integer> ips = descriptor.getGeoipClientOrigins();
assertNotNull(ips);
@@ -1117,8 +1243,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testDirreqStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DirreqStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = DirreqStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328921993000L, descriptor.getDirreqStatsEndMillis());
assertEquals(86400L, descriptor.getDirreqStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getDirreqV3Ips();
@@ -1237,8 +1363,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testEntryStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = EntryStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = EntryStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getEntryStatsEndMillis());
assertEquals(86400L, descriptor.getEntryStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getEntryIps();
@@ -1262,8 +1388,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testCellStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = CellStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = CellStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getCellStatsEndMillis());
assertEquals(86400L, descriptor.getCellStatsIntervalLength());
List<Integer> processedCells = descriptor.getCellProcessedCells();
@@ -1319,8 +1445,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testConnBiDirectValid()
throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithConnBiDirectLine("conn-bi-direct 2012-02-11 01:59:39 "
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithConnBiDirectLine("conn-bi-direct 2012-02-11 01:59:39 "
+ "(86400 s) 42173,1591,1310,1744");
assertEquals(1328925579000L,
descriptor.getConnBiDirectStatsEndMillis());
@@ -1340,35 +1466,35 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testExitStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = ExitStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = ExitStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getExitStatsEndMillis());
assertEquals(86400L, descriptor.getExitStatsIntervalLength());
String[] ports = new String[] { "25", "80", "443", "49755",
"52563", "52596", "57528", "60912", "61351", "64811", "other" };
int[] writtenValues = new int[] { 74647, 31370, 20577, 23, 12, 1111,
4, 11, 6, 3365, 2592 };
- int i = 0;
+ int index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitKibibytesWritten().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(writtenValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(writtenValues[index++], e.getValue().intValue());
}
int[] readValues = new int[] { 35562, 1254256, 110279, 9396, 1911,
648, 1188, 1427, 1824, 14, 3054 };
- i = 0;
+ index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitKibibytesRead().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(readValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(readValues[index++], e.getValue().intValue());
}
int[] streamsValues = new int[] { 369748, 64212, 151660, 4, 4, 4, 4,
4, 4, 4, 1212 };
- i = 0;
+ index = 0;
for (Map.Entry<String, Long> e :
descriptor.getExitStreamsOpened().entrySet()) {
- assertEquals(ports[i], e.getKey());
- assertEquals(streamsValues[i++], e.getValue().intValue());
+ assertEquals(ports[index], e.getKey());
+ assertEquals(streamsValues[index++], e.getValue().intValue());
}
}
@@ -1416,8 +1542,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testBridgeStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = BridgeStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = BridgeStatsBuilder
+ .createWithDefaultLines();
assertEquals(1328925579000L, descriptor.getBridgeStatsEndMillis());
assertEquals(86400L, descriptor.getBridgeStatsIntervalLength());
SortedMap<String, Integer> ips = descriptor.getBridgeIps();
@@ -1482,8 +1608,8 @@ public class ExtraInfoDescriptorImplTest {
@Test()
public void testHidservStatsValid() throws DescriptorParseException {
- ExtraInfoDescriptor descriptor = HidservStatsBuilder.
- createWithDefaultLines();
+ ExtraInfoDescriptor descriptor = HidservStatsBuilder
+ .createWithDefaultLines();
assertEquals(1449152816000L, descriptor.getHidservStatsEndMillis());
assertEquals(86400L, descriptor.getHidservStatsIntervalLength());
assertEquals(36474281.0, descriptor.getHidservRendRelayedCells(),
@@ -1575,8 +1701,8 @@ public class ExtraInfoDescriptorImplTest {
public void testUnrecognizedLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- ExtraInfoDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(unrecognizedLine, false);
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
@@ -1727,7 +1853,8 @@ public class ExtraInfoDescriptorImplTest {
+ "geoip6-db-digest 212DE17D5A368DCAFA19B95F168BFFA101145A93\n"
+ "router-digest-sha256 "
+ "TvrqpjI7OmCtwGwair/NHUxg5ROVVQYz6/EDyXsDHR4\n"
- + "router-digest 00B98F076B586272C3172B7F3DA29ADEE75F2ED8\n").getBytes();
+ + "router-digest 00B98F076B586272C3172B7F3DA29ADEE75F2ED8\n")
+ .getBytes();
BridgeExtraInfoDescriptor descriptor =
new BridgeExtraInfoDescriptorImpl(descriptorBytes, true);
assertEquals("TvrqpjI7OmCtwGwair/NHUxg5ROVVQYz6/EDyXsDHR4",
diff --git a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
index abb51db..20b0849 100644
--- a/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
@@ -1,20 +1,19 @@
+/* Copyright 2015--2017 The Tor Project
+ * See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
-import org.junit.Test;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.Microdescriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
public class MicrodescriptorImplTest {
/* Helper class to build a microdescriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String onionKeyLines = "onion-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBALNZ4pNsHHkl7a+kFWbBmPHNAepjjvuhjTr1TaMB3UKuCRaXJmS2Qr"
@@ -22,20 +21,25 @@ public class MicrodescriptorImplTest {
+ "UutXaZ\nfkyty5XOgV4Qucx9wokzTMCHlO0V0x9y0FwFsK5Nb6ugqfQLLQ6XAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static Microdescriptor createWithDefaultLines()
throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
return new MicrodescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyLine =
"ntor-onion-key PXLa7IGE+TzPDMsM5j9rFnDa37rd6kfZa5QuzqqJukw=";
+
private String idLine = "id rsa1024 bvegfGxp8k7T9QFpjPTrPaJTa/8";
+
private static Microdescriptor createWithIdLine(String line)
throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.idLine = line;
return new MicrodescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.onionKeyLines != null) {
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 57a2d89..ebcbd83 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -1,9 +1,7 @@
/* Copyright 2011--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.DirectorySignature;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -11,15 +9,17 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.DirectorySignature;
+import org.torproject.descriptor.NetworkStatusEntry;
+import org.torproject.descriptor.RelayNetworkStatusConsensus;
+
+import org.junit.Test;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
-import org.junit.Test;
-import org.torproject.descriptor.NetworkStatusEntry;
-import org.torproject.descriptor.RelayNetworkStatusConsensus;
-
/* TODO Add test cases for all lines starting with "opt ". */
/* Test parsing of network status consensuses. The main focus is on
@@ -31,6 +31,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a directory source based on default data and
* modifications requested by test methods. */
private static class DirSourceBuilder {
+
private static RelayNetworkStatusConsensus
createWithDirSource(String dirSourceString)
throws DescriptorParseException {
@@ -39,7 +40,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String nickname = "gabelmoo";
+
private static RelayNetworkStatusConsensus
createWithNickname(String string)
throws DescriptorParseException {
@@ -47,7 +50,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.nickname = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String identity = "ED03BB616EB2F60BEC80151114BB25CEF515B226";
+
private static RelayNetworkStatusConsensus
createWithIdentity(String string)
throws DescriptorParseException {
@@ -55,7 +60,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.identity = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String hostName = "212.112.245.170";
+
private static RelayNetworkStatusConsensus
createWithHostName(String string)
throws DescriptorParseException {
@@ -63,7 +70,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.hostName = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String address = "212.112.245.170";
+
private static RelayNetworkStatusConsensus
createWithAddress(String string)
throws DescriptorParseException {
@@ -71,7 +80,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.address = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String dirPort = "80";
+
private static RelayNetworkStatusConsensus
createWithDirPort(String string)
throws DescriptorParseException {
@@ -79,7 +90,9 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.dirPort = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String orPort = "443";
+
private static RelayNetworkStatusConsensus
createWithOrPort(String string)
throws DescriptorParseException {
@@ -87,8 +100,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.orPort = string;
return createWithDirSource(dsb.buildDirSource());
}
+
private String contactLine = "contact 4096R/C5AA446D Sebastian Hahn "
+ "<tor(a)sebastianhahn.net>";
+
private static RelayNetworkStatusConsensus
createWithContactLine(String line)
throws DescriptorParseException {
@@ -96,8 +111,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.contactLine = line;
return createWithDirSource(dsb.buildDirSource());
}
+
private String voteDigestLine =
"vote-digest 0F398A5834D2C139E1D92310B09F814F243354D1";
+
private static RelayNetworkStatusConsensus
createWithVoteDigestLine(String line)
throws DescriptorParseException {
@@ -105,6 +122,7 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.voteDigestLine = line;
return createWithDirSource(dsb.buildDirSource());
}
+
private String buildDirSource() {
StringBuilder sb = new StringBuilder();
String dirSourceLine = "dir-source " + this.nickname + " "
@@ -127,6 +145,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a status entry based on default data and
* modifications requested by test methods. */
private static class StatusEntryBuilder {
+
private static RelayNetworkStatusConsensus
createWithStatusEntry(String statusEntryString)
throws DescriptorParseException {
@@ -135,7 +154,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String nickname = "right2privassy3";
+
private static RelayNetworkStatusConsensus
createWithNickname(String string)
throws DescriptorParseException {
@@ -143,7 +164,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.nickname = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String fingerprintBase64 = "ADQ6gCT3DiFHKPDFr3rODBUI8HM";
+
private static RelayNetworkStatusConsensus
createWithFingerprintBase64(String string)
throws DescriptorParseException {
@@ -151,7 +174,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.fingerprintBase64 = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String descriptorBase64 = "Yiti+nayuT2Efe2X1+M4nslwVuU";
+
private static RelayNetworkStatusConsensus
createWithDescriptorBase64(String string)
throws DescriptorParseException {
@@ -159,7 +184,9 @@ public class RelayNetworkStatusConsensusImplTest {
seb.descriptorBase64 = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String publishedString = "2011-11-29 21:34:27";
+
private static RelayNetworkStatusConsensus
createWithPublishedString(String string)
throws DescriptorParseException {
@@ -167,55 +194,75 @@ public class RelayNetworkStatusConsensusImplTest {
seb.publishedString = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String address = "50.63.8.215";
+
private static RelayNetworkStatusConsensus
createWithAddress(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.address = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String orPort = "9023";
+
private static RelayNetworkStatusConsensus
createWithOrPort(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.orPort = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
private String dirPort = "0";
+
private static RelayNetworkStatusConsensus
createWithDirPort(String string) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.dirPort = string;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String sLine = "s Exit Fast Named Running Stable Valid";
+
private static RelayNetworkStatusConsensus
createWithSLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.sLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String vLine = "v Tor 0.2.1.29 (r8e9b25e6c7a2e70c)";
+
private static RelayNetworkStatusConsensus
createWithVLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.vLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String wLine = "w Bandwidth=1";
+
private static RelayNetworkStatusConsensus
createWithWLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.wLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:membername")
private String pLine = "p accept 80,1194,1220,1293";
+
private static RelayNetworkStatusConsensus
createWithPLine(String line) throws DescriptorParseException {
StatusEntryBuilder seb = new StatusEntryBuilder();
seb.pLine = line;
return createWithStatusEntry(seb.buildStatusEntry());
}
+
+ @SuppressWarnings("checkstyle:localvariablename")
private String buildStatusEntry() {
StringBuilder sb = new StringBuilder();
String rLine = "r " + nickname + " " + fingerprintBase64 + " "
@@ -244,6 +291,7 @@ public class RelayNetworkStatusConsensusImplTest {
/* Helper class to build a directory signature based on default data and
* modifications requested by test methods. */
private static class DirectorySignatureBuilder {
+
private static RelayNetworkStatusConsensus
createWithDirectorySignature(String directorySignatureString)
throws DescriptorParseException {
@@ -252,7 +300,9 @@ public class RelayNetworkStatusConsensusImplTest {
return new RelayNetworkStatusConsensusImpl(cb.buildConsensus(),
true);
}
+
private String identity = "ED03BB616EB2F60BEC80151114BB25CEF515B226";
+
private static RelayNetworkStatusConsensus
createWithIdentity(String string)
throws DescriptorParseException {
@@ -260,8 +310,10 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.identity = string;
return createWithDirectorySignature(dsb.buildDirectorySignature());
}
+
private String signingKey =
"845CF1D0B370CA443A8579D18E7987E7E532F639";
+
private static RelayNetworkStatusConsensus
createWithSigningKey(String string)
throws DescriptorParseException {
@@ -269,6 +321,7 @@ public class RelayNetworkStatusConsensusImplTest {
dsb.signingKey = string;
return createWithDirectorySignature(dsb.buildDirectorySignature());
}
+
private String buildDirectorySignature() {
String directorySignature = "directory-signature " + identity + " "
+ signingKey + "\n"
@@ -1093,16 +1146,16 @@ public class RelayNetworkStatusConsensusImplTest {
@Test()
public void testBandwidthWeightsLineNoSpace()
throws DescriptorParseException {
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithBandwidthWeightsLine("bandwidth-weights");
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithBandwidthWeightsLine("bandwidth-weights");
assertNotNull(consensus.getBandwidthWeights());
}
@Test()
public void testBandwidthWeightsLineOneSpace()
throws DescriptorParseException {
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithBandwidthWeightsLine("bandwidth-weights ");
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithBandwidthWeightsLine("bandwidth-weights ");
assertNotNull(consensus.getBandwidthWeights());
}
@@ -1185,8 +1238,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedHeaderLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedHeaderLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedHeaderLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1204,8 +1257,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirSourceLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1223,8 +1276,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedStatusEntryLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedStatusEntryLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedStatusEntryLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1242,8 +1295,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirectoryFooterLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedFooterLine(unrecognizedLine, false);
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedFooterLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, consensus.getUnrecognizedLines());
@@ -1261,8 +1314,8 @@ public class RelayNetworkStatusConsensusImplTest {
public void testUnrecognizedDirectorySignatureLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusConsensus consensus = ConsensusBuilder.
- createWithUnrecognizedDirectorySignatureLine(unrecognizedLine,
+ RelayNetworkStatusConsensus consensus = ConsensusBuilder
+ .createWithUnrecognizedDirectorySignatureLine(unrecognizedLine,
false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
index 8f4ece2..d550d26 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusImplTest.java
@@ -1,37 +1,31 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import org.torproject.descriptor.DescriptorParseException;
import org.junit.Test;
-import org.torproject.descriptor.RelayNetworkStatus;
public class RelayNetworkStatusImplTest {
- private final static String validHeader = "network-status-version 2\n"
- + "dir-source 194.109.206.212 194.109.206.212 80\n"
- + "fingerprint 7EA6EAD6FD83083C538F44038BBFA077587DD755\n"
- + "contact 1024R/8D56913D Alex de Joode <adejoode(a)sabotage.org>\n"
- + "published 2012-03-01 00:10:43\n"
- + "dir-options\n"
- + "dir-signing-key\n"
- + "-----BEGIN RSA PUBLIC KEY-----\n"
- + "MIGJAoGBAL7QJ6cmXhMlexV97ehnV5hn5ePOeo0sbDYXhlfw52CheEycoUqSD9Y/\n"
- + "3qEo0Rm7XTEol0dRW34ca1LMIXGM4B4whXxBKCRRYe1RY6nF70zb2EUuaHWEWc+f\n"
- + "c6JWYUWZSPpW1uyjyLPUI/ikyyH7zmtR4MfhSeNdt2zSakojYNaPAgMBAAE=\n"
- + "-----END RSA PUBLIC KEY-----\n";
-
- private final static String validStatus =
- "@type network-status-2 1.0\n" + validHeader;
+ private static final String validHeader = "network-status-version 2\n"
+ + "dir-source 194.109.206.212 194.109.206.212 80\n"
+ + "fingerprint 7EA6EAD6FD83083C538F44038BBFA077587DD755\n"
+ + "contact 1024R/8D56913D Alex de Joode <adejoode(a)sabotage.org>\n"
+ + "published 2012-03-01 00:10:43\n"
+ + "dir-options\n"
+ + "dir-signing-key\n"
+ + "-----BEGIN RSA PUBLIC KEY-----\n"
+ + "MIGJAoGBAL7QJ6cmXhMlexV97ehnV5hn5ePOeo0sbDYXhlfw52CheEycoUqSD9Y/\n"
+ + "3qEo0Rm7XTEol0dRW34ca1LMIXGM4B4whXxBKCRRYe1RY6nF70zb2EUuaHWEWc+f\n"
+ + "c6JWYUWZSPpW1uyjyLPUI/ikyyH7zmtR4MfhSeNdt2zSakojYNaPAgMBAAE=\n"
+ + "-----END RSA PUBLIC KEY-----\n";
+
+ private static final String validStatus =
+ "@type network-status-2 1.0\n" + validHeader;
@Test(expected = DescriptorParseException.class)
public void testParseBrokenHeader() throws DescriptorParseException {
@@ -42,12 +36,11 @@ public class RelayNetworkStatusImplTest {
@Test()
public void testValidHeader() throws DescriptorParseException {
- RelayNetworkStatusImpl rnsi
- = new RelayNetworkStatusImpl(validStatus.getBytes(), true);
+ RelayNetworkStatusImpl rnsi =
+ new RelayNetworkStatusImpl(validStatus.getBytes(), true);
rnsi.parseHeader(validHeader.getBytes());
assertEquals(rnsi.getContactLine(),
- "1024R/8D56913D Alex de Joode <adejoode(a)sabotage.org>");
+ "1024R/8D56913D Alex de Joode <adejoode(a)sabotage.org>");
}
-
}
diff --git a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 79cb78c..847c538 100644
--- a/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -1,21 +1,22 @@
/* Copyright 2011--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
-import org.torproject.descriptor.DirectorySignature;
+package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.DirectorySignature;
+import org.torproject.descriptor.RelayNetworkStatusVote;
+
+import org.junit.Test;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.junit.Test;
-import org.torproject.descriptor.RelayNetworkStatusVote;
-
/* TODO Add test cases for all lines starting with "opt ". */
/* Test parsing of network status votes. Some of the vote-parsing code is
@@ -27,7 +28,9 @@ public class RelayNetworkStatusVoteImplTest {
/* Helper class to build a vote based on default data and modifications
* requested by test methods. */
private static class VoteBuilder {
+
private String networkStatusVersionLine = "network-status-version 3";
+
private static RelayNetworkStatusVote
createWithNetworkStatusVersionLine(String line)
throws DescriptorParseException {
@@ -35,7 +38,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.networkStatusVersionLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String voteStatusLine = "vote-status vote";
+
private static RelayNetworkStatusVote
createWithVoteStatusLine(String line)
throws DescriptorParseException {
@@ -43,8 +48,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.voteStatusLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String consensusMethodsLine =
"consensus-methods 1 2 3 4 5 6 7 8 9 10 11";
+
private static RelayNetworkStatusVote
createWithConsensusMethodsLine(String line)
throws DescriptorParseException {
@@ -52,7 +59,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.consensusMethodsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String publishedLine = "published 2011-11-30 08:50:01";
+
private static RelayNetworkStatusVote
createWithPublishedLine(String line)
throws DescriptorParseException {
@@ -60,7 +69,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.publishedLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String validAfterLine = "valid-after 2011-11-30 09:00:00";
+
private static RelayNetworkStatusVote
createWithValidAfterLine(String line)
throws DescriptorParseException {
@@ -68,7 +79,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.validAfterLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String freshUntilLine = "fresh-until 2011-11-30 10:00:00";
+
private static RelayNetworkStatusVote
createWithFreshUntilLine(String line)
throws DescriptorParseException {
@@ -76,7 +89,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.freshUntilLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String validUntilLine = "valid-until 2011-11-30 12:00:00";
+
private static RelayNetworkStatusVote
createWithValidUntilLine(String line)
throws DescriptorParseException {
@@ -84,7 +99,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.validUntilLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String votingDelayLine = "voting-delay 300 300";
+
private static RelayNetworkStatusVote
createWithVotingDelayLine(String line)
throws DescriptorParseException {
@@ -92,8 +109,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.votingDelayLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String clientVersionsLine = "client-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
private static RelayNetworkStatusVote
createWithClientVersionsLine(String line)
throws DescriptorParseException {
@@ -101,8 +120,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.clientVersionsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String serverVersionsLine = "server-versions 0.2.1.31,"
+ "0.2.2.34,0.2.3.6-alpha,0.2.3.7-alpha,0.2.3.8-alpha";
+
private static RelayNetworkStatusVote
createWithServerVersionsLine(String line)
throws DescriptorParseException {
@@ -110,7 +131,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.serverVersionsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String packageLines = null;
+
protected static RelayNetworkStatusVote
createWithPackageLines(String lines)
throws DescriptorParseException {
@@ -118,8 +141,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.packageLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String knownFlagsLine = "known-flags Authority BadExit Exit "
+ "Fast Guard HSDir Named Running Stable Unnamed V2Dir Valid";
+
private static RelayNetworkStatusVote
createWithKnownFlagsLine(String line)
throws DescriptorParseException {
@@ -127,10 +152,12 @@ public class RelayNetworkStatusVoteImplTest {
vb.knownFlagsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String flagThresholdsLine = "flag-thresholds "
+ "stable-uptime=693369 stable-mtbf=153249 fast-speed=40960 "
+ "guard-wfu=94.669% guard-tk=691200 guard-bw-inc-exits=174080 "
+ "guard-bw-exc-exits=184320 enough-mtbf=1";
+
private static RelayNetworkStatusVote
createWithFlagThresholdsLine(String line)
throws DescriptorParseException {
@@ -138,11 +165,13 @@ public class RelayNetworkStatusVoteImplTest {
vb.flagThresholdsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String paramsLine = "params "
+ "CircuitPriorityHalflifeMsec=30000 bwauthbestratio=1 "
+ "bwauthcircs=1 bwauthdescbw=0 bwauthkp=10000 bwauthpid=1 "
+ "bwauthtd=5000 bwauthti=50000 bwauthtidecay=5000 cbtnummodes=3 "
+ "cbtquantile=80 circwindow=1000 refuseunknownexits=1";
+
private static RelayNetworkStatusVote
createWithParamsLine(String line)
throws DescriptorParseException {
@@ -150,9 +179,11 @@ public class RelayNetworkStatusVoteImplTest {
vb.paramsLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirSourceLine = "dir-source urras "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C 208.83.223.34 "
+ "208.83.223.34 443 80";
+
private static RelayNetworkStatusVote
createWithDirSourceLine(String line)
throws DescriptorParseException {
@@ -160,8 +191,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirSourceLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String contactLine = "contact 4096R/E012B42D Jacob Appelbaum "
+ "<jacob(a)appelbaum.net>";
+
private static RelayNetworkStatusVote
createWithContactLine(String line)
throws DescriptorParseException {
@@ -169,7 +202,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.contactLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String legacyDirKeyLine = null;
+
private static RelayNetworkStatusVote
createWithLegacyDirKeyLine(String line)
throws DescriptorParseException {
@@ -177,8 +212,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.legacyDirKeyLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCertificateVersionLine =
"dir-key-certificate-version 3";
+
private static RelayNetworkStatusVote
createWithDirKeyCertificateVersionLine(String line)
throws DescriptorParseException {
@@ -186,8 +223,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCertificateVersionLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String fingerprintLine = "fingerprint "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C";
+
private static RelayNetworkStatusVote
createWithFingerprintLine(String line)
throws DescriptorParseException {
@@ -195,8 +234,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.fingerprintLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyPublishedLine = "dir-key-published 2011-04-27 "
+ "05:34:37";
+
private static RelayNetworkStatusVote
createWithDirKeyPublishedLine(String line)
throws DescriptorParseException {
@@ -204,8 +245,10 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyPublishedLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyExpiresLine = "dir-key-expires 2012-04-27 "
+ "05:34:37";
+
private static RelayNetworkStatusVote
createWithDirKeyExpiresLine(String line)
throws DescriptorParseException {
@@ -213,6 +256,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyExpiresLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirIdentityKeyLines = "dir-identity-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIIBigKCAYEAtKpuLgVK25sfScjsxfVU1ljofrDygt9GP7bNJl/rghX42KUT97"
@@ -225,6 +269,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "TvcaKz9CEj4XcKm+kOmzejYmIa\nkbWNcRpXPiUZ+xmwGtsq30xrzqiONmERkx"
+ "qlmf7bVQPFvh3Kz6hGcmTBhTbHSe9h\nzDgmdaTNn3EHAgMBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static RelayNetworkStatusVote
createWithDirIdentityKeyLines(String lines)
throws DescriptorParseException {
@@ -232,6 +277,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirIdentityKeyLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirSigningKeyLines = "dir-signing-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBAN05qyHFQlTqykMP8yLuD4G2UuYulD4Xs8iSX5uqF+WGsUA1E4zZh4"
@@ -239,6 +285,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "mBGsN7\nPUXyMNjwRKL6UvrcbYk1d2mRBLO7SAP/sFW5fHhIBVeLIWrzQ19rAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static RelayNetworkStatusVote
createWithDirSigningKeyLines(String lines)
throws DescriptorParseException {
@@ -246,12 +293,14 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirSigningKeyLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCrosscertLines = "dir-key-crosscert\n"
+ "-----BEGIN ID SIGNATURE-----\n"
+ "rPBFn6IJ6TvAHj4pSwlg+RTn1fP89JGSVa08wuyJr5dAvZsdakQXvRjamT9oJU"
+ "aZ\nnY5Rl/tRlGuSQ0BglTPPKoXdKERK0FUr9f0EKrQy7NDUgE2j9losiRuyKz"
+ "hA3neZ\nK4yF8bhqAwM51u7fzAhIjNeRif9c04rhFJJCseco84w=\n"
+ "-----END ID SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirKeyCrosscertLines(String lines)
throws DescriptorParseException {
@@ -259,6 +308,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCrosscertLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String dirKeyCertificationLines = "dir-key-certification\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "hPSh6FuohNF5ccjiMbkvr8cZJwGFuL11cNtwN9k0X3pUdFZVATIEkqBe7z+rE2"
@@ -271,6 +321,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "bEGbvY/P8mzVAZxp3Yz+sRtNel\nC1SWz/Fx+Saex5oI7DJ3xtSD4XqKb/wYwZ"
+ "FT8IxDYq1t2tFXdHxd4QPRVcvc0zYC\n"
+ "-----END SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirKeyCertificationLines(String lines)
throws DescriptorParseException {
@@ -278,14 +329,18 @@ public class RelayNetworkStatusVoteImplTest {
vb.dirKeyCertificationLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private List<String> statusEntries = null;
+
private static RelayNetworkStatusVote createWithStatusEntries(
List<String> statusEntries) throws DescriptorParseException {
VoteBuilder vb = new VoteBuilder();
vb.statusEntries = statusEntries;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String directoryFooterLine = "directory-footer";
+
private static RelayNetworkStatusVote
createWithDirectoryFooterLine(String line)
throws DescriptorParseException {
@@ -293,6 +348,7 @@ public class RelayNetworkStatusVoteImplTest {
vb.directoryFooterLine = line;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String directorySignatureLines = "directory-signature "
+ "80550987E1D626E3EBA5E5E75A458DE0626D088C "
+ "EEB9299D295C1C815E289FBF2F2BBEA5F52FDD19\n"
@@ -301,6 +357,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "F3Yh\nrXVaaoP07r6Ta+s0g1Zijm3lms50Nk/4tV2p8Y63c3F4Q3DAnK40Oi"
+ "kfOIwEj+Ny\n+zBRQssP3hPhTPOj/A7o3mZZwtL6x1sxpeu/nME1l5E=\n"
+ "-----END SIGNATURE-----";
+
private static RelayNetworkStatusVote
createWithDirectorySignatureLines(String lines)
throws DescriptorParseException {
@@ -308,7 +365,9 @@ public class RelayNetworkStatusVoteImplTest {
vb.directorySignatureLines = lines;
return new RelayNetworkStatusVoteImpl(vb.buildVote(), true);
}
+
private String unrecognizedHeaderLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedHeaderLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -318,7 +377,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirSourceLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedDirSourceLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -328,7 +389,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedStatusEntryLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedStatusEntryLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -338,7 +401,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedFooterLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedFooterLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -348,7 +413,9 @@ public class RelayNetworkStatusVoteImplTest {
return new RelayNetworkStatusVoteImpl(vb.buildVote(),
failUnrecognizedDescriptorLines);
}
+
private String unrecognizedDirectorySignatureLine = null;
+
protected static RelayNetworkStatusVote
createWithUnrecognizedDirectorySignatureLine(String line,
boolean failUnrecognizedDescriptorLines)
@@ -378,6 +445,7 @@ public class RelayNetworkStatusVoteImplTest {
+ "m 8,9,10,11 "
+ "sha256=9ciEx9t0McXk9A06I7qwN7pxuNOdpCP64RV/6cx2Zkc");
}
+
private byte[] buildVote() {
StringBuilder sb = new StringBuilder();
this.appendHeader(sb);
@@ -387,6 +455,7 @@ public class RelayNetworkStatusVoteImplTest {
this.appendDirectorySignature(sb);
return sb.toString().getBytes();
}
+
private void appendHeader(StringBuilder sb) {
if (this.networkStatusVersionLine != null) {
sb.append(this.networkStatusVersionLine).append("\n");
@@ -434,6 +503,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedHeaderLine).append("\n");
}
}
+
private void appendDirSource(StringBuilder sb) {
if (this.dirSourceLine != null) {
sb.append(this.dirSourceLine).append("\n");
@@ -472,6 +542,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedDirSourceLine).append("\n");
}
}
+
private void appendStatusEntries(StringBuilder sb) {
for (String statusEntry : this.statusEntries) {
sb.append(statusEntry).append("\n");
@@ -480,6 +551,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedStatusEntryLine).append("\n");
}
}
+
private void appendFooter(StringBuilder sb) {
if (this.directoryFooterLine != null) {
sb.append(this.directoryFooterLine).append("\n");
@@ -488,6 +560,7 @@ public class RelayNetworkStatusVoteImplTest {
sb.append(this.unrecognizedFooterLine).append("\n");
}
}
+
private void appendDirectorySignature(StringBuilder sb) {
if (this.directorySignatureLines != null) {
sb.append(directorySignatureLines).append("\n");
@@ -517,8 +590,8 @@ public class RelayNetworkStatusVoteImplTest {
assertEquals(30000, (int) vote.getConsensusParams().get(
"CircuitPriorityHalflifeMsec"));
assertEquals("Tor 0.2.1.29 (r8e9b25e6c7a2e70c)",
- vote.getStatusEntry("00343A8024F70E214728F0C5AF7ACE0C1508F073").
- getVersion());
+ vote.getStatusEntry("00343A8024F70E214728F0C5AF7ACE0C1508F073")
+ .getVersion());
assertEquals(3, vote.getDirKeyCertificateVersion());
assertEquals("80550987E1D626E3EBA5E5E75A458DE0626D088C",
vote.getIdentity());
@@ -832,11 +905,11 @@ public class RelayNetworkStatusVoteImplTest {
}
}
- @Test(expected = DescriptorParseException.class)
- public void testPackageIncomplete() throws DescriptorParseException {
- String packageLine = "package shouldbesecond 0 http";
- ConsensusBuilder.createWithPackageLines(packageLine);
- }
+ @Test(expected = DescriptorParseException.class)
+ public void testPackageIncomplete() throws DescriptorParseException {
+ String packageLine = "package shouldbesecond 0 http";
+ ConsensusBuilder.createWithPackageLines(packageLine);
+ }
@Test(expected = DescriptorParseException.class)
public void testKnownFlagsNoLine() throws DescriptorParseException {
@@ -1284,8 +1357,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedHeaderLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedHeaderLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedHeaderLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
@@ -1303,8 +1376,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedDirSourceLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedDirSourceLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
@@ -1321,8 +1394,8 @@ public class RelayNetworkStatusVoteImplTest {
public void testUnrecognizedFooterLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- RelayNetworkStatusVote vote = VoteBuilder.
- createWithUnrecognizedFooterLine(unrecognizedLine, false);
+ RelayNetworkStatusVote vote = VoteBuilder
+ .createWithUnrecognizedFooterLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, vote.getUnrecognizedLines());
diff --git a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index 0daa83b..3769ead 100644
--- a/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -1,14 +1,20 @@
/* Copyright 2012--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
-import org.torproject.descriptor.DescriptorParseException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.torproject.descriptor.BandwidthHistory;
+import org.torproject.descriptor.DescriptorParseException;
+import org.torproject.descriptor.ServerDescriptor;
+
+import org.junit.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -16,68 +22,79 @@ import java.util.Arrays;
import java.util.List;
import java.util.SortedMap;
-import org.junit.Test;
-import org.torproject.descriptor.BandwidthHistory;
-import org.torproject.descriptor.ServerDescriptor;
-
/* Test parsing of relay server descriptors. */
public class ServerDescriptorImplTest {
/* Helper class to build a descriptor based on default data and
* modifications requested by test methods. */
private static class DescriptorBuilder {
+
private String routerLine = "router saberrider2008 94.134.192.243 "
+ "9001 0 0";
+
private static ServerDescriptor createWithRouterLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String bandwidthLine = "bandwidth 51200 51200 53470";
+
private static ServerDescriptor createWithBandwidthLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.bandwidthLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String platformLine = "platform Tor 0.2.2.35 "
+ "(git-b04388f9e7546a9f) on Linux i686";
+
private static ServerDescriptor createWithPlatformLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.platformLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String publishedLine = "published 2012-01-01 04:03:19";
+
private static ServerDescriptor createWithPublishedLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.publishedLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String fingerprintLine = "opt fingerprint D873 3048 FC8E "
+ "C910 2466 AD8F 3098 622B F1BF 71FD";
+
private static ServerDescriptor createWithFingerprintLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.fingerprintLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hibernatingLine = null;
+
private static ServerDescriptor createWithHibernatingLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hibernatingLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String uptimeLine = "uptime 48";
+
private static ServerDescriptor createWithUptimeLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.uptimeLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String onionKeyLines = "onion-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBAKM+iiHhO6eHsvd6Xjws9z9EQB1V/Bpuy5ciGJ1U4V9SeiKooSo5Bp"
@@ -85,12 +102,14 @@ public class ServerDescriptorImplTest {
+ "uC3cTF\n9wE4WXY4nX7w0RTN18UVLxrt1A9PP0cobFNiPs9rzJCbKFfacOkpAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static ServerDescriptor createWithOnionKeyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.onionKeyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String signingKeyLines = "signing-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBALMm3r3QDh482Ewe6Ub9wvRIfmEkoNX6q5cEAtQRNHSDcNx41gjELb"
@@ -98,99 +117,126 @@ public class ServerDescriptorImplTest {
+ "DhUROG\n8URDIhQoixcUeyyrVB8sxliSstKimulGnB7xpjYOlO8JKaHLNL4TAg"
+ "MBAAE=\n"
+ "-----END RSA PUBLIC KEY-----";
+
private static ServerDescriptor createWithSigningKeyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.signingKeyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String onionKeyCrosscertLines = null;
+
private static ServerDescriptor createWithOnionKeyCrosscertLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.onionKeyCrosscertLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyCrosscertLines = null;
+
private static ServerDescriptor createWithNtorOnionKeyCrosscertLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ntorOnionKeyCrosscertLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String exitPolicyLines = "reject *:*";
+
private static ServerDescriptor createWithExitPolicyLines(
String lines) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.exitPolicyLines = lines;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String contactLine = "contact Random Person <nobody AT "
+ "example dot com>";
+
private static ServerDescriptor createWithContactLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.contactLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String familyLine = null;
+
private static ServerDescriptor createWithFamilyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.familyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String readHistoryLine = null;
+
private static ServerDescriptor createWithReadHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.readHistoryLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String writeHistoryLine = null;
+
private static ServerDescriptor createWithWriteHistoryLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.writeHistoryLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String eventdnsLine = null;
+
private static ServerDescriptor createWithEventdnsLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.eventdnsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String cachesExtraInfoLine = null;
+
private static ServerDescriptor createWithCachesExtraInfoLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.cachesExtraInfoLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String extraInfoDigestLine = "opt extra-info-digest "
+ "1469D1550738A25B1E7B47CDDBCD7B2899F51B74";
+
private static ServerDescriptor createWithExtraInfoDigestLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.extraInfoDigestLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String hiddenServiceDirLine = "opt hidden-service-dir";
+
private static ServerDescriptor createWithHiddenServiceDirLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.hiddenServiceDirLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String protocolsLine = "opt protocols Link 1 2 Circuit 1";
+
private static ServerDescriptor createWithProtocolsLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.protocolsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String allowSingleHopExitsLine = null;
+
private static ServerDescriptor
createWithAllowSingleHopExitsLine(String line)
throws DescriptorParseException {
@@ -198,40 +244,50 @@ public class ServerDescriptorImplTest {
db.allowSingleHopExitsLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ipv6PolicyLine = null;
+
private static ServerDescriptor createWithIpv6PolicyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ipv6PolicyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String ntorOnionKeyLine = null;
+
private static ServerDescriptor createWithNtorOnionKeyLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.ntorOnionKeyLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String tunnelledDirServerLine = null;
+
private static ServerDescriptor createWithTunnelledDirServerLine(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.tunnelledDirServerLine = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String routerSignatureLines = "router-signature\n"
+ "-----BEGIN SIGNATURE-----\n"
+ "o4j+kH8UQfjBwepUnr99v0ebN8RpzHJ/lqYsTojXHy9kMr1RNI9IDeSzA7PSqT"
+ "uV\n4PL8QsGtlfwthtIoZpB2srZeyN/mcpA9fa1JXUrt/UN9K/+32Cyaad7h0n"
+ "HE6Xfb\njqpXDpnBpvk4zjmzjjKYnIsUWTnADmu0fo3xTRqXi7g=\n"
+ "-----END SIGNATURE-----";
+
private static ServerDescriptor createWithRouterSignatureLines(
String line) throws DescriptorParseException {
DescriptorBuilder db = new DescriptorBuilder();
db.routerSignatureLines = line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private String unrecognizedLine = null;
+
private static ServerDescriptor createWithUnrecognizedLine(
String line, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -240,7 +296,9 @@ public class ServerDescriptorImplTest {
return new RelayServerDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
+
private byte[] nonAsciiLineBytes = null;
+
private static ServerDescriptor createWithNonAsciiLineBytes(
byte[] lineBytes, boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
@@ -249,8 +307,13 @@ public class ServerDescriptorImplTest {
return new RelayServerDescriptorImpl(db.buildDescriptor(),
failUnrecognizedDescriptorLines);
}
- private String identityEd25519Lines = null,
- masterKeyEd25519Line = null, routerSigEd25519Line = null;
+
+ private String identityEd25519Lines = null;
+
+ private String masterKeyEd25519Line = null;
+
+ private String routerSigEd25519Line = null;
+
private static ServerDescriptor createWithEd25519Lines(
String identityEd25519Lines, String masterKeyEd25519Line,
String routerSigEd25519Line) throws DescriptorParseException {
@@ -260,6 +323,7 @@ public class ServerDescriptorImplTest {
db.routerSigEd25519Line = routerSigEd25519Line;
return new RelayServerDescriptorImpl(db.buildDescriptor(), true);
}
+
private byte[] buildDescriptor() {
StringBuilder sb = new StringBuilder();
if (this.routerLine != null) {
@@ -418,8 +482,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testRouterOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithRouterLine("opt router saberrider2008 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithRouterLine("opt router saberrider2008 "
+ "94.134.192.243 9001 0 0");
assertEquals("saberrider2008", descriptor.getNickname());
assertEquals("94.134.192.243", descriptor.getAddress());
@@ -455,8 +519,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNicknameTwoSpaces() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithRouterLine("router saberrider2008 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithRouterLine("router saberrider2008 "
+ "94.134.192.243 9001 0 0");
assertEquals("saberrider2008", descriptor.getNickname());
assertEquals("94.134.192.243", descriptor.getAddress());
@@ -512,15 +576,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testPlatformMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine(null);
assertNull(descriptor.getPlatform());
}
@Test()
public void testPlatformOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("opt platform Tor 0.2.2.35 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("opt platform Tor 0.2.2.35 "
+ "(git-b04388f9e7546a9f) on Linux i686");
assertEquals("Tor 0.2.2.35 (git-b04388f9e7546a9f) on Linux i686",
descriptor.getPlatform());
@@ -528,22 +592,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testPlatformNoSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("platform");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("platform");
assertEquals("", descriptor.getPlatform());
}
@Test()
public void testPlatformSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPlatformLine("platform ");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPlatformLine("platform ");
assertEquals("", descriptor.getPlatform());
}
@Test()
public void testProtocolsNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithProtocolsLine("protocols Link 1 2 Circuit 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithProtocolsLine("protocols Link 1 2 Circuit 1");
assertEquals(Arrays.asList(new Integer[] {1, 2}),
descriptor.getLinkProtocolVersions());
assertEquals(Arrays.asList(new Integer[] {1}),
@@ -551,7 +615,7 @@ public class ServerDescriptorImplTest {
}
@Test(expected = DescriptorParseException.class)
- public void testProtocolsAB() throws DescriptorParseException {
+ public void testProtocolsAb() throws DescriptorParseException {
DescriptorBuilder.createWithProtocolsLine("opt protocols Link A B "
+ "Circuit 1");
}
@@ -569,8 +633,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testPublishedOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-01-01 04:03:19");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-01-01 04:03:19");
assertEquals(1325390599000L, descriptor.getPublishedMillis());
}
@@ -599,15 +663,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testPublishedMillis() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithPublishedLine("opt published 2012-01-01 04:03:19.123");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithPublishedLine("opt published 2012-01-01 04:03:19.123");
assertEquals(1325390599000L, descriptor.getPublishedMillis());
}
@Test()
public void testFingerprintNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFingerprintLine("fingerprint D873 3048 FC8E C910 2466 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFingerprintLine("fingerprint D873 3048 FC8E C910 2466 "
+ "AD8F 3098 622B F1BF 71FD");
assertEquals("D8733048FC8EC9102466AD8F3098622BF1BF71FD",
descriptor.getFingerprint());
@@ -639,15 +703,15 @@ public class ServerDescriptorImplTest {
@Test()
public void testUptimeMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUptimeLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUptimeLine(null);
assertNull(descriptor.getUptime());
}
@Test()
public void testUptimeOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUptimeLine("opt uptime 48");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUptimeLine("opt uptime 48");
assertEquals(48, descriptor.getUptime().longValue());
}
@@ -678,8 +742,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testBandwidthOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithBandwidthLine("opt bandwidth 51200 51200 53470");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithBandwidthLine("opt bandwidth 51200 51200 53470");
assertEquals(51200, (int) descriptor.getBandwidthRate());
assertEquals(51200, (int) descriptor.getBandwidthBurst());
assertEquals(53470, (int) descriptor.getBandwidthObserved());
@@ -700,8 +764,8 @@ public class ServerDescriptorImplTest {
/* This is allowed, because Tor versions 0.0.8 and older only wrote
* bandwidth lines with rate and burst values, but no observed
* value. */
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithBandwidthLine("bandwidth 51200 51200");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithBandwidthLine("bandwidth 51200 51200");
assertEquals(51200, (int) descriptor.getBandwidthRate());
assertEquals(51200, (int) descriptor.getBandwidthBurst());
assertEquals(-1, (int) descriptor.getBandwidthObserved());
@@ -721,8 +785,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExtraInfoDigestNoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine("extra-info-digest "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine("extra-info-digest "
+ "1469D1550738A25B1E7B47CDDBCD7B2899F51B74");
assertEquals("1469D1550738A25B1E7B47CDDBCD7B2899F51B74",
descriptor.getExtraInfoDigest());
@@ -753,8 +817,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExtraInfoDigestMissing()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine(null);
assertNull(descriptor.getExtraInfoDigest());
}
@@ -766,8 +830,8 @@ public class ServerDescriptorImplTest {
"V609l+N6ActBveebfNbH5lQ6wHDNstDkFgyqEhBHwtA";
String extraInfoDigestLine = String.format("extra-info-digest %s %s",
extraInfoDigest, additionalExtraInfoDigest);
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExtraInfoDigestLine(extraInfoDigestLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExtraInfoDigestLine(extraInfoDigestLine);
assertEquals(extraInfoDigest, descriptor.getExtraInfoDigest());
}
@@ -796,16 +860,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testHiddenServiceDirMissing()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine(null);
assertNull(descriptor.getHiddenServiceDirVersions());
}
@Test()
public void testHiddenServiceDirNoOpt()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine("hidden-service-dir");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine("hidden-service-dir");
assertEquals(Arrays.asList(new Integer[] {2}),
descriptor.getHiddenServiceDirVersions());
}
@@ -813,23 +877,23 @@ public class ServerDescriptorImplTest {
@Test()
public void testHiddenServiceDirVersions2And3()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHiddenServiceDirLine("hidden-service-dir 2 3");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHiddenServiceDirLine("hidden-service-dir 2 3");
assertEquals(Arrays.asList(new Integer[] {2, 3}),
descriptor.getHiddenServiceDirVersions());
}
@Test()
public void testContactMissing() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine(null);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine(null);
assertNull(descriptor.getContact());
}
@Test()
public void testContactOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("opt contact Random Person");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("opt contact Random Person");
assertEquals("Random Person", descriptor.getContact());
}
@@ -841,8 +905,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testContactNoSpace() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("contact");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("contact");
assertEquals("", descriptor.getContact());
}
@@ -856,24 +920,24 @@ public class ServerDescriptorImplTest {
+ "07\rmTQoP40G4zqOrVEOOcXpdSiRnHWJYfgTnkibNZrOZEZLn3H1ywpovEgESm"
+ "oGEdAX\roid3XuIYRpRnqoafbFg9sg+OofX/mGrO+5ACfagQ9rlfx2oxCWijYw"
+ "pYFRk3NhCY=\r=Xaw3\r-----END PGP PUBLIC KEY BLOCK-----";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithContactLine("contact " + contactString);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithContactLine("contact " + contactString);
assertEquals(contactString, descriptor.getContact());
}
@Test()
public void testExitPolicyRejectAllAcceptAll()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("reject *:*\naccept *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("reject *:*\naccept *:*");
assertEquals(Arrays.asList(new String[] {"reject *:*", "accept *:*"}),
descriptor.getExitPolicyLines());
}
@Test()
public void testExitPolicyOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("opt reject *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("opt reject *:*");
assertEquals(Arrays.asList(new String[] {"reject *:*"}),
descriptor.getExitPolicyLines());
}
@@ -886,8 +950,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExitPolicyAccept80RejectAll()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("accept *:80\nreject *:*");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("accept *:80\nreject *:*");
assertEquals(Arrays.asList(new String[] {"accept *:80",
"reject *:*"}), descriptor.getExitPolicyLines());
}
@@ -916,8 +980,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testExitPolicyMaskTypes() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithExitPolicyLines("reject 192.168.0.0/16:*\n"
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithExitPolicyLines("reject 192.168.0.0/16:*\n"
+ "reject 94.134.192.243/255.255.255.0:*");
assertEquals(Arrays.asList(new String[] { "reject 192.168.0.0/16:*",
"reject 94.134.192.243/255.255.255.0:*"}),
@@ -947,22 +1011,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testHibernatingOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("opt hibernating 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("opt hibernating 1");
assertTrue(descriptor.isHibernating());
}
@Test()
public void testHibernatingFalse() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("hibernating 0");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("hibernating 0");
assertFalse(descriptor.isHibernating());
}
@Test()
public void testHibernatingTrue() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithHibernatingLine("hibernating 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithHibernatingLine("hibernating 1");
assertTrue(descriptor.isHibernating());
}
@@ -978,16 +1042,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("opt family saberrider2008");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("opt family saberrider2008");
assertEquals(Arrays.asList(new String[] {"saberrider2008"}),
descriptor.getFamilyEntries());
}
@Test()
public void testFamilyFingerprint() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD");
assertEquals(Arrays.asList(new String[] {
"$D8733048FC8EC9102466AD8F3098622BF1BF71FD"}),
@@ -996,8 +1060,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyNickname() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family saberrider2008");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family saberrider2008");
assertEquals(Arrays.asList(new String[] {"saberrider2008"}),
descriptor.getFamilyEntries());
}
@@ -1023,8 +1087,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyFingerprintNicknameNamed()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD=saberrider2008");
assertEquals(Arrays.asList(new String[]
{ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD=saberrider2008" }),
@@ -1034,8 +1098,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testFamilyFingerprintNicknameUnnamed()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithFamilyLine("family "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithFamilyLine("family "
+ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008");
assertEquals(Arrays.asList(new String[]
{ "$D8733048FC8EC9102466AD8F3098622BF1BF71FD~saberrider2008" }),
@@ -1046,16 +1110,16 @@ public class ServerDescriptorImplTest {
public void testWriteHistory() throws DescriptorParseException {
String writeHistoryLine = "write-history 2012-01-01 03:51:44 (900 s) "
+ "4345856,261120,7591936,1748992";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine(writeHistoryLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine(writeHistoryLine);
assertNotNull(descriptor.getWriteHistory());
BandwidthHistory parsedWriteHistory = descriptor.getWriteHistory();
assertEquals(writeHistoryLine, parsedWriteHistory.getLine());
- assertEquals(1325389904000L, (long) parsedWriteHistory.
- getHistoryEndMillis());
+ assertEquals(1325389904000L, (long) parsedWriteHistory
+ .getHistoryEndMillis());
assertEquals(900L, (long) parsedWriteHistory.getIntervalLength());
- SortedMap<Long, Long> bandwidthValues = parsedWriteHistory.
- getBandwidthValues();
+ SortedMap<Long, Long> bandwidthValues = parsedWriteHistory
+ .getBandwidthValues();
assertEquals(4345856L, (long) bandwidthValues.remove(1325387204000L));
assertEquals(261120L, (long) bandwidthValues.remove(1325388104000L));
assertEquals(7591936L, (long) bandwidthValues.remove(1325389004000L));
@@ -1065,8 +1129,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistoryOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("opt write-history 2012-01-01 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("opt write-history 2012-01-01 "
+ "03:51:44 (900 s) 4345856,261120,7591936,1748992");
assertNotNull(descriptor.getWriteHistory());
}
@@ -1115,25 +1179,25 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistoryNoValuesSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(900 s) ");
- assertEquals(900, (long) descriptor.getWriteHistory().
- getIntervalLength());
- assertTrue(descriptor.getWriteHistory().getBandwidthValues().
- isEmpty());
+ assertEquals(900, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
+ assertTrue(descriptor.getWriteHistory().getBandwidthValues()
+ .isEmpty());
}
@Test()
public void testWriteHistoryNoValuesNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(900 s)");
- assertEquals(900, (long) descriptor.getWriteHistory().
- getIntervalLength());
- assertTrue(descriptor.getWriteHistory().getBandwidthValues().
- isEmpty());
+ assertEquals(900, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
+ assertTrue(descriptor.getWriteHistory().getBandwidthValues()
+ .isEmpty());
}
@Test(expected = DescriptorParseException.class)
@@ -1152,27 +1216,27 @@ public class ServerDescriptorImplTest {
@Test()
public void testWriteHistory1800Seconds()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithWriteHistoryLine("write-history 2012-01-01 03:51:44 "
+ "(1800 s) 4345856");
- assertEquals(1800L, (long) descriptor.getWriteHistory().
- getIntervalLength());
+ assertEquals(1800L, (long) descriptor.getWriteHistory()
+ .getIntervalLength());
}
@Test()
public void testReadHistory() throws DescriptorParseException {
String readHistoryLine = "read-history 2012-01-01 03:51:44 (900 s) "
+ "4268032,139264,7797760,1415168";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithReadHistoryLine(readHistoryLine);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithReadHistoryLine(readHistoryLine);
assertNotNull(descriptor.getReadHistory());
BandwidthHistory parsedReadHistory = descriptor.getReadHistory();
assertEquals(readHistoryLine, parsedReadHistory.getLine());
- assertEquals(1325389904000L, (long) parsedReadHistory.
- getHistoryEndMillis());
+ assertEquals(1325389904000L, (long) parsedReadHistory
+ .getHistoryEndMillis());
assertEquals(900L, (long) parsedReadHistory.getIntervalLength());
- SortedMap<Long, Long> bandwidthValues = parsedReadHistory.
- getBandwidthValues();
+ SortedMap<Long, Long> bandwidthValues = parsedReadHistory
+ .getBandwidthValues();
assertEquals(4268032L, (long) bandwidthValues.remove(1325387204000L));
assertEquals(139264L, (long) bandwidthValues.remove(1325388104000L));
assertEquals(7797760L, (long) bandwidthValues.remove(1325389004000L));
@@ -1191,22 +1255,22 @@ public class ServerDescriptorImplTest {
@Test()
public void testEventdnsOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("opt eventdns 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("opt eventdns 1");
assertTrue(descriptor.getUsesEnhancedDnsLogic());
}
@Test()
public void testEventdns1() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("eventdns 1");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("eventdns 1");
assertTrue(descriptor.getUsesEnhancedDnsLogic());
}
@Test()
public void testEventdns0() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithEventdnsLine("eventdns 0");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithEventdnsLine("eventdns 0");
assertFalse(descriptor.getUsesEnhancedDnsLogic());
}
@@ -1222,16 +1286,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testCachesExtraInfoOpt() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithCachesExtraInfoLine("opt caches-extra-info");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithCachesExtraInfoLine("opt caches-extra-info");
assertTrue(descriptor.getCachesExtraInfo());
}
@Test()
public void testCachesExtraInfoNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithCachesExtraInfoLine("caches-extra-info");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithCachesExtraInfoLine("caches-extra-info");
assertTrue(descriptor.getCachesExtraInfo());
}
@@ -1244,16 +1308,16 @@ public class ServerDescriptorImplTest {
@Test()
public void testAllowSingleHopExitsOpt()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithAllowSingleHopExitsLine("opt allow-single-hop-exits");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithAllowSingleHopExitsLine("opt allow-single-hop-exits");
assertTrue(descriptor.getAllowSingleHopExits());
}
@Test()
public void testAllowSingleHopExitsNoSpace()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithAllowSingleHopExitsLine("allow-single-hop-exits");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithAllowSingleHopExitsLine("allow-single-hop-exits");
assertTrue(descriptor.getAllowSingleHopExits());
}
@@ -1278,8 +1342,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testIpv6PolicyLine() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithIpv6PolicyLine("ipv6-policy accept 80,1194,1220,1293");
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithIpv6PolicyLine("ipv6-policy accept 80,1194,1220,1293");
assertEquals("accept", descriptor.getIpv6DefaultPolicy());
assertEquals("80,1194,1220,1293", descriptor.getIpv6PortList());
}
@@ -1317,8 +1381,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNtorOnionKeyLine() throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithNtorOnionKeyLine("ntor-onion-key "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithNtorOnionKeyLine("ntor-onion-key "
+ "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY=");
assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
descriptor.getNtorOnionKey());
@@ -1327,8 +1391,8 @@ public class ServerDescriptorImplTest {
@Test()
public void testNtorOnionKeyLineNoPadding()
throws DescriptorParseException {
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithNtorOnionKeyLine("ntor-onion-key "
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithNtorOnionKeyLine("ntor-onion-key "
+ "Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY");
assertEquals("Y/XgaHcPIJVa4D55kir9QLH8rEYAaLXuv3c3sm8jYhY",
descriptor.getNtorOnionKey());
@@ -1403,8 +1467,8 @@ public class ServerDescriptorImplTest {
public void testUnrecognizedLineIgnore()
throws DescriptorParseException {
String unrecognizedLine = "unrecognized-line 1";
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(unrecognizedLine, false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(unrecognizedLine, false);
List<String> unrecognizedLines = new ArrayList<>();
unrecognizedLines.add(unrecognizedLine);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
@@ -1426,8 +1490,8 @@ public class ServerDescriptorImplTest {
for (String line : unrecognizedLines) {
sb.append("\n").append(line);
}
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(sb.toString().substring(1), false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(sb.toString().substring(1), false);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
@@ -1447,8 +1511,8 @@ public class ServerDescriptorImplTest {
for (String line : unrecognizedLines) {
sb.append("\n").append(line);
}
- ServerDescriptor descriptor = DescriptorBuilder.
- createWithUnrecognizedLine(sb.toString().substring(1), false);
+ ServerDescriptor descriptor = DescriptorBuilder
+ .createWithUnrecognizedLine(sb.toString().substring(1), false);
assertEquals(unrecognizedLines, descriptor.getUnrecognizedLines());
}
@@ -1579,7 +1643,7 @@ public class ServerDescriptorImplTest {
public void testOnionKeyCrosscertDuplicate()
throws DescriptorParseException {
DescriptorBuilder.createWithOnionKeyCrosscertLines(
- ONION_KEY_CROSSCERT_LINES + "\n" + ONION_KEY_CROSSCERT_LINES);
+ ONION_KEY_CROSSCERT_LINES + "\n" + ONION_KEY_CROSSCERT_LINES);
}
@Test()
diff --git a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
index 62d0875..080d16d 100644
--- a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
@@ -1,19 +1,21 @@
/* Copyright 2015--2017 The Tor Project
* See LICENSE for licensing information */
+
package org.torproject.descriptor.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.List;
+import org.torproject.descriptor.Descriptor;
import org.junit.Test;
-import org.torproject.descriptor.Descriptor;
+
+import java.util.List;
public class TorperfResultImplTest {
@Test()
- public void testAnnotatedInput() throws Exception{
+ public void testAnnotatedInput() throws Exception {
TorperfResultImpl result = (TorperfResultImpl)
(TorperfResultImpl.parseTorperfResults((torperfAnnotation + input)
.getBytes("US-ASCII"), false).get(0));
@@ -29,7 +31,7 @@ public class TorperfResultImplTest {
}
@Test()
- public void testPartiallyAnnotatedInput() throws Exception{
+ public void testPartiallyAnnotatedInput() throws Exception {
byte[] asciiBytes = (torperfAnnotation
+ input + input + input).getBytes("US-ASCII");
List<Descriptor> result = TorperfResultImpl.parseTorperfResults(
1
0