connectionpool

Details

The ConnectionPool manages a pool of TLS connections to entry nodes. The main job of the ConnectionPool is to hand out TLS connections to requesting circuits and keep track of all the open connections. TLS connections to the same entry nodes are shared among circuits.

class connection.connectionpool.TLSClientContextFactory[source]

Bases: twisted.internet.ssl.ClientContextFactory

isClient = 1
method = 4
getContext()[source]
class connection.connectionpool.ConnectionPool[source]

Bases: object

A pool of TLS connections to entry nodes.

getConnection(relay)[source]

Return a deferred which will fire (if connection attempt is successful) with a Connection Protocol made to relay.

There are three general cases to handle for incoming connection requests:

  1. We already have an open TLS connection to the requested relay. In this case, immediately callback the deferred with the open connection.
  2. We’re currently trying to connect to this relay. In this case, add the request to a pending request list for this relay. When the connection is made successfully, callback all pending request deferreds with the Connection, or errback all pending request deferreds on failure.
  3. We have no open or pending connections to this relay (i.e. this is the first connection request to this relay). In this case, create a new list of pending requests for this connection and add the current request. Create an SSL endpoint and add an appropriate callback and errback. If the request is successful, callback all pending requests with the open connection when it opens; errback all pending requests on failure.
Parameters:relay (stem.descriptor.server_descriptor.RelayDescriptor) – relay to make a TLS connection to
Returns:twisted.internet.defer.Deferred which, on success, will callback with an oppy.connection.connection.Connection Protocol object
removeConnection(fingerprint)[source]

Remove the connection to relay with fingerprint from the connection pool.

Parameters:fingerprint (str) – fingerprint of connection to remove
shouldDestroyConnection(fingerprint)[source]

Return True if ConnectionPool thinks we should destroy the TLS connection to relay with fingerprint.

Called when the number of circuits on a connection drops to zero.

Note

For now, we always return True. Eventually, we may want to maintain a connection to any guards, even if there are no currently open circuits.

Parameters:fingerprint (str) – fingerprint of connection to check
Returns:bool True if we think this connection should be destroyed

Previous topic

connection

Next topic

connection

This Page