Index: trunk/db_sqlite.go
===================================================================
--- trunk/db_sqlite.go	(revision 645)
+++ trunk/db_sqlite.go	(revision 652)
@@ -209,9 +209,9 @@
 }
 
-func (db *SqliteDB) Stats() (*DatabaseStats, error) {
+func (db *SqliteDB) Stats(ctx context.Context) (*DatabaseStats, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -235,9 +235,9 @@
 }
 
-func (db *SqliteDB) ListUsers() ([]User, error) {
+func (db *SqliteDB) ListUsers(ctx context.Context) ([]User, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -267,9 +267,9 @@
 }
 
-func (db *SqliteDB) GetUser(username string) (*User, error) {
+func (db *SqliteDB) GetUser(ctx context.Context, username string) (*User, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -288,9 +288,9 @@
 }
 
-func (db *SqliteDB) StoreUser(user *User) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) StoreUser(ctx context.Context, user *User) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -324,9 +324,9 @@
 }
 
-func (db *SqliteDB) DeleteUser(id int64) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) DeleteUser(ctx context.Context, id int64) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -372,9 +372,9 @@
 }
 
-func (db *SqliteDB) ListNetworks(userID int64) ([]Network, error) {
+func (db *SqliteDB) ListNetworks(ctx context.Context, userID int64) ([]Network, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -421,9 +421,9 @@
 }
 
-func (db *SqliteDB) StoreNetwork(userID int64, network *Network) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) StoreNetwork(ctx context.Context, userID int64, network *Network) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -491,9 +491,9 @@
 }
 
-func (db *SqliteDB) DeleteNetwork(id int64) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) DeleteNetwork(ctx context.Context, id int64) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -522,9 +522,9 @@
 }
 
-func (db *SqliteDB) ListChannels(networkID int64) ([]Channel, error) {
+func (db *SqliteDB) ListChannels(ctx context.Context, networkID int64) ([]Channel, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -559,9 +559,9 @@
 }
 
-func (db *SqliteDB) StoreChannel(networkID int64, ch *Channel) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) StoreChannel(ctx context.Context, networkID int64, ch *Channel) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -599,9 +599,9 @@
 }
 
-func (db *SqliteDB) DeleteChannel(id int64) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) DeleteChannel(ctx context.Context, id int64) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -610,9 +610,9 @@
 }
 
-func (db *SqliteDB) ListDeliveryReceipts(networkID int64) ([]DeliveryReceipt, error) {
+func (db *SqliteDB) ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error) {
 	db.lock.RLock()
 	defer db.lock.RUnlock()
 
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
@@ -643,9 +643,9 @@
 }
 
-func (db *SqliteDB) StoreClientDeliveryReceipts(networkID int64, client string, receipts []DeliveryReceipt) error {
-	db.lock.Lock()
-	defer db.lock.Unlock()
-
-	ctx, cancel := context.WithTimeout(context.TODO(), sqliteQueryTimeout)
+func (db *SqliteDB) StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error {
+	db.lock.Lock()
+	defer db.lock.Unlock()
+
+	ctx, cancel := context.WithTimeout(ctx, sqliteQueryTimeout)
 	defer cancel()
 
