leekspin.util
Common general utilities.
-
getArgParser
()[source]
Get our ArgumentParser
.
-
randomIP
()[source]
Create a random IPv4 or IPv6 address.
-
randomIPv4
()[source]
Create a random IPv4 address.
-
randomIPv6
()[source]
Create a random IPv6 address.
-
randomPort
()[source]
Get a random integer in the range [1026, 65530]
.
The reason that port 1025 is missing is because the IPv6 port (in the
or-address
/a
lines), if there will be one, will be whatever the
random ORPort is, minus one.
The pluggable transport in the extrainfo descriptor (if there are any) are
calculated as the random ORPort, plus some.
-
getHexString
(size)[source]
Get a capitalised hexidecimal string size bytes long.
Parameters: | size (int) – The number of bytes in the returned string. |
Return type: | str |
Returns: | A hex string. |
-
makeTimeStamp
(now=None, fmt=None, variation=False, period=None)[source]
Get a random timestamp suitable for a bridge server descriptor.
Parameters: |
- now (int) – The time, in seconds since the Epoch, to generate the
timestamp for (and to consider as the maximum time, if other options
are enabled).
- fmt (str) – A strftime(3) format string for the timestamp. If not
given, defaults to ISO-8601 format without the
'T' separator.
- variation (bool) – If True, enable timestamp variation. Otherwise,
make all timestamps be set to the current time.
- period (int or None) – If given, vary the generated timestamps to be a random time
between period hours ago and the current time. If
None ,
generate completely random timestamps which are anywhere between the
Unix Epoch and the current time. This parameter only has an effect if
variation is enabled.
|
-
writeDescToFile
(filename, descriptors)[source]
Open filename and write a string containing descriptors into it.
Parameters: |
- filename (str) – The name of the file to write to.
- descriptors (str) – A giant string containing descriptors,
newlines, formatting, whatever is necessary to make it look like a
file tor would generate.
|