Skip to content

Commit 900369e

Browse files
committed
Signing identities for FederationClient
1 parent 715dc88 commit 900369e

File tree

7 files changed

+117
-91
lines changed

7 files changed

+117
-91
lines changed

authstate.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ type StateProvider interface {
1717

1818
type FederatedStateClient interface {
1919
LookupState(
20-
ctx context.Context, s ServerName, roomID, eventID string, roomVersion RoomVersion,
20+
ctx context.Context, origin, s ServerName, roomID, eventID string, roomVersion RoomVersion,
2121
) (res RespState, err error)
2222
LookupStateIDs(
23-
ctx context.Context, s ServerName, roomID, eventID string,
23+
ctx context.Context, origin, s ServerName, roomID, eventID string,
2424
) (res RespStateIDs, err error)
2525
}
2626

2727
// FederatedStateProvider is an implementation of StateProvider which solely uses federation requests to retrieve events.
2828
type FederatedStateProvider struct {
2929
FedClient FederatedStateClient
3030
// The remote server to ask.
31+
Origin ServerName
3132
Server ServerName
3233
// Set to true to remember the auth event IDs for the room at various states
3334
RememberAuthEvents bool
@@ -38,7 +39,7 @@ type FederatedStateProvider struct {
3839

3940
// StateIDsBeforeEvent implements StateProvider
4041
func (p *FederatedStateProvider) StateIDsBeforeEvent(ctx context.Context, event *HeaderedEvent) ([]string, error) {
41-
res, err := p.FedClient.LookupStateIDs(ctx, p.Server, event.RoomID(), event.EventID())
42+
res, err := p.FedClient.LookupStateIDs(ctx, p.Origin, p.Server, event.RoomID(), event.EventID())
4243
if err != nil {
4344
return nil, err
4445
}
@@ -50,7 +51,7 @@ func (p *FederatedStateProvider) StateIDsBeforeEvent(ctx context.Context, event
5051

5152
// StateBeforeEvent implements StateProvider
5253
func (p *FederatedStateProvider) StateBeforeEvent(ctx context.Context, roomVer RoomVersion, event *HeaderedEvent, eventIDs []string) (map[string]*Event, error) {
53-
res, err := p.FedClient.LookupState(ctx, p.Server, event.RoomID(), event.EventID(), roomVer)
54+
res, err := p.FedClient.LookupState(ctx, p.Origin, p.Server, event.RoomID(), event.EventID(), roomVer)
5455
if err != nil {
5556
return nil, err
5657
}

backfill.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type BackfillClient interface {
1111
// Backfill performs a backfill request to the given server.
1212
// https://matrix.org/docs/spec/server_server/latest#get-matrix-federation-v1-backfill-roomid
13-
Backfill(ctx context.Context, server ServerName, roomID string, limit int, fromEventIDs []string) (Transaction, error)
13+
Backfill(ctx context.Context, origin, server ServerName, roomID string, limit int, fromEventIDs []string) (Transaction, error)
1414
}
1515

1616
// BackfillRequester contains the necessary functions to perform backfill requests from one server to another.
@@ -45,7 +45,7 @@ type BackfillRequester interface {
4545
// but to verify it we need to know the prev_events of fromEventIDs.
4646
//
4747
// TODO: When does it make sense to return errors?
48-
func RequestBackfill(ctx context.Context, b BackfillRequester, keyRing JSONVerifier,
48+
func RequestBackfill(ctx context.Context, origin ServerName, b BackfillRequester, keyRing JSONVerifier,
4949
roomID string, ver RoomVersion, fromEventIDs []string, limit int) ([]*HeaderedEvent, error) {
5050

5151
if len(fromEventIDs) == 0 {
@@ -67,7 +67,7 @@ func RequestBackfill(ctx context.Context, b BackfillRequester, keyRing JSONVerif
6767
return nil, fmt.Errorf("gomatrixserverlib: RequestBackfill context cancelled %w", ctx.Err())
6868
}
6969
// fetch some events, and try a different server if it fails
70-
txn, err := b.Backfill(ctx, s, roomID, limit, fromEventIDs)
70+
txn, err := b.Backfill(ctx, origin, s, roomID, limit, fromEventIDs)
7171
if err != nil {
7272
continue // try the next server
7373
}

backfill_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
type testBackfillRequester struct {
1414
servers []ServerName
15-
backfillFn func(server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error)
15+
backfillFn func(origin, server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error)
1616
authEventsToProvide [][]byte
1717
stateIDsAtEvent map[string][]string
1818
callOrderForStateIDsBeforeEvent []string // event IDs called
@@ -28,8 +28,8 @@ func (t *testBackfillRequester) StateBeforeEvent(ctx context.Context, roomVer Ro
2828
func (t *testBackfillRequester) ServersAtEvent(ctx context.Context, roomID, eventID string) []ServerName {
2929
return t.servers
3030
}
31-
func (t *testBackfillRequester) Backfill(ctx context.Context, server ServerName, roomID string, limit int, fromEventIDs []string) (Transaction, error) {
32-
txn, err := t.backfillFn(server, roomID, fromEventIDs, limit)
31+
func (t *testBackfillRequester) Backfill(ctx context.Context, origin, server ServerName, roomID string, limit int, fromEventIDs []string) (Transaction, error) {
32+
txn, err := t.backfillFn(origin, server, roomID, fromEventIDs, limit)
3333
if err != nil {
3434
return Transaction{}, err
3535
}
@@ -92,14 +92,14 @@ func TestRequestBackfillMultipleServers(t *testing.T) {
9292
"$fnwGrQEpiOIUoDU2:baba.is.you": {"$WCraVpPZe5TtHAqs:baba.is.you"},
9393
"$WCraVpPZe5TtHAqs:baba.is.you": nil,
9494
},
95-
backfillFn: func(server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error) {
95+
backfillFn: func(origin, server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error) {
9696
if roomID != testRoomID {
9797
return nil, fmt.Errorf("bad room id: %s", roomID)
9898
}
9999
if server == serverA {
100100
// server A returns events 1 and 3.
101101
return &Transaction{
102-
Origin: serverA,
102+
Origin: origin,
103103
OriginServerTS: AsTimestamp(time.Now()),
104104
PDUs: []json.RawMessage{
105105
testBackfillEvents[1], testBackfillEvents[3],
@@ -108,7 +108,7 @@ func TestRequestBackfillMultipleServers(t *testing.T) {
108108
} else if server == serverB {
109109
// server B returns events 0 and 2 and 3.
110110
return &Transaction{
111-
Origin: serverB,
111+
Origin: origin,
112112
OriginServerTS: AsTimestamp(time.Now()),
113113
PDUs: []json.RawMessage{
114114
testBackfillEvents[0], testBackfillEvents[2], testBackfillEvents[3],
@@ -118,7 +118,7 @@ func TestRequestBackfillMultipleServers(t *testing.T) {
118118
return nil, fmt.Errorf("bad server name: %s", server)
119119
},
120120
}
121-
result, err := RequestBackfill(ctx, tbr, keyRing, testRoomID, RoomVersionV1, testFromEventIDs, testLimit)
121+
result, err := RequestBackfill(ctx, serverA, tbr, keyRing, testRoomID, RoomVersionV1, testFromEventIDs, testLimit)
122122
if err != nil {
123123
t.Fatalf("RequestBackfill got error: %s", err)
124124
}
@@ -157,13 +157,13 @@ func TestRequestBackfillTopologicalSort(t *testing.T) {
157157
"$fnwGrQEpiOIUoDU2:baba.is.you": {"$WCraVpPZe5TtHAqs:baba.is.you"},
158158
"$WCraVpPZe5TtHAqs:baba.is.you": nil,
159159
},
160-
backfillFn: func(server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error) {
160+
backfillFn: func(origin, server ServerName, roomID string, fromEventIDs []string, limit int) (*Transaction, error) {
161161
if roomID != testRoomID {
162162
return nil, fmt.Errorf("bad room id: %s", roomID)
163163
}
164164
if server == serverA {
165165
return &Transaction{
166-
Origin: serverA,
166+
Origin: origin,
167167
OriginServerTS: AsTimestamp(time.Now()),
168168
PDUs: []json.RawMessage{
169169
testBackfillEvents[0], testBackfillEvents[1], testBackfillEvents[2], testBackfillEvents[3],
@@ -173,7 +173,7 @@ func TestRequestBackfillTopologicalSort(t *testing.T) {
173173
return nil, fmt.Errorf("bad server name: %s", server)
174174
},
175175
}
176-
result, err := RequestBackfill(ctx, tbr, keyRing, testRoomID, RoomVersionV1, testFromEventIDs, testLimit)
176+
result, err := RequestBackfill(ctx, serverA, tbr, keyRing, testRoomID, RoomVersionV1, testFromEventIDs, testLimit)
177177
if err != nil {
178178
t.Fatalf("RequestBackfill got error: %s", err)
179179
}

0 commit comments

Comments
 (0)