bridgedb.bridgerequest

API for creating classes which store information on the type of bridges requested by a client.

Inheritance diagram of BridgeRequestBase

interface IRequestBridges[source]

Interface specification of client options for requested bridges.

filters

A list of callables used to filter bridges from a hashring.

ipVersion

The IP version of bridge addresses to distribute to the client.

transports

A list of strings of Pluggable Transport types requested.

notBlockedIn

A list of two-character country codes. The distributed bridges should not be blocked in these countries.

valid

A boolean. Should be True if the client’s request was valid.

client

This should be some information unique to the client making the request for bridges, such that we are able to HMAC this unique data, via getHashringPlacement(), in order to place the client into a hashring (determining which bridge addresses they get in the request response).

addFilter()

Add a filter to the list of filters.

clearFilters()

Clear the list of filters.

generateFilters()

Build the list of callables, filters, according to the current contents of the lists of transports, notBlockedIn, and the ipVersion.

getHashringPlacement()

Use some unique parameters of the client making this request to obtain a value which we can use to place them into one of the hashrings with :class:`~bridgedb.bridges.Bridge`s in it, in order to give that client different bridges than other clients.

isValid()

Determine if the request is valid according to some parameters.

withIPv4()

Set the ipVersion to IPv4.

withIPv6()

Set the ipVersion to IPv6.

withPluggableTransportType(typeOfPT)

Add this typeOfPT to the list of requested transports.

withoutBlockInCountry(countryCode)

Add this countryCode to the list of countries which distributed bridges should not be blocked in (notBlockedIn).

class BridgeRequestBase(ipVersion=None)[source]

Bases: object

A generic base class for storing options of a client bridge request.

Variables:
  • filters (list) – A list of callables used to filter bridges from a hashring.
  • transports (list) – A list of strings of Pluggable Transport types requested.
  • notBlockedIn (list) – A list of two-character country codes. The distributed bridges should not be blocked in these countries.
  • client (str) – This should be some information unique to the client making the request for bridges, such that we are able to HMAC this unique data in order to place the client into a hashring (determining which bridge addresses they get in the request response). It defaults to the string 'default'.
  • valid (bool) – Should be True if the client’s request was valid.
ipVersion

The IP version of bridge addresses to distribute to the client.

Return type:int
Returns:Either 4 or 6.
getHashringPlacement(key, client=None)[source]

Create an HMAC of some client info using a key.

Parameters:
  • key (str) – The key to use for HMACing.
  • client (str) – Some (hopefully unique) information about the client who is requesting bridges, such as an IP or email address.
Return type:

long

Returns:

A long specifying index of the first node in a hashring to be distributed to the client. This value should obviously be used mod the number of nodes in the hashring.

isValid(valid=None)[source]

Get or set the validity of this bridge request.

If called without parameters, this method will return the current state, otherwise (if called with the valid parameter), it will set the current state of validity for this request.

Parameters:valid (bool) – If given, set the validity state of this request. Otherwise, get the current state.
withIPv4()[source]

Set the ipVersion to IPv4.

withIPv6()[source]

Set the ipVersion to IPv6.

withoutBlockInCountry(country)[source]

Add this countryCode to the list of countries which distributed bridges should not be blocked in (notBlockedIn).

withPluggableTransportType(pt)[source]

Add this pt to the list of requested transports.

Parameters:pt (str) – A PluggableTransport. methodname.
addFilter(filtre)[source]

Add a filtre to the list of filters.

Parameters:filter (callable) – A filter function, e.g. one generated via bridgedb.filters.
clearFilters()[source]

Clear the list of filters.

justOnePTType()[source]

Get just one bridge type (e.g. a methodname of PluggableTransport) at a time!

generateFilters()[source]

Build the list of callables, filters, according to the current contents of the lists of transports, notBlockedIn, and the ipVersion.