diff options
author | Kegsay <kegan@matrix.org> | 2020-08-20 17:03:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-20 17:03:07 +0100 |
commit | 6d6bb7513710db1009c474eff031434916feda1b (patch) | |
tree | 62eb40ba6944580a7cf6da1541d7070ad65bd362 /keyserver | |
parent | 068a3d3c9f9be3473b68e3a13912182caf1c7117 (diff) |
Add FederationClient interface to federationsender (#1284)
* Add FederationClient interface to federationsender
- Use a shim struct in HTTP mode to keep the same API as `FederationClient`.
- Use `federationsender` instead of `FederationClient` in `keyserver`.
* Pointers not values
* Review comments
* Fix unit tests
* Rejig backoff
* Unbreak test
* Remove debug logs
* Review comments and linting
Diffstat (limited to 'keyserver')
-rw-r--r-- | keyserver/internal/device_list_update.go | 9 | ||||
-rw-r--r-- | keyserver/internal/internal.go | 3 | ||||
-rw-r--r-- | keyserver/keyserver.go | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/keyserver/internal/device_list_update.go b/keyserver/internal/device_list_update.go index dd8fb700..36918256 100644 --- a/keyserver/internal/device_list_update.go +++ b/keyserver/internal/device_list_update.go @@ -22,6 +22,7 @@ import ( "sync" "time" + fedsenderapi "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -65,7 +66,7 @@ type DeviceListUpdater struct { db DeviceListUpdaterDatabase producer KeyChangeProducer - fedClient *gomatrixserverlib.FederationClient + fedClient fedsenderapi.FederationClient workerChans []chan gomatrixserverlib.ServerName // When device lists are stale for a user, they get inserted into this map with a channel which `Update` will @@ -103,7 +104,7 @@ type KeyChangeProducer interface { // NewDeviceListUpdater creates a new updater which fetches fresh device lists when they go stale. func NewDeviceListUpdater( - db DeviceListUpdaterDatabase, producer KeyChangeProducer, fedClient *gomatrixserverlib.FederationClient, + db DeviceListUpdaterDatabase, producer KeyChangeProducer, fedClient fedsenderapi.FederationClient, numWorkers int, ) *DeviceListUpdater { return &DeviceListUpdater{ @@ -304,7 +305,7 @@ func (u *DeviceListUpdater) worker(ch chan gomatrixserverlib.ServerName) { continue } else { scheduledRetries[serverName] = time.Now().Add(cooloffPeriod) - go inject(serverName, cooloffPeriod) // TODO: Backoff? + go inject(serverName, cooloffPeriod) continue } } @@ -312,7 +313,7 @@ func (u *DeviceListUpdater) worker(ch chan gomatrixserverlib.ServerName) { shouldRetry := u.processServer(serverName) if shouldRetry { scheduledRetries[serverName] = time.Now().Add(cooloffPeriod) - go inject(serverName, cooloffPeriod) // TODO: Backoff? + go inject(serverName, cooloffPeriod) } } } diff --git a/keyserver/internal/internal.go b/keyserver/internal/internal.go index 31fb1236..53afe0a6 100644 --- a/keyserver/internal/internal.go +++ b/keyserver/internal/internal.go @@ -22,6 +22,7 @@ import ( "sync" "time" + fedsenderapi "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/producers" "github.com/matrix-org/dendrite/keyserver/storage" @@ -36,7 +37,7 @@ import ( type KeyInternalAPI struct { DB storage.Database ThisServer gomatrixserverlib.ServerName - FedClient *gomatrixserverlib.FederationClient + FedClient fedsenderapi.FederationClient UserAPI userapi.UserInternalAPI Producer *producers.KeyChange Updater *DeviceListUpdater diff --git a/keyserver/keyserver.go b/keyserver/keyserver.go index 04136938..2e561363 100644 --- a/keyserver/keyserver.go +++ b/keyserver/keyserver.go @@ -17,13 +17,13 @@ package keyserver import ( "github.com/Shopify/sarama" "github.com/gorilla/mux" + fedsenderapi "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/internal" "github.com/matrix-org/dendrite/keyserver/inthttp" "github.com/matrix-org/dendrite/keyserver/producers" "github.com/matrix-org/dendrite/keyserver/storage" - "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" ) @@ -36,7 +36,7 @@ func AddInternalRoutes(router *mux.Router, intAPI api.KeyInternalAPI) { // NewInternalAPI returns a concerete implementation of the internal API. Callers // can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes. func NewInternalAPI( - cfg *config.KeyServer, fedClient *gomatrixserverlib.FederationClient, producer sarama.SyncProducer, + cfg *config.KeyServer, fedClient fedsenderapi.FederationClient, producer sarama.SyncProducer, ) api.KeyInternalAPI { db, err := storage.NewDatabase(&cfg.Database) if err != nil { |