bridgedb.filters

Functions for filtering Bridges.

bySubring(hmac, assigned, total)[source]

Create a filter function which filters for only the bridges which fall into the same assigned subhashring (based on the results of an hmac function).

Parameters:
  • hmac (callable) – An HMAC function, i.e. as returned from bridgedb.crypto.getHMACFunc().
  • assigned (int) – The subring number that we wish to draw bridges from. For example, if a user is assigned to subring 2of3 based on their IP address, then this function should only return bridges which would also be assigned to subring 2of3.
  • total (int) – The total number of subrings.
Return type:

callable

Returns:

A filter function for Bridges.

byFilters(filtres)[source]

Returns a filter which filters by multiple filtres.

Parameters:filtres (list) – A list (or other iterable) of callables which some Bridges should be filtered according to.
Return type:callable
Returns:A filter function for Bridges.
byIPv(ipVersion=None)[source]

Return True if at least one of the bridge‘s addresses has the specified ipVersion.

Parameters:ipVersion (int) – Either 4 or 6.
byIPv4(bridge)

Determine if the bridge has an IPv4 address.

Parameters:bridge (bridgedb.bridges.Bridge) – A bridge to filter.
Return type:bool
Returns:True if the bridge has an address with the correct IP version; False otherwise.
byIPv6(bridge)

Determine if the bridge has an IPv6 address.

Parameters:bridge (bridgedb.bridges.Bridge) – A bridge to filter.
Return type:bool
Returns:True if the bridge has an address with the correct IP version; False otherwise.
byTransport(methodname=None, ipVersion=None)[source]

Returns a filter function for a Bridge.

The returned filter function should be called on a Bridge. It returns True if the Bridge has a PluggableTransport such that:

  1. The methodname matches methodname, and,
  2. The bridgedb.bridges.PluggableTransport.address.version equals the ipVersion.
Parameters:
  • methodname (str) – A Pluggable Transport methodname.
  • ipVersion (int) – Either 4 or 6. The IP version that the Bridge‘s PluggableTransport address should have.
Return type:

callable

Returns:

A filter function for Bridges.

byNotBlockedIn(countryCode=None, methodname=None, ipVersion=4)[source]

Returns a filter function for Bridges.

If a Pluggable Transport methodname was not specified, the returned filter function returns True if any of the Bridge‘s addresses or PluggableTransport addresses aren’t blocked in countryCode. See isBlockedIn().

Otherwise, if a Pluggable Transport methodname was specified, it returns True if the Bridge has a PluggableTransport such that:

  1. The methodname matches methodname,
  2. The bridgedb.bridges.PluggableTransport.address.version equals the ipVersion, and,
  3. The PluggableTransport. address isn’t known to be blocked in countryCode.
Parameters:
  • countryCode (str or None) – A two-letter country code which the filtered PluggableTransports should not be blocked in.
  • methodname (str) – A Pluggable Transport methodname.
  • ipVersion (int) – Either 4 or 6. The IP version that the PluggableTransports‘s addresses should have.
Return type:

callable

Returns:

A filter function for Bridges.