Index: /trunk/cmd/sojuctl/main.go
===================================================================
--- /trunk/cmd/sojuctl/main.go	(revision 651)
+++ /trunk/cmd/sojuctl/main.go	(revision 652)
@@ -3,4 +3,5 @@
 import (
 	"bufio"
+	"context"
 	"flag"
 	"fmt"
@@ -76,5 +77,5 @@
 			Admin:    *admin,
 		}
-		if err := db.StoreUser(&user); err != nil {
+		if err := db.StoreUser(context.TODO(), &user); err != nil {
 			log.Fatalf("failed to create user: %v", err)
 		}
@@ -86,5 +87,5 @@
 		}
 
-		user, err := db.GetUser(username)
+		user, err := db.GetUser(context.TODO(), username)
 		if err != nil {
 			log.Fatalf("failed to get user: %v", err)
@@ -102,5 +103,5 @@
 
 		user.Password = string(hashed)
-		if err := db.StoreUser(user); err != nil {
+		if err := db.StoreUser(context.TODO(), user); err != nil {
 			log.Fatalf("failed to update password: %v", err)
 		}
Index: /trunk/contrib/znc-import.go
===================================================================
--- /trunk/contrib/znc-import.go	(revision 651)
+++ /trunk/contrib/znc-import.go	(revision 652)
@@ -3,4 +3,5 @@
 import (
 	"bufio"
+	"context"
 	"flag"
 	"fmt"
@@ -80,5 +81,5 @@
 	}
 
-	l, err := db.ListUsers()
+	l, err := db.ListUsers(context.TODO())
 	if err != nil {
 		log.Fatalf("failed to list users in DB: %v", err)
@@ -112,10 +113,10 @@
 		u.Admin = section.Values.Get("Admin") == "true"
 
-		if err := db.StoreUser(u); err != nil {
+		if err := db.StoreUser(context.TODO(), u); err != nil {
 			log.Fatalf("failed to store user %q: %v", username, err)
 		}
 		userID := u.ID
 
-		l, err := db.ListNetworks(userID)
+		l, err := db.ListNetworks(context.TODO(), userID)
 		if err != nil {
 			log.Fatalf("failed to list networks for user %q: %v", username, err)
@@ -184,9 +185,9 @@
 			n.Enabled = section.Values.Get("IRCConnectEnabled") != "false"
 
-			if err := db.StoreNetwork(userID, n); err != nil {
+			if err := db.StoreNetwork(context.TODO(), userID, n); err != nil {
 				logger.Fatalf("failed to store network: %v", err)
 			}
 
-			l, err := db.ListChannels(n.ID)
+			l, err := db.ListChannels(context.TODO(), n.ID)
 			if err != nil {
 				logger.Fatalf("failed to list channels: %v", err)
@@ -218,5 +219,5 @@
 				ch.Detached = section.Values.Get("Detached") == "true"
 
-				if err := db.StoreChannel(n.ID, ch); err != nil {
+				if err := db.StoreChannel(context.TODO(), n.ID, ch); err != nil {
 					logger.Printf("channel %q: failed to store channel: %v", chName, err)
 				}
Index: /trunk/db.go
===================================================================
--- /trunk/db.go	(revision 651)
+++ /trunk/db.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"fmt"
 	"net/url"
@@ -10,20 +11,20 @@
 type Database interface {
 	Close() error
-	Stats() (*DatabaseStats, error)
+	Stats(ctx context.Context) (*DatabaseStats, error)
 
-	ListUsers() ([]User, error)
-	GetUser(username string) (*User, error)
-	StoreUser(user *User) error
-	DeleteUser(id int64) error
+	ListUsers(ctx context.Context) ([]User, error)
+	GetUser(ctx context.Context, username string) (*User, error)
+	StoreUser(ctx context.Context, user *User) error
+	DeleteUser(ctx context.Context, id int64) error
 
-	ListNetworks(userID int64) ([]Network, error)
-	StoreNetwork(userID int64, network *Network) error
-	DeleteNetwork(id int64) error
-	ListChannels(networkID int64) ([]Channel, error)
-	StoreChannel(networKID int64, ch *Channel) error
-	DeleteChannel(id int64) error
+	ListNetworks(ctx context.Context, userID int64) ([]Network, error)
+	StoreNetwork(ctx context.Context, userID int64, network *Network) error
+	DeleteNetwork(ctx context.Context, id int64) error
+	ListChannels(ctx context.Context, networkID int64) ([]Channel, error)
+	StoreChannel(ctx context.Context, networKID int64, ch *Channel) error
+	DeleteChannel(ctx context.Context, id int64) error
 
-	ListDeliveryReceipts(networkID int64) ([]DeliveryReceipt, error)
-	StoreClientDeliveryReceipts(networkID int64, client string, receipts []DeliveryReceipt) error
+	ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error)
+	StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error
 }
 
Index: /trunk/db_postgres.go
===================================================================
--- /trunk/db_postgres.go	(revision 651)
+++ /trunk/db_postgres.go	(revision 652)
@@ -148,6 +148,6 @@
 }
 
-func (db *PostgresDB) Stats() (*DatabaseStats, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) Stats(ctx context.Context) (*DatabaseStats, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -164,6 +164,6 @@
 }
 
-func (db *PostgresDB) ListUsers() ([]User, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) ListUsers(ctx context.Context) ([]User, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -193,6 +193,6 @@
 }
 
-func (db *PostgresDB) GetUser(username string) (*User, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) GetUser(ctx context.Context, username string) (*User, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -211,6 +211,6 @@
 }
 
-func (db *PostgresDB) StoreUser(user *User) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) StoreUser(ctx context.Context, user *User) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -235,6 +235,6 @@
 }
 
-func (db *PostgresDB) DeleteUser(id int64) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) DeleteUser(ctx context.Context, id int64) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -243,6 +243,6 @@
 }
 
-func (db *PostgresDB) ListNetworks(userID int64) ([]Network, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) ListNetworks(ctx context.Context, userID int64) ([]Network, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -287,6 +287,6 @@
 }
 
-func (db *PostgresDB) StoreNetwork(userID int64, network *Network) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) StoreNetwork(ctx context.Context, userID int64, network *Network) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -339,6 +339,6 @@
 }
 
-func (db *PostgresDB) DeleteNetwork(id int64) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) DeleteNetwork(ctx context.Context, id int64) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -347,6 +347,6 @@
 }
 
-func (db *PostgresDB) ListChannels(networkID int64) ([]Channel, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) ListChannels(ctx context.Context, networkID int64) ([]Channel, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -381,6 +381,6 @@
 }
 
-func (db *PostgresDB) StoreChannel(networkID int64, ch *Channel) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) StoreChannel(ctx context.Context, networkID int64, ch *Channel) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -409,6 +409,6 @@
 }
 
-func (db *PostgresDB) DeleteChannel(id int64) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) DeleteChannel(ctx context.Context, id int64) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -417,6 +417,6 @@
 }
 
-func (db *PostgresDB) ListDeliveryReceipts(networkID int64) ([]DeliveryReceipt, error) {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error) {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
@@ -445,6 +445,6 @@
 }
 
-func (db *PostgresDB) StoreClientDeliveryReceipts(networkID int64, client string, receipts []DeliveryReceipt) error {
-	ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
+func (db *PostgresDB) StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error {
+	ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
 	defer cancel()
 
Index: /trunk/db_sqlite.go
===================================================================
--- /trunk/db_sqlite.go	(revision 651)
+++ /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()
 
Index: /trunk/downstream.go
===================================================================
--- /trunk/downstream.go	(revision 651)
+++ /trunk/downstream.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"crypto/tls"
 	"encoding/base64"
@@ -977,5 +978,5 @@
 	username, clientName, networkName := unmarshalUsername(username)
 
-	u, err := dc.srv.db.GetUser(username)
+	u, err := dc.srv.db.GetUser(context.TODO(), username)
 	if err != nil {
 		dc.logger.Printf("failed authentication for %q: user not found: %v", username, err)
@@ -1378,5 +1379,5 @@
 			}
 			n.Nick = nick
-			err = dc.srv.db.StoreNetwork(dc.user.ID, &n.Network)
+			err = dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &n.Network)
 		})
 		if err != nil {
@@ -1428,5 +1429,5 @@
 
 				n.Realname = storeRealname
-				if err := dc.srv.db.StoreNetwork(dc.user.ID, &n.Network); err != nil {
+				if err := dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &n.Network); err != nil {
 					dc.logger.Printf("failed to store network realname: %v", err)
 					storeErr = err
@@ -1517,5 +1518,5 @@
 				uc.network.channels.SetValue(upstreamName, ch)
 			}
-			if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
+			if err := dc.srv.db.StoreChannel(context.TODO(), uc.network.ID, ch); err != nil {
 				dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
 			}
@@ -1549,5 +1550,5 @@
 					uc.network.channels.SetValue(upstreamName, ch)
 				}
-				if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
+				if err := dc.srv.db.StoreChannel(context.TODO(), uc.network.ID, ch); err != nil {
 					dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
 				}
@@ -2446,5 +2447,5 @@
 	n.SASL.Plain.Username = username
 	n.SASL.Plain.Password = password
-	if err := dc.srv.db.StoreNetwork(dc.user.ID, &n.Network); err != nil {
+	if err := dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &n.Network); err != nil {
 		dc.logger.Printf("failed to save NickServ credentials: %v", err)
 	}
Index: /trunk/server.go
===================================================================
--- /trunk/server.go	(revision 651)
+++ /trunk/server.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"fmt"
 	"log"
@@ -86,5 +87,5 @@
 
 func (s *Server) Start() error {
-	users, err := s.db.ListUsers()
+	users, err := s.db.ListUsers(context.TODO())
 	if err != nil {
 		return err
@@ -127,5 +128,5 @@
 	}
 
-	err := s.db.StoreUser(user)
+	err := s.db.StoreUser(context.TODO(), user)
 	if err != nil {
 		return nil, fmt.Errorf("could not create user in db: %v", err)
Index: /trunk/server_test.go
===================================================================
--- /trunk/server_test.go	(revision 651)
+++ /trunk/server_test.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"net"
 	"testing"
@@ -44,5 +45,5 @@
 
 	record := &User{Username: testUsername, Password: string(hashed)}
-	if err := db.StoreUser(record); err != nil {
+	if err := db.StoreUser(context.TODO(), record); err != nil {
 		t.Fatalf("failed to store test user: %v", err)
 	}
@@ -69,5 +70,5 @@
 		Enabled: true,
 	}
-	if err := db.StoreNetwork(user.ID, network); err != nil {
+	if err := db.StoreNetwork(context.TODO(), user.ID, network); err != nil {
 		t.Fatalf("failed to store test network: %v", err)
 	}
Index: /trunk/service.go
===================================================================
--- /trunk/service.go	(revision 651)
+++ /trunk/service.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"crypto/sha1"
 	"crypto/sha256"
@@ -658,5 +659,5 @@
 	net.SASL.Mechanism = "EXTERNAL"
 
-	if err := dc.srv.db.StoreNetwork(dc.user.ID, &net.Network); err != nil {
+	if err := dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &net.Network); err != nil {
 		return err
 	}
@@ -699,5 +700,5 @@
 	net.SASL.Mechanism = "PLAIN"
 
-	if err := dc.srv.db.StoreNetwork(dc.user.ID, &net.Network); err != nil {
+	if err := dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &net.Network); err != nil {
 		return err
 	}
@@ -723,5 +724,5 @@
 	net.SASL.Mechanism = ""
 
-	if err := dc.srv.db.StoreNetwork(dc.user.ID, &net.Network); err != nil {
+	if err := dc.srv.db.StoreNetwork(context.TODO(), dc.user.ID, &net.Network); err != nil {
 		return err
 	}
@@ -861,5 +862,5 @@
 	u.stop()
 
-	if err := dc.srv.db.DeleteUser(u.ID); err != nil {
+	if err := dc.srv.db.DeleteUser(context.TODO(), u.ID); err != nil {
 		return fmt.Errorf("failed to delete user: %v", err)
 	}
@@ -1016,5 +1017,5 @@
 	uc.updateChannelAutoDetach(upstreamName)
 
-	if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
+	if err := dc.srv.db.StoreChannel(context.TODO(), uc.network.ID, ch); err != nil {
 		return fmt.Errorf("failed to update channel: %v", err)
 	}
@@ -1025,5 +1026,5 @@
 
 func handleServiceServerStatus(dc *downstreamConn, params []string) error {
-	dbStats, err := dc.user.srv.db.Stats()
+	dbStats, err := dc.user.srv.db.Stats(context.TODO())
 	if err != nil {
 		return err
Index: /trunk/upstream.go
===================================================================
--- /trunk/upstream.go	(revision 651)
+++ /trunk/upstream.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"crypto"
 	"crypto/sha256"
@@ -1517,5 +1518,5 @@
 	if ch.ReattachOn == FilterMessage || (ch.ReattachOn == FilterHighlight && uc.network.isHighlight(msg)) {
 		uc.network.attach(ch)
-		if err := uc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
+		if err := uc.srv.db.StoreChannel(context.TODO(), uc.network.ID, ch); err != nil {
 			uc.logger.Printf("failed to update channel %q: %v", ch.Name, err)
 		}
Index: /trunk/user.go
===================================================================
--- /trunk/user.go	(revision 651)
+++ /trunk/user.go	(revision 652)
@@ -2,4 +2,5 @@
 
 import (
+	"context"
 	"crypto/sha256"
 	"encoding/binary"
@@ -331,5 +332,5 @@
 	}
 
-	if err := net.user.srv.db.DeleteChannel(ch.ID); err != nil {
+	if err := net.user.srv.db.DeleteChannel(context.TODO(), ch.ID); err != nil {
 		return err
 	}
@@ -368,5 +369,5 @@
 	})
 
-	if err := net.user.srv.db.StoreClientDeliveryReceipts(net.ID, clientName, receipts); err != nil {
+	if err := net.user.srv.db.StoreClientDeliveryReceipts(context.TODO(), net.ID, clientName, receipts); err != nil {
 		net.logger.Printf("failed to store delivery receipts for client %q: %v", clientName, err)
 	}
@@ -488,5 +489,5 @@
 	}()
 
-	networks, err := u.srv.db.ListNetworks(u.ID)
+	networks, err := u.srv.db.ListNetworks(context.TODO(), u.ID)
 	if err != nil {
 		u.logger.Printf("failed to list networks for user %q: %v", u.Username, err)
@@ -496,5 +497,5 @@
 	for _, record := range networks {
 		record := record
-		channels, err := u.srv.db.ListChannels(record.ID)
+		channels, err := u.srv.db.ListChannels(context.TODO(), record.ID)
 		if err != nil {
 			u.logger.Printf("failed to list channels for user %q, network %q: %v", u.Username, record.GetName(), err)
@@ -506,5 +507,5 @@
 
 		if u.hasPersistentMsgStore() {
-			receipts, err := u.srv.db.ListDeliveryReceipts(record.ID)
+			receipts, err := u.srv.db.ListDeliveryReceipts(context.TODO(), record.ID)
 			if err != nil {
 				u.logger.Printf("failed to load delivery receipts for user %q, network %q: %v", u.Username, network.GetName(), err)
@@ -591,5 +592,5 @@
 			}
 			uc.network.detach(c)
-			if err := uc.srv.db.StoreChannel(uc.network.ID, c); err != nil {
+			if err := uc.srv.db.StoreChannel(context.TODO(), uc.network.ID, c); err != nil {
 				u.logger.Printf("failed to store updated detached channel %q: %v", c.Name, err)
 			}
@@ -780,5 +781,5 @@
 
 	network := newNetwork(u, record, nil)
-	err := u.srv.db.StoreNetwork(u.ID, &network.Network)
+	err := u.srv.db.StoreNetwork(context.TODO(), u.ID, &network.Network)
 	if err != nil {
 		return nil, err
@@ -822,5 +823,5 @@
 	}
 
-	if err := u.srv.db.StoreNetwork(u.ID, record); err != nil {
+	if err := u.srv.db.StoreNetwork(context.TODO(), u.ID, record); err != nil {
 		return nil, err
 	}
@@ -889,5 +890,5 @@
 	}
 
-	if err := u.srv.db.DeleteNetwork(network.ID); err != nil {
+	if err := u.srv.db.DeleteNetwork(context.TODO(), network.ID); err != nil {
 		return err
 	}
@@ -915,5 +916,5 @@
 
 	realnameUpdated := u.Realname != record.Realname
-	if err := u.srv.db.StoreUser(record); err != nil {
+	if err := u.srv.db.StoreUser(context.TODO(), record); err != nil {
 		return fmt.Errorf("failed to update user %q: %v", u.Username, err)
 	}
