This module has low-level functionality for parsing bridges and arranging them into hashrings for distributors.
BridgeRingParameters
(needPorts=[], needFlags=[])[source]¶Bases: object
Store validated settings on minimum number of Bridges with certain attributes which should be included in any generated subring of a hashring.
Variables: |
---|
Control the creation of subrings by including a minimum number of bridges which possess certain attributes.
Parameters: |
|
---|---|
Raises: | An |
BridgeRing
(key, answerParameters=None)[source]¶Bases: object
Arranges bridges into a hashring based on an hmac function.
Create a new BridgeRing, using key as its hmac key.
Parameters: |
|
---|---|
Variables: |
|
setName
(name)[source]¶Tag a unique name to this hashring for identification.
Parameters: | name (string) – The name for this hashring. |
---|
insert
(bridge)[source]¶Add a bridge to this hashring.
The bridge’s position in the hashring is dependent upon the HMAC of the raw hash digest of the bridge’s ID key. The function used to generate the HMAC, :ivar:`BridgeRing.hmac`, is unique to each individual hashring.
If the (presumably same) bridge is already at that determined position in this hashring, replace the old one.
Parameters: | bridge (Bridge ) – The bridge to insert into this hashring. |
---|
_getBridgeKeysAt
(pos, N=1)[source]¶Bisect a list of bridges at a specified position, pos, and retrieve bridges from that point onwards, wrapping around the hashring if necessary.
If the number of bridges requested, N, is larger that the size of this hashring, return the entire ring. Otherwise:
Sort this bridges in this hashring, if it is currently unsorted.
Bisect the sorted bridges. If the bridge at the desired position, pos, already exists within this hashring, the the bisection result is the bridge at position pos. Otherwise, the bisection result is the first position after pos which has a bridge assigned to it.
Try to obtain N bridges, starting at (and including) the bridge in the requested position, pos.
- If there aren’t N bridges after pos, wrap back around to the beginning of the hashring and obtain bridges until we have N bridges.
Check that the number of bridges obtained is indeed N, then return them.
Parameters: |
|
---|---|
Return type: | |
Returns: | A list of :class:`~bridgedb.Bridges.Bridge`s. |
getBridges
(pos, N=1)[source]¶Return N bridges appearing in this hashring after a position.
Parameters: |
|
---|---|
Return type: | |
Returns: | A list of :class:`~bridgedb.bridges.Bridge`s. |
FixedBridgeSplitter
(key, rings)[source]¶Bases: object
Splits bridges up based on an HMAC and assigns them to one of several subhashrings with equal probability.
dumpAssignments
(filename, description='')[source]¶Write all bridges assigned to this hashring to filename
.
Parameters: | description (string) – If given, include a description next to the
index number of the ring from FilteredBridgeSplitter.rings
the following bridges were assigned to. For example, if the
description is "IPv6 obfs2 bridges" the line would read:
"IPv6 obfs2 bridges ring=3" . |
---|
UnallocatedHolder
[source]¶Bases: object
A pseudo-bridgeholder that ignores its bridges and leaves them unassigned.
BridgeSplitter
(key)[source]¶Bases: object
Splits incoming bridges up based on an HMAC, and assigns them to sub-bridgeholders with different probabilities. Bridge ←→ BridgeSplitter associations are recorded in a store.
FilteredBridgeSplitter
(key, max_cached_rings=3)[source]¶Bases: object
Places bridges into subrings based upon sets of filters.
The set of subrings and conditions used to assign Bridge`s should
be passed to :meth:`~FilteredBridgeSplitter.addRing
.
Create a hashring which filters bridges into sub hashrings.
Parameters: |
|
---|---|
Variables: |
|
insert
(bridge)[source]¶Insert a bridge into all appropriate sub-hashrings.
For all sub-hashrings, the bridge
will only be added iff it passes
the filter functions for that sub-hashring.
Parameters: | bridge (Bridge ) – The bridge to add. |
---|
extractFilterNames
(ringname)[source]¶Get the names of the filters applied to a particular sub hashring.
Parameters: | ringname (str) – A unique name identifying a sub hashring. |
---|---|
Return type: | list |
Returns: | A sorted list of strings, all the function names of the filters applied to the sub hashring named ringname. |
addRing
(subring, ringname, filterFn, populate_from=None)[source]¶Add a subring to this hashring.
Parameters: |
|
---|---|
Return type: | |
Returns: | False if there was a problem adding the subring, True otherwise. |