commit a56c96d66c880e60ddf818697b006502f3177eac Author: iwakeh iwakeh@torproject.org Date: Fri Jun 23 08:37:42 2017 +0000
Remove all deprecation warnings. Test might not compile yet. Part of task-22154. --- .../descriptor/DescriptorDownloader.java | 201 ------------- .../org/torproject/descriptor/DescriptorFile.java | 84 ------ .../descriptor/DescriptorParseException.java | 4 +- .../torproject/descriptor/DescriptorParser.java | 17 -- .../torproject/descriptor/DescriptorReader.java | 84 ------ .../torproject/descriptor/DescriptorRequest.java | 104 ------- .../descriptor/DescriptorSourceFactory.java | 40 +-- .../org/torproject/descriptor/DirSourceEntry.java | 10 - .../descriptor/DirectoryKeyCertificate.java | 10 - .../torproject/descriptor/DirectorySignature.java | 11 - .../java/org/torproject/descriptor/ExitList.java | 11 - .../org/torproject/descriptor/ExitListEntry.java | 55 ---- .../torproject/descriptor/ExtraInfoDescriptor.java | 47 --- .../org/torproject/descriptor/Microdescriptor.java | 11 - .../torproject/descriptor/NetworkStatusEntry.java | 11 - .../org/torproject/descriptor/RelayDirectory.java | 11 - .../torproject/descriptor/RelayNetworkStatus.java | 11 - .../descriptor/RelayNetworkStatusConsensus.java | 24 -- .../descriptor/RelayNetworkStatusVote.java | 29 -- .../torproject/descriptor/ServerDescriptor.java | 48 +-- .../impl/BridgeExtraInfoDescriptorImpl.java | 7 +- .../descriptor/impl/BridgeNetworkStatusImpl.java | 16 +- .../descriptor/impl/BridgePoolAssignmentImpl.java | 3 +- .../impl/BridgeServerDescriptorImpl.java | 7 +- .../descriptor/impl/DescriptorCollectorImpl.java | 264 ----------------- .../descriptor/impl/DescriptorDownloaderImpl.java | 294 ------------------- .../descriptor/impl/DescriptorFileImpl.java | 93 ------ .../torproject/descriptor/impl/DescriptorImpl.java | 13 +- .../descriptor/impl/DescriptorParseException.java | 23 -- .../descriptor/impl/DescriptorParserImpl.java | 55 ++-- .../descriptor/impl/DescriptorReaderImpl.java | 145 +-------- .../descriptor/impl/DescriptorRequestImpl.java | 137 --------- .../descriptor/impl/DirSourceEntryImpl.java | 23 +- .../descriptor/impl/DirectoryDownloader.java | 111 ------- .../impl/DirectoryKeyCertificateImpl.java | 18 +- .../descriptor/impl/DirectorySignatureImpl.java | 23 +- .../descriptor/impl/DownloadCoordinator.java | 11 - .../descriptor/impl/DownloadCoordinatorImpl.java | 323 --------------------- .../descriptor/impl/ExitListEntryImpl.java | 69 +---- .../torproject/descriptor/impl/ExitListImpl.java | 27 +- .../descriptor/impl/ExtraInfoDescriptorImpl.java | 50 +--- .../descriptor/impl/MicrodescriptorImpl.java | 21 +- .../descriptor/impl/NetworkStatusEntryImpl.java | 24 +- .../descriptor/impl/NetworkStatusImpl.java | 13 +- .../descriptor/impl/RelayDirectoryImpl.java | 27 +- .../impl/RelayExtraInfoDescriptorImpl.java | 7 +- .../impl/RelayNetworkStatusConsensusImpl.java | 36 +-- .../descriptor/impl/RelayNetworkStatusImpl.java | 14 +- .../impl/RelayNetworkStatusVoteImpl.java | 43 +-- .../descriptor/impl/RelayServerDescriptorImpl.java | 7 +- .../descriptor/impl/ServerDescriptorImpl.java | 48 +-- .../descriptor/impl/TorperfResultImpl.java | 14 +- .../descriptor/impl/UnparseableDescriptorImpl.java | 4 +- .../descriptor/DummyDownloaderImplementation.java | 15 - .../impl/DescriptorCollectorImplTest.java | 121 -------- 55 files changed, 136 insertions(+), 2793 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/DescriptorDownloader.java b/src/main/java/org/torproject/descriptor/DescriptorDownloader.java deleted file mode 100644 index 52b25bf..0000000 --- a/src/main/java/org/torproject/descriptor/DescriptorDownloader.java +++ /dev/null @@ -1,201 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor; - -import java.util.Iterator; -import java.util.Set; - -/** - * Descriptor source that downloads relay descriptors from directory - * authorities or mirrors. - * - * <p>Downloading descriptors is done in a batch which starts after - * setting any configuration options and initiating the download - * process.</p> - * - * @deprecated Removed as descriptor source in favor of the much more widely - * used {@link DescriptorCollector}. - * - * @since 1.0.0 - */ -public interface DescriptorDownloader { - - /** - * Add a directory authority to download descriptors from, which is - * only required for downloading network status votes and will be used - * when no directory mirrors are available. - * - * @since 1.0.0 - */ - public void addDirectoryAuthority(String nickname, String ip, - int dirPort); - - /** - * Add a directory mirror to download descriptors from, which is - * preferred for downloading descriptors, except for network status - * votes which are only available on directory authorities. - * - * @since 1.0.0 - */ - public void addDirectoryMirror(String nickname, String ip, int dirPort); - - /** - * Include the current network status consensus in the downloads. - * - * @since 1.0.0 - */ - public void setIncludeCurrentConsensus(); - - /** - * Include the current network status consensus in the downloads, and - * attempt to download it from all directory authorities. - * - * <p>The primary purpose of doing this is to compare different - * consensuses and download characteristics to each other. Typically, - * downloading from a single directory mirror or authority is - * sufficient.</p> - * - * @since 1.0.0 - */ - public void setIncludeCurrentConsensusFromAllDirectoryAuthorities(); - - /** - * Include the current network status votes referenced from a - * previously downloaded consensus in the downloads, which requires - * downloading the current consensus from at least one directory mirror - * or authority. - * - * @since 1.0.0 - */ - public void setIncludeCurrentReferencedVotes(); - - /** - * Include the current network status vote published by the given - * directory authority in the downloads, which requires downloading from - * at least one directory authority. - * - * @since 1.0.0 - */ - public void setIncludeCurrentVote(String fingerprint); - - /** - * Include the current network status votes published by the given - * directory authorities in the downloads, which requires downloading - * from at least one directory authority. - * - * @since 1.0.0 - */ - public void setIncludeCurrentVotes(Set<String> fingerprints); - - /** - * Include all server descriptors referenced from a previously - * downloaded network status consensus in the downloads. - * - * @since 1.0.0 - */ - public void setIncludeReferencedServerDescriptors(); - - /** - * Exclude the server descriptor with the given identifier from the - * downloads even if it's referenced from a consensus and we're supposed - * to download all referenced server descriptors. - * - * @since 1.0.0 - */ - public void setExcludeServerDescriptor(String identifier); - - /** - * Exclude the server descriptors with the given identifiers from the - * downloads even if they are referenced from a consensus and we're - * supposed to download all referenced server descriptors. - * - * @since 1.0.0 - */ - public void setExcludeServerDescriptors(Set<String> identifier); - - /** - * Include all extra-info descriptors referenced from previously - * downloaded server descriptors in the downloads. - * - * @since 1.0.0 - */ - public void setIncludeReferencedExtraInfoDescriptors(); - - /** - * Exclude the extra-info descriptor with the given identifier from the - * downloads even if it's referenced from a server descriptor and we're - * supposed to download all referenced extra-info descriptors. - * - * @since 1.0.0 - */ - public void setExcludeExtraInfoDescriptor(String identifier); - - /** - * Exclude the extra-info descriptors with the given identifiers from - * the downloads even if they are referenced from server descriptors - * and we're supposed to download all referenced extra-info - * descriptors. - * - * @since 1.0.0 - */ - public void setExcludeExtraInfoDescriptors(Set<String> identifiers); - - /** - * Define a connect timeout for a single request. - * - * <p>If a timeout expires, no further requests will be sent to the - * directory authority or mirror. Setting this value to 0 disables the - * connect timeout. Default value is 1 minute (60 * 1000).</p> - * - * @since 1.0.0 - */ - public void setConnectTimeout(long connectTimeoutMillis); - - /** - * Define a read timeout for a single request. - * - * <p>If a timeout expires, no further requests will be sent to the - * directory authority or mirror. Setting this value to 0 disables the - * read timeout. Default value is 1 minute (60 * 1000).</p> - * - * @since 1.0.0 - */ - public void setReadTimeout(long readTimeoutMillis); - - /** - * Define a global timeout for all requests. - * - * <p>Once this timeout expires, all running requests are aborted and no - * further requests are made. Setting this value to 0 disables the - * global timeout. Default is 1 hour (60 * 60 * 1000).</p> - * - * @since 1.0.0 - */ - public void setGlobalTimeout(long globalTimeoutMillis); - - /** - * Fail descriptor parsing when encountering an unrecognized line. - * - * <p>This option is not set by default, because the Tor specifications - * allow for new lines to be added that shall be ignored by older Tor - * versions. But some applications may want to handle unrecognized - * descriptor lines explicitly.</p> - * - * @since 1.0.0 - */ - public void setFailUnrecognizedDescriptorLines(); - - /** - * Download the previously configured relay descriptors and make them - * available via the returned blocking iterator. - * - * <p>Whenever the downloader runs out of descriptors and expects to - * provide more shortly after, it blocks the caller. This method can - * only be run once.</p> - * - * @since 1.0.0 - */ - public Iterator<DescriptorRequest> downloadDescriptors(); -} - diff --git a/src/main/java/org/torproject/descriptor/DescriptorFile.java b/src/main/java/org/torproject/descriptor/DescriptorFile.java deleted file mode 100644 index e8c0d21..0000000 --- a/src/main/java/org/torproject/descriptor/DescriptorFile.java +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor; - -import java.io.File; -import java.util.List; - -/** - * Container for descriptors read from a file. - * - * <p>When the {@link DescriptorReader} reads descriptors from local files - * it provides an iterator over these containers which in turn contain - * references to classes implementing the {@link Descriptor} interface. - * This container also stores potentially useful meta-data about the - * descriptor file.</p> - * - * @deprecated Irrelevant after introducing - * {@link DescriptorReader#readDescriptors(File...)}, which returns - * {@link Descriptor}s rather than {@link DescriptorFile}s, and including - * the descriptor file reference in {@link Descriptor#getDescriptorFile()} - * and the first thrown {@link DescriptorParseException} in - * {@link UnparseableDescriptor#getDescriptorParseException()}. - * - * @since 1.0.0 - */ -public interface DescriptorFile { - - /** - * Return the directory where this descriptor file was contained, or - * null if the file was contained in a tarball. - * - * @since 1.0.0 - */ - public File getDirectory(); - - /** - * Return the tarball where this descriptor file was contained, or null - * if the file was not contained in a tarball. - * - * @since 1.0.0 - */ - public File getTarball(); - - /** - * Return the descriptor file itself, or null if the descriptor file - * was contained in a tarball. - * - * @since 1.0.0 - */ - public File getFile(); - - /** - * Return the descriptor file name, which is either the absolute path - * of the file on disk, or the tar file entry name. - * - * @since 1.0.0 - */ - public String getFileName(); - - /** - * Return the time in milliseconds since the epoch when the descriptor - * file on disk was last modified. - * - * @since 1.0.0 - */ - public long getLastModified(); - - /** - * Return the descriptors contained in the descriptor file. - * - * @since 1.0.0 - */ - public List<Descriptor> getDescriptors(); - - /** - * Return the first exception that was thrown when reading this file or - * parsing its content, or null if no exception was thrown. - * - * @since 1.0.0 - */ - public Exception getException(); -} - diff --git a/src/main/java/org/torproject/descriptor/DescriptorParseException.java b/src/main/java/org/torproject/descriptor/DescriptorParseException.java index 5f46077..c9e7d93 100644 --- a/src/main/java/org/torproject/descriptor/DescriptorParseException.java +++ b/src/main/java/org/torproject/descriptor/DescriptorParseException.java @@ -9,9 +9,7 @@ package org.torproject.descriptor; * * @since 1.0.0 */ -@SuppressWarnings("deprecation") -public class DescriptorParseException - extends org.torproject.descriptor.impl.DescriptorParseException { +public class DescriptorParseException extends Exception {
private static final long serialVersionUID = 100L;
diff --git a/src/main/java/org/torproject/descriptor/DescriptorParser.java b/src/main/java/org/torproject/descriptor/DescriptorParser.java index 61f69f4..0082b5f 100644 --- a/src/main/java/org/torproject/descriptor/DescriptorParser.java +++ b/src/main/java/org/torproject/descriptor/DescriptorParser.java @@ -24,23 +24,6 @@ import java.util.List; public interface DescriptorParser {
/** - * Fail descriptor parsing when encountering an unrecognized line. - * - * <p>This option is not set by default, because the Tor specifications - * allow for new lines to be added that shall be ignored by older Tor - * versions. But some applications may want to handle unrecognized - * descriptor lines explicitly.</p> - * - * @deprecated Removed in an attempt to simplify the interface. Applications - * that must fail descriptors with unrecognized lines can instead check - * whether {@link Descriptor#getUnrecognizedLines()} returns any lines. - * - * @since 1.0.0 - */ - public void setFailUnrecognizedDescriptorLines( - boolean failUnrecognizedDescriptorLines); - - /** * Parse descriptors in the given byte array, possibly parsing the * publication time from the file name, depending on the descriptor * type. diff --git a/src/main/java/org/torproject/descriptor/DescriptorReader.java b/src/main/java/org/torproject/descriptor/DescriptorReader.java index e15e5d9..4adff39 100644 --- a/src/main/java/org/torproject/descriptor/DescriptorReader.java +++ b/src/main/java/org/torproject/descriptor/DescriptorReader.java @@ -4,7 +4,6 @@ package org.torproject.descriptor;
import java.io.File; -import java.util.Iterator; import java.util.SortedMap;
/** @@ -38,46 +37,6 @@ import java.util.SortedMap; public interface DescriptorReader {
/** - * Add a local directory to read descriptors from, which may contain - * descriptor files or tarballs containing descriptor files. - * - * @deprecated Replaced with a parameter in {@link #readDescriptors(File...)}, - * which ignores any directories added via this deprecated method. - * - * @since 1.0.0 - */ - public void addDirectory(File directory); - - /** - * Add a tarball to read descriptors from, which may be uncompressed, - * bz2-compressed, or xz-compressed. - * - * @deprecated Replaced with a parameter in {@link #readDescriptors(File...)}, - * which ignores any tarballs added via this deprecated method. - * - * @since 1.0.0 - */ - public void addTarball(File tarball); - - /** - * Exclude files that are listed in the given history file and that - * haven't changed since they have last been read. - * - * <p>Add a new line for each descriptor that is read in this execution - * and remove lines for files that don't exist anymore.</p> - * - * <p>Lines in the history file contain the last modified time in - * milliseconds since the epoch and the absolute path of a file.</p> - * - * @deprecated Replaced by {@link #setHistoryFile(File)} and - * {@link #saveHistoryFile(File)} which let the application explicitly - * tell us when it's done processing read descriptors. - * - * @since 1.0.0 - */ - public void setExcludeFiles(File historyFile); - - /** * Set a history file to load before reading descriptors and exclude * descriptor files that haven't changed since they have last been read. * @@ -136,35 +95,6 @@ public interface DescriptorReader { public SortedMap<String, Long> getParsedFiles();
/** - * Fail descriptor parsing when encountering an unrecognized line. - * - * <p>This option is not set by default, because the Tor specifications - * allow for new lines to be added that shall be ignored by older Tor - * versions. But some applications may want to handle unrecognized - * descriptor lines explicitly.</p> - * - * @deprecated Removed in an attempt to simplify the interface. Applications - * that must fail descriptors with unrecognized lines can instead check - * whether {@link Descriptor#getUnrecognizedLines()} returns any lines. - * - * @since 1.0.0 - */ - public void setFailUnrecognizedDescriptorLines(); - - /** - * Don't keep more than this number of parsed descriptor files in the - * queue. - * - * <p>The default is 100, but if descriptor files contain hundreds or - * even thousands of descriptors, that default may be too high.</p> - * - * @deprecated Replaced with {@link #setMaxDescriptorsInQueue(int)}. - * - * @since 1.0.0 - */ - public void setMaxDescriptorFilesInQueue(int max); - - /** * Don't keep more than this number of descriptors in the queue (default: * 100). * @@ -175,20 +105,6 @@ public interface DescriptorReader { public void setMaxDescriptorsInQueue(int maxDescriptorsInQueue);
/** - * Read the previously configured descriptors and make them available - * via the returned blocking iterator. - * - * <p>Whenever the reader runs out of descriptors and expects to provide - * more shortly after, it blocks the caller. This method can only be - * run once.</p> - * - * @deprecated Replaced with {@link #readDescriptors(File...)}. - * - * @since 1.0.0 - */ - public Iterator<DescriptorFile> readDescriptors(); - - /** * Read descriptors from the given descriptor file(s) and return the parsed * descriptors. * diff --git a/src/main/java/org/torproject/descriptor/DescriptorRequest.java b/src/main/java/org/torproject/descriptor/DescriptorRequest.java deleted file mode 100644 index 9009ca8..0000000 --- a/src/main/java/org/torproject/descriptor/DescriptorRequest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor; - -import java.util.List; - -/** - * Container for descriptors downloaded from a directory authority or - * mirror. - * - * <p>When the {@link DescriptorDownloader} downloads descriptors from - * directory authorities or mirrors it provides an iterator over these - * containers which in turn contain references to classes implementing the - * {@link Descriptor} interface. This container also stores potentially - * useful meta-data about the descriptor request.</p> - * - * @deprecated Removed as descriptor container together with - * {@link DescriptorDownloader} in favor of the much more widely used - * {@link DescriptorCollector}. - * - * @since 1.0.0 - */ -public interface DescriptorRequest { - - /** - * Return the request URL that was used in this request. - * - * @since 1.0.0 - */ - public String getRequestUrl(); - - /** - * Return the nickname of the directory mirror or authority as - * previously configured. - * - * @since 1.0.0 - */ - public String getDirectoryNickname(); - - /** - * Return the first exception that was thrown when making this request - * or parsing the response, or null if no exception was thrown. - * - * @since 1.0.0 - */ - public Exception getException(); - - /** - * Return the response code that the directory mirror or authority - * returned. - * - * @since 1.0.0 - */ - public int getResponseCode(); - - /** - * Return the time in milliseconds since the epoch when this request - * was started. - * - * @since 1.0.0 - */ - public long getRequestStart(); - - /** - * Return the time in milliseconds since the epoch when this request - * ended. - * - * @since 1.0.0 - */ - public long getRequestEnd(); - - /** - * Return whether this request ended, because the connect timeout has - * expired. - * - * @since 1.0.0 - */ - public boolean connectTimeoutHasExpired(); - - /** - * Return whether this request ended, because the read timeout has - * expired. - * - * @since 1.0.0 - */ - public boolean readTimeoutHasExpired(); - - /** - * Return whether this request ended, because the global timeout for - * all requests has expired. - * - * @since 1.0.0 - */ - public boolean globalTimeoutHasExpired(); - - /** - * Return the descriptors contained in the reply. - * - * @since 1.0.0 - */ - public List<Descriptor> getDescriptors(); -} - diff --git a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java index 7125ace..f2c1a43 100644 --- a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java +++ b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java @@ -11,10 +11,9 @@ import org.slf4j.LoggerFactory; * * <p>Descriptor sources are the only producers of classes implementing * the {@link Descriptor} superinterface. There exist descriptor sources - * for obtaining remote descriptor data ({@link DescriptorDownloader} and - * {@link DescriptorCollector}) and descriptor sources for processing - * local descriptor data ({@link DescriptorReader} and - * {@link DescriptorParser}).</p> + * for obtaining remote descriptor data ({@link DescriptorCollector}) and + * descriptor sources for processing local descriptor data + * ({@link DescriptorReader} and {@link DescriptorParser}).</p> * * <p>By default, this factory returns implementations from the library's * own impl package. This may be overridden by setting Java properties, @@ -23,7 +22,6 @@ import org.slf4j.LoggerFactory; * <p>These properties can be used for setting the implementation:</p> * <ul> * <li>{@code descriptor.collector}</li> - * <li>{@code descriptor.downloader}</li> * <li>{@code descriptor.parser}</li> * <li>{@code descriptor.reader}</li> * </ul> @@ -46,15 +44,6 @@ public final class DescriptorSourceFactory { DescriptorSourceFactory.class);
/** - * Default implementation of the {@link DescriptorDownloader} - * descriptor source. - * - * @since 1.0.0 - */ - public static final String DOWNLOADER_DEFAULT = - "org.torproject.descriptor.impl.DescriptorDownloaderImpl"; - - /** * Default implementation of the {@link DescriptorParser} descriptor * source. * @@ -101,16 +90,6 @@ public final class DescriptorSourceFactory {
/** * Property name for overriding the implementation of the - * {@link DescriptorDownloader} descriptor source, which is by default - * set to the class in {@link #DOWNLOADER_DEFAULT}. - * - * @since 1.0.0 - */ - public static final String DOWNLOADER_PROPERTY = - "descriptor.downloader"; - - /** - * Property name for overriding the implementation of the * {@link DescriptorCollector} descriptor source, which is by default * set to the class in {@link #COLLECTOR_DEFAULT}. * @@ -139,16 +118,6 @@ public final class DescriptorSourceFactory { }
/** - * Create a new {@link DescriptorDownloader} by instantiating the class - * in {@link #DOWNLOADER_PROPERTY}. - * - * @since 1.0.0 - */ - public static final DescriptorDownloader createDescriptorDownloader() { - return (DescriptorDownloader) retrieve(DOWNLOADER_PROPERTY); - } - - /** * Create a new {@link DescriptorCollector} by instantiating the class * in {@link #COLLECTOR_PROPERTY}. * @@ -166,9 +135,6 @@ public final class DescriptorSourceFactory { case PARSER_PROPERTY: clazzName = System.getProperty(type, PARSER_DEFAULT); break; - case DOWNLOADER_PROPERTY: - clazzName = System.getProperty(type, DOWNLOADER_DEFAULT); - break; case READER_PROPERTY: clazzName = System.getProperty(type, READER_DEFAULT); break; diff --git a/src/main/java/org/torproject/descriptor/DirSourceEntry.java b/src/main/java/org/torproject/descriptor/DirSourceEntry.java index 9996ff2..69e8525 100644 --- a/src/main/java/org/torproject/descriptor/DirSourceEntry.java +++ b/src/main/java/org/torproject/descriptor/DirSourceEntry.java @@ -89,16 +89,6 @@ public interface DirSourceEntry { * Return the SHA-1 vote digest, encoded as 40 lower-case hexadecimal * characters. * - * @deprecated Renamed to {@link #getVoteDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getVoteDigest(); - - /** - * Return the SHA-1 vote digest, encoded as 40 lower-case hexadecimal - * characters. - * * @since 1.7.0 */ public String getVoteDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java b/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java index f2d37ad..2819fc3 100644 --- a/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java +++ b/src/main/java/org/torproject/descriptor/DirectoryKeyCertificate.java @@ -102,16 +102,6 @@ public interface DirectoryKeyCertificate extends Descriptor { * Return the SHA-1 certificate digest, encoded as 40 lower-case * hexadecimal characters. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getCertificateDigest(); - - /** - * Return the SHA-1 certificate digest, encoded as 40 lower-case - * hexadecimal characters. - * * @since 1.7.0 */ public String getDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/DirectorySignature.java b/src/main/java/org/torproject/descriptor/DirectorySignature.java index bb3d5c4..9ce44df 100644 --- a/src/main/java/org/torproject/descriptor/DirectorySignature.java +++ b/src/main/java/org/torproject/descriptor/DirectorySignature.java @@ -37,17 +37,6 @@ public interface DirectorySignature { * in the version 3 directory protocol, encoded as 40 upper-case * hexadecimal characters. * - * @deprecated Renamed to {@link #getSigningKeyDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getSigningKeyDigest(); - - /** - * Return the SHA-1 digest of the authority's medium-term signing key - * in the version 3 directory protocol, encoded as 40 upper-case - * hexadecimal characters. - * * @since 1.7.0 */ public String getSigningKeyDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/ExitList.java b/src/main/java/org/torproject/descriptor/ExitList.java index 052362a..2623ee5 100644 --- a/src/main/java/org/torproject/descriptor/ExitList.java +++ b/src/main/java/org/torproject/descriptor/ExitList.java @@ -74,17 +74,6 @@ public interface ExitList extends Descriptor { /** * Return the unordered set of exit scan results. * - * @since 1.0.0 - * @deprecated The {@link ExitListEntry} type has been deprecated and - * superseded by {@link ExitList.Entry} which is returned by - * {@link #getEntries()}. - */ - @Deprecated - public Set<ExitListEntry> getExitListEntries(); - - /** - * Return the unordered set of exit scan results. - * * @since 1.1.0 */ public Set<ExitList.Entry> getEntries(); diff --git a/src/main/java/org/torproject/descriptor/ExitListEntry.java b/src/main/java/org/torproject/descriptor/ExitListEntry.java deleted file mode 100644 index 94d5970..0000000 --- a/src/main/java/org/torproject/descriptor/ExitListEntry.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2012--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor; - -/** - * Exit list entry containing results from a single exit scan. - * - * @since 1.0.0 - * @deprecated Superseded by {@link ExitList.Entry}. - */ -@Deprecated -public interface ExitListEntry extends ExitList.Entry { - - /** - * Return the scanned relay's fingerprint, which is a SHA-1 digest of - * the relays's public identity key, encoded as 40 upper-case - * hexadecimal characters. - * - * @since 1.0.0 - */ - public String getFingerprint(); - - /** - * Return the time in milliseconds since the epoch when the scanned - * relay's last known descriptor was published. - * - * @since 1.0.0 - */ - public long getPublishedMillis(); - - /** - * Return the time in milliseconds since the epoch when the network - * status that this scan was based on was published. - * - * @since 1.0.0 - */ - public long getLastStatusMillis(); - - /** - * Return the IPv4 address in dotted-quad format that was determined in - * the scan. - * - * @since 1.0.0 - */ - public String getExitAddress(); - - /** - * Return the scan time in milliseconds since the epoch. - * - * @since 1.0.0 - */ - public long getScanMillis(); -} - diff --git a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java index 04a46d4..333c853 100644 --- a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java +++ b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java @@ -48,18 +48,6 @@ public interface ExtraInfoDescriptor extends Descriptor { * characters, that is used to reference this descriptor from a server * descriptor. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getExtraInfoDigest(); - - /** - * Return the SHA-1 descriptor digest, encoded as 40 lower-case (relay - * descriptors) or upper-case (bridge descriptors) hexadecimal - * characters, that is used to reference this descriptor from a server - * descriptor. - * * @since 1.7.0 */ public String getDigestSha1Hex(); @@ -69,17 +57,6 @@ public interface ExtraInfoDescriptor extends Descriptor { * characters without padding characters, that may be used to reference * this descriptor from a server descriptor. * - * @deprecated Renamed to {@link #getDigestSha256Base64()}. - * - * @since 1.1.0 - */ - public String getExtraInfoDigestSha256(); - - /** - * Return the SHA-256 descriptor digest, encoded as 43 base64 - * characters without padding characters, that may be used to reference - * this descriptor from a server descriptor. - * * @since 1.7.0 */ public String getDigestSha256Base64(); @@ -135,18 +112,6 @@ public interface ExtraInfoDescriptor extends Descriptor { * upper-case hexadecimal characters, or null if no GeoIP database * digest is included. * - * @deprecated Renamed to {@link #getGeoipDbDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getGeoipDbDigest(); - - /** - * Return a SHA-1 digest of the GeoIP database file used by this server - * to resolve client IP addresses to country codes, encoded as 40 - * upper-case hexadecimal characters, or null if no GeoIP database - * digest is included. - * * @since 1.7.0 */ public String getGeoipDbDigestSha1Hex(); @@ -157,18 +122,6 @@ public interface ExtraInfoDescriptor extends Descriptor { * upper-case hexadecimal characters, or null if no GeoIPv6 database * digest is included. * - * @deprecated Renamed to {@link #getGeoip6DbDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getGeoip6DbDigest(); - - /** - * Return a SHA-1 digest of the GeoIPv6 database file used by this - * server to resolve client IP addresses to country codes, encoded as 40 - * upper-case hexadecimal characters, or null if no GeoIPv6 database - * digest is included. - * * @since 1.7.0 */ public String getGeoip6DbDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/Microdescriptor.java b/src/main/java/org/torproject/descriptor/Microdescriptor.java index b49b8bb..ef69417 100644 --- a/src/main/java/org/torproject/descriptor/Microdescriptor.java +++ b/src/main/java/org/torproject/descriptor/Microdescriptor.java @@ -28,17 +28,6 @@ public interface Microdescriptor extends Descriptor { * characters without padding characters, that is used to reference this * descriptor from a vote or microdescriptor consensus. * - * @deprecated Renamed to {@link #getDigestSha256Base64()}. - * - * @since 1.0.0 - */ - public String getMicrodescriptorDigest(); - - /** - * Return the SHA-256 descriptor digest, encoded as 43 base64 - * characters without padding characters, that is used to reference this - * descriptor from a vote or microdescriptor consensus. - * * @since 1.7.0 */ public String getDigestSha256Base64(); diff --git a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java index 9c5dae5..bbc0173 100644 --- a/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java +++ b/src/main/java/org/torproject/descriptor/NetworkStatusEntry.java @@ -93,17 +93,6 @@ public interface NetworkStatusEntry { * base64 characters without padding characters, if the containing network * status is a vote or microdesc consensus, or null otherwise. * - * @deprecated Renamed to {@link #getMicrodescriptorDigestsSha256Base64()}. - * - * @since 1.0.0 - */ - public Set<String> getMicrodescriptorDigests(); - - /** - * Return the (possibly empty) set of microdescriptor digests, encoded as 43 - * base64 characters without padding characters, if the containing network - * status is a vote or microdesc consensus, or null otherwise. - * * @since 1.7.0 */ public Set<String> getMicrodescriptorDigestsSha256Base64(); diff --git a/src/main/java/org/torproject/descriptor/RelayDirectory.java b/src/main/java/org/torproject/descriptor/RelayDirectory.java index dd696cf..f05f65d 100644 --- a/src/main/java/org/torproject/descriptor/RelayDirectory.java +++ b/src/main/java/org/torproject/descriptor/RelayDirectory.java @@ -97,17 +97,6 @@ public interface RelayDirectory extends Descriptor { * hexadecimal characters, that the directory authority used to sign the * directory. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getDirectoryDigest(); - - /** - * Return the SHA-1 directory digest, encoded as 40 lower-case - * hexadecimal characters, that the directory authority used to sign the - * directory. - * * @since 1.7.0 */ public String getDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java index b14d0c3..1197c2e 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatus.java @@ -169,17 +169,6 @@ public interface RelayNetworkStatus extends Descriptor { * characters, that the directory authority used to sign the network * status. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getStatusDigest(); - - /** - * Return the SHA-1 status digest, encoded as 40 lower-case hexadecimal - * characters, that the directory authority used to sign the network - * status. - * * @since 1.7.0 */ public String getDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java index fe66007..2b433dc 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatusConsensus.java @@ -252,19 +252,6 @@ public interface RelayNetworkStatusConsensus extends Descriptor { public NetworkStatusEntry getStatusEntry(String fingerprint);
/** - * Return directory signatures of this consensus, with map keys being - * SHA-1 digests of the authorities' identity keys in the version 3 - * directory protocol, encoded as 40 upper-case hexadecimal characters. - * - * @deprecated Replaced by {@link #getSignatures()} which permits an - * arbitrary number of signatures made by an authority using the - * same identity key digest and different algorithms. - * - * @since 1.0.0 - */ - public SortedMap<String, DirectorySignature> getDirectorySignatures(); - - /** * Return the list of signatures contained in this consensus. * * @since 1.3.0 @@ -286,17 +273,6 @@ public interface RelayNetworkStatusConsensus extends Descriptor { * hexadecimal characters that directory authorities use to sign the * consensus. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getConsensusDigest(); - - /** - * Return the SHA-1 digest of this consensus, encoded as 40 lower-case - * hexadecimal characters that directory authorities use to sign the - * consensus. - * * @since 1.7.0 */ public String getDigestSha1Hex(); diff --git a/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java b/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java index 5d9d039..1e4b0a5 100644 --- a/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java +++ b/src/main/java/org/torproject/descriptor/RelayNetworkStatusVote.java @@ -408,21 +408,6 @@ public interface RelayNetworkStatusVote extends Descriptor { public String getDirSigningKey();
/** - * Return the SHA-1 digest of the authority's signing key, encoded as - * 40 upper-case hexadecimal characters, or null if this digest cannot - * be obtained from the directory signature. - * - * @deprecated Removed in order to be more explicit that authorities may - * use different digest algorithms than "sha1"; see - * {@link #getSignatures()} and - * {@link DirectorySignature#getSigningKeyDigestSha1Hex()} for - * alternatives. - * - * @since 1.0.0 - */ - public String getSigningKeyDigest(); - - /** * Return the signature of the authority's identity key made using the * authority's signing key, or null if the vote does not contain such a * signature. @@ -470,20 +455,6 @@ public interface RelayNetworkStatusVote extends Descriptor { public NetworkStatusEntry getStatusEntry(String fingerprint);
/** - * Return the directory signature of this vote, with the single map key - * being the SHA-1 digest of the authority's identity key in the version - * 3 directory protocol, encoded as 40 upper-case hexadecimal - * characters. - * - * @deprecated Replaced by {@link #getSignatures()} which permits an - * arbitrary number of signatures made by the authority using the - * same identity key digest and different algorithms. - * - * @since 1.0.0 - */ - public SortedMap<String, DirectorySignature> getDirectorySignatures(); - - /** * Return a list of signatures contained in this vote, which is * typically a single signature made by the authority but which may also * be more than one signature made with different keys or algorithms. diff --git a/src/main/java/org/torproject/descriptor/ServerDescriptor.java b/src/main/java/org/torproject/descriptor/ServerDescriptor.java index 3ac0cc9..0aeb543 100644 --- a/src/main/java/org/torproject/descriptor/ServerDescriptor.java +++ b/src/main/java/org/torproject/descriptor/ServerDescriptor.java @@ -51,18 +51,6 @@ public interface ServerDescriptor extends Descriptor { * characters, that is used to reference this descriptor from a network * status descriptor. * - * @deprecated Renamed to {@link #getDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getServerDescriptorDigest(); - - /** - * Return the SHA-1 descriptor digest, encoded as 40 lower-case (relay - * descriptors) or upper-case (bridge descriptors) hexadecimal - * characters, that is used to reference this descriptor from a network - * status descriptor. - * * @since 1.7.0 */ public String getDigestSha1Hex(); @@ -72,17 +60,6 @@ public interface ServerDescriptor extends Descriptor { * characters without padding characters, that may be used to reference * this server descriptor from a network status descriptor. * - * @deprecated Renamed to {@link #getDigestSha256Base64()}. - * - * @since 1.1.0 - */ - public String getServerDescriptorDigestSha256(); - - /** - * Return the SHA-256 descriptor digest, encoded as 43 base64 - * characters without padding characters, that may be used to reference - * this server descriptor from a network status descriptor. - * * @since 1.7.0 */ public String getDigestSha256Base64(); @@ -113,7 +90,7 @@ public interface ServerDescriptor extends Descriptor {
/** * Return the TCP port where this server accepts SOCKS connections, - * which is deprecated and should always be 0. + * which is deprecated in the Tor Protocol and should always be 0. * * @since 1.0.0 */ @@ -322,17 +299,6 @@ public interface ServerDescriptor extends Descriptor { * encoded as 40 upper-case hexadecimal characters, or null if the * server did not upload a corresponding extra-info descriptor. * - * @deprecated Renamed to {@link #getExtraInfoDigestSha1Hex()}. - * - * @since 1.0.0 - */ - public String getExtraInfoDigest(); - - /** - * Return the SHA-1 digest of the server's extra-info descriptor, - * encoded as 40 upper-case hexadecimal characters, or null if the - * server did not upload a corresponding extra-info descriptor. - * * @since 1.7.0 */ public String getExtraInfoDigestSha1Hex(); @@ -343,18 +309,6 @@ public interface ServerDescriptor extends Descriptor { * if the server either did not upload a corresponding extra-info * descriptor or did not refer to it using a SHA-256 digest. * - * @deprecated Renamed to {@link #getExtraInfoDigestSha256Base64()}. - * - * @since 1.1.0 - */ - public String getExtraInfoDigestSha256(); - - /** - * Return the SHA-256 digest of the server's extra-info descriptor, - * encoded as 43 base64 characters without padding characters, or null - * if the server either did not upload a corresponding extra-info - * descriptor or did not refer to it using a SHA-256 digest. - * * @since 1.7.0 */ public String getExtraInfoDigestSha256Base64(); diff --git a/src/main/java/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java index b2b3e99..d8941a6 100644 --- a/src/main/java/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/BridgeExtraInfoDescriptorImpl.java @@ -12,10 +12,9 @@ public class BridgeExtraInfoDescriptorImpl extends ExtraInfoDescriptorImpl implements BridgeExtraInfoDescriptor {
protected BridgeExtraInfoDescriptorImpl(byte[] descriptorBytes, - int[] offsetAndLimit, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, offsetAndLimit, descriptorFile, - failUnrecognizedDescriptorLines); + int[] offsetAndLimit, File descriptorFile) + throws DescriptorParseException { + super(descriptorBytes, offsetAndLimit, descriptorFile); } }
diff --git a/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java index a54c91c..01cd221 100644 --- a/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java @@ -20,10 +20,10 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl implements BridgeNetworkStatus {
protected BridgeNetworkStatusImpl(byte[] rawDescriptorBytes, - int[] offsetAndLength, File descriptorFile, String fileName, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { + int[] offsetAndLength, File descriptorFile, String fileName) + throws DescriptorParseException { super(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false, false); + false, false); this.setPublishedMillisFromFileName(fileName); }
@@ -86,14 +86,8 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl this.parseFlagThresholdsLine(line, parts); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in bridge network status."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } } } diff --git a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java index b2015ff..195690b 100644 --- a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java @@ -18,8 +18,7 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl protected BridgePoolAssignmentImpl(byte[] rawDescriptorBytes, int[] offsetAndlength, File descriptorFile, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(rawDescriptorBytes, offsetAndlength, descriptorFile, - failUnrecognizedDescriptorLines, false); + super(rawDescriptorBytes, offsetAndlength, descriptorFile, false); this.parseDescriptorBytes(); this.checkExactlyOnceKeys(EnumSet.of(Key.BRIDGE_POOL_ASSIGNMENT)); this.checkFirstKey(Key.BRIDGE_POOL_ASSIGNMENT); diff --git a/src/main/java/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java index 30da220..8125102 100644 --- a/src/main/java/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/BridgeServerDescriptorImpl.java @@ -12,10 +12,9 @@ public class BridgeServerDescriptorImpl extends ServerDescriptorImpl implements BridgeServerDescriptor {
protected BridgeServerDescriptorImpl(byte[] rawDescriptorBytes, - int[] offsetAndLength, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines); + int[] offsetAndLength, File descriptorFile) + throws DescriptorParseException { + super(rawDescriptorBytes, offsetAndLength, descriptorFile); } }
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java deleted file mode 100644 index 214227f..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java +++ /dev/null @@ -1,264 +0,0 @@ -/* Copyright 2015--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.DescriptorCollector; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Map; -import java.util.Scanner; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.Stack; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.GZIPInputStream; - -/** - * Download files from a CollecTor instance based on the remote instance's - * directory listings. - * - * @deprecated Replaced by {@link DescriptorIndexCollector} which uses the - * remote instance's index.json file as a more robust alternative to parsing - * the remote instance's directory listings. - */ -public class DescriptorCollectorImpl implements DescriptorCollector { - - private static Logger log = LoggerFactory - .getLogger(DescriptorCollectorImpl.class); - - @Override - public void collectDescriptors(String collecTorBaseUrl, - String[] remoteDirectories, long minLastModified, - File localDirectory, boolean deleteExtraneousLocalFiles) { - collecTorBaseUrl = collecTorBaseUrl.endsWith("/") - ? collecTorBaseUrl.substring(0, collecTorBaseUrl.length() - 1) - : collecTorBaseUrl; - if (minLastModified < 0) { - throw new IllegalArgumentException("A negative minimum " - + "last-modified time is not permitted."); - } - if (localDirectory.exists() && !localDirectory.isDirectory()) { - throw new IllegalArgumentException("Local directory already exists " - + "and is not a directory."); - } - SortedMap<String, Long> localFiles = - this.statLocalDirectory(localDirectory); - SortedMap<String, String> fetchedDirectoryListings = - this.fetchRemoteDirectories(collecTorBaseUrl, remoteDirectories); - SortedSet<String> parsedDirectories = new TreeSet<>(); - SortedMap<String, Long> remoteFiles = new TreeMap<>(); - for (Map.Entry<String, String> e - : fetchedDirectoryListings.entrySet()) { - String remoteDirectory = e.getKey(); - String directoryListing = e.getValue(); - SortedMap<String, Long> parsedRemoteFiles = - this.parseDirectoryListing(remoteDirectory, directoryListing); - if (parsedRemoteFiles == null) { - continue; - } - parsedDirectories.add(remoteDirectory); - remoteFiles.putAll(parsedRemoteFiles); - } - this.fetchRemoteFiles(collecTorBaseUrl, remoteFiles, minLastModified, - localDirectory, localFiles); - if (deleteExtraneousLocalFiles) { - this.deleteExtraneousLocalFiles(parsedDirectories, remoteFiles, - localDirectory, localFiles); - } - } - - SortedMap<String, Long> statLocalDirectory( - File localDirectory) { - SortedMap<String, Long> localFiles = new TreeMap<>(); - if (!localDirectory.exists()) { - return localFiles; - } - Stack<File> files = new Stack<>(); - files.add(localDirectory); - while (!files.isEmpty()) { - File file = files.pop(); - if (file.isDirectory()) { - files.addAll(Arrays.asList(file.listFiles())); - } else { - String localPath = file.getPath().substring( - localDirectory.getPath().length()); - localFiles.put(localPath, file.lastModified()); - } - } - return localFiles; - } - - SortedMap<String, String> fetchRemoteDirectories( - String collecTorBaseUrl, String[] remoteDirectories) { - SortedMap<String, String> fetchedDirectoryListings = new TreeMap<>(); - for (String remoteDirectory : remoteDirectories) { - String remoteDirectoryWithSlashAtBeginAndEnd = - (remoteDirectory.startsWith("/") ? "" : "/") + remoteDirectory - + (remoteDirectory.endsWith("/") ? "" : "/"); - String directoryUrl = collecTorBaseUrl - + remoteDirectoryWithSlashAtBeginAndEnd; - String directoryListing = this.fetchRemoteDirectory(directoryUrl); - if (directoryListing.length() > 0) { - fetchedDirectoryListings.put( - remoteDirectoryWithSlashAtBeginAndEnd, directoryListing); - } - } - return fetchedDirectoryListings; - } - - String fetchRemoteDirectory(String urlString) { - StringBuilder sb = new StringBuilder(); - HttpURLConnection huc = null; - try { - URL url = new URL(urlString); - huc = (HttpURLConnection) url.openConnection(); - huc.setRequestMethod("GET"); - huc.connect(); - int responseCode = huc.getResponseCode(); - if (responseCode == 200) { - BufferedReader br = new BufferedReader(new InputStreamReader( - huc.getInputStream())); - String line; - while ((line = br.readLine()) != null) { - sb.append(line).append("\n"); - } - br.close(); - } - } catch (IOException e) { - log.error("Cannot fetch remote directory.", e); - if (huc != null) { - huc.disconnect(); - } - return ""; - } - return sb.toString(); - } - - final Pattern directoryListingLinePattern = - Pattern.compile(".* href="([^"/]+)"" /* filename */ - + ".*>(\d{4}-\w{2}-\d{2} \d{2}:\d{2})\s*<.*"); /* dateTime */ - - SortedMap<String, Long> parseDirectoryListing( - String remoteDirectory, String directoryListing) { - SortedMap<String, Long> remoteFiles = new TreeMap<>(); - DateFormat dateTimeFormat = ParseHelper.getDateFormat( - "yyyy-MM-dd HH:mm"); - try { - Scanner scanner = new Scanner(directoryListing); - scanner.useDelimiter("\n"); - while (scanner.hasNext()) { - String line = scanner.next(); - Matcher matcher = directoryListingLinePattern.matcher(line); - if (matcher.matches()) { - String filename = matcher.group(1); - long lastModifiedMillis = dateTimeFormat.parse( - matcher.group(2)).getTime(); - remoteFiles.put(remoteDirectory + filename, lastModifiedMillis); - } - } - scanner.close(); - } catch (ParseException e) { - log.error("Cannot parse directory listing: " + directoryListing, e); - return null; - } - return remoteFiles; - } - - void fetchRemoteFiles(String collecTorBaseUrl, - SortedMap<String, Long> remoteFiles, long minLastModified, - File localDirectory, SortedMap<String, Long> localFiles) { - for (Map.Entry<String, Long> e : remoteFiles.entrySet()) { - String filename = e.getKey(); - long lastModifiedMillis = e.getValue(); - if (lastModifiedMillis < minLastModified - || (localFiles.containsKey(filename) - && localFiles.get(filename) >= lastModifiedMillis)) { - continue; - } - String url = collecTorBaseUrl + filename; - File destinationFile = new File(localDirectory.getPath() - + filename); - this.fetchRemoteFile(url, destinationFile, lastModifiedMillis); - } - } - - void fetchRemoteFile(String urlString, File destinationFile, - long lastModifiedMillis) { - HttpURLConnection huc = null; - try { - File destinationDirectory = destinationFile.getParentFile(); - destinationDirectory.mkdirs(); - File tempDestinationFile = new File(destinationDirectory, "." - + destinationFile.getName()); - BufferedOutputStream bos = new BufferedOutputStream( - new FileOutputStream(tempDestinationFile)); - URL url = new URL(urlString); - huc = (HttpURLConnection) url.openConnection(); - huc.setRequestMethod("GET"); - if (!urlString.endsWith(".xz")) { - huc.addRequestProperty("Accept-Encoding", "gzip"); - } - huc.connect(); - int responseCode = huc.getResponseCode(); - if (responseCode == 200) { - InputStream is; - if (huc.getContentEncoding() != null - && huc.getContentEncoding().equalsIgnoreCase("gzip")) { - is = new GZIPInputStream(huc.getInputStream()); - } else { - is = huc.getInputStream(); - } - BufferedInputStream bis = new BufferedInputStream(is); - int len; - byte[] data = new byte[8192]; - while ((len = bis.read(data, 0, 8192)) >= 0) { - bos.write(data, 0, len); - } - bis.close(); - bos.close(); - tempDestinationFile.renameTo(destinationFile); - destinationFile.setLastModified(lastModifiedMillis); - } - } catch (IOException e) { - log.error("Cannot fetch remote file.", e); - if (huc != null) { - huc.disconnect(); - } - } - } - - void deleteExtraneousLocalFiles( - SortedSet<String> parsedDirectories, - SortedMap<String, Long> remoteFiles, File localDirectory, - SortedMap<String, Long> localFiles) { - for (String localPath : localFiles.keySet()) { - for (String remoteDirectory : parsedDirectories) { - if (localPath.startsWith(remoteDirectory)) { - if (!remoteFiles.containsKey(localPath)) { - new File(localDirectory.getPath() + localPath).delete(); - } - } - } - } - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java deleted file mode 100644 index 807abac..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorDownloaderImpl.java +++ /dev/null @@ -1,294 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.DescriptorDownloader; -import org.torproject.descriptor.DescriptorRequest; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; - -public class DescriptorDownloaderImpl - implements DescriptorDownloader { - - private boolean hasStartedDownloading = false; - - private SortedMap<String, DirectoryDownloader> directoryAuthorities = - new TreeMap<>(); - - @Override - public void addDirectoryAuthority(String nickname, String ip, - int dirPort) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.checkDirectoryParameters(nickname, ip, dirPort); - DirectoryDownloader directoryAuthority = new DirectoryDownloader( - nickname, ip, dirPort); - this.directoryAuthorities.put(nickname, directoryAuthority); - } - - private SortedMap<String, DirectoryDownloader> directoryMirrors = - new TreeMap<>(); - - @Override - public void addDirectoryMirror(String nickname, String ip, - int dirPort) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.checkDirectoryParameters(nickname, ip, dirPort); - DirectoryDownloader directoryMirror = new DirectoryDownloader( - nickname, ip, dirPort); - this.directoryMirrors.put(nickname, directoryMirror); - /* TODO Implement prioritizing mirrors for non-vote downloads. */ - throw new UnsupportedOperationException("Prioritizing directory " - + "mirrors over directory authorities is not implemented yet. " - + "Until it is, configuring directory mirrors is misleading and " - + "therefore not supported."); - } - - private void checkDirectoryParameters(String nickname, String ip, - int dirPort) { - if (nickname == null || nickname.length() < 1) { - throw new IllegalArgumentException("'" + nickname + "' is not a " - + "valid nickname."); - } - if (ip == null || ip.length() < 7 || ip.split("\.").length != 4) { - throw new IllegalArgumentException("'" + ip + "' is not a valid IP " - + "address."); - } - if (dirPort < 1 || dirPort > 65535) { - throw new IllegalArgumentException(String.valueOf(dirPort) + " is " - + "not a valid DirPort."); - } - /* TODO Relax the requirement for directory nicknames to be unique. - * In theory, we can identify them by ip+port. */ - if (this.directoryAuthorities.containsKey(nickname) - || this.directoryMirrors.containsKey(nickname)) { - throw new IllegalArgumentException("Directory nicknames must be " - + "unique."); - } - } - - private boolean downloadConsensus = false; - - @Override - public void setIncludeCurrentConsensus() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.downloadConsensus = true; - } - - private boolean downloadConsensusFromAllAuthorities = false; - - @Override - public void setIncludeCurrentConsensusFromAllDirectoryAuthorities() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.downloadConsensusFromAllAuthorities = true; - } - - private boolean includeCurrentReferencedVotes = false; - - @Override - public void setIncludeCurrentReferencedVotes() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.includeCurrentReferencedVotes = true; - } - - private Set<String> downloadVotes = new HashSet<>(); - - @Override - public void setIncludeCurrentVote(String fingerprint) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.checkVoteFingerprint(fingerprint); - this.downloadVotes.add(fingerprint); - } - - @Override - public void setIncludeCurrentVotes(Set<String> fingerprints) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - if (fingerprints == null) { - throw new IllegalArgumentException("Set of fingerprints must not " - + "be null."); - } - for (String fingerprint : fingerprints) { - this.checkVoteFingerprint(fingerprint); - } - for (String fingerprint : fingerprints) { - this.setIncludeCurrentVote(fingerprint); - } - } - - private void checkVoteFingerprint(String fingerprint) { - if (fingerprint == null || fingerprint.length() != 40) { - throw new IllegalArgumentException("'" + fingerprint + "' is not a " - + "valid fingerprint."); - } - } - - @Override - public void setIncludeReferencedServerDescriptors() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading server " - + "descriptors is not implemented yet."); - } - - @Override - public void setExcludeServerDescriptor(String identifier) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading server " - + "descriptors is not implemented yet."); - } - - @Override - public void setExcludeServerDescriptors(Set<String> identifier) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading server " - + "descriptors is not implemented yet."); - } - - @Override - public void setIncludeReferencedExtraInfoDescriptors() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading extra-info " - + "descriptors is not implemented yet."); - } - - @Override - public void setExcludeExtraInfoDescriptor(String identifier) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading extra-info " - + "descriptors is not implemented yet."); - } - - @Override - public void setExcludeExtraInfoDescriptors(Set<String> identifiers) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - /* TODO Implement me. */ - throw new UnsupportedOperationException("Downloading extra-info " - + "descriptors is not implemented yet."); - } - - private long readTimeoutMillis = 60L * 1000L; - - @Override - public void setReadTimeout(long readTimeoutMillis) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - if (readTimeoutMillis < 0L) { - throw new IllegalArgumentException("Read timeout value " - + String.valueOf(readTimeoutMillis) + " may not be " - + "negative."); - } - this.readTimeoutMillis = readTimeoutMillis; - } - - private long connectTimeoutMillis = 60L * 1000L; - - @Override - public void setConnectTimeout(long connectTimeoutMillis) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - if (connectTimeoutMillis < 0L) { - throw new IllegalArgumentException("Connect timeout value " - + String.valueOf(connectTimeoutMillis) + " may not be " - + "negative."); - } - this.connectTimeoutMillis = connectTimeoutMillis; - } - - private long globalTimeoutMillis = 60L * 60L * 1000L; - - @Override - public void setGlobalTimeout(long globalTimeoutMillis) { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - if (globalTimeoutMillis < 0L) { - throw new IllegalArgumentException("Global timeout value " - + String.valueOf(globalTimeoutMillis) + " may not be " - + "negative."); - } - this.globalTimeoutMillis = globalTimeoutMillis; - } - - private boolean failUnrecognizedDescriptorLines = false; - - @Override - public void setFailUnrecognizedDescriptorLines() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to download."); - } - this.failUnrecognizedDescriptorLines = true; - } - - @Override - public Iterator<DescriptorRequest> downloadDescriptors() { - if (this.hasStartedDownloading) { - throw new IllegalStateException("Initiating downloads is only " - + "permitted once."); - } - this.hasStartedDownloading = true; - DownloadCoordinatorImpl downloadCoordinator = - new DownloadCoordinatorImpl(this.directoryAuthorities, - this.directoryMirrors, this.downloadConsensus, - this.downloadConsensusFromAllAuthorities, this.downloadVotes, - this.includeCurrentReferencedVotes, this.connectTimeoutMillis, - this.readTimeoutMillis, this.globalTimeoutMillis, - this.failUnrecognizedDescriptorLines); - Iterator<DescriptorRequest> descriptorQueue = downloadCoordinator - .getDescriptorQueue(); - return descriptorQueue; - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorFileImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorFileImpl.java deleted file mode 100644 index 561e0b8..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorFileImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.Descriptor; -import org.torproject.descriptor.DescriptorFile; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class DescriptorFileImpl implements DescriptorFile { - - private File directory; - - protected void setDirectory(File directory) { - this.directory = directory; - } - - @Override - public File getDirectory() { - return this.directory; - } - - private File tarball; - - protected void setTarball(File tarball) { - this.tarball = tarball; - } - - @Override - public File getTarball() { - return this.tarball; - } - - private File file; - - protected void setFile(File file) { - this.file = file; - } - - @Override - public File getFile() { - return this.file; - } - - private String fileName; - - protected void setFileName(String fileName) { - this.fileName = fileName; - } - - @Override - public String getFileName() { - return this.fileName; - } - - private long lastModified; - - protected void setLastModified(long lastModified) { - this.lastModified = lastModified; - } - - @Override - public long getLastModified() { - return this.lastModified; - } - - private List<Descriptor> descriptors; - - protected void setDescriptors(List<Descriptor> descriptors) { - this.descriptors = descriptors; - } - - @Override - public List<Descriptor> getDescriptors() { - return this.descriptors == null ? new ArrayList<Descriptor>() - : new ArrayList<>(this.descriptors); - } - - private Exception exception; - - protected void setException(Exception exception) { - this.exception = exception; - } - - @Override - public Exception getException() { - return this.exception; - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java index acbee50..eec89a4 100644 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java @@ -184,8 +184,6 @@ public abstract class DescriptorImpl implements Descriptor { return splitParts; }
- protected boolean failUnrecognizedDescriptorLines = false; - protected List<String> unrecognizedLines;
@Override @@ -195,7 +193,7 @@ public abstract class DescriptorImpl implements Descriptor { }
protected DescriptorImpl(byte[] rawDescriptorBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines) { + File descriptorFile) { int offset = offsetAndLength[0]; int length = offsetAndLength[1]; if (offset < 0 || offset + length > rawDescriptorBytes.length @@ -208,15 +206,12 @@ public abstract class DescriptorImpl implements Descriptor { this.offset = offset; this.length = length; this.descriptorFile = descriptorFile; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; }
protected DescriptorImpl(byte[] rawDescriptorBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines, - boolean blankLinesAllowed) throws DescriptorParseException { - this(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines); + File descriptorFile, boolean blankLinesAllowed) + throws DescriptorParseException { + this(rawDescriptorBytes, offsetAndLength, descriptorFile); this.cutOffAnnotations(); this.countKeys(rawDescriptorBytes, blankLinesAllowed); } diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java b/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java deleted file mode 100644 index 8583ef2..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -/** - * @deprecated Replaced by - * org.torproject.descriptor.DescriptorParseException - */ -@Deprecated public class DescriptorParseException extends Exception { - - private static final long serialVersionUID = 100L; - - protected DescriptorParseException(String message) { - super(message); - } - - protected DescriptorParseException(String message, Exception ex) { - super(message, ex); - } - -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java index a0be85c..dbdfca9 100644 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java @@ -19,15 +19,6 @@ import java.util.List;
public class DescriptorParserImpl implements DescriptorParser {
- private boolean failUnrecognizedDescriptorLines; - - @Override - public void setFailUnrecognizedDescriptorLines( - boolean failUnrecognizedDescriptorLines) { - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; - } - @Override public List<Descriptor> parseDescriptors( byte[] rawDescriptorBytes, String fileName) @@ -46,8 +37,7 @@ public class DescriptorParserImpl implements DescriptorParser { * below and ran into a parse issue. */ List<Descriptor> parsedDescriptors = new ArrayList<>(); parsedDescriptors.add(new UnparseableDescriptorImpl(rawDescriptorBytes, - new int[] { 0, rawDescriptorBytes.length }, descriptorFile, - failUnrecognizedDescriptorLines, e)); + new int[] { 0, rawDescriptorBytes.length }, descriptorFile, e)); return parsedDescriptors; } } @@ -71,7 +61,7 @@ public class DescriptorParserImpl implements DescriptorParser { NL + Key.VOTE_STATUS.keyword + SP + "consensus" + NL))) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.NETWORK_STATUS_VERSION, RelayNetworkStatusConsensusImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type network-status-vote-3 1.") || ((firstLines.startsWith( Key.NETWORK_STATUS_VERSION.keyword + SP + "3" + NL) @@ -81,59 +71,59 @@ public class DescriptorParserImpl implements DescriptorParser { NL + Key.VOTE_STATUS.keyword + SP + "vote" + NL))) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.NETWORK_STATUS_VERSION, RelayNetworkStatusVoteImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type bridge-network-status 1.") || firstLines.startsWith(Key.R.keyword + SP)) { List<Descriptor> parsedDescriptors = new ArrayList<>(); parsedDescriptors.add(new BridgeNetworkStatusImpl( rawDescriptorBytes, new int[] { 0, rawDescriptorBytes.length }, - descriptorFile, fileName, this.failUnrecognizedDescriptorLines)); + descriptorFile, fileName)); return parsedDescriptors; } else if (firstLines.startsWith("@type bridge-server-descriptor 1.")) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.ROUTER, BridgeServerDescriptorImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type server-descriptor 1.") || firstLines.startsWith(Key.ROUTER.keyword + SP) || firstLines.contains(NL + Key.ROUTER.keyword + SP)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.ROUTER, RelayServerDescriptorImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type bridge-extra-info 1.")) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.EXTRA_INFO, BridgeExtraInfoDescriptorImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type extra-info 1.") || firstLines.startsWith(Key.EXTRA_INFO.keyword + SP) || firstLines.contains(NL + Key.EXTRA_INFO.keyword + SP)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.EXTRA_INFO, RelayExtraInfoDescriptorImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type microdescriptor 1.") || firstLines.startsWith(Key.ONION_KEY.keyword + NL) || firstLines.contains(NL + Key.ONION_KEY.keyword + NL)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.ONION_KEY, MicrodescriptorImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type bridge-pool-assignment 1.") || firstLines.startsWith(Key.BRIDGE_POOL_ASSIGNMENT.keyword + SP) || firstLines.contains(NL + Key.BRIDGE_POOL_ASSIGNMENT.keyword + SP)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.BRIDGE_POOL_ASSIGNMENT, BridgePoolAssignmentImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type dir-key-certificate-3 1.") || firstLines.startsWith(Key.DIR_KEY_CERTIFICATE_VERSION.keyword + SP) || firstLines.contains( NL + Key.DIR_KEY_CERTIFICATE_VERSION.keyword + SP)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.DIR_KEY_CERTIFICATE_VERSION, DirectoryKeyCertificateImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type tordnsel 1.") || firstLines.startsWith("ExitNode" + SP) || firstLines.contains(NL + "ExitNode" + SP)) { List<Descriptor> parsedDescriptors = new ArrayList<>(); parsedDescriptors.add(new ExitListImpl(rawDescriptorBytes, descriptorFile, - fileName, this.failUnrecognizedDescriptorLines)); + fileName)); return parsedDescriptors; } else if (firstLines.startsWith("@type network-status-2 1.") || firstLines.startsWith( @@ -142,16 +132,16 @@ public class DescriptorParserImpl implements DescriptorParser { NL + Key.NETWORK_STATUS_VERSION.keyword + SP + "2" + NL)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.NETWORK_STATUS_VERSION, RelayNetworkStatusImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type directory 1.") || firstLines.startsWith(Key.SIGNED_DIRECTORY.keyword + NL) || firstLines.contains(NL + Key.SIGNED_DIRECTORY.keyword + NL)) { return this.parseDescriptors(rawDescriptorBytes, descriptorFile, Key.SIGNED_DIRECTORY, RelayDirectoryImpl.class, - this.failUnrecognizedDescriptorLines, includeUnparseableDescriptors); + includeUnparseableDescriptors); } else if (firstLines.startsWith("@type torperf 1.")) { return TorperfResultImpl.parseTorperfResults(rawDescriptorBytes, - descriptorFile, this.failUnrecognizedDescriptorLines); + descriptorFile); } else { throw new DescriptorParseException("Could not detect descriptor " + "type in descriptor starting with '" + firstLines + "'."); @@ -161,7 +151,6 @@ public class DescriptorParserImpl implements DescriptorParser { private List<Descriptor> parseDescriptors(byte[] rawDescriptorBytes, File descriptorFile, Key key, Class<? extends DescriptorImpl> descriptorClass, - boolean failUnrecognizedDescriptorLines, boolean includeUnparseableDescriptors) throws DescriptorParseException { List<Descriptor> parsedDescriptors = new ArrayList<>(); Constructor<? extends DescriptorImpl> constructor; @@ -213,13 +202,11 @@ public class DescriptorParserImpl implements DescriptorParser { endDescriptor - startAnnotations }; try { parsedDescriptors.add(this.parseDescriptor(rawDescriptorBytes, - offsetAndLength, descriptorFile, constructor, - failUnrecognizedDescriptorLines)); + offsetAndLength, descriptorFile, constructor)); } catch (DescriptorParseException e) { if (includeUnparseableDescriptors) { parsedDescriptors.add(new UnparseableDescriptorImpl( - rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, e)); + rawDescriptorBytes, offsetAndLength, descriptorFile, e)); } else { throw e; } @@ -231,11 +218,11 @@ public class DescriptorParserImpl implements DescriptorParser {
Descriptor parseDescriptor(byte[] rawDescriptorBytes, int[] offsetAndLength, File descriptorFile, - Constructor<? extends DescriptorImpl> constructor, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { + Constructor<? extends DescriptorImpl> constructor) + throws DescriptorParseException { try { - return constructor.newInstance(rawDescriptorBytes, - offsetAndLength, descriptorFile, failUnrecognizedDescriptorLines); + return constructor.newInstance(rawDescriptorBytes, offsetAndLength, + descriptorFile); } catch (InvocationTargetException e) { if (null != e.getCause() && e.getCause() instanceof DescriptorParseException) { diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java index 54e26fc..e2bf987 100644 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java @@ -4,7 +4,6 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.Descriptor; -import org.torproject.descriptor.DescriptorFile; import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.DescriptorParser; import org.torproject.descriptor.DescriptorReader; @@ -27,7 +26,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -42,40 +40,13 @@ public class DescriptorReaderImpl implements DescriptorReader {
private List<File> directories = new ArrayList<>();
- @Override - public void addDirectory(File directory) { - if (this.hasStartedReading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to read."); - } - this.directories.add(directory); - } - private List<File> tarballs = new ArrayList<>();
- @Override - public void addTarball(File tarball) { - if (this.hasStartedReading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to read."); - } - this.tarballs.add(tarball); - } - private File autoSaveHistoryFile;
private File manualSaveHistoryFile;
@Override - public void setExcludeFiles(File historyFile) { - if (this.hasStartedReading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to read."); - } - this.autoSaveHistoryFile = historyFile; - } - - @Override public void setHistoryFile(File historyFile) { if (this.hasStartedReading) { throw new IllegalStateException("Reconfiguration is not permitted " @@ -113,28 +84,8 @@ public class DescriptorReaderImpl implements DescriptorReader { return new TreeMap<>(this.reader.parsedFilesAfter); }
- private boolean failUnrecognizedDescriptorLines = false; - - @Override - public void setFailUnrecognizedDescriptorLines() { - if (this.hasStartedReading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to read."); - } - this.failUnrecognizedDescriptorLines = true; - } - private Integer maxDescriptorFilesInQueue = null;
- @Override - public void setMaxDescriptorFilesInQueue(int max) { - if (this.hasStartedReading) { - throw new IllegalStateException("Reconfiguration is not permitted " - + "after starting to read."); - } - this.maxDescriptorFilesInQueue = max; - } - private int maxDescriptorsInQueue = 100;
@Override @@ -149,28 +100,6 @@ public class DescriptorReaderImpl implements DescriptorReader { private DescriptorReaderRunnable reader;
@Override - public Iterator<DescriptorFile> readDescriptors() { - if (this.hasStartedReading) { - throw new IllegalStateException("Initiating reading is only " - + "permitted once."); - } - this.hasStartedReading = true; - BlockingIteratorImpl<DescriptorFile> descriptorQueue = - this.maxDescriptorFilesInQueue == null - ? new BlockingIteratorImpl<DescriptorFile>() - : new BlockingIteratorImpl<DescriptorFile>( - this.maxDescriptorFilesInQueue); - this.reader = new DescriptorReaderRunnable(this.directories, - this.tarballs, descriptorQueue, this.autoSaveHistoryFile, - this.manualSaveHistoryFile, this.excludedFiles, - this.failUnrecognizedDescriptorLines); - Thread readerThread = new Thread(this.reader); - readerThread.setDaemon(true); - readerThread.start(); - return descriptorQueue; - } - - @Override public Iterable<Descriptor> readDescriptors(File... descriptorFiles) { if (this.hasStartedReading) { throw new IllegalStateException("Initiating reading is only " @@ -181,8 +110,7 @@ public class DescriptorReaderImpl implements DescriptorReader { new BlockingIteratorImpl<>(this.maxDescriptorsInQueue); this.reader = new DescriptorReaderRunnable( descriptorFiles, descriptorQueue, this.autoSaveHistoryFile, - this.manualSaveHistoryFile, this.excludedFiles, - this.failUnrecognizedDescriptorLines); + this.manualSaveHistoryFile, this.excludedFiles); Thread readerThread = new Thread(this.reader); readerThread.setDaemon(true); readerThread.start(); @@ -208,8 +136,6 @@ public class DescriptorReaderImpl implements DescriptorReader {
private BlockingIteratorImpl<Descriptor> descriptorQueue;
- private BlockingIteratorImpl<DescriptorFile> descriptorFileQueue; - private File autoSaveHistoryFile;
private File manualSaveHistoryFile; @@ -226,31 +152,10 @@ public class DescriptorReaderImpl implements DescriptorReader {
private boolean hasFinishedReading = false;
- private DescriptorReaderRunnable(List<File> directories, - List<File> tarballs, - BlockingIteratorImpl<DescriptorFile> descriptorFileQueue, - File autoSaveHistoryFile, File manualSaveHistoryFile, - SortedMap<String, Long> excludedFiles, - boolean failUnrecognizedDescriptorLines) { - this.directories = directories; - this.tarballs = tarballs; - this.descriptorFileQueue = descriptorFileQueue; - this.autoSaveHistoryFile = autoSaveHistoryFile; - this.manualSaveHistoryFile = manualSaveHistoryFile; - if (excludedFiles != null) { - this.excludedFilesBefore = excludedFiles; - } - this.failUnrecognizedDescriptorLines = failUnrecognizedDescriptorLines; - this.descriptorParser = new DescriptorParserImpl(); - this.descriptorParser.setFailUnrecognizedDescriptorLines( - failUnrecognizedDescriptorLines); - } - private DescriptorReaderRunnable(File[] descriptorFiles, BlockingIteratorImpl<Descriptor> descriptorQueue, File autoSaveHistoryFile, File manualSaveHistoryFile, - SortedMap<String, Long> excludedFiles, - boolean failUnrecognizedDescriptorLines) { + SortedMap<String, Long> excludedFiles) { this.descriptorFiles = descriptorFiles; this.descriptorQueue = descriptorQueue; this.autoSaveHistoryFile = autoSaveHistoryFile; @@ -260,8 +165,6 @@ public class DescriptorReaderImpl implements DescriptorReader { } this.failUnrecognizedDescriptorLines = failUnrecognizedDescriptorLines; this.descriptorParser = new DescriptorParserImpl(); - this.descriptorParser.setFailUnrecognizedDescriptorLines( - failUnrecognizedDescriptorLines); }
public void run() { @@ -276,9 +179,6 @@ public class DescriptorReaderImpl implements DescriptorReader { log.error("Bug: uncaught exception or error while " + "reading descriptors: " + t.getMessage(), t); } finally { - if (null != this.descriptorFileQueue) { - this.descriptorFileQueue.setOutOfDescriptors(); - } if (null != this.descriptorQueue) { this.descriptorQueue.setOutOfDescriptors(); } @@ -453,20 +353,6 @@ public class DescriptorReaderImpl implements DescriptorReader { continue; } this.parsedFilesAfter.put(absolutePath, lastModifiedMillis); - DescriptorFileImpl descriptorFile = new DescriptorFileImpl(); - try { - descriptorFile.setDirectory(directory); - descriptorFile.setFile(file); - descriptorFile.setFileName(file.getAbsolutePath()); - descriptorFile.setLastModified(lastModifiedMillis); - descriptorFile.setDescriptors(this.readFile(file)); - } catch (DescriptorParseException e) { - descriptorFile.setException(e); - } catch (IOException e) { - descriptorFile.setException(e); - abortReading = true; - } - this.descriptorFileQueue.add(descriptorFile); } } } @@ -513,33 +399,6 @@ public class DescriptorReaderImpl implements DescriptorReader { if (tae.isDirectory()) { continue; } - DescriptorFileImpl descriptorFile = - new DescriptorFileImpl(); - descriptorFile.setTarball(tarball); - descriptorFile.setFileName(tae.getName()); - descriptorFile.setLastModified(tae.getLastModifiedDate() - .getTime()); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int len; - byte[] data = new byte[1024]; - while ((len = bis.read(data, 0, 1024)) >= 0) { - baos.write(data, 0, len); - } - byte[] rawDescriptorBytes = baos.toByteArray(); - if (rawDescriptorBytes.length < 1) { - continue; - } - try { - String fileName = tae.getName().substring( - tae.getName().lastIndexOf("/") + 1); - List<Descriptor> parsedDescriptors = - this.descriptorParser.parseDescriptors( - rawDescriptorBytes, fileName); - descriptorFile.setDescriptors(parsedDescriptors); - } catch (DescriptorParseException e) { - descriptorFile.setException(e); - } - this.descriptorFileQueue.add(descriptorFile); } } } catch (IOException e) { diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorRequestImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorRequestImpl.java deleted file mode 100644 index 7362935..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DescriptorRequestImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.Descriptor; -import org.torproject.descriptor.DescriptorRequest; - -import java.util.List; - -public class DescriptorRequestImpl implements DescriptorRequest { - - private String requestedResource; - - protected void setRequestedResource(String requestedResource) { - this.requestedResource = requestedResource; - } - - protected String getRequestedResource() { - return this.requestedResource; - } - - private String descriptorType; - - protected void setDescriptorType(String descriptorType) { - this.descriptorType = descriptorType; - } - - protected String getDescriptorType() { - return this.descriptorType; - } - - private byte[] responseBytes; - - protected byte[] getResponseBytes() { - return this.responseBytes; - } - - protected void setResponseBytes(byte[] responseBytes) { - this.responseBytes = responseBytes; - } - - private String requestUrl; - - @Override - public String getRequestUrl() { - return this.requestUrl; - } - - private String directoryNickname; - - protected void setDirectoryNickname(String directoryNickname) { - this.directoryNickname = directoryNickname; - } - - @Override - public String getDirectoryNickname() { - return this.directoryNickname; - } - - private int responseCode; - - protected void setResponseCode(int responseCode) { - this.responseCode = responseCode; - } - - @Override - public int getResponseCode() { - return this.responseCode; - } - - private long requestStart; - - protected void setRequestStart(long requestStart) { - this.requestStart = requestStart; - } - - @Override - public long getRequestStart() { - return this.requestStart; - } - - private long requestEnd; - - protected void setRequestEnd(long requestEnd) { - this.requestEnd = requestEnd; - } - - @Override - public long getRequestEnd() { - return this.requestEnd; - } - - private boolean connectTimeoutHasExpired; - - @Override - public boolean connectTimeoutHasExpired() { - return this.connectTimeoutHasExpired; - } - - private boolean readTimeoutHasExpired; - - @Override - public boolean readTimeoutHasExpired() { - return this.readTimeoutHasExpired; - } - - private boolean globalTimeoutHasExpired; - - @Override - public boolean globalTimeoutHasExpired() { - return this.globalTimeoutHasExpired; - } - - private List<Descriptor> descriptors; - - protected void setDescriptors(List<Descriptor> descriptors) { - this.descriptors = descriptors; - } - - @Override - public List<Descriptor> getDescriptors() { - return this.descriptors; - } - - private Exception exception; - - protected void setException(Exception exception) { - this.exception = exception; - } - - @Override - public Exception getException() { - return this.exception; - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java index 770ca61..630b886 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java @@ -31,8 +31,6 @@ public class DirSourceEntryImpl implements DirSourceEntry { return this.parent.getRawDescriptorBytes(this.offset, this.length); }
- private boolean failUnrecognizedDescriptorLines; - private List<String> unrecognizedLines;
protected List<String> getAndClearUnrecognizedLines() { @@ -41,14 +39,11 @@ public class DirSourceEntryImpl implements DirSourceEntry { return lines; }
- protected DirSourceEntryImpl(DescriptorImpl parent, int offset, int length, - boolean failUnrecognizedDescriptorLines) + protected DirSourceEntryImpl(DescriptorImpl parent, int offset, int length) throws DescriptorParseException { this.parent = parent; this.offset = offset; this.length = length; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; this.parseDirSourceEntryBytes(); this.checkAndClearKeys(); } @@ -117,15 +112,10 @@ public class DirSourceEntryImpl implements DirSourceEntry { break; default: if (!skipCrypto) { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in dir-source entry."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -237,11 +227,6 @@ public class DirSourceEntryImpl implements DirSourceEntry { private String voteDigest;
@Override - public String getVoteDigest() { - return this.getVoteDigestSha1Hex(); - } - - @Override public String getVoteDigestSha1Hex() { return this.voteDigest; } diff --git a/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java b/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java deleted file mode 100644 index 7b3f977..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.DescriptorParser; -import org.torproject.descriptor.DescriptorSourceFactory; - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.zip.InflaterInputStream; - -/* Download descriptors from one directory authority or mirror. First, - * ask the coordinator thread to create a request, run it, and deliver - * the response. Repeat until the coordinator thread says there are no - * further requests to make. */ -public class DirectoryDownloader implements Runnable { - - private String nickname; - - private String ipPort; - - private DescriptorParser descriptorParser; - - protected DirectoryDownloader(String nickname, String ip, int dirPort) { - this.nickname = nickname; - this.ipPort = ip + ":" + String.valueOf(dirPort); - this.descriptorParser = - DescriptorSourceFactory.createDescriptorParser(); - } - - private DownloadCoordinator downloadCoordinator; - - protected void setDownloadCoordinator( - DownloadCoordinator downloadCoordinator) { - this.downloadCoordinator = downloadCoordinator; - } - - private long connectTimeout; - - protected void setConnectTimeout(long connectTimeout) { - this.connectTimeout = connectTimeout; - } - - private long readTimeout; - - protected void setReadTimeout(long readTimeout) { - this.readTimeout = readTimeout; - } - - protected void setFailUnrecognizedDescriptorLines( - boolean failUnrecognizedDescriptorLines) { - this.descriptorParser.setFailUnrecognizedDescriptorLines( - failUnrecognizedDescriptorLines); - } - - @Override - public void run() { - boolean keepRunning = true; - do { - DescriptorRequestImpl request = - this.downloadCoordinator.createRequest(this.nickname); - if (request != null) { - String urlString = "http://" + this.ipPort - + request.getRequestedResource(); - request.setRequestStart(System.currentTimeMillis()); - HttpURLConnection huc = null; - try { - URL url = new URL(urlString); - huc = (HttpURLConnection) url.openConnection(); - huc.setConnectTimeout((int) this.connectTimeout); - huc.setReadTimeout((int) this.readTimeout); - huc.setRequestMethod("GET"); - huc.connect(); - int responseCode = huc.getResponseCode(); - request.setResponseCode(responseCode); - if (responseCode == 200) { - BufferedInputStream in = new BufferedInputStream( - new InflaterInputStream(huc.getInputStream())); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int len; - byte[] data = new byte[8192]; - while ((len = in.read(data, 0, 8192)) >= 0) { - baos.write(data, 0, len); - } - in.close(); - byte[] responseBytes = baos.toByteArray(); - request.setResponseBytes(responseBytes); - request.setRequestEnd(System.currentTimeMillis()); - request.setDescriptors(this.descriptorParser.parseDescriptors( - responseBytes, null)); - } - } catch (Exception e) { - request.setException(e); - if (huc != null) { - huc.disconnect(); - } - /* Stop downloading from this directory if there are any - * problems, e.g., refused connections. */ - keepRunning = false; - } - this.downloadCoordinator.deliverResponse(request); - } else { - keepRunning = false; - } - } while (keepRunning); - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java index 6beb9b5..59357d5 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java @@ -18,8 +18,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl protected DirectoryKeyCertificateImpl(byte[] rawDescriptorBytes, int[] offsetAndLength, File descriptorFile, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false); + super(rawDescriptorBytes, offsetAndLength, descriptorFile, false); this.parseDescriptorBytes(); this.calculateDigestSha1Hex(Key.DIR_KEY_CERTIFICATE_VERSION.keyword + SP, NL + Key.DIR_KEY_CERTIFICATION.keyword + NL); @@ -107,15 +106,10 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl if (crypto != null) { crypto.append(line).append(NL); } else { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in directory key certificate."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -261,9 +255,5 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl return this.dirKeyCertification; }
- @Override - public String getCertificateDigest() { - return this.getDigestSha1Hex(); - } }
diff --git a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java index be0abf8..b638002 100644 --- a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java @@ -21,8 +21,6 @@ public class DirectorySignatureImpl implements DirectorySignature {
private int length;
- private boolean failUnrecognizedDescriptorLines; - private List<String> unrecognizedLines;
protected List<String> getAndClearUnrecognizedLines() { @@ -32,13 +30,10 @@ public class DirectorySignatureImpl implements DirectorySignature { }
protected DirectorySignatureImpl(DescriptorImpl parent, int offset, - int length, boolean failUnrecognizedDescriptorLines) - throws DescriptorParseException { + int length) throws DescriptorParseException { this.parent = parent; this.offset = offset; this.length = length; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; this.parseDirectorySignatureBytes(); }
@@ -84,15 +79,10 @@ public class DirectorySignatureImpl implements DirectorySignature { if (crypto != null) { crypto.append(line).append(NL); } else { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in dir-source entry."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -117,11 +107,6 @@ public class DirectorySignatureImpl implements DirectorySignature { private String signingKeyDigest;
@Override - public String getSigningKeyDigest() { - return this.getSigningKeyDigestSha1Hex(); - } - - @Override public String getSigningKeyDigestSha1Hex() { return this.signingKeyDigest; } diff --git a/src/main/java/org/torproject/descriptor/impl/DownloadCoordinator.java b/src/main/java/org/torproject/descriptor/impl/DownloadCoordinator.java deleted file mode 100644 index 0d78f06..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DownloadCoordinator.java +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -public interface DownloadCoordinator { - - public DescriptorRequestImpl createRequest(String nickname); - - public void deliverResponse(DescriptorRequestImpl request); -} diff --git a/src/main/java/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java b/src/main/java/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java deleted file mode 100644 index c79a7cc..0000000 --- a/src/main/java/org/torproject/descriptor/impl/DownloadCoordinatorImpl.java +++ /dev/null @@ -1,323 +0,0 @@ -/* Copyright 2011--2017 The Tor Project - * See LICENSE for licensing information */ - -package org.torproject.descriptor.impl; - -import org.torproject.descriptor.Descriptor; -import org.torproject.descriptor.DescriptorRequest; -import org.torproject.descriptor.DirSourceEntry; -import org.torproject.descriptor.RelayNetworkStatusConsensus; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeSet; - -/* TODO This whole download logic is a mess and needs a cleanup. */ -public class DownloadCoordinatorImpl implements DownloadCoordinator { - - private static Logger log = LoggerFactory - .getLogger(DownloadCoordinatorImpl.class); - - private BlockingIteratorImpl<DescriptorRequest> descriptorQueue = - new BlockingIteratorImpl<>(); - - protected Iterator<DescriptorRequest> getDescriptorQueue() { - return this.descriptorQueue; - } - - private SortedSet<String> runningDirectories; - - private SortedMap<String, DirectoryDownloader> directoryAuthorities; - - private SortedMap<String, DirectoryDownloader> directoryMirrors; - - private boolean downloadConsensusFromAllAuthorities; - - private boolean includeCurrentReferencedVotes; - - private long connectTimeoutMillis; - - private long readTimeoutMillis; - - private long globalTimeoutMillis; - - private boolean failUnrecognizedDescriptorLines; - - protected DownloadCoordinatorImpl( - SortedMap<String, DirectoryDownloader> directoryAuthorities, - SortedMap<String, DirectoryDownloader> directoryMirrors, - boolean downloadConsensus, - boolean downloadConsensusFromAllAuthorities, - Set<String> downloadVotes, boolean includeCurrentReferencedVotes, - long connectTimeoutMillis, long readTimeoutMillis, - long globalTimeoutMillis, boolean failUnrecognizedDescriptorLines) { - this.directoryAuthorities = directoryAuthorities; - this.directoryMirrors = directoryMirrors; - this.runningDirectories = new TreeSet<>(); - this.runningDirectories.addAll(directoryAuthorities.keySet()); - this.runningDirectories.addAll(directoryMirrors.keySet()); - this.missingConsensus = downloadConsensus; - this.downloadConsensusFromAllAuthorities = - downloadConsensusFromAllAuthorities; - this.missingVotes = downloadVotes; - this.includeCurrentReferencedVotes = includeCurrentReferencedVotes; - this.connectTimeoutMillis = connectTimeoutMillis; - this.readTimeoutMillis = readTimeoutMillis; - this.globalTimeoutMillis = globalTimeoutMillis; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; - if (this.directoryMirrors.isEmpty() - && this.directoryAuthorities.isEmpty()) { - this.descriptorQueue.setOutOfDescriptors(); - log.warn("There were no directories configured. Nothing to download."); - } else { - GlobalTimer globalTimer = new GlobalTimer(this.globalTimeoutMillis, - this); - this.globalTimerThread = new Thread(globalTimer); - this.globalTimerThread.start(); - for (DirectoryDownloader directoryMirror - : this.directoryMirrors.values()) { - directoryMirror.setDownloadCoordinator(this); - directoryMirror.setConnectTimeout(this.connectTimeoutMillis); - directoryMirror.setReadTimeout(this.readTimeoutMillis); - directoryMirror.setFailUnrecognizedDescriptorLines( - this.failUnrecognizedDescriptorLines); - new Thread(directoryMirror).start(); - } - for (DirectoryDownloader directoryAuthority - : this.directoryAuthorities.values()) { - directoryAuthority.setDownloadCoordinator(this); - directoryAuthority.setConnectTimeout(this.connectTimeoutMillis); - directoryAuthority.setReadTimeout(this.readTimeoutMillis); - directoryAuthority.setFailUnrecognizedDescriptorLines( - this.failUnrecognizedDescriptorLines); - new Thread(directoryAuthority).start(); - } - } - } - - /* Interrupt all downloads if the total download time exceeds a given - * time. */ - private Thread globalTimerThread; - - private static class GlobalTimer implements Runnable { - - private long timeoutMillis; - - private DownloadCoordinatorImpl downloadCoordinator; - - private GlobalTimer(long timeoutMillis, - DownloadCoordinatorImpl downloadCoordinator) { - this.timeoutMillis = timeoutMillis; - this.downloadCoordinator = downloadCoordinator; - } - - public void run() { - long started = System.currentTimeMillis(); - long sleep; - while ((sleep = started + this.timeoutMillis - - System.currentTimeMillis()) > 0L) { - try { - Thread.sleep(sleep); - } catch (InterruptedException e) { - return; - } - } - this.downloadCoordinator.interruptAllDownloads(); - } - } - - /* Are we missing the consensus, and should the next directory that - * hasn't tried downloading it before attempt to download it? */ - private boolean missingConsensus = false; - - /* Which directories are currently attempting to download the - * consensus? */ - private Set<String> requestingConsensuses = new HashSet<>(); - - /* Which directories have attempted to download the consensus so far, - * including those directories that are currently attempting it? */ - private Set<String> requestedConsensuses = new HashSet<>(); - - /* Which votes are we currently missing? */ - private Set<String> missingVotes = new HashSet<>(); - - /* Which vote (map value) is a given directory (map key) currently - * attempting to download? */ - private Map<String, String> requestingVotes = new HashMap<>(); - - /* Which votes (map value) has a given directory (map key) attempted or - * is currently attempting to download? */ - private Map<String, Set<String>> requestedVotes = new HashMap<>(); - - private boolean hasFinishedDownloading = false; - - /* Look up what request a directory should make next. If there is - * nothing to do right now, but maybe later, block the caller. If - * we're done downloading, return null to notify the caller. */ - @Override - public synchronized DescriptorRequestImpl createRequest( - String nickname) { - while (!this.hasFinishedDownloading) { - DescriptorRequestImpl request = new DescriptorRequestImpl(); - request.setDirectoryNickname(nickname); - if ((this.missingConsensus - || (this.downloadConsensusFromAllAuthorities - && this.directoryAuthorities.containsKey(nickname))) - && !this.requestedConsensuses.contains(nickname)) { - if (!this.downloadConsensusFromAllAuthorities) { - this.missingConsensus = false; - } - this.requestingConsensuses.add(nickname); - this.requestedConsensuses.add(nickname); - request.setRequestedResource( - "/tor/status-vote/current/consensus.z"); - request.setDescriptorType("consensus"); - return request; - } - if (!this.missingVotes.isEmpty() - && this.directoryAuthorities.containsKey(nickname)) { - String requestingVote = null; - for (String missingVote : this.missingVotes) { - if (!this.requestedVotes.containsKey(nickname) - || !this.requestedVotes.get(nickname).contains( - missingVote)) { - requestingVote = missingVote; - } - } - if (requestingVote != null) { - this.requestingVotes.put(nickname, requestingVote); - if (!this.requestedVotes.containsKey(nickname)) { - this.requestedVotes.put(nickname, new HashSet<String>()); - } - this.requestedVotes.get(nickname).add(requestingVote); - this.missingVotes.remove(requestingVote); - request.setRequestedResource("/tor/status-vote/current/" - + requestingVote + ".z"); - request.setDescriptorType("vote"); - return request; - } - } - /* TODO Add server descriptors and extra-info descriptors later. */ - try { - this.wait(); - } catch (InterruptedException e) { - /* TODO What shall we do? */ - } - } - return null; - } - - /* Deliver a response which may either contain one or more descriptors - * or a failure response code. Update the lists of missing descriptors, - * decide if there are more descriptors to download, and wake up any - * waiting downloader threads. */ - @Override - public synchronized void deliverResponse( - DescriptorRequestImpl response) { - String nickname = response.getDirectoryNickname(); - if (response.getException() != null) { - this.runningDirectories.remove(nickname); - } - switch (response.getDescriptorType()) { - case "consensus": - this.requestingConsensuses.remove(nickname); - if (response.getResponseCode() == 200 - && response.getDescriptors() != null) { - if (this.includeCurrentReferencedVotes) { - /* TODO Only add votes if the consensus is not older than one - * hour. Or does that make no sense? */ - for (Descriptor parsedDescriptor - : response.getDescriptors()) { - if (!(parsedDescriptor - instanceof RelayNetworkStatusConsensus)) { - continue; - } - RelayNetworkStatusConsensus parsedConsensus = - (RelayNetworkStatusConsensus) parsedDescriptor; - for (DirSourceEntry dirSource - : parsedConsensus.getDirSourceEntries().values()) { - String identity = dirSource.getIdentity(); - if (!this.missingVotes.contains(identity)) { - boolean alreadyRequested = false; - for (Set<String> requestedBefore - : this.requestedVotes.values()) { - if (requestedBefore.contains(identity)) { - alreadyRequested = true; - break; - } - } - if (!alreadyRequested) { - this.missingVotes.add(identity); - } - } - } - } - /* TODO Later, add referenced server descriptors. */ - } - } else { - this.missingConsensus = true; - } - break; - case "vote": - String requestedVote = requestingVotes.remove(nickname); - if (response.getResponseCode() != 200) { - this.missingVotes.add(requestedVote); - } - break; - default: - /* nothing to be done */ - } - if (response.getRequestEnd() != 0L) { - this.descriptorQueue.add(response); - } - boolean doneDownloading = true; - if ((this.missingConsensus - || this.downloadConsensusFromAllAuthorities) - && (!this.requestedConsensuses.containsAll( - this.runningDirectories) - || !this.requestingConsensuses.isEmpty())) { - doneDownloading = false; - } - if (!this.requestingVotes.isEmpty()) { - doneDownloading = false; - } else if (!this.missingVotes.isEmpty()) { - if (!this.requestedVotes.keySet().containsAll( - this.runningDirectories)) { - doneDownloading = false; - } else { - for (String missingVote : this.missingVotes) { - for (String runningDirectory : this.runningDirectories) { - Set<String> reqVotes = this.requestedVotes.get( - runningDirectory); - if (!reqVotes.contains(missingVote)) { - doneDownloading = false; - } - } - } - } - } - if (doneDownloading) { - this.hasFinishedDownloading = true; - this.globalTimerThread.interrupt(); - this.descriptorQueue.setOutOfDescriptors(); - } - /* Wake up all waiting downloader threads. Maybe they can now - * download something, or they'll realize we're done downloading. */ - this.notifyAll(); - } - - private synchronized void interruptAllDownloads() { - this.hasFinishedDownloading = true; - this.notifyAll(); - } -} - diff --git a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java index c0d8b52..06b6a96 100644 --- a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java @@ -5,7 +5,6 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.ExitList; -import org.torproject.descriptor.ExitListEntry;
import java.util.ArrayList; import java.util.HashMap; @@ -15,12 +14,10 @@ import java.util.Scanner; import java.util.SortedSet; import java.util.TreeSet;
-public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry { +public class ExitListEntryImpl implements ExitList.Entry {
private String exitListEntryString;
- private boolean failUnrecognizedDescriptorLines; - private List<String> unrecognizedLines;
protected List<String> getAndClearUnrecognizedLines() { @@ -29,37 +26,9 @@ public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry { return lines; }
- @Deprecated - private ExitListEntryImpl(String fingerprint, long publishedMillis, - long lastStatusMillis, String exitAddress, long scanMillis) { - this.fingerprint = fingerprint; - this.publishedMillis = publishedMillis; - this.lastStatusMillis = lastStatusMillis; - this.exitAddresses.put(exitAddress, scanMillis); - } - - @Deprecated - List<ExitListEntry> oldEntries() { - List<ExitListEntry> result = new ArrayList<>(); - if (this.exitAddresses.size() > 1) { - for (Map.Entry<String, Long> entry - : this.exitAddresses.entrySet()) { - result.add(new ExitListEntryImpl(this.fingerprint, - this.publishedMillis, this.lastStatusMillis, entry.getKey(), - entry.getValue())); - } - } else { - result.add(this); - } - return result; - } - - protected ExitListEntryImpl(String exitListEntryString, - boolean failUnrecognizedDescriptorLines) + protected ExitListEntryImpl(String exitListEntryString) throws DescriptorParseException { this.exitListEntryString = exitListEntryString; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; this.initializeKeywords(); this.parseExitListEntry(); this.checkAndClearKeywords(); @@ -114,15 +83,10 @@ public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry { this.parseExitAddressLine(line, parts); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in exit list entry."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -192,34 +156,11 @@ public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry { return this.lastStatusMillis; }
- private String exitAddress; - - @Override - public String getExitAddress() { - if (null == exitAddress) { - Map.Entry<String, Long> randomEntry = - this.exitAddresses.entrySet().iterator().next(); - this.exitAddress = randomEntry.getKey(); - this.scanMillis = randomEntry.getValue(); - } - return this.exitAddress; - } - private Map<String, Long> exitAddresses = new HashMap<>();
@Override public Map<String, Long> getExitAddresses() { return new HashMap<>(this.exitAddresses); } - - private long scanMillis; - - @Override - public long getScanMillis() { - if (null == exitAddress) { - getExitAddress(); - } - return scanMillis; - } }
diff --git a/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java b/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java index d16856a..d67ccd9 100644 --- a/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java @@ -5,7 +5,6 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException; import org.torproject.descriptor.ExitList; -import org.torproject.descriptor.ExitListEntry;
import java.io.File; import java.text.ParseException; @@ -20,10 +19,9 @@ import java.util.TimeZone; public class ExitListImpl extends DescriptorImpl implements ExitList {
protected ExitListImpl(byte[] rawDescriptorBytes, File descriptorfile, - String fileName, boolean failUnrecognizedDescriptorLines) - throws DescriptorParseException { + String fileName) throws DescriptorParseException { super(rawDescriptorBytes, new int[] { 0, rawDescriptorBytes.length }, - descriptorfile, failUnrecognizedDescriptorLines, false); + descriptorfile, false); this.splitAndParseExitListEntries(); this.setPublishedMillisFromFileName(fileName); } @@ -88,14 +86,8 @@ public class ExitListImpl extends DescriptorImpl implements ExitList { sb.append(line).append(ExitList.EOL); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in exit list."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } } } @@ -106,9 +98,8 @@ public class ExitListImpl extends DescriptorImpl implements ExitList { protected void parseExitListEntry(String exitListEntryString) throws DescriptorParseException { ExitListEntryImpl exitListEntry = new ExitListEntryImpl( - exitListEntryString, this.failUnrecognizedDescriptorLines); + exitListEntryString); this.exitListEntries.add(exitListEntry); - this.oldExitListEntries.addAll(exitListEntry.oldEntries()); List<String> unrecognizedExitListEntryLines = exitListEntry .getAndClearUnrecognizedLines(); if (unrecognizedExitListEntryLines != null) { @@ -126,13 +117,7 @@ public class ExitListImpl extends DescriptorImpl implements ExitList { return this.downloadedMillis; }
- private Set<ExitListEntry> oldExitListEntries = new HashSet<>(); - - @Deprecated - @Override - public Set<ExitListEntry> getExitListEntries() { - return new HashSet<>(this.oldExitListEntries); - } + private Set<ExitList.Entry> oldExitListEntries = new HashSet<>();
private Set<ExitList.Entry> exitListEntries = new HashSet<>();
diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java index 32a4dcc..3f84902 100644 --- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java @@ -35,10 +35,9 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl Key.PADDING_COUNTS);
protected ExtraInfoDescriptorImpl(byte[] descriptorBytes, - int[] offsetAndLimit, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, offsetAndLimit, descriptorFile, - failUnrecognizedDescriptorLines, false); + int[] offsetAndLimit, File descriptorFile) + throws DescriptorParseException { + super(descriptorBytes, offsetAndLimit, descriptorFile, false); this.parseDescriptorBytes(); this.checkExactlyOnceKeys(exactlyOnceKeys); Set<Key> dirreqStatsKeys = EnumSet.of( @@ -260,16 +259,10 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl this.parseIdentityEd25519CryptoBlock(cryptoString); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized crypto " - + "block '" + cryptoString + "' in extra-info " - + "descriptor."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.addAll(cryptoLines); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.addAll(cryptoLines); } cryptoLines = null; nextCrypto = Key.EMPTY; @@ -279,15 +272,10 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl cryptoLines.add(line); } else { ParseHelper.parseKeyword(line, partsNoOpt[0]); - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in extra-info descriptor."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -833,16 +821,6 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl this.setDigestSha256Base64(partsNoOpt[1]); }
- @Override - public String getExtraInfoDigest() { - return this.getDigestSha1Hex(); - } - - @Override - public String getExtraInfoDigestSha256() { - return this.getDigestSha256Base64(); - } - private String nickname;
@Override @@ -881,11 +859,6 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl private String geoipDbDigest;
@Override - public String getGeoipDbDigest() { - return this.getGeoipDbDigestSha1Hex(); - } - - @Override public String getGeoipDbDigestSha1Hex() { return this.geoipDbDigest; } @@ -893,11 +866,6 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl private String geoip6DbDigest;
@Override - public String getGeoip6DbDigest() { - return this.getGeoip6DbDigestSha1Hex(); - } - - @Override public String getGeoip6DbDigestSha1Hex() { return this.geoip6DbDigest; } diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java index d9c284e..6acb845 100644 --- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java @@ -19,10 +19,9 @@ public class MicrodescriptorImpl extends DescriptorImpl implements Microdescriptor {
protected MicrodescriptorImpl(byte[] descriptorBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines) + File descriptorFile) throws DescriptorParseException { - super(descriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false); + super(descriptorBytes, offsetAndLength, descriptorFile, false); this.parseDescriptorBytes(); this.calculateDigestSha256Base64(Key.ONION_KEY.keyword + NL); this.checkExactlyOnceKeys(EnumSet.of(Key.ONION_KEY)); @@ -89,15 +88,10 @@ public class MicrodescriptorImpl extends DescriptorImpl crypto.append(line).append(NL); } else { ParseHelper.parseKeyword(line, parts[0]); - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in microdescriptor."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -213,11 +207,6 @@ public class MicrodescriptorImpl extends DescriptorImpl } }
- @Override - public String getMicrodescriptorDigest() { - return this.getDigestSha256Base64(); - } - private String onionKey;
@Override diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java index 64c688e..e6f7bad 100644 --- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java @@ -40,8 +40,6 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
private boolean microdescConsensus;
- private boolean failUnrecognizedDescriptorLines; - private List<String> unrecognizedLines;
protected List<String> getAndClearUnrecognizedLines() { @@ -51,14 +49,12 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry { }
protected NetworkStatusEntryImpl(DescriptorImpl parent, int offset, - int length, boolean microdescConsensus, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { + int length, boolean microdescConsensus) + throws DescriptorParseException { this.parent = parent; this.offset = offset; this.length = length; this.microdescConsensus = microdescConsensus; - this.failUnrecognizedDescriptorLines = - failUnrecognizedDescriptorLines; this.parseStatusEntryBytes(); this.clearAtMostOnceKeys(); } @@ -120,15 +116,10 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry { this.parseIdLine(line, parts); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in status entry."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -344,11 +335,6 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry { private Set<String> microdescriptorDigests;
@Override - public Set<String> getMicrodescriptorDigests() { - return this.getMicrodescriptorDigestsSha256Base64(); - } - - @Override public Set<String> getMicrodescriptorDigestsSha256Base64() { return this.microdescriptorDigests == null ? null : new HashSet<>(this.microdescriptorDigests); diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java index 5695353..b025c1b 100644 --- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java @@ -20,11 +20,10 @@ import java.util.TreeMap; public abstract class NetworkStatusImpl extends DescriptorImpl {
protected NetworkStatusImpl(byte[] rawDescriptorBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines, - boolean containsDirSourceEntries, boolean blankLinesAllowed) - throws DescriptorParseException { + File descriptorFile, boolean containsDirSourceEntries, + boolean blankLinesAllowed) throws DescriptorParseException { super(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, blankLinesAllowed); + blankLinesAllowed); this.splitAndParseParts(containsDirSourceEntries); }
@@ -102,7 +101,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl { protected void parseDirSource(int offset, int length) throws DescriptorParseException { DirSourceEntryImpl dirSourceEntry = new DirSourceEntryImpl( - this, offset, length, this.failUnrecognizedDescriptorLines); + this, offset, length); this.dirSourceEntries.put(dirSourceEntry.getIdentity(), dirSourceEntry); List<String> unrecognizedDirSourceLines = dirSourceEntry @@ -141,7 +140,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl { protected void parseStatusEntry(int offset, int length) throws DescriptorParseException { NetworkStatusEntryImpl statusEntry = new NetworkStatusEntryImpl( - this, offset, length, false, this.failUnrecognizedDescriptorLines); + this, offset, length, false); this.statusEntries.put(statusEntry.getFingerprint(), statusEntry); List<String> unrecognizedStatusEntryLines = statusEntry .getAndClearUnrecognizedLines(); @@ -162,7 +161,7 @@ public abstract class NetworkStatusImpl extends DescriptorImpl { this.signatures = new ArrayList<>(); } DirectorySignatureImpl signature = new DirectorySignatureImpl( - this, offset, length, failUnrecognizedDescriptorLines); + this, offset, length); this.signatures.add(signature); List<String> unrecognizedStatusEntryLines = signature .getAndClearUnrecognizedLines(); diff --git a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java index 79ab862..a312f24 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java @@ -19,10 +19,8 @@ public class RelayDirectoryImpl extends DescriptorImpl implements RelayDirectory {
protected RelayDirectoryImpl(byte[] directoryBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines) - throws DescriptorParseException { - super(directoryBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, true); + File descriptorFile) throws DescriptorParseException { + super(directoryBytes, offsetAndLength, descriptorFile, true); this.splitAndParseParts(); this.calculateDigestSha1Hex(Key.SIGNED_DIRECTORY.keyword + NL, NL + Key.DIRECTORY_SIGNATURE.keyword + SP); @@ -144,15 +142,10 @@ public class RelayDirectoryImpl extends DescriptorImpl if (crypto != null) { crypto.append(line).append(NL); } else { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in v1 directory."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -195,8 +188,7 @@ public class RelayDirectoryImpl extends DescriptorImpl try { ServerDescriptorImpl serverDescriptor = new RelayServerDescriptorImpl(this.rawDescriptorBytes, - new int[] { offset, length }, this.getDescriptorFile(), - this.failUnrecognizedDescriptorLines); + new int[] { offset, length }, this.getDescriptorFile()); this.serverDescriptors.add(serverDescriptor); } catch (DescriptorParseException e) { this.serverDescriptorParseExceptions.add(e); @@ -238,9 +230,6 @@ public class RelayDirectoryImpl extends DescriptorImpl default: if (crypto != null) { crypto.append(line).append(NL); - } else if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in v2 network status."); } else { if (this.unrecognizedLines == null) { this.unrecognizedLines = new ArrayList<>(); @@ -449,9 +438,5 @@ public class RelayDirectoryImpl extends DescriptorImpl return this.nickname; }
- @Override - public String getDirectoryDigest() { - return this.getDigestSha1Hex(); - } }
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java index 9644f90..7ed696e 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayExtraInfoDescriptorImpl.java @@ -12,10 +12,9 @@ public class RelayExtraInfoDescriptorImpl extends ExtraInfoDescriptorImpl implements RelayExtraInfoDescriptor {
protected RelayExtraInfoDescriptorImpl(byte[] descriptorBytes, - int[] offsetAndLimit, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, offsetAndLimit, descriptorFile, - failUnrecognizedDescriptorLines); + int[] offsetAndLimit, File descriptorFile) + throws DescriptorParseException { + super(descriptorBytes, offsetAndLimit, descriptorFile); this.calculateDigestSha1Hex(Key.EXTRA_INFO.keyword + SP, NL + Key.ROUTER_SIGNATURE.keyword + NL); this.calculateDigestSha256Base64(Key.EXTRA_INFO.keyword + SP, diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java index 0e853bb..7c6f7e0 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java @@ -23,10 +23,9 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl implements RelayNetworkStatusConsensus {
protected RelayNetworkStatusConsensusImpl(byte[] consensusBytes, - int[] offsetAndLimit, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(consensusBytes, offsetAndLimit, descriptorFile, - failUnrecognizedDescriptorLines, true, false); + int[] offsetAndLimit, File descriptorFile) + throws DescriptorParseException { + super(consensusBytes, offsetAndLimit, descriptorFile, true, false); Set<Key> exactlyOnceKeys = EnumSet.of( Key.VOTE_STATUS, Key.CONSENSUS_METHOD, Key.VALID_AFTER, Key.FRESH_UNTIL, Key.VALID_UNTIL, Key.VOTING_DELAY, Key.KNOWN_FLAGS); @@ -107,14 +106,8 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl this.parseSharedRandCurrentValueLine(line, parts); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in consensus."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } } } @@ -125,8 +118,7 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl protected void parseStatusEntry(int offset, int length) throws DescriptorParseException { NetworkStatusEntryImpl statusEntry = new NetworkStatusEntryImpl(this, - offset, length, this.microdescConsensus, - this.failUnrecognizedDescriptorLines); + offset, length, this.microdescConsensus); this.statusEntries.put(statusEntry.getFingerprint(), statusEntry); List<String> unrecognizedStatusEntryLines = statusEntry .getAndClearUnrecognizedLines(); @@ -152,15 +144,10 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl this.parseBandwidthWeightsLine(line, parts); break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in consensus."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -345,11 +332,6 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl parts, 1); }
- @Override - public String getConsensusDigest() { - return this.getDigestSha1Hex(); - } - private int networkStatusVersion;
@Override diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java index 8ebea2d..f77e903 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java @@ -22,8 +22,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl protected RelayNetworkStatusImpl(byte[] statusBytes, int[] offsetAndLength, File descriptorFile, boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(statusBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false, true); + super(statusBytes, offsetAndLength, descriptorFile, false, true); Set<Key> exactlyOnceKeys = EnumSet.of( Key.NETWORK_STATUS_VERSION, Key.DIR_SOURCE, Key.FINGERPRINT, Key.CONTACT, Key.DIR_SIGNING_KEY, Key.PUBLISHED); @@ -97,9 +96,6 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl default: if (crypto != null) { crypto.append(line).append(NL); - } else if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in v2 network status."); } else { if (this.unrecognizedLines == null) { this.unrecognizedLines = new ArrayList<>(); @@ -149,9 +145,6 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl default: if (crypto != null) { crypto.append(line).append(NL); - } else if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in v2 network status."); } else { if (this.unrecognizedLines == null) { this.unrecognizedLines = new ArrayList<>(); @@ -247,11 +240,6 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl this.nickname = ParseHelper.parseNickname(line, parts[1]); }
- @Override - public String getStatusDigest() { - return this.getDigestSha1Hex(); - } - private int networkStatusVersion;
@Override diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java index 93d6f12..df36b26 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java @@ -4,7 +4,6 @@ package org.torproject.descriptor.impl;
import org.torproject.descriptor.DescriptorParseException; -import org.torproject.descriptor.DirectorySignature; import org.torproject.descriptor.RelayNetworkStatusVote;
import java.io.File; @@ -25,10 +24,9 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl implements RelayNetworkStatusVote {
protected RelayNetworkStatusVoteImpl(byte[] voteBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines) + File descriptorFile) throws DescriptorParseException { - super(voteBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false, false); + super(voteBytes, offsetAndLength, descriptorFile, false, false); Set<Key> exactlyOnceKeys = EnumSet.of( Key.VOTE_STATUS, Key.PUBLISHED, Key.VALID_AFTER, Key.FRESH_UNTIL, Key.VALID_UNTIL, Key.VOTING_DELAY, Key.KNOWN_FLAGS, Key.DIR_SOURCE, @@ -213,15 +211,10 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl if (crypto != null) { crypto.append(line).append(NL); } else { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in vote."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -588,15 +581,10 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl while (scanner.hasNext()) { String line = scanner.next(); if (!line.equals(Key.DIRECTORY_FOOTER.keyword)) { - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in vote."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -748,21 +736,6 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl return this.dirKeyCertification; }
- @Override - public String getSigningKeyDigest() { - String signingKeyDigest = null; - if (this.signatures != null && !this.signatures.isEmpty()) { - for (DirectorySignature signature : this.signatures) { - if (DirectorySignatureImpl.DEFAULT_ALGORITHM.equals( - signature.getAlgorithm())) { - signingKeyDigest = signature.getSigningKeyDigestSha1Hex(); - break; - } - } - } - return signingKeyDigest; - } - private int networkStatusVersion;
@Override diff --git a/src/main/java/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java index 23e9152..fd2464b 100644 --- a/src/main/java/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/RelayServerDescriptorImpl.java @@ -12,10 +12,9 @@ public class RelayServerDescriptorImpl extends ServerDescriptorImpl implements RelayServerDescriptor {
protected RelayServerDescriptorImpl(byte[] descriptorBytes, - int[] offsetAndLength, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { - super(descriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines); + int[] offsetAndLength, File descriptorFile) + throws DescriptorParseException { + super(descriptorBytes, offsetAndLength, descriptorFile); this.calculateDigestSha1Hex(Key.ROUTER.keyword + SP, NL + Key.ROUTER_SIGNATURE.keyword + NL); this.calculateDigestSha256Base64(Key.ROUTER.keyword + SP, diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java index f434d84..80ed473 100644 --- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java @@ -36,10 +36,8 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl Key.ROUTER, Key.BANDWIDTH, Key.PUBLISHED);
protected ServerDescriptorImpl(byte[] descriptorBytes, int[] offsetAndLength, - File descriptorFile, boolean failUnrecognizedDescriptorLines) - throws DescriptorParseException { - super(descriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines, false); + File descriptorFile) throws DescriptorParseException { + super(descriptorBytes, offsetAndLength, descriptorFile, false); this.parseDescriptorBytes(); this.checkExactlyOnceKeys(exactlyOnce); this.checkAtMostOnceKeys(atMostOnce); @@ -210,15 +208,10 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl this.ntorOnionKeyCrosscert = cryptoString; break; default: - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized crypto " - + "block '" + cryptoString + "' in server descriptor."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.addAll(cryptoLines); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.addAll(cryptoLines); } cryptoLines = null; nextCrypto = Key.EMPTY; @@ -229,15 +222,10 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl cryptoLines.add(line); } else { ParseHelper.parseKeyword(line, partsNoOpt[0]); - if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized line '" - + line + "' in server descriptor."); - } else { - if (this.unrecognizedLines == null) { - this.unrecognizedLines = new ArrayList<>(); - } - this.unrecognizedLines.add(line); + if (this.unrecognizedLines == null) { + this.unrecognizedLines = new ArrayList<>(); } + this.unrecognizedLines.add(line); } } } @@ -676,16 +664,6 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl this.setDigestSha256Base64(partsNoOpt[1]); }
- @Override - public String getServerDescriptorDigest() { - return this.getDigestSha1Hex(); - } - - @Override - public String getServerDescriptorDigestSha256() { - return this.getDigestSha256Base64(); - } - private String nickname;
@Override @@ -865,11 +843,6 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl private String extraInfoDigest;
@Override - public String getExtraInfoDigest() { - return this.getExtraInfoDigestSha1Hex(); - } - - @Override public String getExtraInfoDigestSha1Hex() { return this.extraInfoDigest; } @@ -877,11 +850,6 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl private String extraInfoDigestSha256;
@Override - public String getExtraInfoDigestSha256() { - return this.getExtraInfoDigestSha256Base64(); - } - - @Override public String getExtraInfoDigestSha256Base64() { return this.extraInfoDigestSha256; } diff --git a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java index 1ff0fe3..408b08c 100644 --- a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java @@ -22,8 +22,8 @@ public class TorperfResultImpl extends DescriptorImpl implements TorperfResult {
protected static List<Descriptor> parseTorperfResults( - byte[] rawDescriptorBytes, File descriptorFile, - boolean failUnrecognizedDescriptorLines) throws DescriptorParseException { + byte[] rawDescriptorBytes, File descriptorFile) + throws DescriptorParseException { if (rawDescriptorBytes.length == 0) { throw new DescriptorParseException("Descriptor is empty."); } @@ -50,18 +50,17 @@ public class TorperfResultImpl extends DescriptorImpl /* XXX21932 */ parsedDescriptors.add(new TorperfResultImpl( (typeAnnotation + line).getBytes(StandardCharsets.UTF_8), - descriptorFile, failUnrecognizedDescriptorLines)); + descriptorFile)); typeAnnotation = ""; } } return parsedDescriptors; }
- protected TorperfResultImpl(byte[] rawDescriptorBytes, File descriptorFile, - boolean failUnrecognizedDescriptorLines) + protected TorperfResultImpl(byte[] rawDescriptorBytes, File descriptorFile) throws DescriptorParseException { super(rawDescriptorBytes, new int[] { 0, rawDescriptorBytes.length }, - descriptorFile, failUnrecognizedDescriptorLines, false); + descriptorFile, false); this.parseTorperfResultLine(); }
@@ -173,9 +172,6 @@ public class TorperfResultImpl extends DescriptorImpl default: if (key.startsWith("DATAPERC")) { this.parseDataPercentile(value, keyValue, line); - } else if (this.failUnrecognizedDescriptorLines) { - throw new DescriptorParseException("Unrecognized key '" + key - + "' in line '" + line + "'."); } else { if (this.unrecognizedKeys == null) { this.unrecognizedKeys = new TreeMap<>(); diff --git a/src/main/java/org/torproject/descriptor/impl/UnparseableDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/UnparseableDescriptorImpl.java index 4a0e772..7174621 100644 --- a/src/main/java/org/torproject/descriptor/impl/UnparseableDescriptorImpl.java +++ b/src/main/java/org/torproject/descriptor/impl/UnparseableDescriptorImpl.java @@ -14,10 +14,8 @@ public class UnparseableDescriptorImpl extends DescriptorImpl
protected UnparseableDescriptorImpl(byte[] rawDescriptorBytes, int[] offsetAndLength, File descriptorFile, - boolean failUnrecognizedDescriptorLines, DescriptorParseException descriptorParseException) { - super(rawDescriptorBytes, offsetAndLength, descriptorFile, - failUnrecognizedDescriptorLines); + super(rawDescriptorBytes, offsetAndLength, descriptorFile); this.descriptorParseException = descriptorParseException; }
diff --git a/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java b/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java deleted file mode 100644 index dce3372..0000000 --- a/src/test/java/org/torproject/descriptor/DummyDownloaderImplementation.java +++ /dev/null @@ -1,15 +0,0 @@ -/* 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/impl/DescriptorCollectorImplTest.java b/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java deleted file mode 100644 index c2f9674..0000000 --- a/src/test/java/org/torproject/descriptor/impl/DescriptorCollectorImplTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* 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 static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import java.util.SortedMap; - -public class DescriptorCollectorImplTest { - - private static final String REMOTE_DIRECTORY_CONSENSUSES = - "/recent/relay-descriptors/consensuses/"; - - @Test - public void testOneFile() { - String remoteFilename = "2015-05-24-12-00-00-consensus"; - String directoryListing = "<tr><td valign="top">" - + "<img src="/icons/unknown.gif" alt="[ ]"></td><td>" - + "<a href="" + remoteFilename + "">" - + "2015-05-24-12-00-00-consensus</a></td>" - + "<td align="right">2015-05-24 12:08 </td>" - + "<td align="right">1.5M</td><td> </td></tr>"; - SortedMap<String, Long> remoteFiles = - new DescriptorCollectorImpl().parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNotNull(remoteFiles); - assertSame(1, remoteFiles.size()); - assertEquals(REMOTE_DIRECTORY_CONSENSUSES + remoteFilename, - remoteFiles.firstKey()); - assertEquals((Long) 1432469280000L, - remoteFiles.get(remoteFiles.firstKey())); - } - - @Test - public void testSameFileTwoTimestampsLastWins() { - String remoteFilename = "2015-05-24-12-00-00-consensus"; - String firstTimestamp = "2015-05-24 12:04"; - String secondTimestamp = "2015-05-24 12:08"; - String lineFormat = "<tr><td valign="top">" - + "<img src="/icons/unknown.gif" alt="[ ]"></td><td>" - + "<a href="%s">2015-05-24-12-00-00-consensus</a></td>" - + "<td align="right">%s </td>" - + "<td align="right">1.5M</td><td> </td></tr>\n"; - String directoryListing = String.format(lineFormat + lineFormat, - remoteFilename, firstTimestamp, remoteFilename, secondTimestamp); - SortedMap<String, Long> remoteFiles = - new DescriptorCollectorImpl().parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNotNull(remoteFiles); - assertSame(1, remoteFiles.size()); - assertEquals(REMOTE_DIRECTORY_CONSENSUSES + remoteFilename, - remoteFiles.firstKey()); - assertEquals((Long) 1432469280000L, - remoteFiles.get(remoteFiles.firstKey())); - } - - @Test - public void testSubDirectoryOnly() { - String directoryListing = "<tr><td valign="top">" - + "<img src="/icons/folder.gif" alt="[DIR]"></td><td>" - + "<a href="subdir/">subdir/</a></td>" - + "<td align="right">2015-05-27 14:07 </td>" - + "<td align="right"> - </td><td> </td></tr>"; - DescriptorCollectorImpl collector = new DescriptorCollectorImpl(); - SortedMap<String, Long> remoteFiles = collector.parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNotNull(remoteFiles); - assertTrue(remoteFiles.isEmpty()); - } - - @Test - public void testParentDirectoryOnly() { - String directoryListing = "<tr><td valign="top">" - + "<img src="/icons/back.gif" alt="[DIR]"></td><td>" - + "<a href="/recent/relay-descriptors/">Parent Directory</a>" - + "</td><td> </td><td align="right"> - </td>" - + "<td> </td></tr>"; - DescriptorCollectorImpl collector = new DescriptorCollectorImpl(); - SortedMap<String, Long> remoteFiles = collector.parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNotNull(remoteFiles); - assertTrue(remoteFiles.isEmpty()); - } - - @Test - public void testUnexpectedDateFormat() { - String directoryListing = "<tr><td valign="top">" - + "<img src="/icons/unknown.gif" alt="[ ]"></td><td>" - + "<a href="2015-05-24-12-00-00-consensus">" - + "2015-05-24-12-00-00-consensus</a></td>" - + "<td align="right">24-May-2015 12:08 </td>" - + "<td align="right">1.5M</td><td> </td></tr>"; - SortedMap<String, Long> remoteFiles = - new DescriptorCollectorImpl().parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNotNull(remoteFiles); - assertTrue(remoteFiles.isEmpty()); - } - - @Test - public void testInvalidDate() { - String directoryListing = "<tr><td valign="top">" - + "<img src="/icons/unknown.gif" alt="[ ]"></td><td>" - + "<a href="2015-05-24-12-00-00-consensus">" - + "2015-05-24-12-00-00-consensus</a></td>" - + "<td align="right">2015-05-34 12:08 </td>" - + "<td align="right">1.5M</td><td> </td></tr>"; - SortedMap<String, Long> remoteFiles = - new DescriptorCollectorImpl().parseDirectoryListing( - REMOTE_DIRECTORY_CONSENSUSES, directoryListing); - assertNull(remoteFiles); - } -} -
tor-commits@lists.torproject.org