Functions for creating mock [bridge-]server-descriptors
.
generateServerDescriptor
(nick, fingerprint, timestamp, ipv4, ipv6, port, vers, protocols, uptime, bandwidth, extraInfoHexDigest, onionKeyLine, signingKeyLine, publicNTORKey, bridge=True)[source]¶Generate an @type [bridge-]server-descriptor
.
Parameters: |
|
---|
makeProtocolsLine
(version=None)[source]¶Generate an appropriate [bridge-]server-descriptor
protocols
line.
Parameters: | version (str) – One of SERVER_VERSIONS . |
---|---|
Return type: | str |
Returns: | An @type [bridge-]server-descriptor protocols line. |
makeExtraInfoDigestLine
(hexdigest, version)[source]¶Create a line to embed the hex SHA-1 digest of the extrainfo.
Parameters: |
|
---|---|
Return type: | |
Returns: | An |
makeFingerprintLine
(fingerprint, version=None)[source]¶Generate an appropriate [bridge-]server-descriptor
fingerprint
line.
Parameters: |
|
---|---|
Return type: | |
Returns: | An |
makeBandwidthLine
(variance=30)[source]¶Create a random bandwidth
line with some plausible bandwidth burst
variance.
From dir-spec.txt §2.1 “Router descriptors”:
"bandwidth" bandwidth-avg bandwidth-burst bandwidth-observed NL
[Exactly once]
Estimated bandwidth for this router, in bytes per second. The
"average" bandwidth is the volume per second that the OR is willing
to sustain over long periods; the "burst" bandwidth is the volume
that the OR is willing to sustain in very short intervals. The
"observed" value is an estimate of the capacity this relay can
handle. The relay remembers the max bandwidth sustained output over
any ten second period in the past day, and another sustained input.
The "observed" value is the lesser of these two numbers.
The observed
bandwidth, in this function, is taken as some random value,
bounded between 20KB/s and 2MB/s. For example, say:
>>> import math
>>> variance = 25
>>> observed = 180376
>>> percentage = float(variance) / 100.
>>> percentage
0.25
The variance
in this context is the percentage of the observed
bandwidth, which will be added to the observed
bandwidth, and becomes
the value for the burst
bandwidth:
>>> burst = observed + math.ceil(observed * percentage)
>>> assert burst > observed
This doesn’t do much, since the burst
bandwidth in a real
@type [bridge-]server-descriptor
is reported by the OR; this function
mostly serves to avoid generating completely-crazy, totally-implausible
bandwidth values. The average
bandwidth value is then just the mean
value of the other two.
Parameters: | variance (int) – The percent of the fake observed bandwidth to
increase the burst bandwidth by. |
---|---|
Return type: | str |
Returns: | A bandwidth line for an @type [bridge-]server-descriptor . |
makeHSDirLine
(version)[source]¶This line doesn’t do much… all the cool kids are HSDir
s these days.
Parameters: | version (str) – One of SERVER_VERSIONS . |
---|---|
Return type: | str |
Returns: | An @type [bridge-]server-descriptor hidden-service-dir
line. |