Commit Graph

340 Commits

Author SHA1 Message Date
Karsten Loesing
3c98457777 Prepare for 1.9.0 release. 2017-06-20 22:36:58 +02:00
Karsten Loesing
a113feb2c4 Add new method to retrieve raw descriptor length.
When we switched from storing copies of byte[] to storing byte[]
references, offset, and length, getRawDescriptor() suddenly became
more expensive than before.  (Before that, copying bytes in the first
place was always expensive.)  If an application only calls
Descriptor#getRawDescriptorBytes() to learn the array length, there's
now a more efficient way to provide that information.
2017-06-20 20:24:12 +02:00
Karsten Loesing
1062da637f Make DescriptorFile obsolete.
This change simplifies the DescriptorReader interface and allows for
shorter and more concise application code.  The result is that
DescriptorReader returns Descriptor instances rather than
DescriptorFile instances containing Descriptors and accepts a maximum
queue size in Descriptors, DescriptorFile is deprecated, and
Descriptor contains a File reference to the descriptor file.
Implements #22141.

Related to this change, this commit introduces a new
UnparseableDescriptor to be returned by DescriptorParser and
DescriptorReader if a descriptor cannot be parsed, as opposed to
throwing a DescriptorParseException or skipping the entire descriptor
file (fixes #22139), respectively.

Also related to this change, DescriptorParser now returns an Iterable
instead of a List, which prepares parsing large descriptor files
descriptor by descriptor (will be tackled in #20395).
2017-06-20 20:21:29 +02:00
Karsten Loesing
0236dc7771 Rename two parse* methods to verify*. 2017-06-19 11:42:18 +02:00
Karsten Loesing
de9600a5dc Change encoding of microdescriptor digests in network status entries.
Fixes #22640.
2017-06-17 21:39:24 +02:00
Karsten Loesing
47a69b342f Add a test for the encoding of microdescriptor digests in votes 2017-06-17 21:18:11 +02:00
Karsten Loesing
59dc55fbe1 Bump version to 1.8.2-dev. 2017-06-16 17:03:41 +02:00
Karsten Loesing
be96d96b83 Prepare for 1.8.2 release. 2017-06-16 16:54:50 +02:00
iwakeh
3affad3f88 Add test for task-22634. 2017-06-16 12:55:35 +00:00
iwakeh
5954b34462 Make DescriptorParserImpl.parseDescriptor easily accessible for testing. 2017-06-16 12:55:34 +00:00
Karsten Loesing
0917016f6b Fix a regression in parsing descriptors. 2017-06-16 14:55:33 +02:00
iwakeh
1ac254697b Escalate NoSuchAlgorithmExceptions. 2017-06-16 11:40:57 +02:00
Karsten Loesing
c7a4ffe6cc Replace all @Test() with @Test. 2017-06-12 10:10:04 +02:00
iwakeh
83cf2bb101 Minor readability and space changes.
Removed check that cannot evaluate as true.
2017-06-12 10:08:44 +02:00
iwakeh
c39a15a2ff Also check exception message in tests. Part of task-22280. 2017-06-12 10:08:38 +02:00
Karsten Loesing
569795e282 Bump version to 1.8.1-dev. 2017-06-08 16:00:34 +02:00
Karsten Loesing
e0e5d87aac Prepare for 1.8.1 release. 2017-06-08 09:44:47 +02:00
iwakeh
352b717071 Implements fix discovered by karsten.
Implements task-22533.
2017-06-07 07:07:50 +00:00
iwakeh
f18c6ef8b7 Part of task-22533: failing test. 2017-06-07 07:07:49 +00:00
Karsten Loesing
d739229ebc Bump version to 1.8.0-dev. 2017-06-07 09:07:48 +02:00
Karsten Loesing
086b046057 Prepare for 1.8.0 release. 2017-06-06 15:28:52 +02:00
iwakeh
a3f4168467 Added simple tests for DescriptorImpl. 2017-06-06 15:08:55 +02:00
Karsten Loesing
6052e22b08 Don't compute bridge descriptor digests.
These calls will fail for computing bridge descriptor digests, because
there are no `-----END SIGNATURE-----` lines in sanitized bridge
descriptors.
2017-06-06 15:08:55 +02:00
Karsten Loesing
a4d184bf94 Store raw descriptors as byte[], offset, and length.
Prior to this commit we read raw descriptor bytes from disk, split
them into serveral byte[] for each contained descriptor, and stored
those copies together with descriptors.  We further copied descriptor
parts, like signatures or status entries, and stored those copies as
well.

Overall, we temporarily required up to 3 times the size of descriptor
files just to store raw descriptor contents: 1) the entire descriptor
file read to memory, 2) copies of all contained descriptors, and 3)
copies of contained descriptor parts.  After moving on to the next
descriptor file, 1) was freed, but 2) and 3) remained in memory.  This
was rather wasteful.

With this commit we store raw descriptors as reference to the byte[]
containing the entire descriptor file plus offset and length of the
part containing one descriptor.  Similarly we store raw descriptor
parts as a reference to the full descriptor plus offset and length of
the descriptor part.  This saves a lot of memory, and it avoids
unnecessary array copying.

This change is also a step towards not storing raw descriptor contents
in memory at all, but instead leaving contents on disk and accessing
parts as needed.  However, this commit does not take that step yet.

The original purpose of this commit was to prepare switching from the
platform's default charset to UTF-8 for #21932.  The idea was to
reduce access to DescriptorImpl#rawDescriptorBytes and add all methods
working on those bytes, including converting them to a String, to
DescriptorImpl.  This commit achieves this purpose by preparing that
switch, yet it does not take that step, either.  Switching to UTF-8 is
midly backward-incompatible, so it'll have to wait until 2.0.0.
However, switching will be much easier based on the changes in this
commit.

Many of these changes in this commit are interdependent which makes it
difficult to split up this commit with reasonable effort.  Still, in
order to facilitate reviews, here is an explanation of changes made in
this commit from top to bottom:

Move all code for processing raw descriptor bytes from a) detecting
the descriptor type, b) finding descriptor starts and ends, up to c)
invoking the right DescriptorImpl subclass constructors from
DescriptorImpl and its subclasses over to DescriptorParserImpl.

Include offset and limit in the constructors of DescriptorImpl and
most of its subclasses.

Refer to directory and network status parts in RelayDirectoryImpl and
NetworkStatusImpl and its subclasses by offset and length rather than
passing copies of raw descriptors.

Provide two overloaded methods DescriptorImpl#newScanner() that
internally handle the byte[]-to-String conversion rather than leaving
this task to all DescriptorImpl subclasses.

In DescriptorImpl, rather than storing a copy of raw descriptor bytes
per descriptor, store a reference to a potentially larger byte[],
containing all descriptors read from a given file, together with
offset and length.

Provide various methods in DescriptorImpl that provide access to raw
descriptor bytes and that internally handle issues like unified
character encoding.

Include an XXX21932 tag in all places where byte[] is currently
converted to String using the platform's default charset.

Update existing methods in DescriptorImpl to only access
rawDescriptorBytes within offset and offset + length.

In classes referenced from DescriptorImpl subclasses, like
DirSourceEntryImpl and NetworkStatusEntryImpl, rather than storing a
copy of raw descriptor bytes, store a reference to the parent
DescriptorImpl instance together with offset and length.

Change raw descriptor bytes in ExitListEntryImpl into a String,
because the byte[] we stored there was never read from disk but
generated by ourselves using String#getBytes() using the platform's
default charset.  We also never used raw bytes in ExitListEntryImpl
anyway.  Admittedly, we could use offset and length there, too, but
the amount of saved memory is likely not worth the necessary code
changes.

Remove redundant zero-length checks from DescriptorImpl subclasses
including ExitListImpl, NetworkStatusImpl, and RelayDirectoryImpl.
These checks are redundant, because we already performed the same
checks in DescriptorImpl#countKeys().

Move commonly used helper methods for finding the first index of a
keyword or splitting descriptory by keyword from DescriptorImpl
subclasses, like NetworkStatusImpl and RelayDirectoryImpl, to
DescriptorImpl.

In test classes, replace the numerous invocations of DescriptorImpl
subclass constructors with local buildSomething() methods, so that
future changes to constructor signatures won't produce a diff as long
as this one.
2017-06-06 15:08:49 +02:00
Karsten Loesing
fadcaa4b20 Fix encoding bug in RelayDirectoryImpl and NetworkStatusImpl. 2017-06-06 15:03:50 +02:00
Karsten Loesing
232ea426b5 Fix bug in digest computation. 2017-06-06 15:03:40 +02:00
Karsten Loesing
74de0a5d7a Move descriptor digest computation to DescriptorImpl.
The main intention behind this change is to reduce the number of
places in the code where byte[] is converted to String.  But another
reason is to reduce code duplication, which would have been sufficient
to make this change.
2017-06-06 15:02:41 +02:00
Karsten Loesing
82f555ee35 Fix encoding of Microdescriptor's getDigestSha256Base64(). 2017-06-06 15:02:27 +02:00
Karsten Loesing
823fa496ce Fix bug in newly simplified method. 2017-06-04 17:37:18 +02:00
Karsten Loesing
38221ed097 Simplify and avoid repetition in parse helper methods.
Implements #22279.
2017-06-01 10:44:27 +02:00
Karsten Loesing
2362535963 Move latest change log entry to next release. 2017-05-26 16:14:17 +02:00
iwakeh
df6bdc8d9b Implements task-19607.
Use enums for keywords as well as enum sets and maps.
Use constants for repeated strings.
2017-05-26 16:08:57 +02:00
Karsten Loesing
bd52bcaeb5 Bump version to 1.7.0-dev. 2017-05-17 14:00:41 +02:00
Karsten Loesing
6941084f25 Prepare for 1.7.0 release. 2017-05-16 16:53:49 +02:00
Karsten Loesing
b82c054dbf Fix a few checkstyle complaints about whitespace. 2017-05-16 16:53:42 +02:00
Karsten Loesing
3c0b08135a Test for empty keys in more places. 2017-05-16 16:26:20 +02:00
iwakeh
08ccbf83f7 Reverse equality test in if-statements.
(This should be in checkstyle.)
2017-05-16 16:26:20 +02:00
iwakeh
8456cb154a Make all tests pass. Implements task-22217. 2017-05-16 16:26:20 +02:00
iwakeh
cdab58758a Let tests also verify error message (for all padding-count related tests).
Added some tests of which two don't pass yet.
2017-05-16 16:26:14 +02:00
Karsten Loesing
75844d046c Parse "padding-counts" lines in extra-info descriptors.
Implements #22217.
2017-05-16 16:23:43 +02:00
Karsten Loesing
f6252f909f Tweak change log. 2017-05-12 12:14:57 +02:00
Karsten Loesing
091fc90e17 Deprecate setFailUnrecognizedDescriptorLines().
Implements #22228.
2017-05-11 21:03:45 +02:00
Karsten Loesing
d242a2aa4d Add descriptor digest to vote and streamline method names.
Implements #20333.
2017-05-10 16:15:01 +02:00
Karsten Loesing
2187c711ad Add change log entry for #22190. 2017-05-10 14:26:07 +02:00
iwakeh
e927475c12 Make tests pass again and solve task-22190. 2017-05-09 15:17:09 +00:00
iwakeh
f483211795 Provided failing test for issue in task-22190. 2017-05-09 15:17:08 +00:00
iwakeh
3e3636b8d8 Extended JavaDoc explanation. Part of task-22190. 2017-05-09 15:17:07 +00:00
Karsten Loesing
2ed7d618b1 Tweak change log a bit. 2017-05-09 17:17:06 +02:00
Karsten Loesing
71885a8e69 Accept extra arguments in extra-info descriptors.
According to the specification it's valid to add extra arguments to
descriptor lines unless they are tagged with "[No extra arguments]".
This is not the case for any of the statistics-related lines in
extra-info descriptors, so we should allow extra arguments there.

Fixes #21934.
2017-05-09 17:15:32 +02:00
Karsten Loesing
ee696b09f0 Add support for six new key-value pairs added by OnionPerf.
OnionPerf adds six new key-value pairs to the .tpf format that
Torperf/CollecTor did not produce: ENDPOINTLOCAL, ENDPOINTPROXY,
ENDPOINTREMOTE, HOSTNAMELOCAL, HOSTNAMEREMOTE, and SOURCEADDRESS.

We should add support for these keys to metrics-lib, so that we can
start using their values.

Implements #22122.
2017-05-08 20:49:20 +02:00