PathConstraints
PathConstraints represent constraints on a path through the Tor network. They are constructed by passing a dict of {‘keyword’: ‘value’} as an argument for each node. A list of filters is built for each node. Then, using the satisfy() method, a PathConstraints object can select only the RelayDescriptors that satisfy the proper constraints.
Path constraint objects can be used as follows (suppose relays is a list of RelayDescriptors):
>>> p = PathConstraints(entry={'ntor': True, 'flags': ['Fast', 'Guard']},
>>> middle={'ntor': True, 'flags': ['Stable'],
>>> exit={'ntor': True, 'flags': ['Exit'],
>>> 'exit_to_port': 443})
>>> entry_candidates = p.satisfy(node='entry', relays)
entry_candidates would now be a list of all relays that satisfy the entry node constraints.
PathSelector
PathSelector objects simplify choosing a full path. PathSelectors take a PathConstraints object as an argument to the constructor. When getPath() is called, PathSelectors use these PathConstraints to build a path through the Tor network, taking care of some additional concerns including:
- not selecting two relays in the same family
- not selecting two relays in the same /16
- not selecting the same relay in a path twice
getPath() returns a deferred that will fire with the chosen Path object.
Bases: tuple
Path(entry, middle, exit)
Alias for field number 0
Alias for field number 2
Alias for field number 1
Bases: object
Represent a set of path constraints.
Return the subset of relays that satisfies the path constraints for chosen node.
Parameters: |
|
---|---|
Returns: | list, stem.descriptor.server_descriptor.RelayDescriptor all RelayDescriptors from relays that satisfy the path constraints for the chosen node position |
Bases: object
Select a path based on some path constraints.
Filter the current set of RelayDescriptors and randomly choose an entry, middle, and exit node that satisfy the desired path constraints.
We currently just use the absolutely bare minimum path constraints, namely:
- no two relays in the same family
- no two relays in the same /16
- each relay has the required default flags
Parameters: | constraints (oppy.path.path.PathConstraints) – path constraints to satisfy |
---|---|
Returns: | twisted.internet.defer.Deferred that fires with an oppy.path.Path |