bridgedb.Storage

_escapeValue(v)[source]
timeToStr(t)[source]
strToTime(t)[source]
class BridgeData(hex_key, address, or_port, distributor='unallocated', first_seen='', last_seen='')[source]

Bases: object

Value class carrying bridge information: hex_key - The unique hex key of the given bridge address - Bridge IP address or_port - Bridge TCP port distributor - The distributor (or pseudo-distributor) through which

this bridge is being announced

first_seen - When did we first see this bridge online? last_seen - When was the last time we saw this bridge online?

class Database(sqlite_fname)[source]

Bases: object

commit()[source]
rollback()[source]
close()[source]
insertBridgeAndGetRing(bridge, setRing, seenAt, validRings, defaultPool='unallocated')[source]

Updates info about bridge, setting ring to setRing if none was set. Also sets distributor to `defaultPool’ if the bridge was found in the database, but its distributor isn’t valid anymore.

Returns the name of the distributor the bridge is assigned to.

cleanEmailedBridges(expireBefore)[source]
getEmailTime(addr)[source]
setEmailTime(addr, whenMailed)[source]
getAllBridges()[source]

Return a list of BridgeData value classes of all bridges in the database

getBridgesForDistributor(distributor)[source]

Return a list of BridgeData value classes of all bridges in the database that are allocated to distributor ‘distributor’

updateDistributorForHexKey(distributor, hex_key)[source]
getWarnedEmail(addr)[source]
setWarnedEmail(addr, warned=True, whenWarned=1437453856.676141)[source]
cleanWarnedEmails(expireBefore)[source]
updateIntoBridgeHistory(bh)[source]
delBridgeHistory(fp)[source]
getBridgeHistory(fp)[source]
getAllBridgeHistory()[source]
getBridgesLastUpdatedBefore(statusPublicationMillis)[source]
openDatabase(sqlite_file)[source]
class DBGeneratorContextManager(gen)[source]

Bases: contextlib.GeneratorContextManager

Helper for @contextmanager decorator.

Overload __exit__() so we can call the generator many times

contextmanager(func)[source]

Decorator to for Storage.getDB()

Define getDB() for use by with statement content manager

clearGlobalDB()[source]

Start from scratch.

This is currently only used in unit tests.

initializeDBLock()[source]

Create the lock

This must be called before the first database query

setDBFilename(sqlite_fname)[source]
getDB(*args, **kwds)[source]

Generator: Return a usable database handler

Always return a bridgedb.Storage.Database that is usable within the current thread. If a connection already exists and it was created by the current thread, then return the associated bridgedb.Storage.Database instance. Otherwise, create a new instance, blocking until the existing connection is closed, if applicable.

Note: This is a blocking call (by default), be careful about
deadlocks!
Return type:bridgedb.Storage.Database
Returns:An instance of bridgedb.Storage.Database used to query the database
dbIsLocked()[source]