| | |
- NodeGenerator
-
- BwWeightedGenerator
- OrderedExitGenerator
- UniformGenerator
- NodeRestriction
-
- ConserveExitsRestriction
- CountryCodeRestriction
- CountryRestriction
- ExitPolicyRestriction
- FlagsRestriction
- IdHexRestriction
- MetaNodeRestriction
-
- AtLeastNNodeRestriction
- NotNodeRestriction
- OrNodeRestriction
- MinBWRestriction
- NickRestriction
- OSRestriction
- PercentileRestriction
- VersionExcludeRestriction
- VersionIncludeRestriction
- NodeRestrictionList
- PathRestriction
-
- ContinentJumperRestriction
- ContinentRestriction
- SingleCountryRestriction
- Subnet16Restriction
- UniqueContinentRestriction
- UniqueCountryRestriction
- UniqueRestriction
- PathRestrictionList
- PathSelector
- SelectionManager
- TorCtl.TorCtl.Connection
-
- Connection
- TorCtl.TorCtl.EventHandler
-
- PathBuilder
-
- CircuitHandler
-
- StreamHandler
class BwWeightedGenerator(NodeGenerator) |
| |
This is a generator designed to match the Tor Path Selection
algorithm. It will generate nodes weighted by their bandwidth,
but take the appropriate weighting into account against guard
nodes and exit nodes when they are chosen for positions other
than guard/exit. For background see:
routerlist.c::smartlist_choose_by_bandwidth(),
http://archives.seul.org/or/dev/Jul-2007/msg00021.html,
http://archives.seul.org/or/dev/Jul-2007/msg00056.html, and
https://tor-svn.freehaven.net/svn/tor/trunk/doc/spec/path-spec.txt
The formulas used are from the first or-dev link, but are proven
optimal and equivalent to the ones now used in routerlist.c in the
second or-dev link. |
| |
Methods defined here:
- __init__(self, sorted_r, rstr_list, pathlen, exit=False, guard=False)
- Pass exit=True to create a generator for exit-nodes
- generate(self)
- rewind(self)
Methods inherited from NodeGenerator:
- all_chosen(self)
- Return true if all the routers have been marked as chosen
- mark_chosen(self, r)
- Mark a router as chosen: remove it from the list of routers
that can be returned in the future
- reset_restriction(self, rstr_list)
- Reset the restriction list to a new list
|
class CircuitHandler(PathBuilder) |
| |
CircuitHandler that extends from PathBuilder to handle multiple
circuits as opposed to just one. |
| |
- Method resolution order:
- CircuitHandler
- PathBuilder
- TorCtl.TorCtl.EventHandler
Methods defined here:
- __init__(self, c, selmgr, num_circuits, RouterClass)
- Constructor. 'c' is a Connection, 'selmgr' is a SelectionManager,
'num_circuits' is the number of circuits to keep in the pool,
and 'RouterClass' is a class that inherits from Router and is used
to create annotated Routers.
- build_circuit(self, host, port)
- Build a circuit
- check_circuit_pool(self)
- Init or check the status of the circuit-pool
- circ_status_event(self, c)
- Handle circuit status events
- close_circuit(self, id)
- Close a circuit with given id
Methods inherited from PathBuilder:
- attach_stream_any(self, stream, badcircs)
- Attach a stream to a valid circuit, avoiding any in 'badcircs'
- bandwidth_event(self, b)
- build_path(self)
- Get a path from the SelectionManager's PathSelector, can be used
e.g. for generating paths without actually creating any circuits
- heartbeat_event(self, event)
- This function handles dispatching scheduled jobs. If you
extend PathBuilder and want to implement this function for
some reason, be sure to call the parent class
- new_desc_event(self, d)
- ns_event(self, n)
- read_routers(self, nslist)
- schedule_immediate(self, job)
- Schedules an immediate job to be run before the next event is
processed.
- schedule_low_prio(self, job)
- Schedules a job to be run when a non-time critical event arrives.
- schedule_selmgr(self, job)
- Schedules an immediate job to be run before the next event is
processed. Also notifies the selection manager that it needs
to update itself.
- stream_bw_event(self, s)
- stream_status_event(self, s)
Methods inherited from TorCtl.TorCtl.EventHandler:
- address_mapped_event(self, event)
- Called when Tor adds a mapping for an address if listening
to ADDRESSMAPPED events.
- msg_event(self, event)
- Called when a log message of a given severity arrives if listening
to INFO_MSG, NOTICE_MSG, WARN_MSG, or ERR_MSG events.
- or_conn_status_event(self, event)
- Called when an OR connection's status changes if listening to
ORCONNSTATUS events.
- unknown_event(self, event)
- Called when we get an event type we don't recognize. This
is almost alwyas an error.
|
class Connection(TorCtl.TorCtl.Connection) |
| |
Extended Connection class that provides a method for building circuits |
| |
Methods defined here:
- __init__(self, sock)
- build_circuit(self, pathlen, path_sel)
- Tell Tor to build a circuit chosen by the PathSelector 'path_sel'
Methods inherited from TorCtl.TorCtl.Connection:
- attach_stream(self, streamid, circid, hop=None)
- Attach a stream to a circuit, specify both by IDs. If hop is given,
try to use the specified hop in the circuit as the exit node for
this stream.
- authenticate(self, secret='')
- Send an authenticating secret to Tor. You'll need to call this
method before Tor can start.
- close(self)
- Shut down this controller connection
- close_circuit(self, circid, reason=0, flags=())
- DOCDOC
- close_stream(self, streamid, reason=0, flags=())
- DOCDOC
- debug(self, f)
- DOCDOC
- extend_circuit(self, circid, hops)
- Tell Tor to extend the circuit identified by 'circid' through the
servers named in the list 'hops'.
- get_info(self, name)
- Return the value of the internal information field named 'name'.
Refer to section 3.9 of control-spec.txt for a list of valid names.
DOCDOC
- get_network_status(self, who='all')
- Get the entire network status list. Returns a list of
TorCtl.NetworkStatus instances.
- get_option(self, name)
- Get the value of the configuration option named 'name'. To
retrieve multiple values, pass a list for 'name' instead of
a string. Returns a list of (key,value) pairs.
Refer to section 3.3 of control-spec.txt for a list of valid names.
- get_router(self, ns)
- Fill in a Router class corresponding to a given NS class
- launch_thread(self, daemon=1)
- Launch a background thread to handle messages from the Tor process.
- map_address(self, kvList)
- Sends the MAPADDRESS command for each of the tuples in kvList
- post_descriptor(self, desc)
- read_routers(self, nslist)
- Given a list a NetworkStatuses in 'nslist', this function will
return a list of new Router instances.
- redirect_stream(self, streamid, newaddr, newport='')
- DOCDOC
- reset_options(self, keylist)
- Reset the options listed in 'keylist' to their default values.
Tor started implementing this command in version 0.1.1.7-alpha;
previous versions wanted you to set configuration keys to "".
That no longer works.
- resolve(self, host)
- Launch a remote hostname lookup request:
'host' may be a hostname or IPv4 address
- save_conf(self)
- Flush all configuration changes to disk.
- sendAndRecv(self, msg='', expectedTypes=('250', '251'))
- Helper: Send a command 'msg' to Tor, and wait for a command
in response. If the response type is in expectedTypes,
return a list of (tp,body,extra) tuples. If it is an
error, raise ErrorReply. Otherwise, raise ProtocolError.
- send_signal(self, sig)
- Send the signal 'sig' to the Tor process; The allowed values for
'sig' are listed in section 3.6 of control-spec.
- set_close_handler(self, handler)
- Call 'handler' when the Tor process has closed its connection or
given us an exception. If we close normally, no arguments are
provided; otherwise, it will be called with an exception as its
argument.
- set_event_handler(self, handler)
- Cause future events from the Tor process to be sent to 'handler'.
- set_events(self, events, extended=False)
- Change the list of events that the event handler is interested
in to those in 'events', which is a list of event names.
Recognized event names are listed in section 3.3 of the control-spec
- set_option(self, key, value)
- Set the value of the configuration option 'key' to the value 'value'.
- set_options(self, kvlist)
- Given a list of (key,value) pairs, set them as configuration
options.
|
class NodeGenerator |
| |
Interface for node generation |
| |
Methods defined here:
- __init__(self, sorted_r, rstr_list)
- Constructor. Takes a bandwidth-sorted list of Routers 'sorted_r'
and a NodeRestrictionList 'rstr_list'
- all_chosen(self)
- Return true if all the routers have been marked as chosen
- generate(self)
- Return a python generator that yields routers according to the policy
- mark_chosen(self, r)
- Mark a router as chosen: remove it from the list of routers
that can be returned in the future
- reset_restriction(self, rstr_list)
- Reset the restriction list to a new list
- rewind(self)
- Rewind the generator to the 'beginning'
|
class NodeRestriction |
| |
Interface for node restriction policies |
| |
Methods defined here:
- r_is_ok(self, r)
- Returns true if Router 'r' is acceptable for this restriction
|
class OSRestriction(NodeRestriction) |
| |
Restriction based on operating system |
| |
Methods defined here:
- __init__(self, ok, bad=[])
- Constructor. Accept router OSes that match regexes in 'ok',
rejects those that match regexes in 'bad'.
- r_is_ok(self, r)
- Returns true if r is in 'ok', false if 'r' is in 'bad'. If 'ok'
|
class PathBuilder(TorCtl.TorCtl.EventHandler) |
| |
PathBuilder implementation. Handles circuit construction, subject
to the constraints of the SelectionManager selmgr.
Do not access this object from other threads. Instead, use the
schedule_* functions to schedule work to be done in the thread
of the EventHandler. |
| |
Methods defined here:
- __init__(self, c, selmgr, RouterClass)
- Constructor. 'c' is a Connection, 'selmgr' is a SelectionManager,
and 'RouterClass' is a class that inherits from Router and is used
to create annotated Routers.
- attach_stream_any(self, stream, badcircs)
- Attach a stream to a valid circuit, avoiding any in 'badcircs'
- bandwidth_event(self, b)
- build_path(self)
- Get a path from the SelectionManager's PathSelector, can be used
e.g. for generating paths without actually creating any circuits
- circ_status_event(self, c)
- heartbeat_event(self, event)
- This function handles dispatching scheduled jobs. If you
extend PathBuilder and want to implement this function for
some reason, be sure to call the parent class
- new_desc_event(self, d)
- ns_event(self, n)
- read_routers(self, nslist)
- schedule_immediate(self, job)
- Schedules an immediate job to be run before the next event is
processed.
- schedule_low_prio(self, job)
- Schedules a job to be run when a non-time critical event arrives.
- schedule_selmgr(self, job)
- Schedules an immediate job to be run before the next event is
processed. Also notifies the selection manager that it needs
to update itself.
- stream_bw_event(self, s)
- stream_status_event(self, s)
Methods inherited from TorCtl.TorCtl.EventHandler:
- address_mapped_event(self, event)
- Called when Tor adds a mapping for an address if listening
to ADDRESSMAPPED events.
- msg_event(self, event)
- Called when a log message of a given severity arrives if listening
to INFO_MSG, NOTICE_MSG, WARN_MSG, or ERR_MSG events.
- or_conn_status_event(self, event)
- Called when an OR connection's status changes if listening to
ORCONNSTATUS events.
- unknown_event(self, event)
- Called when we get an event type we don't recognize. This
is almost alwyas an error.
|
class PathRestriction |
| |
Interface for path restriction policies |
| |
Methods defined here:
- path_is_ok(self, path)
- Return true if the list of Routers in path satisfies this restriction
|
class PathSelector |
| |
Implementation of path selection policies. Builds a path according
to entry, middle, and exit generators that satisfies the path
restrictions. |
| |
Methods defined here:
- __init__(self, entry_gen, mid_gen, exit_gen, path_restrict)
- Constructor. The first three arguments are NodeGenerators with
their appropriate restrictions. The 'path_restrict' is a
PathRestrictionList
- build_path(self, pathlen)
- Creates a path of 'pathlen' hops, and returns it as a list of
Router instances
|
class PercentileRestriction(NodeRestriction) |
| |
Restriction to cut out a percentile slice of the network. |
| |
Methods defined here:
- __init__(self, pct_skip, pct_fast, r_list)
- Constructor. Sets up the restriction such that routers in the
'pct_skip' to 'pct_fast' percentile of bandwidth rankings are
returned from the sorted list 'r_list'
- r_is_ok(self, r)
- Returns true if r is in the percentile boundaries (by rank)
|
class SelectionManager |
| |
Helper class to handle configuration updates
The methods are NOT threadsafe. They may ONLY be called from
EventHandler's thread. This means that to update the selection
manager, you must schedule a config update job using
PathBuilder.schedule_selmgr() with a worker function to modify
this object. |
| |
Methods defined here:
- __init__(self, pathlen, order_exits, percent_fast, percent_skip, min_bw, use_all_exits, uniform, use_exit, use_guards, geoip_config=None, restrict_guards=False)
- reconfigure(self, sorted_r)
- This function is called after a configuration change,
to rebuild the RestrictionLists.
- set_target(self, ip, port)
- Called to update the ExitPolicyRestrictions with a new ip and port
|
class StreamHandler(CircuitHandler) |
| |
StreamHandler that extends from the CircuitHandler
to handle attaching streams to an appropriate circuit
in the pool. |
| |
- Method resolution order:
- StreamHandler
- CircuitHandler
- PathBuilder
- TorCtl.TorCtl.EventHandler
Methods defined here:
- __init__(self, c, selmgr, num_circs, RouterClass)
- address_mapped_event(self, event)
- It is necessary to listen to ADDRMAP events to be able to
perform DNS lookups using Tor
- attach_stream_any(self, stream, badcircs)
- Attach a regular user stream
- clear_dns_cache(self)
- Send signal CLEARDNSCACHE
- close_stream(self, id, reason)
- Close a stream with given id and reason
- create_and_attach(self, stream, unattached_streams)
- Create a new circuit and attach (stream + unattached_streams)
- stream_status_event(self, s)
- Catch user stream events
- unknown_event(self, event)
Methods inherited from CircuitHandler:
- build_circuit(self, host, port)
- Build a circuit
- check_circuit_pool(self)
- Init or check the status of the circuit-pool
- circ_status_event(self, c)
- Handle circuit status events
- close_circuit(self, id)
- Close a circuit with given id
Methods inherited from PathBuilder:
- bandwidth_event(self, b)
- build_path(self)
- Get a path from the SelectionManager's PathSelector, can be used
e.g. for generating paths without actually creating any circuits
- heartbeat_event(self, event)
- This function handles dispatching scheduled jobs. If you
extend PathBuilder and want to implement this function for
some reason, be sure to call the parent class
- new_desc_event(self, d)
- ns_event(self, n)
- read_routers(self, nslist)
- schedule_immediate(self, job)
- Schedules an immediate job to be run before the next event is
processed.
- schedule_low_prio(self, job)
- Schedules a job to be run when a non-time critical event arrives.
- schedule_selmgr(self, job)
- Schedules an immediate job to be run before the next event is
processed. Also notifies the selection manager that it needs
to update itself.
- stream_bw_event(self, s)
Methods inherited from TorCtl.TorCtl.EventHandler:
- msg_event(self, event)
- Called when a log message of a given severity arrives if listening
to INFO_MSG, NOTICE_MSG, WARN_MSG, or ERR_MSG events.
- or_conn_status_event(self, event)
- Called when an OR connection's status changes if listening to
ORCONNSTATUS events.
|
|