aboutsummaryrefslogtreecommitdiff
path: root/federationsender/api/api.go
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-08-20 17:03:07 +0100
committerGitHub <noreply@github.com>2020-08-20 17:03:07 +0100
commit6d6bb7513710db1009c474eff031434916feda1b (patch)
tree62eb40ba6944580a7cf6da1541d7070ad65bd362 /federationsender/api/api.go
parent068a3d3c9f9be3473b68e3a13912182caf1c7117 (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 'federationsender/api/api.go')
-rw-r--r--federationsender/api/api.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/federationsender/api/api.go b/federationsender/api/api.go
index 9f9c2645..cea0010d 100644
--- a/federationsender/api/api.go
+++ b/federationsender/api/api.go
@@ -2,14 +2,38 @@ package api
import (
"context"
+ "fmt"
+ "time"
"github.com/matrix-org/dendrite/federationsender/types"
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib"
)
+// FederationClient is a subset of gomatrixserverlib.FederationClient functions which the fedsender
+// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
+// this interface are of type FederationClientError
+type FederationClient interface {
+ GetUserDevices(ctx context.Context, s gomatrixserverlib.ServerName, userID string) (res gomatrixserverlib.RespUserDevices, err error)
+ ClaimKeys(ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (res gomatrixserverlib.RespClaimKeys, err error)
+ QueryKeys(ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string) (res gomatrixserverlib.RespQueryKeys, err error)
+}
+
+// FederationClientError is returned from FederationClient methods in the event of a problem.
+type FederationClientError struct {
+ Err string
+ RetryAfter time.Duration
+ Blacklisted bool
+}
+
+func (e *FederationClientError) Error() string {
+ return fmt.Sprintf("%s - (retry_after=%d, blacklisted=%v)", e.Err, e.RetryAfter, e.Blacklisted)
+}
+
// FederationSenderInternalAPI is used to query information from the federation sender.
type FederationSenderInternalAPI interface {
+ FederationClient
+
// PerformDirectoryLookup looks up a remote room ID from a room alias.
PerformDirectoryLookup(
ctx context.Context,