mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-21 19:21:39 +00:00
refactor: use latest GMSL which splits fed client from matrix room logic (#3051)
Part of a series of refactors on GMSL.
This commit is contained in:
parent
e093005bc2
commit
0db43f13a6
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/syncapi"
|
"github.com/matrix-org/dendrite/syncapi"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func TestAdminResetPassword(t *testing.T) {
|
|||||||
natsInstance := jetstream.NATSInstance{}
|
natsInstance := jetstream.NATSInstance{}
|
||||||
// add a vhost
|
// add a vhost
|
||||||
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
|
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
|
SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"},
|
||||||
})
|
})
|
||||||
|
|
||||||
routers := httputil.NewRouters()
|
routers := httputil.NewRouters()
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import "github.com/matrix-org/gomatrixserverlib"
|
import "github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
// ExtraPublicRoomsProvider provides a way to inject extra published rooms into /publicRooms requests.
|
// ExtraPublicRoomsProvider provides a way to inject extra published rooms into /publicRooms requests.
|
||||||
type ExtraPublicRoomsProvider interface {
|
type ExtraPublicRoomsProvider interface {
|
||||||
// Rooms returns the extra rooms. This is called on-demand by clients, so cache appropriately.
|
// Rooms returns the extra rooms. This is called on-demand by clients, so cache appropriately.
|
||||||
Rooms() []gomatrixserverlib.PublicRoom
|
Rooms() []fclient.PublicRoom
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/userutil"
|
"github.com/matrix-org/dendrite/clientapi/userutil"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
uapi "github.com/matrix-org/dendrite/userapi/api"
|
uapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func TestLoginFromJSONReader(t *testing.T) {
|
|||||||
var userAPI fakeUserInternalAPI
|
var userAPI fakeUserInternalAPI
|
||||||
cfg := &config.ClientAPI{
|
cfg := &config.ClientAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -148,7 +148,7 @@ func TestBadLoginFromJSONReader(t *testing.T) {
|
|||||||
var userAPI fakeUserInternalAPI
|
var userAPI fakeUserInternalAPI
|
||||||
cfg := &config.ClientAPI{
|
cfg := &config.ClientAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ func (d *fakeAccountDatabase) QueryAccountByPassword(ctx context.Context, req *a
|
|||||||
func setup() *UserInteractive {
|
func setup() *UserInteractive {
|
||||||
cfg := &config.ClientAPI{
|
cfg := &config.ClientAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/clientapi/api"
|
"github.com/matrix-org/dendrite/clientapi/api"
|
||||||
@ -37,7 +37,7 @@ func AddPublicRoutes(
|
|||||||
routers httputil.Routers,
|
routers httputil.Routers,
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
natsInstance *jetstream.NATSInstance,
|
natsInstance *jetstream.NATSInstance,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
rsAPI roomserverAPI.ClientRoomserverAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
asAPI appserviceAPI.AppServiceInternalAPI,
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
transactionsCache *transactions.Cache,
|
transactionsCache *transactions.Cache,
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
@ -45,7 +46,7 @@ func (r *roomDirectoryResponse) fillServers(servers []gomatrixserverlib.ServerNa
|
|||||||
func DirectoryRoom(
|
func DirectoryRoom(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
roomAlias string,
|
roomAlias string,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI roomserverAPI.ClientRoomserverAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
fedSenderAPI federationAPI.ClientFederationAPI,
|
fedSenderAPI federationAPI.ClientFederationAPI,
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/api"
|
"github.com/matrix-org/dendrite/clientapi/api"
|
||||||
@ -35,7 +36,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
cacheMu sync.Mutex
|
cacheMu sync.Mutex
|
||||||
publicRoomsCache []gomatrixserverlib.PublicRoom
|
publicRoomsCache []fclient.PublicRoom
|
||||||
)
|
)
|
||||||
|
|
||||||
type PublicRoomReq struct {
|
type PublicRoomReq struct {
|
||||||
@ -56,7 +57,7 @@ type filter struct {
|
|||||||
func GetPostPublicRooms(
|
func GetPostPublicRooms(
|
||||||
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
||||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var request PublicRoomReq
|
var request PublicRoomReq
|
||||||
@ -102,10 +103,10 @@ func GetPostPublicRooms(
|
|||||||
|
|
||||||
func publicRooms(
|
func publicRooms(
|
||||||
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
) (*gomatrixserverlib.RespPublicRooms, error) {
|
) (*fclient.RespPublicRooms, error) {
|
||||||
|
|
||||||
response := gomatrixserverlib.RespPublicRooms{
|
response := fclient.RespPublicRooms{
|
||||||
Chunk: []gomatrixserverlib.PublicRoom{},
|
Chunk: []fclient.PublicRoom{},
|
||||||
}
|
}
|
||||||
var limit int64
|
var limit int64
|
||||||
var offset int64
|
var offset int64
|
||||||
@ -122,7 +123,7 @@ func publicRooms(
|
|||||||
}
|
}
|
||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
var rooms []gomatrixserverlib.PublicRoom
|
var rooms []fclient.PublicRoom
|
||||||
if request.Since == "" {
|
if request.Since == "" {
|
||||||
rooms = refreshPublicRoomCache(ctx, rsAPI, extRoomsProvider, request)
|
rooms = refreshPublicRoomCache(ctx, rsAPI, extRoomsProvider, request)
|
||||||
} else {
|
} else {
|
||||||
@ -146,14 +147,14 @@ func publicRooms(
|
|||||||
return &response, err
|
return &response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterRooms(rooms []gomatrixserverlib.PublicRoom, searchTerm string) []gomatrixserverlib.PublicRoom {
|
func filterRooms(rooms []fclient.PublicRoom, searchTerm string) []fclient.PublicRoom {
|
||||||
if searchTerm == "" {
|
if searchTerm == "" {
|
||||||
return rooms
|
return rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizedTerm := strings.ToLower(searchTerm)
|
normalizedTerm := strings.ToLower(searchTerm)
|
||||||
|
|
||||||
result := make([]gomatrixserverlib.PublicRoom, 0)
|
result := make([]fclient.PublicRoom, 0)
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
if strings.Contains(strings.ToLower(room.Name), normalizedTerm) ||
|
if strings.Contains(strings.ToLower(room.Name), normalizedTerm) ||
|
||||||
strings.Contains(strings.ToLower(room.Topic), normalizedTerm) ||
|
strings.Contains(strings.ToLower(room.Topic), normalizedTerm) ||
|
||||||
@ -214,7 +215,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO
|
|||||||
// limit=3&since=6 => G (prev='3', next='')
|
// limit=3&since=6 => G (prev='3', next='')
|
||||||
//
|
//
|
||||||
// A value of '-1' for prev/next indicates no position.
|
// A value of '-1' for prev/next indicates no position.
|
||||||
func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (subset []gomatrixserverlib.PublicRoom, prev, next int) {
|
func sliceInto(slice []fclient.PublicRoom, since int64, limit int64) (subset []fclient.PublicRoom, prev, next int) {
|
||||||
prev = -1
|
prev = -1
|
||||||
next = -1
|
next = -1
|
||||||
|
|
||||||
@ -241,10 +242,10 @@ func sliceInto(slice []gomatrixserverlib.PublicRoom, since int64, limit int64) (
|
|||||||
func refreshPublicRoomCache(
|
func refreshPublicRoomCache(
|
||||||
ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
ctx context.Context, rsAPI roomserverAPI.ClientRoomserverAPI, extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||||
request PublicRoomReq,
|
request PublicRoomReq,
|
||||||
) []gomatrixserverlib.PublicRoom {
|
) []fclient.PublicRoom {
|
||||||
cacheMu.Lock()
|
cacheMu.Lock()
|
||||||
defer cacheMu.Unlock()
|
defer cacheMu.Unlock()
|
||||||
var extraRooms []gomatrixserverlib.PublicRoom
|
var extraRooms []fclient.PublicRoom
|
||||||
if extRoomsProvider != nil {
|
if extRoomsProvider != nil {
|
||||||
extraRooms = extRoomsProvider.Rooms()
|
extraRooms = extRoomsProvider.Rooms()
|
||||||
}
|
}
|
||||||
@ -269,7 +270,7 @@ func refreshPublicRoomCache(
|
|||||||
util.GetLogger(ctx).WithError(err).Error("PopulatePublicRooms failed")
|
util.GetLogger(ctx).WithError(err).Error("PopulatePublicRooms failed")
|
||||||
return publicRoomsCache
|
return publicRoomsCache
|
||||||
}
|
}
|
||||||
publicRoomsCache = []gomatrixserverlib.PublicRoom{}
|
publicRoomsCache = []fclient.PublicRoom{}
|
||||||
publicRoomsCache = append(publicRoomsCache, pubRooms...)
|
publicRoomsCache = append(publicRoomsCache, pubRooms...)
|
||||||
publicRoomsCache = append(publicRoomsCache, extraRooms...)
|
publicRoomsCache = append(publicRoomsCache, extraRooms...)
|
||||||
publicRoomsCache = dedupeAndShuffle(publicRoomsCache)
|
publicRoomsCache = dedupeAndShuffle(publicRoomsCache)
|
||||||
@ -281,16 +282,16 @@ func refreshPublicRoomCache(
|
|||||||
return publicRoomsCache
|
return publicRoomsCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPublicRoomsFromCache() []gomatrixserverlib.PublicRoom {
|
func getPublicRoomsFromCache() []fclient.PublicRoom {
|
||||||
cacheMu.Lock()
|
cacheMu.Lock()
|
||||||
defer cacheMu.Unlock()
|
defer cacheMu.Unlock()
|
||||||
return publicRoomsCache
|
return publicRoomsCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func dedupeAndShuffle(in []gomatrixserverlib.PublicRoom) []gomatrixserverlib.PublicRoom {
|
func dedupeAndShuffle(in []fclient.PublicRoom) []fclient.PublicRoom {
|
||||||
// de-duplicate rooms with the same room ID. We can join the room via any of these aliases as we know these servers
|
// de-duplicate rooms with the same room ID. We can join the room via any of these aliases as we know these servers
|
||||||
// are alive and well, so we arbitrarily pick one (purposefully shuffling them to spread the load a bit)
|
// are alive and well, so we arbitrarily pick one (purposefully shuffling them to spread the load a bit)
|
||||||
var publicRooms []gomatrixserverlib.PublicRoom
|
var publicRooms []fclient.PublicRoom
|
||||||
haveRoomIDs := make(map[string]bool)
|
haveRoomIDs := make(map[string]bool)
|
||||||
rand.Shuffle(len(in), func(i, j int) {
|
rand.Shuffle(len(in), func(i, j int) {
|
||||||
in[i], in[j] = in[j], in[i]
|
in[i], in[j] = in[j], in[i]
|
||||||
|
@ -4,17 +4,17 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pubRoom(name string) gomatrixserverlib.PublicRoom {
|
func pubRoom(name string) fclient.PublicRoom {
|
||||||
return gomatrixserverlib.PublicRoom{
|
return fclient.PublicRoom{
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSliceInto(t *testing.T) {
|
func TestSliceInto(t *testing.T) {
|
||||||
slice := []gomatrixserverlib.PublicRoom{
|
slice := []fclient.PublicRoom{
|
||||||
pubRoom("a"), pubRoom("b"), pubRoom("c"), pubRoom("d"), pubRoom("e"), pubRoom("f"), pubRoom("g"),
|
pubRoom("a"), pubRoom("b"), pubRoom("c"), pubRoom("d"), pubRoom("e"), pubRoom("f"), pubRoom("g"),
|
||||||
}
|
}
|
||||||
limit := int64(3)
|
limit := int64(3)
|
||||||
@ -22,7 +22,7 @@ func TestSliceInto(t *testing.T) {
|
|||||||
since int64
|
since int64
|
||||||
wantPrev int
|
wantPrev int
|
||||||
wantNext int
|
wantNext int
|
||||||
wantSubset []gomatrixserverlib.PublicRoom
|
wantSubset []fclient.PublicRoom
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
since: 0,
|
since: 0,
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
@ -39,7 +40,7 @@ func TestLogin(t *testing.T) {
|
|||||||
natsInstance := jetstream.NATSInstance{}
|
natsInstance := jetstream.NATSInstance{}
|
||||||
// add a vhost
|
// add a vhost
|
||||||
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
|
cfg.Global.VirtualHosts = append(cfg.Global.VirtualHosts, &config.VirtualHost{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"},
|
SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"},
|
||||||
})
|
})
|
||||||
|
|
||||||
cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
|
cm := sqlutil.NewConnectionManager(processCtx, cfg.Global.DatabaseOptions)
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
@ -39,7 +40,7 @@ func GetProfile(
|
|||||||
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
||||||
userID string,
|
userID string,
|
||||||
asAPI appserviceAPI.AppServiceInternalAPI,
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
profile, err := getProfile(req.Context(), profileAPI, cfg, userID, asAPI, federation)
|
profile, err := getProfile(req.Context(), profileAPI, cfg, userID, asAPI, federation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -67,7 +68,7 @@ func GetProfile(
|
|||||||
func GetAvatarURL(
|
func GetAvatarURL(
|
||||||
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
||||||
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
|
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
|
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
|
||||||
p, ok := profile.JSON.(eventutil.UserProfile)
|
p, ok := profile.JSON.(eventutil.UserProfile)
|
||||||
@ -156,7 +157,7 @@ func SetAvatarURL(
|
|||||||
func GetDisplayName(
|
func GetDisplayName(
|
||||||
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
req *http.Request, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
||||||
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
|
userID string, asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
|
profile := GetProfile(req, profileAPI, cfg, userID, asAPI, federation)
|
||||||
p, ok := profile.JSON.(eventutil.UserProfile)
|
p, ok := profile.JSON.(eventutil.UserProfile)
|
||||||
@ -292,7 +293,7 @@ func getProfile(
|
|||||||
ctx context.Context, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
ctx context.Context, profileAPI userapi.ProfileAPI, cfg *config.ClientAPI,
|
||||||
userID string,
|
userID string,
|
||||||
asAPI appserviceAPI.AppServiceInternalAPI,
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
) (*authtypes.Profile, error) {
|
) (*authtypes.Profile, error) {
|
||||||
localpart, domain, err := gomatrixserverlib.SplitID('@', userID)
|
localpart, domain, err := gomatrixserverlib.SplitID('@', userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/base"
|
"github.com/matrix-org/dendrite/setup/base"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -55,7 +56,7 @@ func Setup(
|
|||||||
asAPI appserviceAPI.AppServiceInternalAPI,
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
userAPI userapi.ClientUserAPI,
|
userAPI userapi.ClientUserAPI,
|
||||||
userDirectoryProvider userapi.QuerySearchProfilesAPI,
|
userDirectoryProvider userapi.QuerySearchProfilesAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
syncProducer *producers.SyncAPIProducer,
|
syncProducer *producers.SyncAPIProducer,
|
||||||
transactionsCache *transactions.Cache,
|
transactionsCache *transactions.Cache,
|
||||||
federationSender federationAPI.ClientFederationAPI,
|
federationSender federationAPI.ClientFederationAPI,
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
userdb "github.com/matrix-org/dendrite/userapi/storage"
|
userdb "github.com/matrix-org/dendrite/userapi/storage"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
@ -41,7 +42,7 @@ type ThreePIDsResponse struct {
|
|||||||
//
|
//
|
||||||
// POST /account/3pid/email/requestToken
|
// POST /account/3pid/email/requestToken
|
||||||
// POST /register/email/requestToken
|
// POST /register/email/requestToken
|
||||||
func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *config.ClientAPI, client *gomatrixserverlib.Client) util.JSONResponse {
|
func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *config.ClientAPI, client *fclient.Client) util.JSONResponse {
|
||||||
var body threepid.EmailAssociationRequest
|
var body threepid.EmailAssociationRequest
|
||||||
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
|
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
|
||||||
return *reqErr
|
return *reqErr
|
||||||
@ -92,7 +93,7 @@ func RequestEmailToken(req *http.Request, threePIDAPI api.ClientUserAPI, cfg *co
|
|||||||
// CheckAndSave3PIDAssociation implements POST /account/3pid
|
// CheckAndSave3PIDAssociation implements POST /account/3pid
|
||||||
func CheckAndSave3PIDAssociation(
|
func CheckAndSave3PIDAssociation(
|
||||||
req *http.Request, threePIDAPI api.ClientUserAPI, device *api.Device,
|
req *http.Request, threePIDAPI api.ClientUserAPI, device *api.Device,
|
||||||
cfg *config.ClientAPI, client *gomatrixserverlib.Client,
|
cfg *config.ClientAPI, client *fclient.Client,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var body threepid.EmailAssociationCheckRequest
|
var body threepid.EmailAssociationCheckRequest
|
||||||
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
|
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ func SearchUserDirectory(
|
|||||||
provider userapi.QuerySearchProfilesAPI,
|
provider userapi.QuerySearchProfilesAPI,
|
||||||
searchString string,
|
searchString string,
|
||||||
limit int,
|
limit int,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
localServerName gomatrixserverlib.ServerName,
|
localServerName gomatrixserverlib.ServerName,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if limit < 10 {
|
if limit < 10 {
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EmailAssociationRequest represents the request defined at https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken
|
// EmailAssociationRequest represents the request defined at https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken
|
||||||
@ -58,7 +58,7 @@ type SID struct {
|
|||||||
// Returns an error if there was a problem sending the request or decoding the
|
// Returns an error if there was a problem sending the request or decoding the
|
||||||
// response, or if the identity server responded with a non-OK status.
|
// response, or if the identity server responded with a non-OK status.
|
||||||
func CreateSession(
|
func CreateSession(
|
||||||
ctx context.Context, req EmailAssociationRequest, cfg *config.ClientAPI, client *gomatrixserverlib.Client,
|
ctx context.Context, req EmailAssociationRequest, cfg *config.ClientAPI, client *fclient.Client,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
if err := isTrusted(req.IDServer, cfg); err != nil {
|
if err := isTrusted(req.IDServer, cfg); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -112,7 +112,7 @@ type GetValidatedResponse struct {
|
|||||||
// response, or if the identity server responded with a non-OK status.
|
// response, or if the identity server responded with a non-OK status.
|
||||||
func CheckAssociation(
|
func CheckAssociation(
|
||||||
ctx context.Context, creds Credentials, cfg *config.ClientAPI,
|
ctx context.Context, creds Credentials, cfg *config.ClientAPI,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
) (bool, string, string, error) {
|
) (bool, string, string, error) {
|
||||||
if err := isTrusted(creds.IDServer, cfg); err != nil {
|
if err := isTrusted(creds.IDServer, cfg); err != nil {
|
||||||
return false, "", "", err
|
return false, "", "", err
|
||||||
@ -146,7 +146,7 @@ func CheckAssociation(
|
|||||||
// identifier and a Matrix ID.
|
// identifier and a Matrix ID.
|
||||||
// Returns an error if there was a problem sending the request or decoding the
|
// Returns an error if there was a problem sending the request or decoding the
|
||||||
// response, or if the identity server responded with a non-OK status.
|
// response, or if the identity server responded with a non-OK status.
|
||||||
func PublishAssociation(ctx context.Context, creds Credentials, userID string, cfg *config.ClientAPI, client *gomatrixserverlib.Client) error {
|
func PublishAssociation(ctx context.Context, creds Credentials, userID string, cfg *config.ClientAPI, client *fclient.Client) error {
|
||||||
if err := isTrusted(creds.IDServer, cfg); err != nil {
|
if err := isTrusted(creds.IDServer, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -30,7 +31,7 @@ var (
|
|||||||
// TestGoodUserID checks that correct localpart is returned for a valid user ID.
|
// TestGoodUserID checks that correct localpart is returned for a valid user ID.
|
||||||
func TestGoodUserID(t *testing.T) {
|
func TestGoodUserID(t *testing.T) {
|
||||||
cfg := &config.Global{
|
cfg := &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ func TestGoodUserID(t *testing.T) {
|
|||||||
// TestWithLocalpartOnly checks that localpart is returned when usernameParam contains only localpart.
|
// TestWithLocalpartOnly checks that localpart is returned when usernameParam contains only localpart.
|
||||||
func TestWithLocalpartOnly(t *testing.T) {
|
func TestWithLocalpartOnly(t *testing.T) {
|
||||||
cfg := &config.Global{
|
cfg := &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -68,7 +69,7 @@ func TestWithLocalpartOnly(t *testing.T) {
|
|||||||
// TestIncorrectDomain checks for error when there's server name mismatch.
|
// TestIncorrectDomain checks for error when there's server name mismatch.
|
||||||
func TestIncorrectDomain(t *testing.T) {
|
func TestIncorrectDomain(t *testing.T) {
|
||||||
cfg := &config.Global{
|
cfg := &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: invalidServerName,
|
ServerName: invalidServerName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ func TestIncorrectDomain(t *testing.T) {
|
|||||||
// TestBadUserID checks that ParseUsernameParam fails for invalid user ID
|
// TestBadUserID checks that ParseUsernameParam fails for invalid user ID
|
||||||
func TestBadUserID(t *testing.T) {
|
func TestBadUserID(t *testing.T) {
|
||||||
cfg := &config.Global{
|
cfg := &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"nhooyr.io/websocket"
|
"nhooyr.io/websocket"
|
||||||
|
|
||||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||||
@ -91,17 +91,17 @@ func createTransport(s *pineconeSessions.Sessions) *http.Transport {
|
|||||||
|
|
||||||
func CreateClient(
|
func CreateClient(
|
||||||
s *pineconeSessions.Sessions,
|
s *pineconeSessions.Sessions,
|
||||||
) *gomatrixserverlib.Client {
|
) *fclient.Client {
|
||||||
return gomatrixserverlib.NewClient(
|
return fclient.NewClient(
|
||||||
gomatrixserverlib.WithTransport(createTransport(s)),
|
fclient.WithTransport(createTransport(s)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFederationClient(
|
func CreateFederationClient(
|
||||||
cfg *config.Dendrite, s *pineconeSessions.Sessions,
|
cfg *config.Dendrite, s *pineconeSessions.Sessions,
|
||||||
) *gomatrixserverlib.FederationClient {
|
) *fclient.FederationClient {
|
||||||
return gomatrixserverlib.NewFederationClient(
|
return fclient.NewFederationClient(
|
||||||
cfg.Global.SigningIdentities(),
|
cfg.Global.SigningIdentities(),
|
||||||
gomatrixserverlib.WithTransport(createTransport(s)),
|
fclient.WithTransport(createTransport(s)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/defaults"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/defaults"
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||||
@ -32,14 +33,14 @@ type PineconeRoomProvider struct {
|
|||||||
r *pineconeRouter.Router
|
r *pineconeRouter.Router
|
||||||
s *pineconeSessions.Sessions
|
s *pineconeSessions.Sessions
|
||||||
fedSender api.FederationInternalAPI
|
fedSender api.FederationInternalAPI
|
||||||
fedClient *gomatrixserverlib.FederationClient
|
fedClient *fclient.FederationClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPineconeRoomProvider(
|
func NewPineconeRoomProvider(
|
||||||
r *pineconeRouter.Router,
|
r *pineconeRouter.Router,
|
||||||
s *pineconeSessions.Sessions,
|
s *pineconeSessions.Sessions,
|
||||||
fedSender api.FederationInternalAPI,
|
fedSender api.FederationInternalAPI,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *fclient.FederationClient,
|
||||||
) *PineconeRoomProvider {
|
) *PineconeRoomProvider {
|
||||||
p := &PineconeRoomProvider{
|
p := &PineconeRoomProvider{
|
||||||
r: r,
|
r: r,
|
||||||
@ -50,7 +51,7 @@ func NewPineconeRoomProvider(
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PineconeRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
func (p *PineconeRoomProvider) Rooms() []fclient.PublicRoom {
|
||||||
list := map[gomatrixserverlib.ServerName]struct{}{}
|
list := map[gomatrixserverlib.ServerName]struct{}{}
|
||||||
for k := range defaults.DefaultServerNames {
|
for k := range defaults.DefaultServerNames {
|
||||||
list[k] = struct{}{}
|
list[k] = struct{}{}
|
||||||
@ -67,14 +68,14 @@ func (p *PineconeRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
|||||||
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
||||||
// Returns a list of public rooms.
|
// Returns a list of public rooms.
|
||||||
func bulkFetchPublicRoomsFromServers(
|
func bulkFetchPublicRoomsFromServers(
|
||||||
ctx context.Context, fedClient *gomatrixserverlib.FederationClient,
|
ctx context.Context, fedClient *fclient.FederationClient,
|
||||||
origin gomatrixserverlib.ServerName,
|
origin gomatrixserverlib.ServerName,
|
||||||
homeservers map[gomatrixserverlib.ServerName]struct{},
|
homeservers map[gomatrixserverlib.ServerName]struct{},
|
||||||
) (publicRooms []gomatrixserverlib.PublicRoom) {
|
) (publicRooms []fclient.PublicRoom) {
|
||||||
limit := 200
|
limit := 200
|
||||||
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
||||||
// goroutines send rooms to this channel
|
// goroutines send rooms to this channel
|
||||||
roomCh := make(chan gomatrixserverlib.PublicRoom, int(limit))
|
roomCh := make(chan fclient.PublicRoom, int(limit))
|
||||||
// signalling channel to tell goroutines to stop sending rooms and quit
|
// signalling channel to tell goroutines to stop sending rooms and quit
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
// signalling to say when we can close the room channel
|
// signalling to say when we can close the room channel
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/defaults"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-pinecone/defaults"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||||
@ -38,7 +39,7 @@ type PineconeUserProvider struct {
|
|||||||
r *pineconeRouter.Router
|
r *pineconeRouter.Router
|
||||||
s *pineconeSessions.Sessions
|
s *pineconeSessions.Sessions
|
||||||
userAPI userapi.QuerySearchProfilesAPI
|
userAPI userapi.QuerySearchProfilesAPI
|
||||||
fedClient *gomatrixserverlib.FederationClient
|
fedClient *fclient.FederationClient
|
||||||
}
|
}
|
||||||
|
|
||||||
const PublicURL = "/_matrix/p2p/profiles"
|
const PublicURL = "/_matrix/p2p/profiles"
|
||||||
@ -47,7 +48,7 @@ func NewPineconeUserProvider(
|
|||||||
r *pineconeRouter.Router,
|
r *pineconeRouter.Router,
|
||||||
s *pineconeSessions.Sessions,
|
s *pineconeSessions.Sessions,
|
||||||
userAPI userapi.QuerySearchProfilesAPI,
|
userAPI userapi.QuerySearchProfilesAPI,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *fclient.FederationClient,
|
||||||
) *PineconeUserProvider {
|
) *PineconeUserProvider {
|
||||||
p := &PineconeUserProvider{
|
p := &PineconeUserProvider{
|
||||||
r: r,
|
r: r,
|
||||||
@ -94,7 +95,7 @@ func (p *PineconeUserProvider) QuerySearchProfiles(ctx context.Context, req *use
|
|||||||
// Returns a list of user profiles.
|
// Returns a list of user profiles.
|
||||||
func bulkFetchUserDirectoriesFromServers(
|
func bulkFetchUserDirectoriesFromServers(
|
||||||
ctx context.Context, req *userapi.QuerySearchProfilesRequest,
|
ctx context.Context, req *userapi.QuerySearchProfilesRequest,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *fclient.FederationClient,
|
||||||
homeservers map[gomatrixserverlib.ServerName]struct{},
|
homeservers map[gomatrixserverlib.ServerName]struct{},
|
||||||
) (profiles []authtypes.Profile) {
|
) (profiles []authtypes.Profile) {
|
||||||
jsonBody, err := json.Marshal(req)
|
jsonBody, err := json.Marshal(req)
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
type yggroundtripper struct {
|
type yggroundtripper struct {
|
||||||
@ -17,7 +17,7 @@ func (y *yggroundtripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
return y.inner.RoundTrip(req)
|
return y.inner.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) CreateClient() *gomatrixserverlib.Client {
|
func (n *Node) CreateClient() *fclient.Client {
|
||||||
tr := &http.Transport{}
|
tr := &http.Transport{}
|
||||||
tr.RegisterProtocol(
|
tr.RegisterProtocol(
|
||||||
"matrix", &yggroundtripper{
|
"matrix", &yggroundtripper{
|
||||||
@ -31,14 +31,14 @@ func (n *Node) CreateClient() *gomatrixserverlib.Client {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return gomatrixserverlib.NewClient(
|
return fclient.NewClient(
|
||||||
gomatrixserverlib.WithTransport(tr),
|
fclient.WithTransport(tr),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) CreateFederationClient(
|
func (n *Node) CreateFederationClient(
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
) *gomatrixserverlib.FederationClient {
|
) *fclient.FederationClient {
|
||||||
tr := &http.Transport{}
|
tr := &http.Transport{}
|
||||||
tr.RegisterProtocol(
|
tr.RegisterProtocol(
|
||||||
"matrix", &yggroundtripper{
|
"matrix", &yggroundtripper{
|
||||||
@ -52,8 +52,8 @@ func (n *Node) CreateFederationClient(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return gomatrixserverlib.NewFederationClient(
|
return fclient.NewFederationClient(
|
||||||
cfg.Global.SigningIdentities(),
|
cfg.Global.SigningIdentities(),
|
||||||
gomatrixserverlib.WithTransport(tr),
|
fclient.WithTransport(tr),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,18 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggconn"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggconn"
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type YggdrasilRoomProvider struct {
|
type YggdrasilRoomProvider struct {
|
||||||
node *yggconn.Node
|
node *yggconn.Node
|
||||||
fedSender api.FederationInternalAPI
|
fedSender api.FederationInternalAPI
|
||||||
fedClient *gomatrixserverlib.FederationClient
|
fedClient *fclient.FederationClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewYggdrasilRoomProvider(
|
func NewYggdrasilRoomProvider(
|
||||||
node *yggconn.Node, fedSender api.FederationInternalAPI, fedClient *gomatrixserverlib.FederationClient,
|
node *yggconn.Node, fedSender api.FederationInternalAPI, fedClient *fclient.FederationClient,
|
||||||
) *YggdrasilRoomProvider {
|
) *YggdrasilRoomProvider {
|
||||||
p := &YggdrasilRoomProvider{
|
p := &YggdrasilRoomProvider{
|
||||||
node: node,
|
node: node,
|
||||||
@ -42,7 +43,7 @@ func NewYggdrasilRoomProvider(
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *YggdrasilRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
func (p *YggdrasilRoomProvider) Rooms() []fclient.PublicRoom {
|
||||||
return bulkFetchPublicRoomsFromServers(
|
return bulkFetchPublicRoomsFromServers(
|
||||||
context.Background(), p.fedClient,
|
context.Background(), p.fedClient,
|
||||||
gomatrixserverlib.ServerName(p.node.DerivedServerName()),
|
gomatrixserverlib.ServerName(p.node.DerivedServerName()),
|
||||||
@ -53,14 +54,14 @@ func (p *YggdrasilRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
|||||||
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
||||||
// Returns a list of public rooms.
|
// Returns a list of public rooms.
|
||||||
func bulkFetchPublicRoomsFromServers(
|
func bulkFetchPublicRoomsFromServers(
|
||||||
ctx context.Context, fedClient *gomatrixserverlib.FederationClient,
|
ctx context.Context, fedClient *fclient.FederationClient,
|
||||||
origin gomatrixserverlib.ServerName,
|
origin gomatrixserverlib.ServerName,
|
||||||
homeservers []gomatrixserverlib.ServerName,
|
homeservers []gomatrixserverlib.ServerName,
|
||||||
) (publicRooms []gomatrixserverlib.PublicRoom) {
|
) (publicRooms []fclient.PublicRoom) {
|
||||||
limit := 200
|
limit := 200
|
||||||
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
||||||
// goroutines send rooms to this channel
|
// goroutines send rooms to this channel
|
||||||
roomCh := make(chan gomatrixserverlib.PublicRoom, int(limit))
|
roomCh := make(chan fclient.PublicRoom, int(limit))
|
||||||
// signalling channel to tell goroutines to stop sending rooms and quit
|
// signalling channel to tell goroutines to stop sending rooms and quit
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
// signalling to say when we can close the room channel
|
// signalling to say when we can close the room channel
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
@ -96,9 +96,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create DNS cache
|
// create DNS cache
|
||||||
var dnsCache *gomatrixserverlib.DNSCache
|
var dnsCache *fclient.DNSCache
|
||||||
if cfg.Global.DNSCache.Enabled {
|
if cfg.Global.DNSCache.Enabled {
|
||||||
dnsCache = gomatrixserverlib.NewDNSCache(
|
dnsCache = fclient.NewDNSCache(
|
||||||
cfg.Global.DNSCache.CacheSize,
|
cfg.Global.DNSCache.CacheSize,
|
||||||
cfg.Global.DNSCache.CacheLifetime,
|
cfg.Global.DNSCache.CacheLifetime,
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
var requestFrom = flag.String("from", "", "the server name that the request should originate from")
|
var requestFrom = flag.String("from", "", "the server name that the request should originate from")
|
||||||
@ -49,8 +50,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverName := gomatrixserverlib.ServerName(*requestFrom)
|
serverName := gomatrixserverlib.ServerName(*requestFrom)
|
||||||
client := gomatrixserverlib.NewFederationClient(
|
client := fclient.NewFederationClient(
|
||||||
[]*gomatrixserverlib.SigningIdentity{
|
[]*fclient.SigningIdentity{
|
||||||
{
|
{
|
||||||
ServerName: serverName,
|
ServerName: serverName,
|
||||||
KeyID: gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
KeyID: gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/types"
|
"github.com/matrix-org/dendrite/federationapi/types"
|
||||||
)
|
)
|
||||||
@ -22,8 +23,8 @@ type FederationInternalAPI interface {
|
|||||||
|
|
||||||
QueryServerKeys(ctx context.Context, request *QueryServerKeysRequest, response *QueryServerKeysResponse) error
|
QueryServerKeys(ctx context.Context, request *QueryServerKeysRequest, response *QueryServerKeysResponse) error
|
||||||
LookupServerKeys(ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
LookupServerKeys(ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
||||||
MSC2836EventRelationships(ctx context.Context, origin, dst gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error)
|
MSC2836EventRelationships(ctx context.Context, origin, dst gomatrixserverlib.ServerName, r fclient.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res fclient.MSC2836EventRelationshipsResponse, err error)
|
||||||
MSC2946Spaces(ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res gomatrixserverlib.MSC2946SpacesResponse, err error)
|
MSC2946Spaces(ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res fclient.MSC2946SpacesResponse, err error)
|
||||||
|
|
||||||
// Broadcasts an EDU to all servers in rooms we are joined to. Used in the yggdrasil demos.
|
// Broadcasts an EDU to all servers in rooms we are joined to. Used in the yggdrasil demos.
|
||||||
PerformBroadcastEDU(
|
PerformBroadcastEDU(
|
||||||
@ -66,9 +67,9 @@ type RoomserverFederationAPI interface {
|
|||||||
// containing only the server names (without information for membership events).
|
// containing only the server names (without information for membership events).
|
||||||
// The response will include this server if they are joined to the room.
|
// The response will include this server if they are joined to the room.
|
||||||
QueryJoinedHostServerNamesInRoom(ctx context.Context, request *QueryJoinedHostServerNamesInRoomRequest, response *QueryJoinedHostServerNamesInRoomResponse) error
|
QueryJoinedHostServerNamesInRoom(ctx context.Context, request *QueryJoinedHostServerNamesInRoomRequest, response *QueryJoinedHostServerNamesInRoomResponse) error
|
||||||
GetEventAuth(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res gomatrixserverlib.RespEventAuth, err error)
|
GetEventAuth(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res fclient.RespEventAuth, err error)
|
||||||
GetEvent(ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
GetEvent(ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
||||||
LookupMissingEvents(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMissingEvents, err error)
|
LookupMissingEvents(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, missing fclient.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res fclient.RespMissingEvents, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type P2PFederationAPI interface {
|
type P2PFederationAPI interface {
|
||||||
@ -98,45 +99,45 @@ type P2PFederationAPI interface {
|
|||||||
// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
|
// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
|
||||||
// this interface are of type FederationClientError
|
// this interface are of type FederationClientError
|
||||||
type KeyserverFederationAPI interface {
|
type KeyserverFederationAPI interface {
|
||||||
GetUserDevices(ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string) (res gomatrixserverlib.RespUserDevices, err error)
|
GetUserDevices(ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string) (res fclient.RespUserDevices, err error)
|
||||||
ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (res gomatrixserverlib.RespClaimKeys, err error)
|
ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (res fclient.RespClaimKeys, err error)
|
||||||
QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (res gomatrixserverlib.RespQueryKeys, err error)
|
QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (res fclient.RespQueryKeys, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// an interface for gmsl.FederationClient - contains functions called by federationapi only.
|
// an interface for gmsl.FederationClient - contains functions called by federationapi only.
|
||||||
type FederationClient interface {
|
type FederationClient interface {
|
||||||
P2PFederationClient
|
P2PFederationClient
|
||||||
gomatrixserverlib.KeyClient
|
gomatrixserverlib.KeyClient
|
||||||
SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res gomatrixserverlib.RespSend, err error)
|
SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res fclient.RespSend, err error)
|
||||||
|
|
||||||
// Perform operations
|
// Perform operations
|
||||||
LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res gomatrixserverlib.RespDirectory, err error)
|
LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res fclient.RespDirectory, err error)
|
||||||
Peek(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, peekID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespPeek, err error)
|
Peek(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, peekID string, roomVersions []gomatrixserverlib.RoomVersion) (res fclient.RespPeek, err error)
|
||||||
MakeJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMakeJoin, err error)
|
MakeJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res fclient.RespMakeJoin, err error)
|
||||||
SendJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res gomatrixserverlib.RespSendJoin, err error)
|
SendJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res fclient.RespSendJoin, err error)
|
||||||
MakeLeave(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string) (res gomatrixserverlib.RespMakeLeave, err error)
|
MakeLeave(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string) (res fclient.RespMakeLeave, err error)
|
||||||
SendLeave(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (err error)
|
SendLeave(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (err error)
|
||||||
SendInviteV2(ctx context.Context, origin, s gomatrixserverlib.ServerName, request gomatrixserverlib.InviteV2Request) (res gomatrixserverlib.RespInviteV2, err error)
|
SendInviteV2(ctx context.Context, origin, s gomatrixserverlib.ServerName, request gomatrixserverlib.InviteV2Request) (res fclient.RespInviteV2, err error)
|
||||||
|
|
||||||
GetEvent(ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
GetEvent(ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
||||||
|
|
||||||
GetEventAuth(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res gomatrixserverlib.RespEventAuth, err error)
|
GetEventAuth(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res fclient.RespEventAuth, err error)
|
||||||
GetUserDevices(ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string) (gomatrixserverlib.RespUserDevices, error)
|
GetUserDevices(ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string) (fclient.RespUserDevices, error)
|
||||||
ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (gomatrixserverlib.RespClaimKeys, error)
|
ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (fclient.RespClaimKeys, error)
|
||||||
QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (gomatrixserverlib.RespQueryKeys, error)
|
QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (fclient.RespQueryKeys, error)
|
||||||
Backfill(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string) (res gomatrixserverlib.Transaction, err error)
|
Backfill(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string) (res gomatrixserverlib.Transaction, err error)
|
||||||
MSC2836EventRelationships(ctx context.Context, origin, dst gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error)
|
MSC2836EventRelationships(ctx context.Context, origin, dst gomatrixserverlib.ServerName, r fclient.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res fclient.MSC2836EventRelationshipsResponse, err error)
|
||||||
MSC2946Spaces(ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res gomatrixserverlib.MSC2946SpacesResponse, err error)
|
MSC2946Spaces(ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res fclient.MSC2946SpacesResponse, err error)
|
||||||
|
|
||||||
ExchangeThirdPartyInvite(ctx context.Context, origin, s gomatrixserverlib.ServerName, builder gomatrixserverlib.EventBuilder) (err error)
|
ExchangeThirdPartyInvite(ctx context.Context, origin, s gomatrixserverlib.ServerName, builder gomatrixserverlib.EventBuilder) (err error)
|
||||||
LookupState(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, eventID string, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespState, err error)
|
LookupState(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, eventID string, roomVersion gomatrixserverlib.RoomVersion) (res fclient.RespState, err error)
|
||||||
LookupStateIDs(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, eventID string) (res gomatrixserverlib.RespStateIDs, err error)
|
LookupStateIDs(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, eventID string) (res fclient.RespStateIDs, err error)
|
||||||
LookupMissingEvents(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMissingEvents, err error)
|
LookupMissingEvents(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, missing fclient.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res fclient.RespMissingEvents, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type P2PFederationClient interface {
|
type P2PFederationClient interface {
|
||||||
P2PSendTransactionToRelay(ctx context.Context, u gomatrixserverlib.UserID, t gomatrixserverlib.Transaction, forwardingServer gomatrixserverlib.ServerName) (res gomatrixserverlib.EmptyResp, err error)
|
P2PSendTransactionToRelay(ctx context.Context, u gomatrixserverlib.UserID, t gomatrixserverlib.Transaction, forwardingServer gomatrixserverlib.ServerName) (res fclient.EmptyResp, err error)
|
||||||
P2PGetTransactionFromRelay(ctx context.Context, u gomatrixserverlib.UserID, prev gomatrixserverlib.RelayEntry, relayServer gomatrixserverlib.ServerName) (res gomatrixserverlib.RespGetRelayTransaction, err error)
|
P2PGetTransactionFromRelay(ctx context.Context, u gomatrixserverlib.UserID, prev fclient.RelayEntry, relayServer gomatrixserverlib.ServerName) (res fclient.RespGetRelayTransaction, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FederationClientError is returned from FederationClient methods in the event of a problem.
|
// FederationClientError is returned from FederationClient methods in the event of a problem.
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
@ -48,7 +49,7 @@ func AddPublicRoutes(
|
|||||||
dendriteConfig *config.Dendrite,
|
dendriteConfig *config.Dendrite,
|
||||||
natsInstance *jetstream.NATSInstance,
|
natsInstance *jetstream.NATSInstance,
|
||||||
userAPI userapi.FederationUserAPI,
|
userAPI userapi.FederationUserAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *fclient.FederationClient,
|
||||||
keyRing gomatrixserverlib.JSONVerifier,
|
keyRing gomatrixserverlib.JSONVerifier,
|
||||||
rsAPI roomserverAPI.FederationRoomserverAPI,
|
rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||||
fedAPI federationAPI.FederationInternalAPI,
|
fedAPI federationAPI.FederationInternalAPI,
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/federationapi/routing"
|
"github.com/matrix-org/dendrite/federationapi/routing"
|
||||||
@ -24,12 +25,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
name gomatrixserverlib.ServerName // server name
|
name gomatrixserverlib.ServerName // server name
|
||||||
validity time.Duration // key validity duration from now
|
validity time.Duration // key validity duration from now
|
||||||
config *config.FederationAPI // skeleton config, from TestMain
|
config *config.FederationAPI // skeleton config, from TestMain
|
||||||
fedclient *gomatrixserverlib.FederationClient // uses MockRoundTripper
|
fedclient *fclient.FederationClient // uses MockRoundTripper
|
||||||
cache *caching.Caches // server-specific cache
|
cache *caching.Caches // server-specific cache
|
||||||
api api.FederationInternalAPI // server-specific server key API
|
api api.FederationInternalAPI // server-specific server key API
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) renew() {
|
func (s *server) renew() {
|
||||||
@ -105,9 +106,9 @@ func TestMain(m *testing.M) {
|
|||||||
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
||||||
|
|
||||||
// Create the federation client.
|
// Create the federation client.
|
||||||
s.fedclient = gomatrixserverlib.NewFederationClient(
|
s.fedclient = fclient.NewFederationClient(
|
||||||
s.config.Matrix.SigningIdentities(),
|
s.config.Matrix.SigningIdentities(),
|
||||||
gomatrixserverlib.WithTransport(transport),
|
fclient.WithTransport(transport),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Finally, build the server key APIs.
|
// Finally, build the server key APIs.
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi"
|
"github.com/matrix-org/dendrite/federationapi"
|
||||||
@ -104,7 +105,7 @@ func (f *fedClient) GetServerKeys(ctx context.Context, matrixServer gomatrixserv
|
|||||||
return keys, nil
|
return keys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fedClient) MakeJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMakeJoin, err error) {
|
func (f *fedClient) MakeJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res fclient.RespMakeJoin, err error) {
|
||||||
for _, r := range f.allowJoins {
|
for _, r := range f.allowJoins {
|
||||||
if r.ID == roomID {
|
if r.ID == roomID {
|
||||||
res.RoomVersion = r.Version
|
res.RoomVersion = r.Version
|
||||||
@ -128,7 +129,7 @@ func (f *fedClient) MakeJoin(ctx context.Context, origin, s gomatrixserverlib.Se
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (f *fedClient) SendJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res gomatrixserverlib.RespSendJoin, err error) {
|
func (f *fedClient) SendJoin(ctx context.Context, origin, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res fclient.RespSendJoin, err error) {
|
||||||
f.fedClientMutex.Lock()
|
f.fedClientMutex.Lock()
|
||||||
defer f.fedClientMutex.Unlock()
|
defer f.fedClientMutex.Unlock()
|
||||||
for _, r := range f.allowJoins {
|
for _, r := range f.allowJoins {
|
||||||
@ -142,7 +143,7 @@ func (f *fedClient) SendJoin(ctx context.Context, origin, s gomatrixserverlib.Se
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fedClient) SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res gomatrixserverlib.RespSend, err error) {
|
func (f *fedClient) SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res fclient.RespSend, err error) {
|
||||||
f.fedClientMutex.Lock()
|
f.fedClientMutex.Lock()
|
||||||
defer f.fedClientMutex.Unlock()
|
defer f.fedClientMutex.Unlock()
|
||||||
for _, edu := range t.EDUs {
|
for _, edu := range t.EDUs {
|
||||||
@ -313,9 +314,9 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
||||||
|
|
||||||
fedCli := gomatrixserverlib.NewFederationClient(
|
fedCli := fclient.NewFederationClient(
|
||||||
cfg.Global.SigningIdentities(),
|
cfg.Global.SigningIdentities(),
|
||||||
gomatrixserverlib.WithSkipVerify(true),
|
fclient.WithSkipVerify(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Functions here are "proxying" calls to the gomatrixserverlib federation
|
// Functions here are "proxying" calls to the gomatrixserverlib federation
|
||||||
@ -13,56 +14,56 @@ import (
|
|||||||
func (a *FederationInternalAPI) GetEventAuth(
|
func (a *FederationInternalAPI) GetEventAuth(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName,
|
||||||
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
||||||
) (res gomatrixserverlib.RespEventAuth, err error) {
|
) (res fclient.RespEventAuth, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.GetEventAuth(ctx, origin, s, roomVersion, roomID, eventID)
|
return a.federation.GetEventAuth(ctx, origin, s, roomVersion, roomID, eventID)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespEventAuth{}, err
|
return fclient.RespEventAuth{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespEventAuth), nil
|
return ires.(fclient.RespEventAuth), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) GetUserDevices(
|
func (a *FederationInternalAPI) GetUserDevices(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string,
|
||||||
) (gomatrixserverlib.RespUserDevices, error) {
|
) (fclient.RespUserDevices, error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.GetUserDevices(ctx, origin, s, userID)
|
return a.federation.GetUserDevices(ctx, origin, s, userID)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespUserDevices{}, err
|
return fclient.RespUserDevices{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespUserDevices), nil
|
return ires.(fclient.RespUserDevices), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) ClaimKeys(
|
func (a *FederationInternalAPI) ClaimKeys(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
||||||
) (gomatrixserverlib.RespClaimKeys, error) {
|
) (fclient.RespClaimKeys, error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.ClaimKeys(ctx, origin, s, oneTimeKeys)
|
return a.federation.ClaimKeys(ctx, origin, s, oneTimeKeys)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespClaimKeys{}, err
|
return fclient.RespClaimKeys{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespClaimKeys), nil
|
return ires.(fclient.RespClaimKeys), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) QueryKeys(
|
func (a *FederationInternalAPI) QueryKeys(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string,
|
||||||
) (gomatrixserverlib.RespQueryKeys, error) {
|
) (fclient.RespQueryKeys, error) {
|
||||||
ires, err := a.doRequestIfNotBackingOffOrBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBackingOffOrBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.QueryKeys(ctx, origin, s, keys)
|
return a.federation.QueryKeys(ctx, origin, s, keys)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespQueryKeys{}, err
|
return fclient.RespQueryKeys{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespQueryKeys), nil
|
return ires.(fclient.RespQueryKeys), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) Backfill(
|
func (a *FederationInternalAPI) Backfill(
|
||||||
@ -81,45 +82,46 @@ func (a *FederationInternalAPI) Backfill(
|
|||||||
|
|
||||||
func (a *FederationInternalAPI) LookupState(
|
func (a *FederationInternalAPI) LookupState(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (res gomatrixserverlib.RespState, err error) {
|
) (res gomatrixserverlib.StateResponse, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.LookupState(ctx, origin, s, roomID, eventID, roomVersion)
|
return a.federation.LookupState(ctx, origin, s, roomID, eventID, roomVersion)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespState{}, err
|
return &fclient.RespState{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespState), nil
|
r := ires.(fclient.RespState)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) LookupStateIDs(
|
func (a *FederationInternalAPI) LookupStateIDs(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string,
|
||||||
) (res gomatrixserverlib.RespStateIDs, err error) {
|
) (res gomatrixserverlib.StateIDResponse, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.LookupStateIDs(ctx, origin, s, roomID, eventID)
|
return a.federation.LookupStateIDs(ctx, origin, s, roomID, eventID)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespStateIDs{}, err
|
return fclient.RespStateIDs{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespStateIDs), nil
|
return ires.(fclient.RespStateIDs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) LookupMissingEvents(
|
func (a *FederationInternalAPI) LookupMissingEvents(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string,
|
||||||
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
missing fclient.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (res gomatrixserverlib.RespMissingEvents, err error) {
|
) (res fclient.RespMissingEvents, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
return a.federation.LookupMissingEvents(ctx, origin, s, roomID, missing, roomVersion)
|
return a.federation.LookupMissingEvents(ctx, origin, s, roomID, missing, roomVersion)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gomatrixserverlib.RespMissingEvents{}, err
|
return fclient.RespMissingEvents{}, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.RespMissingEvents), nil
|
return ires.(fclient.RespMissingEvents), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) GetEvent(
|
func (a *FederationInternalAPI) GetEvent(
|
||||||
@ -151,9 +153,9 @@ func (a *FederationInternalAPI) LookupServerKeys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) MSC2836EventRelationships(
|
func (a *FederationInternalAPI) MSC2836EventRelationships(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, r fclient.MSC2836EventRelationshipsRequest,
|
||||||
roomVersion gomatrixserverlib.RoomVersion,
|
roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) {
|
) (res fclient.MSC2836EventRelationshipsResponse, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
@ -162,12 +164,12 @@ func (a *FederationInternalAPI) MSC2836EventRelationships(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.MSC2836EventRelationshipsResponse), nil
|
return ires.(fclient.MSC2836EventRelationshipsResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) MSC2946Spaces(
|
func (a *FederationInternalAPI) MSC2946Spaces(
|
||||||
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
||||||
) (res gomatrixserverlib.MSC2946SpacesResponse, err error) {
|
) (res fclient.MSC2946SpacesResponse, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
ires, err := a.doRequestIfNotBlacklisted(s, func() (interface{}, error) {
|
||||||
@ -176,5 +178,5 @@ func (a *FederationInternalAPI) MSC2946Spaces(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
return ires.(gomatrixserverlib.MSC2946SpacesResponse), nil
|
return ires.(fclient.MSC2946SpacesResponse), nil
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,20 +34,20 @@ const (
|
|||||||
FailuresUntilBlacklist = 8
|
FailuresUntilBlacklist = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *testFedClient) QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (gomatrixserverlib.RespQueryKeys, error) {
|
func (t *testFedClient) QueryKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string) (fclient.RespQueryKeys, error) {
|
||||||
t.queryKeysCalled = true
|
t.queryKeysCalled = true
|
||||||
if t.shouldFail {
|
if t.shouldFail {
|
||||||
return gomatrixserverlib.RespQueryKeys{}, fmt.Errorf("Failure")
|
return fclient.RespQueryKeys{}, fmt.Errorf("Failure")
|
||||||
}
|
}
|
||||||
return gomatrixserverlib.RespQueryKeys{}, nil
|
return fclient.RespQueryKeys{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testFedClient) ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (gomatrixserverlib.RespClaimKeys, error) {
|
func (t *testFedClient) ClaimKeys(ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (fclient.RespClaimKeys, error) {
|
||||||
t.claimKeysCalled = true
|
t.claimKeysCalled = true
|
||||||
if t.shouldFail {
|
if t.shouldFail {
|
||||||
return gomatrixserverlib.RespClaimKeys{}, fmt.Errorf("Failure")
|
return fclient.RespClaimKeys{}, fmt.Errorf("Failure")
|
||||||
}
|
}
|
||||||
return gomatrixserverlib.RespClaimKeys{}, nil
|
return fclient.RespClaimKeys{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFederationClientQueryKeys(t *testing.T) {
|
func TestFederationClientQueryKeys(t *testing.T) {
|
||||||
@ -54,7 +55,7 @@ func TestFederationClientQueryKeys(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "server",
|
ServerName: "server",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -85,7 +86,7 @@ func TestFederationClientQueryKeysBlacklisted(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "server",
|
ServerName: "server",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -115,7 +116,7 @@ func TestFederationClientQueryKeysFailure(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "server",
|
ServerName: "server",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -145,7 +146,7 @@ func TestFederationClientClaimKeys(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "server",
|
ServerName: "server",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -176,7 +177,7 @@ func TestFederationClientClaimKeysBlacklisted(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "server",
|
ServerName: "server",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -255,7 +256,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
|||||||
// waste the effort.
|
// waste the effort.
|
||||||
// TODO: Can we expand Check here to return a list of missing auth
|
// TODO: Can we expand Check here to return a list of missing auth
|
||||||
// events rather than failing one at a time?
|
// events rather than failing one at a time?
|
||||||
var respState *gomatrixserverlib.RespState
|
var respState *fclient.RespState
|
||||||
respState, err = respSendJoin.Check(
|
respState, err = respSendJoin.Check(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
respMakeJoin.RoomVersion,
|
respMakeJoin.RoomVersion,
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,8 +36,8 @@ type testFedClient struct {
|
|||||||
shouldFail bool
|
shouldFail bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res gomatrixserverlib.RespDirectory, err error) {
|
func (t *testFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res fclient.RespDirectory, err error) {
|
||||||
return gomatrixserverlib.RespDirectory{}, nil
|
return fclient.RespDirectory{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPerformWakeupServers(t *testing.T) {
|
func TestPerformWakeupServers(t *testing.T) {
|
||||||
@ -54,7 +55,7 @@ func TestPerformWakeupServers(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "relay",
|
ServerName: "relay",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -96,7 +97,7 @@ func TestQueryRelayServers(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "relay",
|
ServerName: "relay",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -133,7 +134,7 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "relay",
|
ServerName: "relay",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -169,7 +170,7 @@ func TestPerformDirectoryLookup(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "relay",
|
ServerName: "relay",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -204,7 +205,7 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||||||
|
|
||||||
cfg := config.FederationAPI{
|
cfg := config.FederationAPI{
|
||||||
Matrix: &config.Global{
|
Matrix: &config.Global{
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: server,
|
ServerName: server,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ type destinationQueue struct {
|
|||||||
queues *OutgoingQueues
|
queues *OutgoingQueues
|
||||||
db storage.Database
|
db storage.Database
|
||||||
process *process.ProcessContext
|
process *process.ProcessContext
|
||||||
signing map[gomatrixserverlib.ServerName]*gomatrixserverlib.SigningIdentity
|
signing map[gomatrixserverlib.ServerName]*fclient.SigningIdentity
|
||||||
rsAPI api.FederationRoomserverAPI
|
rsAPI api.FederationRoomserverAPI
|
||||||
client fedapi.FederationClient // federation client
|
client fedapi.FederationClient // federation client
|
||||||
origin gomatrixserverlib.ServerName // origin of requests
|
origin gomatrixserverlib.ServerName // origin of requests
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -45,7 +46,7 @@ type OutgoingQueues struct {
|
|||||||
origin gomatrixserverlib.ServerName
|
origin gomatrixserverlib.ServerName
|
||||||
client fedapi.FederationClient
|
client fedapi.FederationClient
|
||||||
statistics *statistics.Statistics
|
statistics *statistics.Statistics
|
||||||
signing map[gomatrixserverlib.ServerName]*gomatrixserverlib.SigningIdentity
|
signing map[gomatrixserverlib.ServerName]*fclient.SigningIdentity
|
||||||
queuesMutex sync.Mutex // protects the below
|
queuesMutex sync.Mutex // protects the below
|
||||||
queues map[gomatrixserverlib.ServerName]*destinationQueue
|
queues map[gomatrixserverlib.ServerName]*destinationQueue
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ func NewOutgoingQueues(
|
|||||||
client fedapi.FederationClient,
|
client fedapi.FederationClient,
|
||||||
rsAPI api.FederationRoomserverAPI,
|
rsAPI api.FederationRoomserverAPI,
|
||||||
statistics *statistics.Statistics,
|
statistics *statistics.Statistics,
|
||||||
signing []*gomatrixserverlib.SigningIdentity,
|
signing []*fclient.SigningIdentity,
|
||||||
) *OutgoingQueues {
|
) *OutgoingQueues {
|
||||||
queues := &OutgoingQueues{
|
queues := &OutgoingQueues{
|
||||||
disabled: disabled,
|
disabled: disabled,
|
||||||
@ -100,7 +101,7 @@ func NewOutgoingQueues(
|
|||||||
origin: origin,
|
origin: origin,
|
||||||
client: client,
|
client: client,
|
||||||
statistics: statistics,
|
statistics: statistics,
|
||||||
signing: map[gomatrixserverlib.ServerName]*gomatrixserverlib.SigningIdentity{},
|
signing: map[gomatrixserverlib.ServerName]*fclient.SigningIdentity{},
|
||||||
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
|
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
|
||||||
}
|
}
|
||||||
for _, identity := range signing {
|
for _, identity := range signing {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/test/testrig"
|
"github.com/matrix-org/dendrite/test/testrig"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"gotest.tools/v3/poll"
|
"gotest.tools/v3/poll"
|
||||||
|
|
||||||
@ -80,24 +81,24 @@ type stubFederationClient struct {
|
|||||||
txRelayCount atomic.Uint32
|
txRelayCount atomic.Uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *stubFederationClient) SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res gomatrixserverlib.RespSend, err error) {
|
func (f *stubFederationClient) SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res fclient.RespSend, err error) {
|
||||||
var result error
|
var result error
|
||||||
if !f.shouldTxSucceed {
|
if !f.shouldTxSucceed {
|
||||||
result = fmt.Errorf("transaction failed")
|
result = fmt.Errorf("transaction failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
f.txCount.Add(1)
|
f.txCount.Add(1)
|
||||||
return gomatrixserverlib.RespSend{}, result
|
return fclient.RespSend{}, result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u gomatrixserverlib.UserID, t gomatrixserverlib.Transaction, forwardingServer gomatrixserverlib.ServerName) (res gomatrixserverlib.EmptyResp, err error) {
|
func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u gomatrixserverlib.UserID, t gomatrixserverlib.Transaction, forwardingServer gomatrixserverlib.ServerName) (res fclient.EmptyResp, err error) {
|
||||||
var result error
|
var result error
|
||||||
if !f.shouldTxRelaySucceed {
|
if !f.shouldTxRelaySucceed {
|
||||||
result = fmt.Errorf("relay transaction failed")
|
result = fmt.Errorf("relay transaction failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
f.txRelayCount.Add(1)
|
f.txRelayCount.Add(1)
|
||||||
return gomatrixserverlib.EmptyResp{}, result
|
return fclient.EmptyResp{}, result
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent {
|
func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent {
|
||||||
@ -127,7 +128,7 @@ func testSetup(failuresUntilBlacklist uint32, failuresUntilAssumedOffline uint32
|
|||||||
rs := &stubFederationRoomServerAPI{}
|
rs := &stubFederationRoomServerAPI{}
|
||||||
|
|
||||||
stats := statistics.NewStatistics(db, failuresUntilBlacklist, failuresUntilAssumedOffline)
|
stats := statistics.NewStatistics(db, failuresUntilBlacklist, failuresUntilAssumedOffline)
|
||||||
signingInfo := []*gomatrixserverlib.SigningIdentity{
|
signingInfo := []*fclient.SigningIdentity{
|
||||||
{
|
{
|
||||||
KeyID: "ed21019:auto",
|
KeyID: "ed21019:auto",
|
||||||
PrivateKey: test.PrivateKeyA,
|
PrivateKey: test.PrivateKeyA,
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
@ -53,10 +54,10 @@ func GetUserDevices(
|
|||||||
return jsonerror.InternalAPIError(req.Context(), err)
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := gomatrixserverlib.RespUserDevices{
|
response := fclient.RespUserDevices{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
StreamID: res.StreamID,
|
StreamID: res.StreamID,
|
||||||
Devices: []gomatrixserverlib.RespUserDevice{},
|
Devices: []fclient.RespUserDevice{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if masterKey, ok := sigRes.MasterKeys[userID]; ok {
|
if masterKey, ok := sigRes.MasterKeys[userID]; ok {
|
||||||
@ -67,7 +68,7 @@ func GetUserDevices(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, dev := range res.Devices {
|
for _, dev := range res.Devices {
|
||||||
var key gomatrixserverlib.RespUserDeviceKeys
|
var key fclient.RespUserDeviceKeys
|
||||||
err := json.Unmarshal(dev.DeviceKeys.KeyJSON, &key)
|
err := json.Unmarshal(dev.DeviceKeys.KeyJSON, &key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(req.Context()).WithError(err).Warnf("malformed device key: %s", string(dev.DeviceKeys.KeyJSON))
|
util.GetLogger(req.Context()).WithError(err).Warnf("malformed device key: %s", string(dev.DeviceKeys.KeyJSON))
|
||||||
@ -79,7 +80,7 @@ func GetUserDevices(
|
|||||||
displayName = gjson.GetBytes(dev.DeviceKeys.KeyJSON, "unsigned.device_display_name").Str
|
displayName = gjson.GetBytes(dev.DeviceKeys.KeyJSON, "unsigned.device_display_name").Str
|
||||||
}
|
}
|
||||||
|
|
||||||
device := gomatrixserverlib.RespUserDevice{
|
device := fclient.RespUserDevice{
|
||||||
DeviceID: dev.DeviceID,
|
DeviceID: dev.DeviceID,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
Keys: key,
|
Keys: key,
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ func GetEventAuth(
|
|||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespEventAuth{
|
JSON: fclient.RespEventAuth{
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
roomserverVersion "github.com/matrix-org/dendrite/roomserver/version"
|
roomserverVersion "github.com/matrix-org/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -218,12 +219,12 @@ func processInvite(
|
|||||||
if isInviteV2 {
|
if isInviteV2 {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespInviteV2{Event: signedEvent.JSON()},
|
JSON: fclient.RespInviteV2{Event: signedEvent.JSON()},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespInvite{Event: signedEvent.JSON()},
|
JSON: fclient.RespInvite{Event: signedEvent.JSON()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -433,7 +434,7 @@ func SendJoin(
|
|||||||
// https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid
|
// https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespSendJoin{
|
JSON: fclient.RespSendJoin{
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
||||||
Origin: cfg.Matrix.ServerName,
|
Origin: cfg.Matrix.ServerName,
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
@ -144,7 +145,7 @@ func LocalKeys(cfg *config.FederationAPI, serverName gomatrixserverlib.ServerNam
|
|||||||
|
|
||||||
func localKeys(cfg *config.FederationAPI, serverName gomatrixserverlib.ServerName) (*gomatrixserverlib.ServerKeys, error) {
|
func localKeys(cfg *config.FederationAPI, serverName gomatrixserverlib.ServerName) (*gomatrixserverlib.ServerKeys, error) {
|
||||||
var keys gomatrixserverlib.ServerKeys
|
var keys gomatrixserverlib.ServerKeys
|
||||||
var identity *gomatrixserverlib.SigningIdentity
|
var identity *fclient.SigningIdentity
|
||||||
var err error
|
var err error
|
||||||
if virtualHost := cfg.Matrix.VirtualHostForHTTPHost(serverName); virtualHost == nil {
|
if virtualHost := cfg.Matrix.VirtualHostForHTTPHost(serverName); virtualHost == nil {
|
||||||
if identity, err = cfg.Matrix.SigningIdentityFor(cfg.Matrix.ServerName); err != nil {
|
if identity, err = cfg.Matrix.SigningIdentityFor(cfg.Matrix.ServerName); err != nil {
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ func GetMissingEvents(
|
|||||||
|
|
||||||
eventsResponse.Events = filterEvents(eventsResponse.Events, roomID)
|
eventsResponse.Events = filterEvents(eventsResponse.Events, roomID)
|
||||||
|
|
||||||
resp := gomatrixserverlib.RespMissingEvents{
|
resp := fclient.RespMissingEvents{
|
||||||
Events: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(eventsResponse.Events),
|
Events: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(eventsResponse.Events),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ func Peek(
|
|||||||
return util.JSONResponse{Code: http.StatusNotFound, JSON: nil}
|
return util.JSONResponse{Code: http.StatusNotFound, JSON: nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
respPeek := gomatrixserverlib.RespPeek{
|
respPeek := fclient.RespPeek{
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
||||||
RoomVersion: response.RoomVersion,
|
RoomVersion: response.RoomVersion,
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
@ -48,9 +49,9 @@ func GetPostPublicRooms(req *http.Request, rsAPI roomserverAPI.FederationRoomser
|
|||||||
|
|
||||||
func publicRooms(
|
func publicRooms(
|
||||||
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.FederationRoomserverAPI,
|
ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||||
) (*gomatrixserverlib.RespPublicRooms, error) {
|
) (*fclient.RespPublicRooms, error) {
|
||||||
|
|
||||||
var response gomatrixserverlib.RespPublicRooms
|
var response fclient.RespPublicRooms
|
||||||
var limit int16
|
var limit int16
|
||||||
var offset int64
|
var offset int64
|
||||||
limit = request.Limit
|
limit = request.Limit
|
||||||
@ -122,7 +123,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// due to lots of switches
|
// due to lots of switches
|
||||||
func fillInRooms(ctx context.Context, roomIDs []string, rsAPI roomserverAPI.FederationRoomserverAPI) ([]gomatrixserverlib.PublicRoom, error) {
|
func fillInRooms(ctx context.Context, roomIDs []string, rsAPI roomserverAPI.FederationRoomserverAPI) ([]fclient.PublicRoom, error) {
|
||||||
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
||||||
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
||||||
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
||||||
@ -144,10 +145,10 @@ func fillInRooms(ctx context.Context, roomIDs []string, rsAPI roomserverAPI.Fede
|
|||||||
util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
|
util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chunk := make([]gomatrixserverlib.PublicRoom, len(roomIDs))
|
chunk := make([]fclient.PublicRoom, len(roomIDs))
|
||||||
i := 0
|
i := 0
|
||||||
for roomID, data := range stateRes.Rooms {
|
for roomID, data := range stateRes.Rooms {
|
||||||
pub := gomatrixserverlib.PublicRoom{
|
pub := fclient.PublicRoom{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
}
|
}
|
||||||
joinCount := 0
|
joinCount := 0
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ func RoomAliasToID(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp gomatrixserverlib.RespDirectory
|
var resp fclient.RespDirectory
|
||||||
|
|
||||||
if domain == cfg.Matrix.ServerName {
|
if domain == cfg.Matrix.ServerName {
|
||||||
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
|
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
|
||||||
@ -71,7 +72,7 @@ func RoomAliasToID(
|
|||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = gomatrixserverlib.RespDirectory{
|
resp = fclient.RespDirectory{
|
||||||
RoomID: queryRes.RoomID,
|
RoomID: queryRes.RoomID,
|
||||||
Servers: serverQueryRes.ServerNames,
|
Servers: serverQueryRes.ServerNames,
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/dendrite/test/testrig"
|
"github.com/matrix-org/dendrite/test/testrig"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
@ -43,7 +44,7 @@ type fakeFedClient struct {
|
|||||||
fedclient.FederationClient
|
fedclient.FederationClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res gomatrixserverlib.RespDirectory, err error) {
|
func (f *fakeFedClient) LookupRoomAlias(ctx context.Context, origin, s gomatrixserverlib.ServerName, roomAlias string) (res fclient.RespDirectory, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func GetState(
|
|||||||
return *err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &gomatrixserverlib.RespState{
|
return util.JSONResponse{Code: http.StatusOK, JSON: &fclient.RespState{
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(authChain),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(authChain),
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateEvents),
|
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateEvents),
|
||||||
}}
|
}}
|
||||||
@ -66,7 +67,7 @@ func GetStateIDs(
|
|||||||
stateEventIDs := getIDsFromEvent(stateEvents)
|
stateEventIDs := getIDsFromEvent(stateEvents)
|
||||||
authEventIDs := getIDsFromEvent(authEvents)
|
authEventIDs := getIDsFromEvent(authEvents)
|
||||||
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: gomatrixserverlib.RespStateIDs{
|
return util.JSONResponse{Code: http.StatusOK, JSON: fclient.RespStateIDs{
|
||||||
StateEventIDs: stateEventIDs,
|
StateEventIDs: stateEventIDs,
|
||||||
AuthEventIDs: authEventIDs,
|
AuthEventIDs: authEventIDs,
|
||||||
},
|
},
|
||||||
|
2
go.mod
2
go.mod
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230320105331-4dd7ff2f0e3a
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230405171344-5f597d85ba4f
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
|
2
go.sum
2
go.sum
@ -323,6 +323,8 @@ github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8
|
|||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230320105331-4dd7ff2f0e3a h1:F6K1i61KcJ8cX/y0Q8/44Dh1w+fpESQd92gq885FDrI=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230320105331-4dd7ff2f0e3a h1:F6K1i61KcJ8cX/y0Q8/44Dh1w+fpESQd92gq885FDrI=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230320105331-4dd7ff2f0e3a/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230320105331-4dd7ff2f0e3a/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230405171344-5f597d85ba4f h1:D7IgZA2DxBroqCTxo2uXEmjj8eCI1OzqqKRE4SAgmBU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230405171344-5f597d85ba4f/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package caching
|
package caching
|
||||||
|
|
||||||
import (
|
import "github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SpaceSummaryRoomsCache interface {
|
type SpaceSummaryRoomsCache interface {
|
||||||
GetSpaceSummary(roomID string) (r gomatrixserverlib.MSC2946SpacesResponse, ok bool)
|
GetSpaceSummary(roomID string) (r fclient.MSC2946SpacesResponse, ok bool)
|
||||||
StoreSpaceSummary(roomID string, r gomatrixserverlib.MSC2946SpacesResponse)
|
StoreSpaceSummary(roomID string, r fclient.MSC2946SpacesResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) GetSpaceSummary(roomID string) (r gomatrixserverlib.MSC2946SpacesResponse, ok bool) {
|
func (c Caches) GetSpaceSummary(roomID string) (r fclient.MSC2946SpacesResponse, ok bool) {
|
||||||
return c.SpaceSummaryRooms.Get(roomID)
|
return c.SpaceSummaryRooms.Get(roomID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) StoreSpaceSummary(roomID string, r gomatrixserverlib.MSC2946SpacesResponse) {
|
func (c Caches) StoreSpaceSummary(roomID string, r fclient.MSC2946SpacesResponse) {
|
||||||
c.SpaceSummaryRooms.Set(roomID, r)
|
c.SpaceSummaryRooms.Set(roomID, r)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ package caching
|
|||||||
import (
|
import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Caches contains a set of references to caches. They may be
|
// Caches contains a set of references to caches. They may be
|
||||||
@ -34,7 +35,7 @@ type Caches struct {
|
|||||||
RoomServerEventTypes Cache[types.EventTypeNID, string] // eventType NID -> eventType
|
RoomServerEventTypes Cache[types.EventTypeNID, string] // eventType NID -> eventType
|
||||||
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
|
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
|
||||||
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
||||||
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse] // room ID -> space response
|
SpaceSummaryRooms Cache[string, fclient.MSC2946SpacesResponse] // room ID -> space response
|
||||||
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/dgraph-io/ristretto"
|
"github.com/dgraph-io/ristretto"
|
||||||
"github.com/dgraph-io/ristretto/z"
|
"github.com/dgraph-io/ristretto/z"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
|||||||
MaxAge: lesserOf(time.Hour/2, maxAge),
|
MaxAge: lesserOf(time.Hour/2, maxAge),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
SpaceSummaryRooms: &RistrettoCachePartition[string, gomatrixserverlib.MSC2946SpacesResponse]{ // room ID -> space response
|
SpaceSummaryRooms: &RistrettoCachePartition[string, fclient.MSC2946SpacesResponse]{ // room ID -> space response
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: spaceSummaryRoomsCache,
|
Prefix: spaceSummaryRoomsCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
@ -39,7 +40,7 @@ var ErrRoomNoExists = errors.New("room does not exist")
|
|||||||
func QueryAndBuildEvent(
|
func QueryAndBuildEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
||||||
identity *gomatrixserverlib.SigningIdentity, evTime time.Time,
|
identity *fclient.SigningIdentity, evTime time.Time,
|
||||||
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
if queryRes == nil {
|
if queryRes == nil {
|
||||||
@ -59,7 +60,7 @@ func QueryAndBuildEvent(
|
|||||||
func BuildEvent(
|
func BuildEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
||||||
identity *gomatrixserverlib.SigningIdentity, evTime time.Time,
|
identity *fclient.SigningIdentity, evTime time.Time,
|
||||||
eventsNeeded *gomatrixserverlib.StateNeeded, queryRes *api.QueryLatestEventsAndStateResponse,
|
eventsNeeded *gomatrixserverlib.StateNeeded, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
if err := addPrevEventsToEvent(builder, eventsNeeded, queryRes); err != nil {
|
if err := addPrevEventsToEvent(builder, eventsNeeded, queryRes); err != nil {
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
syncTypes "github.com/matrix-org/dendrite/syncapi/types"
|
syncTypes "github.com/matrix-org/dendrite/syncapi/types"
|
||||||
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -97,7 +98,7 @@ func NewTxnReq(
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxnReq) ProcessTransaction(ctx context.Context) (*gomatrixserverlib.RespSend, *util.JSONResponse) {
|
func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *util.JSONResponse) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
@ -107,7 +108,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*gomatrixserverlib.Res
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
results := make(map[string]gomatrixserverlib.PDUResult)
|
results := make(map[string]fclient.PDUResult)
|
||||||
roomVersions := make(map[string]gomatrixserverlib.RoomVersion)
|
roomVersions := make(map[string]gomatrixserverlib.RoomVersion)
|
||||||
getRoomVersion := func(roomID string) gomatrixserverlib.RoomVersion {
|
getRoomVersion := func(roomID string) gomatrixserverlib.RoomVersion {
|
||||||
if v, ok := roomVersions[roomID]; ok {
|
if v, ok := roomVersions[roomID]; ok {
|
||||||
@ -157,14 +158,14 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*gomatrixserverlib.Res
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if api.IsServerBannedFromRoom(ctx, t.rsAPI, event.RoomID(), t.Origin) {
|
if api.IsServerBannedFromRoom(ctx, t.rsAPI, event.RoomID(), t.Origin) {
|
||||||
results[event.EventID()] = gomatrixserverlib.PDUResult{
|
results[event.EventID()] = fclient.PDUResult{
|
||||||
Error: "Forbidden by server ACLs",
|
Error: "Forbidden by server ACLs",
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err = event.VerifyEventSignatures(ctx, t.keys); err != nil {
|
if err = event.VerifyEventSignatures(ctx, t.keys); err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Debugf("Transaction: Couldn't validate signature of event %q", event.EventID())
|
util.GetLogger(ctx).WithError(err).Debugf("Transaction: Couldn't validate signature of event %q", event.EventID())
|
||||||
results[event.EventID()] = gomatrixserverlib.PDUResult{
|
results[event.EventID()] = fclient.PDUResult{
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -187,18 +188,18 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*gomatrixserverlib.Res
|
|||||||
true,
|
true,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Errorf("Transaction: Couldn't submit event %q to input queue: %s", event.EventID(), err)
|
util.GetLogger(ctx).WithError(err).Errorf("Transaction: Couldn't submit event %q to input queue: %s", event.EventID(), err)
|
||||||
results[event.EventID()] = gomatrixserverlib.PDUResult{
|
results[event.EventID()] = fclient.PDUResult{
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
results[event.EventID()] = gomatrixserverlib.PDUResult{}
|
results[event.EventID()] = fclient.PDUResult{}
|
||||||
PDUCountTotal.WithLabelValues("success").Inc()
|
PDUCountTotal.WithLabelValues("success").Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return &gomatrixserverlib.RespSend{PDUs: results}, nil
|
return &fclient.RespSend{PDUs: results}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/mediaapi/storage"
|
"github.com/matrix-org/dendrite/mediaapi/storage"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func AddPublicRoutes(
|
|||||||
cm sqlutil.Connections,
|
cm sqlutil.Connections,
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
userAPI userapi.MediaUserAPI,
|
userAPI userapi.MediaUserAPI,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
) {
|
) {
|
||||||
mediaDB, err := storage.NewMediaAPIDatasource(cm, &cfg.MediaAPI.Database)
|
mediaDB, err := storage.NewMediaAPIDatasource(cm, &cfg.MediaAPI.Database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/mediaapi/types"
|
"github.com/matrix-org/dendrite/mediaapi/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -75,7 +76,7 @@ func Download(
|
|||||||
mediaID types.MediaID,
|
mediaID types.MediaID,
|
||||||
cfg *config.MediaAPI,
|
cfg *config.MediaAPI,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
activeRemoteRequests *types.ActiveRemoteRequests,
|
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||||
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
||||||
isThumbnailRequest bool,
|
isThumbnailRequest bool,
|
||||||
@ -205,7 +206,7 @@ func (r *downloadRequest) doDownload(
|
|||||||
w http.ResponseWriter,
|
w http.ResponseWriter,
|
||||||
cfg *config.MediaAPI,
|
cfg *config.MediaAPI,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
activeRemoteRequests *types.ActiveRemoteRequests,
|
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||||
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
||||||
) (*types.MediaMetadata, error) {
|
) (*types.MediaMetadata, error) {
|
||||||
@ -513,7 +514,7 @@ func (r *downloadRequest) generateThumbnail(
|
|||||||
// Note: The named errorResponse return variable is used in a deferred broadcast of the metadata and error response to waiting goroutines.
|
// Note: The named errorResponse return variable is used in a deferred broadcast of the metadata and error response to waiting goroutines.
|
||||||
func (r *downloadRequest) getRemoteFile(
|
func (r *downloadRequest) getRemoteFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
cfg *config.MediaAPI,
|
cfg *config.MediaAPI,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
activeRemoteRequests *types.ActiveRemoteRequests,
|
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||||
@ -615,7 +616,7 @@ func (r *downloadRequest) broadcastMediaMetadata(activeRemoteRequests *types.Act
|
|||||||
// fetchRemoteFileAndStoreMetadata fetches the file from the remote server and stores its metadata in the database
|
// fetchRemoteFileAndStoreMetadata fetches the file from the remote server and stores its metadata in the database
|
||||||
func (r *downloadRequest) fetchRemoteFileAndStoreMetadata(
|
func (r *downloadRequest) fetchRemoteFileAndStoreMetadata(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
absBasePath config.Path,
|
absBasePath config.Path,
|
||||||
maxFileSizeBytes config.FileSizeBytes,
|
maxFileSizeBytes config.FileSizeBytes,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
@ -713,7 +714,7 @@ func (r *downloadRequest) GetContentLengthAndReader(contentLengthHeader string,
|
|||||||
|
|
||||||
func (r *downloadRequest) fetchRemoteFile(
|
func (r *downloadRequest) fetchRemoteFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
absBasePath config.Path,
|
absBasePath config.Path,
|
||||||
maxFileSizeBytes config.FileSizeBytes,
|
maxFileSizeBytes config.FileSizeBytes,
|
||||||
) (types.Path, bool, error) {
|
) (types.Path, bool, error) {
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
@ -48,7 +49,7 @@ func Setup(
|
|||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
userAPI userapi.MediaUserAPI,
|
userAPI userapi.MediaUserAPI,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
) {
|
) {
|
||||||
rateLimits := httputil.NewRateLimits(&cfg.ClientAPI.RateLimiting)
|
rateLimits := httputil.NewRateLimits(&cfg.ClientAPI.RateLimiting)
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ func makeDownloadAPI(
|
|||||||
cfg *config.MediaAPI,
|
cfg *config.MediaAPI,
|
||||||
rateLimits *httputil.RateLimits,
|
rateLimits *httputil.RateLimits,
|
||||||
db storage.Database,
|
db storage.Database,
|
||||||
client *gomatrixserverlib.Client,
|
client *fclient.Client,
|
||||||
activeRemoteRequests *types.ActiveRemoteRequests,
|
activeRemoteRequests *types.ActiveRemoteRequests,
|
||||||
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
activeThumbnailGeneration *types.ActiveThumbnailGeneration,
|
||||||
) http.HandlerFunc {
|
) http.HandlerFunc {
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RelayInternalAPI is used to query information from the relay server.
|
// RelayInternalAPI is used to query information from the relay server.
|
||||||
@ -51,7 +52,7 @@ type RelayServerAPI interface {
|
|||||||
QueryTransactions(
|
QueryTransactions(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
userID gomatrixserverlib.UserID,
|
userID gomatrixserverlib.UserID,
|
||||||
previousEntry gomatrixserverlib.RelayEntry,
|
previousEntry fclient.RelayEntry,
|
||||||
) (QueryRelayTransactionsResponse, error)
|
) (QueryRelayTransactionsResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/relayapi/api"
|
"github.com/matrix-org/dendrite/relayapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||||||
) error {
|
) error {
|
||||||
// Providing a default RelayEntry (EntryID = 0) is done to ask the relay if there are any
|
// Providing a default RelayEntry (EntryID = 0) is done to ask the relay if there are any
|
||||||
// transactions available for this node.
|
// transactions available for this node.
|
||||||
prevEntry := gomatrixserverlib.RelayEntry{}
|
prevEntry := fclient.RelayEntry{}
|
||||||
asyncResponse, err := r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
asyncResponse, err := r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||||
@ -54,12 +55,12 @@ func (r *RelayInternalAPI) PerformRelayServerSync(
|
|||||||
}
|
}
|
||||||
r.processTransaction(&asyncResponse.Transaction)
|
r.processTransaction(&asyncResponse.Transaction)
|
||||||
|
|
||||||
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
prevEntry = fclient.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||||
for asyncResponse.EntriesQueued {
|
for asyncResponse.EntriesQueued {
|
||||||
// There are still more entries available for this node from the relay.
|
// There are still more entries available for this node from the relay.
|
||||||
logrus.Infof("Retrieving next entry from relay, previous: %v", prevEntry)
|
logrus.Infof("Retrieving next entry from relay, previous: %v", prevEntry)
|
||||||
asyncResponse, err = r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
asyncResponse, err = r.fedClient.P2PGetTransactionFromRelay(ctx, userID, prevEntry, relayServer)
|
||||||
prevEntry = gomatrixserverlib.RelayEntry{EntryID: asyncResponse.EntryID}
|
prevEntry = fclient.RelayEntry{EntryID: asyncResponse.EntryID}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
logrus.Errorf("P2PGetTransactionFromRelay: %s", err.Error())
|
||||||
return err
|
return err
|
||||||
@ -97,7 +98,7 @@ func (r *RelayInternalAPI) PerformStoreTransaction(
|
|||||||
func (r *RelayInternalAPI) QueryTransactions(
|
func (r *RelayInternalAPI) QueryTransactions(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
userID gomatrixserverlib.UserID,
|
userID gomatrixserverlib.UserID,
|
||||||
previousEntry gomatrixserverlib.RelayEntry,
|
previousEntry fclient.RelayEntry,
|
||||||
) (api.QueryRelayTransactionsResponse, error) {
|
) (api.QueryRelayTransactionsResponse, error) {
|
||||||
logrus.Infof("QueryTransactions for %s", userID.Raw())
|
logrus.Infof("QueryTransactions for %s", userID.Raw())
|
||||||
if previousEntry.EntryID > 0 {
|
if previousEntry.EntryID > 0 {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/relayapi/storage/shared"
|
"github.com/matrix-org/dendrite/relayapi/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,15 +38,15 @@ type testFedClient struct {
|
|||||||
func (f *testFedClient) P2PGetTransactionFromRelay(
|
func (f *testFedClient) P2PGetTransactionFromRelay(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
u gomatrixserverlib.UserID,
|
u gomatrixserverlib.UserID,
|
||||||
prev gomatrixserverlib.RelayEntry,
|
prev fclient.RelayEntry,
|
||||||
relayServer gomatrixserverlib.ServerName,
|
relayServer gomatrixserverlib.ServerName,
|
||||||
) (res gomatrixserverlib.RespGetRelayTransaction, err error) {
|
) (res fclient.RespGetRelayTransaction, err error) {
|
||||||
f.queryCount++
|
f.queryCount++
|
||||||
if f.shouldFail {
|
if f.shouldFail {
|
||||||
return res, fmt.Errorf("Error")
|
return res, fmt.Errorf("Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
res = gomatrixserverlib.RespGetRelayTransaction{
|
res = fclient.RespGetRelayTransaction{
|
||||||
Transaction: gomatrixserverlib.Transaction{},
|
Transaction: gomatrixserverlib.Transaction{},
|
||||||
EntryID: 0,
|
EntryID: 0,
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
|
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ func AddPublicRoutes(
|
|||||||
func NewRelayInternalAPI(
|
func NewRelayInternalAPI(
|
||||||
dendriteCfg *config.Dendrite,
|
dendriteCfg *config.Dendrite,
|
||||||
cm sqlutil.Connections,
|
cm sqlutil.Connections,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *fclient.FederationClient,
|
||||||
rsAPI rsAPI.RoomserverInternalAPI,
|
rsAPI rsAPI.RoomserverInternalAPI,
|
||||||
keyRing *gomatrixserverlib.KeyRing,
|
keyRing *gomatrixserverlib.KeyRing,
|
||||||
producer *producers.SyncAPIProducer,
|
producer *producers.SyncAPIProducer,
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/dendrite/test/testrig"
|
"github.com/matrix-org/dendrite/test/testrig"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ func createGetRelayTxnHTTPRequest(serverName gomatrixserverlib.ServerName, userI
|
|||||||
pk := sk.Public().(ed25519.PublicKey)
|
pk := sk.Public().(ed25519.PublicKey)
|
||||||
origin := gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
origin := gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
||||||
req := gomatrixserverlib.NewFederationRequest("GET", origin, serverName, "/_matrix/federation/v1/relay_txn/"+userID)
|
req := gomatrixserverlib.NewFederationRequest("GET", origin, serverName, "/_matrix/federation/v1/relay_txn/"+userID)
|
||||||
content := gomatrixserverlib.RelayEntry{EntryID: 0}
|
content := fclient.RelayEntry{EntryID: 0}
|
||||||
req.SetContent(content)
|
req.SetContent(content)
|
||||||
req.Sign(origin, gomatrixserverlib.KeyID(keyID), sk)
|
req.Sign(origin, gomatrixserverlib.KeyID(keyID), sk)
|
||||||
httpreq, _ := req.HTTPRequest()
|
httpreq, _ := req.HTTPRequest()
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/relayapi/api"
|
"github.com/matrix-org/dendrite/relayapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -35,7 +36,7 @@ func GetTransactionFromRelay(
|
|||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
||||||
|
|
||||||
var previousEntry gomatrixserverlib.RelayEntry
|
var previousEntry fclient.RelayEntry
|
||||||
if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil {
|
if err := json.Unmarshal(fedReq.Content(), &previousEntry); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusInternalServerError,
|
Code: http.StatusInternalServerError,
|
||||||
@ -59,7 +60,7 @@ func GetTransactionFromRelay(
|
|||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: gomatrixserverlib.RespGetRelayTransaction{
|
JSON: fclient.RespGetRelayTransaction{
|
||||||
Transaction: response.Transaction,
|
Transaction: response.Transaction,
|
||||||
EntryID: response.EntryID,
|
EntryID: response.EntryID,
|
||||||
EntriesQueued: response.EntriesQueued,
|
EntriesQueued: response.EntriesQueued,
|
||||||
|
@ -25,12 +25,13 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/relayapi/storage/shared"
|
"github.com/matrix-org/dendrite/relayapi/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createQuery(
|
func createQuery(
|
||||||
userID gomatrixserverlib.UserID,
|
userID gomatrixserverlib.UserID,
|
||||||
prevEntry gomatrixserverlib.RelayEntry,
|
prevEntry fclient.RelayEntry,
|
||||||
) gomatrixserverlib.FederationRequest {
|
) gomatrixserverlib.FederationRequest {
|
||||||
var federationPathPrefixV1 = "/_matrix/federation/v1"
|
var federationPathPrefixV1 = "/_matrix/federation/v1"
|
||||||
path := federationPathPrefixV1 + "/relay_txn/" + userID.Raw()
|
path := federationPathPrefixV1 + "/relay_txn/" + userID.Raw()
|
||||||
@ -60,11 +61,11 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) {
|
|||||||
&db, nil, nil, nil, nil, false, "", true,
|
&db, nil, nil, nil, nil, false, "", true,
|
||||||
)
|
)
|
||||||
|
|
||||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
request := createQuery(*userID, fclient.RelayEntry{})
|
||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.Equal(t, false, jsonResponse.EntriesQueued)
|
assert.Equal(t, false, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ func TestGetInvalidPrevEntryFails(t *testing.T) {
|
|||||||
&db, nil, nil, nil, nil, false, "", true,
|
&db, nil, nil, nil, nil, false, "", true,
|
||||||
)
|
)
|
||||||
|
|
||||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: -1})
|
request := createQuery(*userID, fclient.RelayEntry{EntryID: -1})
|
||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusInternalServerError, response.Code)
|
assert.Equal(t, http.StatusInternalServerError, response.Code)
|
||||||
}
|
}
|
||||||
@ -126,20 +127,20 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||||||
&db, nil, nil, nil, nil, false, "", true,
|
&db, nil, nil, nil, nil, false, "", true,
|
||||||
)
|
)
|
||||||
|
|
||||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
request := createQuery(*userID, fclient.RelayEntry{})
|
||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||||
|
|
||||||
// And once more to clear the queue
|
// And once more to clear the queue
|
||||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.False(t, jsonResponse.EntriesQueued)
|
assert.False(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
@ -189,28 +190,28 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||||||
&db, nil, nil, nil, nil, false, "", true,
|
&db, nil, nil, nil, nil, false, "", true,
|
||||||
)
|
)
|
||||||
|
|
||||||
request := createQuery(*userID, gomatrixserverlib.RelayEntry{})
|
request := createQuery(*userID, fclient.RelayEntry{})
|
||||||
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response := routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse := response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse := response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction, jsonResponse.Transaction)
|
assert.Equal(t, transaction, jsonResponse.Transaction)
|
||||||
|
|
||||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.True(t, jsonResponse.EntriesQueued)
|
assert.True(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, transaction2, jsonResponse.Transaction)
|
assert.Equal(t, transaction2, jsonResponse.Transaction)
|
||||||
|
|
||||||
// And once more to clear the queue
|
// And once more to clear the queue
|
||||||
request = createQuery(*userID, gomatrixserverlib.RelayEntry{EntryID: jsonResponse.EntryID})
|
request = createQuery(*userID, fclient.RelayEntry{EntryID: jsonResponse.EntryID})
|
||||||
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
response = routing.GetTransactionFromRelay(httpReq, &request, relayAPI, *userID)
|
||||||
assert.Equal(t, http.StatusOK, response.Code)
|
assert.Equal(t, http.StatusOK, response.Code)
|
||||||
|
|
||||||
jsonResponse = response.JSON.(gomatrixserverlib.RespGetRelayTransaction)
|
jsonResponse = response.JSON.(fclient.RespGetRelayTransaction)
|
||||||
assert.False(t, jsonResponse.EntriesQueued)
|
assert.False(t, jsonResponse.EntriesQueued)
|
||||||
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
assert.Equal(t, gomatrixserverlib.Transaction{}, jsonResponse.Transaction)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/relayapi/api"
|
"github.com/matrix-org/dendrite/relayapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -36,7 +37,7 @@ func SendTransactionToRelay(
|
|||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
logrus.Infof("Processing send_relay for %s", userID.Raw())
|
logrus.Infof("Processing send_relay for %s", userID.Raw())
|
||||||
|
|
||||||
var txnEvents gomatrixserverlib.RelayEvents
|
var txnEvents fclient.RelayEvents
|
||||||
if err := json.Unmarshal(fedReq.Content(), &txnEvents); err != nil {
|
if err := json.Unmarshal(fedReq.Content(), &txnEvents); err != nil {
|
||||||
logrus.Info("The request body could not be decoded into valid JSON." + err.Error())
|
logrus.Info("The request body could not be decoded into valid JSON." + err.Error())
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -49,7 +50,7 @@ func SendEvents(
|
|||||||
func SendEventWithState(
|
func SendEventWithState(
|
||||||
ctx context.Context, rsAPI InputRoomEventsAPI,
|
ctx context.Context, rsAPI InputRoomEventsAPI,
|
||||||
virtualHost gomatrixserverlib.ServerName, kind Kind,
|
virtualHost gomatrixserverlib.ServerName, kind Kind,
|
||||||
state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent,
|
state *fclient.RespState, event *gomatrixserverlib.HeaderedEvent,
|
||||||
origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
|
origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
|
||||||
) error {
|
) error {
|
||||||
outliers := state.Events(event.RoomVersion)
|
outliers := state.Events(event.RoomVersion)
|
||||||
@ -159,7 +160,7 @@ func IsServerBannedFromRoom(ctx context.Context, rsAPI FederationRoomserverAPI,
|
|||||||
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
|
// PopulatePublicRooms extracts PublicRoom information for all the provided room IDs. The IDs are not checked to see if they are visible in the
|
||||||
// published room directory.
|
// published room directory.
|
||||||
// due to lots of switches
|
// due to lots of switches
|
||||||
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkStateContentAPI) ([]gomatrixserverlib.PublicRoom, error) {
|
func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkStateContentAPI) ([]fclient.PublicRoom, error) {
|
||||||
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
avatarTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.avatar", StateKey: ""}
|
||||||
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
nameTuple := gomatrixserverlib.StateKeyTuple{EventType: "m.room.name", StateKey: ""}
|
||||||
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
canonicalTuple := gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias, StateKey: ""}
|
||||||
@ -181,10 +182,10 @@ func PopulatePublicRooms(ctx context.Context, roomIDs []string, rsAPI QueryBulkS
|
|||||||
util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
|
util.GetLogger(ctx).WithError(err).Error("QueryBulkStateContent failed")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chunk := make([]gomatrixserverlib.PublicRoom, len(roomIDs))
|
chunk := make([]fclient.PublicRoom, len(roomIDs))
|
||||||
i := 0
|
i := 0
|
||||||
for roomID, data := range stateRes.Rooms {
|
for roomID, data := range stateRes.Rooms {
|
||||||
pub := gomatrixserverlib.PublicRoom{
|
pub := fclient.PublicRoom{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
}
|
}
|
||||||
joinCount := 0
|
joinCount := 0
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/Arceliar/phony"
|
"github.com/Arceliar/phony"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
@ -79,7 +80,7 @@ type Inputer struct {
|
|||||||
JetStream nats.JetStreamContext
|
JetStream nats.JetStreamContext
|
||||||
Durable nats.SubOpt
|
Durable nats.SubOpt
|
||||||
ServerName gomatrixserverlib.ServerName
|
ServerName gomatrixserverlib.ServerName
|
||||||
SigningIdentity *gomatrixserverlib.SigningIdentity
|
SigningIdentity *fclient.SigningIdentity
|
||||||
FSAPI fedapi.RoomserverFederationAPI
|
FSAPI fedapi.RoomserverFederationAPI
|
||||||
KeyRing gomatrixserverlib.JSONVerifier
|
KeyRing gomatrixserverlib.JSONVerifier
|
||||||
ACLs *acls.ServerACLs
|
ACLs *acls.ServerACLs
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -646,7 +647,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var res gomatrixserverlib.RespEventAuth
|
var res fclient.RespEventAuth
|
||||||
var found bool
|
var found bool
|
||||||
for _, serverName := range servers {
|
for _, serverName := range servers {
|
||||||
// Request the entire auth chain for the event in question. This should
|
// Request the entire auth chain for the event in question. This should
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -517,10 +518,10 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserve
|
|||||||
t.hadEvent(ev.EventID)
|
t.hadEvent(ev.EventID)
|
||||||
}
|
}
|
||||||
|
|
||||||
var missingResp *gomatrixserverlib.RespMissingEvents
|
var missingResp *fclient.RespMissingEvents
|
||||||
for _, server := range t.servers {
|
for _, server := range t.servers {
|
||||||
var m gomatrixserverlib.RespMissingEvents
|
var m fclient.RespMissingEvents
|
||||||
if m, err = t.federation.LookupMissingEvents(ctx, t.virtualHost, server, e.RoomID(), gomatrixserverlib.MissingEvents{
|
if m, err = t.federation.LookupMissingEvents(ctx, t.virtualHost, server, e.RoomID(), fclient.MissingEvents{
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
// The latest event IDs that the sender already has. These are skipped when retrieving the previous events of latest_events.
|
// The latest event IDs that the sender already has. These are skipped when retrieving the previous events of latest_events.
|
||||||
EarliestEvents: latestEvents,
|
EarliestEvents: latestEvents,
|
||||||
@ -640,8 +641,12 @@ func (t *missingStateReq) lookupMissingStateViaState(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
s := fclient.RespState{
|
||||||
|
StateEvents: state.GetStateEvents(),
|
||||||
|
AuthEvents: state.GetAuthEvents(),
|
||||||
|
}
|
||||||
// Check that the returned state is valid.
|
// Check that the returned state is valid.
|
||||||
authEvents, stateEvents, err := state.Check(ctx, roomVersion, t.keys, nil)
|
authEvents, stateEvents, err := s.Check(ctx, roomVersion, t.keys, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -652,11 +657,11 @@ func (t *missingStateReq) lookupMissingStateViaState(
|
|||||||
// Cache the results of this state lookup and deduplicate anything we already
|
// Cache the results of this state lookup and deduplicate anything we already
|
||||||
// have in the cache, freeing up memory.
|
// have in the cache, freeing up memory.
|
||||||
// We load these as trusted as we called state.Check before which loaded them as untrusted.
|
// We load these as trusted as we called state.Check before which loaded them as untrusted.
|
||||||
for i, evJSON := range state.AuthEvents {
|
for i, evJSON := range s.AuthEvents {
|
||||||
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
|
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
|
||||||
parsedState.AuthEvents[i] = t.cacheAndReturn(ev)
|
parsedState.AuthEvents[i] = t.cacheAndReturn(ev)
|
||||||
}
|
}
|
||||||
for i, evJSON := range state.StateEvents {
|
for i, evJSON := range s.StateEvents {
|
||||||
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
|
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
|
||||||
parsedState.StateEvents[i] = t.cacheAndReturn(ev)
|
parsedState.StateEvents[i] = t.cacheAndReturn(ev)
|
||||||
}
|
}
|
||||||
@ -670,7 +675,7 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
|
|
||||||
t.log.Infof("lookupMissingStateViaStateIDs %s", eventID)
|
t.log.Infof("lookupMissingStateViaStateIDs %s", eventID)
|
||||||
// fetch the state event IDs at the time of the event
|
// fetch the state event IDs at the time of the event
|
||||||
var stateIDs gomatrixserverlib.RespStateIDs
|
var stateIDs gomatrixserverlib.StateIDResponse
|
||||||
var err error
|
var err error
|
||||||
count := 0
|
count := 0
|
||||||
totalctx, totalcancel := context.WithTimeout(ctx, time.Minute*5)
|
totalctx, totalcancel := context.WithTimeout(ctx, time.Minute*5)
|
||||||
@ -688,7 +693,7 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
return nil, fmt.Errorf("t.federation.LookupStateIDs tried %d server(s), last error: %w", count, err)
|
return nil, fmt.Errorf("t.federation.LookupStateIDs tried %d server(s), last error: %w", count, err)
|
||||||
}
|
}
|
||||||
// work out which auth/state IDs are missing
|
// work out which auth/state IDs are missing
|
||||||
wantIDs := append(stateIDs.StateEventIDs, stateIDs.AuthEventIDs...)
|
wantIDs := append(stateIDs.GetStateEventIDs(), stateIDs.GetAuthEventIDs()...)
|
||||||
missing := make(map[string]bool)
|
missing := make(map[string]bool)
|
||||||
var missingEventList []string
|
var missingEventList []string
|
||||||
t.haveEventsMutex.Lock()
|
t.haveEventsMutex.Lock()
|
||||||
@ -730,8 +735,8 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
t.log.WithFields(logrus.Fields{
|
t.log.WithFields(logrus.Fields{
|
||||||
"missing": missingCount,
|
"missing": missingCount,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"total_state": len(stateIDs.StateEventIDs),
|
"total_state": len(stateIDs.GetStateEventIDs()),
|
||||||
"total_auth_events": len(stateIDs.AuthEventIDs),
|
"total_auth_events": len(stateIDs.GetAuthEventIDs()),
|
||||||
}).Debug("Fetching all state at event")
|
}).Debug("Fetching all state at event")
|
||||||
return t.lookupMissingStateViaState(ctx, roomID, eventID, roomVersion)
|
return t.lookupMissingStateViaState(ctx, roomID, eventID, roomVersion)
|
||||||
}
|
}
|
||||||
@ -740,8 +745,8 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
t.log.WithFields(logrus.Fields{
|
t.log.WithFields(logrus.Fields{
|
||||||
"missing": missingCount,
|
"missing": missingCount,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"total_state": len(stateIDs.StateEventIDs),
|
"total_state": len(stateIDs.GetStateEventIDs()),
|
||||||
"total_auth_events": len(stateIDs.AuthEventIDs),
|
"total_auth_events": len(stateIDs.GetAuthEventIDs()),
|
||||||
"concurrent_requests": concurrentRequests,
|
"concurrent_requests": concurrentRequests,
|
||||||
}).Debug("Fetching missing state at event")
|
}).Debug("Fetching missing state at event")
|
||||||
|
|
||||||
@ -808,7 +813,7 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) createRespStateFromStateIDs(
|
func (t *missingStateReq) createRespStateFromStateIDs(
|
||||||
stateIDs gomatrixserverlib.RespStateIDs,
|
stateIDs gomatrixserverlib.StateIDResponse,
|
||||||
) (*parsedRespState, error) { // nolint:unparam
|
) (*parsedRespState, error) { // nolint:unparam
|
||||||
t.haveEventsMutex.Lock()
|
t.haveEventsMutex.Lock()
|
||||||
defer t.haveEventsMutex.Unlock()
|
defer t.haveEventsMutex.Unlock()
|
||||||
@ -816,18 +821,20 @@ func (t *missingStateReq) createRespStateFromStateIDs(
|
|||||||
// create a RespState response using the response to /state_ids as a guide
|
// create a RespState response using the response to /state_ids as a guide
|
||||||
respState := parsedRespState{}
|
respState := parsedRespState{}
|
||||||
|
|
||||||
for i := range stateIDs.StateEventIDs {
|
stateEventIDs := stateIDs.GetStateEventIDs()
|
||||||
ev, ok := t.haveEvents[stateIDs.StateEventIDs[i]]
|
authEventIDs := stateIDs.GetAuthEventIDs()
|
||||||
|
for i := range stateEventIDs {
|
||||||
|
ev, ok := t.haveEvents[stateEventIDs[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Tracef("Missing state event in createRespStateFromStateIDs: %s", stateIDs.StateEventIDs[i])
|
logrus.Tracef("Missing state event in createRespStateFromStateIDs: %s", stateEventIDs[i])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
respState.StateEvents = append(respState.StateEvents, ev)
|
respState.StateEvents = append(respState.StateEvents, ev)
|
||||||
}
|
}
|
||||||
for i := range stateIDs.AuthEventIDs {
|
for i := range authEventIDs {
|
||||||
ev, ok := t.haveEvents[stateIDs.AuthEventIDs[i]]
|
ev, ok := t.haveEvents[authEventIDs[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Tracef("Missing auth event in createRespStateFromStateIDs: %s", stateIDs.AuthEventIDs[i])
|
logrus.Tracef("Missing auth event in createRespStateFromStateIDs: %s", authEventIDs[i])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
respState.AuthEvents = append(respState.AuthEvents, ev)
|
respState.AuthEvents = append(respState.AuthEvents, ev)
|
||||||
|
@ -322,7 +322,7 @@ func (r *Admin) PerformAdminDownloadState(
|
|||||||
stateEventMap := map[string]*gomatrixserverlib.Event{}
|
stateEventMap := map[string]*gomatrixserverlib.Event{}
|
||||||
|
|
||||||
for _, fwdExtremity := range fwdExtremities {
|
for _, fwdExtremity := range fwdExtremities {
|
||||||
var state gomatrixserverlib.RespState
|
var state gomatrixserverlib.StateResponse
|
||||||
state, err = r.Inputer.FSAPI.LookupState(ctx, r.Inputer.ServerName, req.ServerName, req.RoomID, fwdExtremity.EventID, roomInfo.RoomVersion)
|
state, err = r.Inputer.FSAPI.LookupState(ctx, r.Inputer.ServerName, req.ServerName, req.RoomID, fwdExtremity.EventID, roomInfo.RoomVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
@ -331,13 +331,13 @@ func (r *Admin) PerformAdminDownloadState(
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, authEvent := range state.AuthEvents.UntrustedEvents(roomInfo.RoomVersion) {
|
for _, authEvent := range state.GetAuthEvents().UntrustedEvents(roomInfo.RoomVersion) {
|
||||||
if err = authEvent.VerifyEventSignatures(ctx, r.Inputer.KeyRing); err != nil {
|
if err = authEvent.VerifyEventSignatures(ctx, r.Inputer.KeyRing); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
authEventMap[authEvent.EventID()] = authEvent
|
authEventMap[authEvent.EventID()] = authEvent
|
||||||
}
|
}
|
||||||
for _, stateEvent := range state.StateEvents.UntrustedEvents(roomInfo.RoomVersion) {
|
for _, stateEvent := range state.GetStateEvents().UntrustedEvents(roomInfo.RoomVersion) {
|
||||||
if err = stateEvent.VerifyEventSignatures(ctx, r.Inputer.KeyRing); err != nil {
|
if err = stateEvent.VerifyEventSignatures(ctx, r.Inputer.KeyRing); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sentryhttp "github.com/getsentry/sentry-go/http"
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
|
||||||
@ -54,42 +54,42 @@ const HTTPServerTimeout = time.Minute * 5
|
|||||||
|
|
||||||
// CreateClient creates a new client (normally used for media fetch requests).
|
// CreateClient creates a new client (normally used for media fetch requests).
|
||||||
// Should only be called once per component.
|
// Should only be called once per component.
|
||||||
func CreateClient(cfg *config.Dendrite, dnsCache *gomatrixserverlib.DNSCache) *gomatrixserverlib.Client {
|
func CreateClient(cfg *config.Dendrite, dnsCache *fclient.DNSCache) *fclient.Client {
|
||||||
if cfg.Global.DisableFederation {
|
if cfg.Global.DisableFederation {
|
||||||
return gomatrixserverlib.NewClient(
|
return fclient.NewClient(
|
||||||
gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
fclient.WithTransport(noOpHTTPTransport),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
opts := []gomatrixserverlib.ClientOption{
|
opts := []fclient.ClientOption{
|
||||||
gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
fclient.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||||
gomatrixserverlib.WithWellKnownSRVLookups(true),
|
fclient.WithWellKnownSRVLookups(true),
|
||||||
}
|
}
|
||||||
if cfg.Global.DNSCache.Enabled && dnsCache != nil {
|
if cfg.Global.DNSCache.Enabled && dnsCache != nil {
|
||||||
opts = append(opts, gomatrixserverlib.WithDNSCache(dnsCache))
|
opts = append(opts, fclient.WithDNSCache(dnsCache))
|
||||||
}
|
}
|
||||||
client := gomatrixserverlib.NewClient(opts...)
|
client := fclient.NewClient(opts...)
|
||||||
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateFederationClient creates a new federation client. Should only be called
|
// CreateFederationClient creates a new federation client. Should only be called
|
||||||
// once per component.
|
// once per component.
|
||||||
func CreateFederationClient(cfg *config.Dendrite, dnsCache *gomatrixserverlib.DNSCache) *gomatrixserverlib.FederationClient {
|
func CreateFederationClient(cfg *config.Dendrite, dnsCache *fclient.DNSCache) *fclient.FederationClient {
|
||||||
identities := cfg.Global.SigningIdentities()
|
identities := cfg.Global.SigningIdentities()
|
||||||
if cfg.Global.DisableFederation {
|
if cfg.Global.DisableFederation {
|
||||||
return gomatrixserverlib.NewFederationClient(
|
return fclient.NewFederationClient(
|
||||||
identities, gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
identities, fclient.WithTransport(noOpHTTPTransport),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
opts := []gomatrixserverlib.ClientOption{
|
opts := []fclient.ClientOption{
|
||||||
gomatrixserverlib.WithTimeout(time.Minute * 5),
|
fclient.WithTimeout(time.Minute * 5),
|
||||||
gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
fclient.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||||
gomatrixserverlib.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
|
fclient.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
|
||||||
}
|
}
|
||||||
if cfg.Global.DNSCache.Enabled {
|
if cfg.Global.DNSCache.Enabled {
|
||||||
opts = append(opts, gomatrixserverlib.WithDNSCache(dnsCache))
|
opts = append(opts, fclient.WithDNSCache(dnsCache))
|
||||||
}
|
}
|
||||||
client := gomatrixserverlib.NewFederationClient(
|
client := fclient.NewFederationClient(
|
||||||
identities, opts...,
|
identities, opts...,
|
||||||
)
|
)
|
||||||
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
||||||
|
@ -8,13 +8,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Global struct {
|
type Global struct {
|
||||||
// Signing identity contains the server name, private key and key ID of
|
// Signing identity contains the server name, private key and key ID of
|
||||||
// the deployment.
|
// the deployment.
|
||||||
gomatrixserverlib.SigningIdentity `yaml:",inline"`
|
fclient.SigningIdentity `yaml:",inline"`
|
||||||
|
|
||||||
// The secondary server names, used for virtual hosting.
|
// The secondary server names, used for virtual hosting.
|
||||||
VirtualHosts []*VirtualHost `yaml:"-"`
|
VirtualHosts []*VirtualHost `yaml:"-"`
|
||||||
@ -167,7 +168,7 @@ func (c *Global) VirtualHostForHTTPHost(serverName gomatrixserverlib.ServerName)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Global) SigningIdentityFor(serverName gomatrixserverlib.ServerName) (*gomatrixserverlib.SigningIdentity, error) {
|
func (c *Global) SigningIdentityFor(serverName gomatrixserverlib.ServerName) (*fclient.SigningIdentity, error) {
|
||||||
for _, id := range c.SigningIdentities() {
|
for _, id := range c.SigningIdentities() {
|
||||||
if id.ServerName == serverName {
|
if id.ServerName == serverName {
|
||||||
return id, nil
|
return id, nil
|
||||||
@ -176,8 +177,8 @@ func (c *Global) SigningIdentityFor(serverName gomatrixserverlib.ServerName) (*g
|
|||||||
return nil, fmt.Errorf("no signing identity for %q", serverName)
|
return nil, fmt.Errorf("no signing identity for %q", serverName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Global) SigningIdentities() []*gomatrixserverlib.SigningIdentity {
|
func (c *Global) SigningIdentities() []*fclient.SigningIdentity {
|
||||||
identities := make([]*gomatrixserverlib.SigningIdentity, 0, len(c.VirtualHosts)+1)
|
identities := make([]*fclient.SigningIdentity, 0, len(c.VirtualHosts)+1)
|
||||||
identities = append(identities, &c.SigningIdentity)
|
identities = append(identities, &c.SigningIdentity)
|
||||||
for _, v := range c.VirtualHosts {
|
for _, v := range c.VirtualHosts {
|
||||||
identities = append(identities, &v.SigningIdentity)
|
identities = append(identities, &v.SigningIdentity)
|
||||||
@ -188,7 +189,7 @@ func (c *Global) SigningIdentities() []*gomatrixserverlib.SigningIdentity {
|
|||||||
type VirtualHost struct {
|
type VirtualHost struct {
|
||||||
// Signing identity contains the server name, private key and key ID of
|
// Signing identity contains the server name, private key and key ID of
|
||||||
// the virtual host.
|
// the virtual host.
|
||||||
gomatrixserverlib.SigningIdentity `yaml:",inline"`
|
fclient.SigningIdentity `yaml:",inline"`
|
||||||
|
|
||||||
// Path to the private key. If not specified, the default global private key
|
// Path to the private key. If not specified, the default global private key
|
||||||
// will be used instead.
|
// will be used instead.
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@ -275,7 +276,7 @@ func Test_SigningIdentityFor(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
virtualHosts []*VirtualHost
|
virtualHosts []*VirtualHost
|
||||||
serverName gomatrixserverlib.ServerName
|
serverName gomatrixserverlib.ServerName
|
||||||
want *gomatrixserverlib.SigningIdentity
|
want *fclient.SigningIdentity
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -290,23 +291,23 @@ func Test_SigningIdentityFor(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "found identity",
|
name: "found identity",
|
||||||
serverName: gomatrixserverlib.ServerName("main"),
|
serverName: gomatrixserverlib.ServerName("main"),
|
||||||
want: &gomatrixserverlib.SigningIdentity{ServerName: "main"},
|
want: &fclient.SigningIdentity{ServerName: "main"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "identity found on virtual hosts",
|
name: "identity found on virtual hosts",
|
||||||
serverName: gomatrixserverlib.ServerName("vh2"),
|
serverName: gomatrixserverlib.ServerName("vh2"),
|
||||||
virtualHosts: []*VirtualHost{
|
virtualHosts: []*VirtualHost{
|
||||||
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"}},
|
{SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"}},
|
||||||
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh2"}},
|
{SigningIdentity: fclient.SigningIdentity{ServerName: "vh2"}},
|
||||||
},
|
},
|
||||||
want: &gomatrixserverlib.SigningIdentity{ServerName: "vh2"},
|
want: &fclient.SigningIdentity{ServerName: "vh2"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := &Global{
|
c := &Global{
|
||||||
VirtualHosts: tt.virtualHosts,
|
VirtualHosts: tt.virtualHosts,
|
||||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
SigningIdentity: fclient.SigningIdentity{
|
||||||
ServerName: "main",
|
ServerName: "main",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/syncapi"
|
"github.com/matrix-org/dendrite/syncapi"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Monolith represents an instantiation of all dependencies required to build
|
// Monolith represents an instantiation of all dependencies required to build
|
||||||
@ -41,8 +42,8 @@ import (
|
|||||||
type Monolith struct {
|
type Monolith struct {
|
||||||
Config *config.Dendrite
|
Config *config.Dendrite
|
||||||
KeyRing *gomatrixserverlib.KeyRing
|
KeyRing *gomatrixserverlib.KeyRing
|
||||||
Client *gomatrixserverlib.Client
|
Client *fclient.Client
|
||||||
FedClient *gomatrixserverlib.FederationClient
|
FedClient *fclient.FederationClient
|
||||||
|
|
||||||
AppserviceAPI appserviceAPI.AppServiceInternalAPI
|
AppserviceAPI appserviceAPI.AppServiceInternalAPI
|
||||||
FederationAPI federationAPI.FederationInternalAPI
|
FederationAPI federationAPI.FederationInternalAPI
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ type EventRelationshipResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MSC2836EventRelationshipsResponse struct {
|
type MSC2836EventRelationshipsResponse struct {
|
||||||
gomatrixserverlib.MSC2836EventRelationshipsResponse
|
fclient.MSC2836EventRelationshipsResponse
|
||||||
ParsedEvents []*gomatrixserverlib.Event
|
ParsedEvents []*gomatrixserverlib.Event
|
||||||
ParsedAuthChain []*gomatrixserverlib.Event
|
ParsedAuthChain []*gomatrixserverlib.Event
|
||||||
}
|
}
|
||||||
@ -399,7 +400,7 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
|
|||||||
serversToQuery := rc.getServersForEventID(parentID)
|
serversToQuery := rc.getServersForEventID(parentID)
|
||||||
var result *MSC2836EventRelationshipsResponse
|
var result *MSC2836EventRelationshipsResponse
|
||||||
for _, srv := range serversToQuery {
|
for _, srv := range serversToQuery {
|
||||||
res, err := rc.fsAPI.MSC2836EventRelationships(rc.ctx, rc.serverName, srv, gomatrixserverlib.MSC2836EventRelationshipsRequest{
|
res, err := rc.fsAPI.MSC2836EventRelationships(rc.ctx, rc.serverName, srv, fclient.MSC2836EventRelationshipsRequest{
|
||||||
EventID: parentID,
|
EventID: parentID,
|
||||||
Direction: "down",
|
Direction: "down",
|
||||||
Limit: 100,
|
Limit: 100,
|
||||||
@ -486,7 +487,7 @@ func walkThread(
|
|||||||
|
|
||||||
// MSC2836EventRelationships performs an /event_relationships request to a remote server
|
// MSC2836EventRelationships performs an /event_relationships request to a remote server
|
||||||
func (rc *reqCtx) MSC2836EventRelationships(eventID string, srv gomatrixserverlib.ServerName, ver gomatrixserverlib.RoomVersion) (*MSC2836EventRelationshipsResponse, error) {
|
func (rc *reqCtx) MSC2836EventRelationships(eventID string, srv gomatrixserverlib.ServerName, ver gomatrixserverlib.RoomVersion) (*MSC2836EventRelationshipsResponse, error) {
|
||||||
res, err := rc.fsAPI.MSC2836EventRelationships(rc.ctx, rc.serverName, srv, gomatrixserverlib.MSC2836EventRelationshipsRequest{
|
res, err := rc.fsAPI.MSC2836EventRelationships(rc.ctx, rc.serverName, srv, fclient.MSC2836EventRelationshipsRequest{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
DepthFirst: rc.req.DepthFirst,
|
DepthFirst: rc.req.DepthFirst,
|
||||||
Direction: rc.req.Direction,
|
Direction: rc.req.Direction,
|
||||||
@ -653,7 +654,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
|
|||||||
messageEvents = append(messageEvents, ev)
|
messageEvents = append(messageEvents, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
respState := gomatrixserverlib.RespState{
|
respState := fclient.RespState{
|
||||||
AuthEvents: res.AuthChain,
|
AuthEvents: res.AuthChain,
|
||||||
StateEvents: stateEvents,
|
StateEvents: stateEvents,
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
@ -48,8 +49,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MSC2946ClientResponse struct {
|
type MSC2946ClientResponse struct {
|
||||||
Rooms []gomatrixserverlib.MSC2946Room `json:"rooms"`
|
Rooms []fclient.MSC2946Room `json:"rooms"`
|
||||||
NextBatch string `json:"next_batch,omitempty"`
|
NextBatch string `json:"next_batch,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable this MSC
|
// Enable this MSC
|
||||||
@ -222,7 +223,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var discoveredRooms []gomatrixserverlib.MSC2946Room
|
var discoveredRooms []fclient.MSC2946Room
|
||||||
|
|
||||||
var cache *paginationInfo
|
var cache *paginationInfo
|
||||||
if w.paginationToken != "" {
|
if w.paginationToken != "" {
|
||||||
@ -275,7 +276,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Collect rooms/events to send back (either locally or fetched via federation)
|
// Collect rooms/events to send back (either locally or fetched via federation)
|
||||||
var discoveredChildEvents []gomatrixserverlib.MSC2946StrippedEvent
|
var discoveredChildEvents []fclient.MSC2946StrippedEvent
|
||||||
|
|
||||||
// If we know about this room and the caller is authorised (joined/world_readable) then pull
|
// If we know about this room and the caller is authorised (joined/world_readable) then pull
|
||||||
// events locally
|
// events locally
|
||||||
@ -306,7 +307,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||||||
|
|
||||||
pubRoom := w.publicRoomsChunk(rv.roomID)
|
pubRoom := w.publicRoomsChunk(rv.roomID)
|
||||||
|
|
||||||
discoveredRooms = append(discoveredRooms, gomatrixserverlib.MSC2946Room{
|
discoveredRooms = append(discoveredRooms, fclient.MSC2946Room{
|
||||||
PublicRoom: *pubRoom,
|
PublicRoom: *pubRoom,
|
||||||
RoomType: roomType,
|
RoomType: roomType,
|
||||||
ChildrenState: events,
|
ChildrenState: events,
|
||||||
@ -379,7 +380,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||||||
}
|
}
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
JSON: gomatrixserverlib.MSC2946SpacesResponse{
|
JSON: fclient.MSC2946SpacesResponse{
|
||||||
Room: discoveredRooms[0],
|
Room: discoveredRooms[0],
|
||||||
Children: discoveredRooms[1:],
|
Children: discoveredRooms[1:],
|
||||||
},
|
},
|
||||||
@ -402,7 +403,7 @@ func (w *walker) stateEvent(roomID, evType, stateKey string) *gomatrixserverlib.
|
|||||||
return queryRes.StateEvents[tuple]
|
return queryRes.StateEvents[tuple]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *walker) publicRoomsChunk(roomID string) *gomatrixserverlib.PublicRoom {
|
func (w *walker) publicRoomsChunk(roomID string) *fclient.PublicRoom {
|
||||||
pubRooms, err := roomserver.PopulatePublicRooms(w.ctx, []string{roomID}, w.rsAPI)
|
pubRooms, err := roomserver.PopulatePublicRooms(w.ctx, []string{roomID}, w.rsAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(w.ctx).WithError(err).Error("failed to PopulatePublicRooms")
|
util.GetLogger(w.ctx).WithError(err).Error("failed to PopulatePublicRooms")
|
||||||
@ -416,7 +417,7 @@ func (w *walker) publicRoomsChunk(roomID string) *gomatrixserverlib.PublicRoom {
|
|||||||
|
|
||||||
// federatedRoomInfo returns more of the spaces graph from another server. Returns nil if this was
|
// federatedRoomInfo returns more of the spaces graph from another server. Returns nil if this was
|
||||||
// unsuccessful.
|
// unsuccessful.
|
||||||
func (w *walker) federatedRoomInfo(roomID string, vias []string) *gomatrixserverlib.MSC2946SpacesResponse {
|
func (w *walker) federatedRoomInfo(roomID string, vias []string) *fclient.MSC2946SpacesResponse {
|
||||||
// only do federated requests for client requests
|
// only do federated requests for client requests
|
||||||
if w.caller == nil {
|
if w.caller == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -440,12 +441,12 @@ func (w *walker) federatedRoomInfo(roomID string, vias []string) *gomatrixserver
|
|||||||
}
|
}
|
||||||
// ensure nil slices are empty as we send this to the client sometimes
|
// ensure nil slices are empty as we send this to the client sometimes
|
||||||
if res.Room.ChildrenState == nil {
|
if res.Room.ChildrenState == nil {
|
||||||
res.Room.ChildrenState = []gomatrixserverlib.MSC2946StrippedEvent{}
|
res.Room.ChildrenState = []fclient.MSC2946StrippedEvent{}
|
||||||
}
|
}
|
||||||
for i := 0; i < len(res.Children); i++ {
|
for i := 0; i < len(res.Children); i++ {
|
||||||
child := res.Children[i]
|
child := res.Children[i]
|
||||||
if child.ChildrenState == nil {
|
if child.ChildrenState == nil {
|
||||||
child.ChildrenState = []gomatrixserverlib.MSC2946StrippedEvent{}
|
child.ChildrenState = []fclient.MSC2946StrippedEvent{}
|
||||||
}
|
}
|
||||||
res.Children[i] = child
|
res.Children[i] = child
|
||||||
}
|
}
|
||||||
@ -653,7 +654,7 @@ func (w *walker) restrictedJoinRuleAllowedRooms(joinRuleEv *gomatrixserverlib.He
|
|||||||
}
|
}
|
||||||
|
|
||||||
// references returns all child references pointing to or from this room.
|
// references returns all child references pointing to or from this room.
|
||||||
func (w *walker) childReferences(roomID string) ([]gomatrixserverlib.MSC2946StrippedEvent, error) {
|
func (w *walker) childReferences(roomID string) ([]fclient.MSC2946StrippedEvent, error) {
|
||||||
createTuple := gomatrixserverlib.StateKeyTuple{
|
createTuple := gomatrixserverlib.StateKeyTuple{
|
||||||
EventType: gomatrixserverlib.MRoomCreate,
|
EventType: gomatrixserverlib.MRoomCreate,
|
||||||
StateKey: "",
|
StateKey: "",
|
||||||
@ -678,12 +679,12 @@ func (w *walker) childReferences(roomID string) ([]gomatrixserverlib.MSC2946Stri
|
|||||||
// escape the `.`s so gjson doesn't think it's nested
|
// escape the `.`s so gjson doesn't think it's nested
|
||||||
roomType := gjson.GetBytes(res.StateEvents[createTuple].Content(), strings.ReplaceAll(ConstCreateEventContentKey, ".", `\.`)).Str
|
roomType := gjson.GetBytes(res.StateEvents[createTuple].Content(), strings.ReplaceAll(ConstCreateEventContentKey, ".", `\.`)).Str
|
||||||
if roomType != ConstCreateEventContentValueSpace {
|
if roomType != ConstCreateEventContentValueSpace {
|
||||||
return []gomatrixserverlib.MSC2946StrippedEvent{}, nil
|
return []fclient.MSC2946StrippedEvent{}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(res.StateEvents, createTuple)
|
delete(res.StateEvents, createTuple)
|
||||||
|
|
||||||
el := make([]gomatrixserverlib.MSC2946StrippedEvent, 0, len(res.StateEvents))
|
el := make([]fclient.MSC2946StrippedEvent, 0, len(res.StateEvents))
|
||||||
for _, ev := range res.StateEvents {
|
for _, ev := range res.StateEvents {
|
||||||
content := gjson.ParseBytes(ev.Content())
|
content := gjson.ParseBytes(ev.Content())
|
||||||
// only return events that have a `via` key as per MSC1772
|
// only return events that have a `via` key as per MSC1772
|
||||||
@ -720,11 +721,11 @@ func (s set) isSet(val string) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripped(ev *gomatrixserverlib.Event) *gomatrixserverlib.MSC2946StrippedEvent {
|
func stripped(ev *gomatrixserverlib.Event) *fclient.MSC2946StrippedEvent {
|
||||||
if ev.StateKey() == nil {
|
if ev.StateKey() == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &gomatrixserverlib.MSC2946StrippedEvent{
|
return &fclient.MSC2946StrippedEvent{
|
||||||
Type: ev.Type(),
|
Type: ev.Type(),
|
||||||
StateKey: *ev.StateKey(),
|
StateKey: *ev.StateKey(),
|
||||||
Content: ev.Content(),
|
Content: ev.Content(),
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/userapi/types"
|
"github.com/matrix-org/dendrite/userapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/internal/pushrules"
|
"github.com/matrix-org/dendrite/internal/pushrules"
|
||||||
@ -719,9 +720,9 @@ type OutputCrossSigningKeyUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CrossSigningKeyUpdate struct {
|
type CrossSigningKeyUpdate struct {
|
||||||
MasterKey *gomatrixserverlib.CrossSigningKey `json:"master_key,omitempty"`
|
MasterKey *fclient.CrossSigningKey `json:"master_key,omitempty"`
|
||||||
SelfSigningKey *gomatrixserverlib.CrossSigningKey `json:"self_signing_key,omitempty"`
|
SelfSigningKey *fclient.CrossSigningKey `json:"self_signing_key,omitempty"`
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeviceKeysEqual returns true if the device keys updates contain the
|
// DeviceKeysEqual returns true if the device keys updates contain the
|
||||||
@ -854,7 +855,7 @@ type PerformClaimKeysResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PerformUploadDeviceKeysRequest struct {
|
type PerformUploadDeviceKeysRequest struct {
|
||||||
gomatrixserverlib.CrossSigningKeys
|
fclient.CrossSigningKeys
|
||||||
// The user that uploaded the key, should be populated by the clientapi.
|
// The user that uploaded the key, should be populated by the clientapi.
|
||||||
UserID string
|
UserID string
|
||||||
}
|
}
|
||||||
@ -864,7 +865,7 @@ type PerformUploadDeviceKeysResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PerformUploadDeviceSignaturesRequest struct {
|
type PerformUploadDeviceSignaturesRequest struct {
|
||||||
Signatures map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice
|
Signatures map[string]map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice
|
||||||
// The user that uploaded the sig, should be populated by the clientapi.
|
// The user that uploaded the sig, should be populated by the clientapi.
|
||||||
UserID string
|
UserID string
|
||||||
}
|
}
|
||||||
@ -888,9 +889,9 @@ type QueryKeysResponse struct {
|
|||||||
// Map of user_id to device_id to device_key
|
// Map of user_id to device_id to device_key
|
||||||
DeviceKeys map[string]map[string]json.RawMessage
|
DeviceKeys map[string]map[string]json.RawMessage
|
||||||
// Maps of user_id to cross signing key
|
// Maps of user_id to cross signing key
|
||||||
MasterKeys map[string]gomatrixserverlib.CrossSigningKey
|
MasterKeys map[string]fclient.CrossSigningKey
|
||||||
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
SelfSigningKeys map[string]fclient.CrossSigningKey
|
||||||
UserSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
UserSigningKeys map[string]fclient.CrossSigningKey
|
||||||
// Set if there was a fatal error processing this query
|
// Set if there was a fatal error processing this query
|
||||||
Error *KeyError
|
Error *KeyError
|
||||||
}
|
}
|
||||||
@ -945,11 +946,11 @@ type QuerySignaturesResponse struct {
|
|||||||
// A map of target user ID -> target key/device ID -> origin user ID -> origin key/device ID -> signatures
|
// A map of target user ID -> target key/device ID -> origin user ID -> origin key/device ID -> signatures
|
||||||
Signatures map[string]map[gomatrixserverlib.KeyID]types.CrossSigningSigMap
|
Signatures map[string]map[gomatrixserverlib.KeyID]types.CrossSigningSigMap
|
||||||
// A map of target user ID -> cross-signing master key
|
// A map of target user ID -> cross-signing master key
|
||||||
MasterKeys map[string]gomatrixserverlib.CrossSigningKey
|
MasterKeys map[string]fclient.CrossSigningKey
|
||||||
// A map of target user ID -> cross-signing self-signing key
|
// A map of target user ID -> cross-signing self-signing key
|
||||||
SelfSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
SelfSigningKeys map[string]fclient.CrossSigningKey
|
||||||
// A map of target user ID -> cross-signing user-signing key
|
// A map of target user ID -> cross-signing user-signing key
|
||||||
UserSigningKeys map[string]gomatrixserverlib.CrossSigningKey
|
UserSigningKeys map[string]fclient.CrossSigningKey
|
||||||
// The request error, if any
|
// The request error, if any
|
||||||
Error *KeyError
|
Error *KeyError
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ func (t *SigningKeyUpdateConsumer) onMessage(ctx context.Context, msgs []*nats.M
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := gomatrixserverlib.CrossSigningKeys{}
|
keys := fclient.CrossSigningKeys{}
|
||||||
if updatePayload.MasterKey != nil {
|
if updatePayload.MasterKey != nil {
|
||||||
keys.MasterKey = *updatePayload.MasterKey
|
keys.MasterKey = *updatePayload.MasterKey
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,12 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/dendrite/userapi/types"
|
"github.com/matrix-org/dendrite/userapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
func sanityCheckKey(key gomatrixserverlib.CrossSigningKey, userID string, purpose gomatrixserverlib.CrossSigningKeyPurpose) error {
|
func sanityCheckKey(key fclient.CrossSigningKey, userID string, purpose fclient.CrossSigningKeyPurpose) error {
|
||||||
// Is there exactly one key?
|
// Is there exactly one key?
|
||||||
if len(key.Keys) != 1 {
|
if len(key.Keys) != 1 {
|
||||||
return fmt.Errorf("should contain exactly one key")
|
return fmt.Errorf("should contain exactly one key")
|
||||||
@ -105,12 +106,12 @@ func sanityCheckKey(key gomatrixserverlib.CrossSigningKey, userID string, purpos
|
|||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) error {
|
func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.PerformUploadDeviceKeysRequest, res *api.PerformUploadDeviceKeysResponse) error {
|
||||||
// Find the keys to store.
|
// Find the keys to store.
|
||||||
byPurpose := map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey{}
|
byPurpose := map[fclient.CrossSigningKeyPurpose]fclient.CrossSigningKey{}
|
||||||
toStore := types.CrossSigningKeyMap{}
|
toStore := types.CrossSigningKeyMap{}
|
||||||
hasMasterKey := false
|
hasMasterKey := false
|
||||||
|
|
||||||
if len(req.MasterKey.Keys) > 0 {
|
if len(req.MasterKey.Keys) > 0 {
|
||||||
if err := sanityCheckKey(req.MasterKey, req.UserID, gomatrixserverlib.CrossSigningKeyPurposeMaster); err != nil {
|
if err := sanityCheckKey(req.MasterKey, req.UserID, fclient.CrossSigningKeyPurposeMaster); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "Master key sanity check failed: " + err.Error(),
|
Err: "Master key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
@ -118,15 +119,15 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeMaster] = req.MasterKey
|
byPurpose[fclient.CrossSigningKeyPurposeMaster] = req.MasterKey
|
||||||
for _, key := range req.MasterKey.Keys { // iterates once, see sanityCheckKey
|
for _, key := range req.MasterKey.Keys { // iterates once, see sanityCheckKey
|
||||||
toStore[gomatrixserverlib.CrossSigningKeyPurposeMaster] = key
|
toStore[fclient.CrossSigningKeyPurposeMaster] = key
|
||||||
}
|
}
|
||||||
hasMasterKey = true
|
hasMasterKey = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.SelfSigningKey.Keys) > 0 {
|
if len(req.SelfSigningKey.Keys) > 0 {
|
||||||
if err := sanityCheckKey(req.SelfSigningKey, req.UserID, gomatrixserverlib.CrossSigningKeyPurposeSelfSigning); err != nil {
|
if err := sanityCheckKey(req.SelfSigningKey, req.UserID, fclient.CrossSigningKeyPurposeSelfSigning); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "Self-signing key sanity check failed: " + err.Error(),
|
Err: "Self-signing key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
@ -134,14 +135,14 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeSelfSigning] = req.SelfSigningKey
|
byPurpose[fclient.CrossSigningKeyPurposeSelfSigning] = req.SelfSigningKey
|
||||||
for _, key := range req.SelfSigningKey.Keys { // iterates once, see sanityCheckKey
|
for _, key := range req.SelfSigningKey.Keys { // iterates once, see sanityCheckKey
|
||||||
toStore[gomatrixserverlib.CrossSigningKeyPurposeSelfSigning] = key
|
toStore[fclient.CrossSigningKeyPurposeSelfSigning] = key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.UserSigningKey.Keys) > 0 {
|
if len(req.UserSigningKey.Keys) > 0 {
|
||||||
if err := sanityCheckKey(req.UserSigningKey, req.UserID, gomatrixserverlib.CrossSigningKeyPurposeUserSigning); err != nil {
|
if err := sanityCheckKey(req.UserSigningKey, req.UserID, fclient.CrossSigningKeyPurposeUserSigning); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "User-signing key sanity check failed: " + err.Error(),
|
Err: "User-signing key sanity check failed: " + err.Error(),
|
||||||
IsInvalidParam: true,
|
IsInvalidParam: true,
|
||||||
@ -149,9 +150,9 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
byPurpose[gomatrixserverlib.CrossSigningKeyPurposeUserSigning] = req.UserSigningKey
|
byPurpose[fclient.CrossSigningKeyPurposeUserSigning] = req.UserSigningKey
|
||||||
for _, key := range req.UserSigningKey.Keys { // iterates once, see sanityCheckKey
|
for _, key := range req.UserSigningKey.Keys { // iterates once, see sanityCheckKey
|
||||||
toStore[gomatrixserverlib.CrossSigningKeyPurposeUserSigning] = key
|
toStore[fclient.CrossSigningKeyPurposeUserSigning] = key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +181,7 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
// If we still can't find a master key for the user then stop the upload.
|
// If we still can't find a master key for the user then stop the upload.
|
||||||
// This satisfies the "Fails to upload self-signing key without master key" test.
|
// This satisfies the "Fails to upload self-signing key without master key" test.
|
||||||
if !hasMasterKey {
|
if !hasMasterKey {
|
||||||
if _, hasMasterKey = existingKeys[gomatrixserverlib.CrossSigningKeyPurposeMaster]; !hasMasterKey {
|
if _, hasMasterKey = existingKeys[fclient.CrossSigningKeyPurposeMaster]; !hasMasterKey {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
Err: "No master key was found",
|
Err: "No master key was found",
|
||||||
IsMissingParam: true,
|
IsMissingParam: true,
|
||||||
@ -191,10 +192,10 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
|
|
||||||
// Check if anything actually changed compared to what we have in the database.
|
// Check if anything actually changed compared to what we have in the database.
|
||||||
changed := false
|
changed := false
|
||||||
for _, purpose := range []gomatrixserverlib.CrossSigningKeyPurpose{
|
for _, purpose := range []fclient.CrossSigningKeyPurpose{
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeMaster,
|
fclient.CrossSigningKeyPurposeMaster,
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeSelfSigning,
|
fclient.CrossSigningKeyPurposeSelfSigning,
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeUserSigning,
|
fclient.CrossSigningKeyPurposeUserSigning,
|
||||||
} {
|
} {
|
||||||
old, gotOld := existingKeys[purpose]
|
old, gotOld := existingKeys[purpose]
|
||||||
new, gotNew := toStore[purpose]
|
new, gotNew := toStore[purpose]
|
||||||
@ -248,10 +249,10 @@ func (a *UserInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.
|
|||||||
update := api.CrossSigningKeyUpdate{
|
update := api.CrossSigningKeyUpdate{
|
||||||
UserID: req.UserID,
|
UserID: req.UserID,
|
||||||
}
|
}
|
||||||
if mk, ok := byPurpose[gomatrixserverlib.CrossSigningKeyPurposeMaster]; ok {
|
if mk, ok := byPurpose[fclient.CrossSigningKeyPurposeMaster]; ok {
|
||||||
update.MasterKey = &mk
|
update.MasterKey = &mk
|
||||||
}
|
}
|
||||||
if ssk, ok := byPurpose[gomatrixserverlib.CrossSigningKeyPurposeSelfSigning]; ok {
|
if ssk, ok := byPurpose[fclient.CrossSigningKeyPurposeSelfSigning]; ok {
|
||||||
update.SelfSigningKey = &ssk
|
update.SelfSigningKey = &ssk
|
||||||
}
|
}
|
||||||
if update.MasterKey == nil && update.SelfSigningKey == nil {
|
if update.MasterKey == nil && update.SelfSigningKey == nil {
|
||||||
@ -279,36 +280,36 @@ func (a *UserInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
|||||||
}
|
}
|
||||||
_ = a.QueryKeys(ctx, queryReq, queryRes)
|
_ = a.QueryKeys(ctx, queryReq, queryRes)
|
||||||
|
|
||||||
selfSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
selfSignatures := map[string]map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
otherSignatures := map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
otherSignatures := map[string]map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
|
|
||||||
// Sort signatures into two groups: one where people have signed their own
|
// Sort signatures into two groups: one where people have signed their own
|
||||||
// keys and one where people have signed someone elses
|
// keys and one where people have signed someone elses
|
||||||
for userID, forUserID := range req.Signatures {
|
for userID, forUserID := range req.Signatures {
|
||||||
for keyID, keyOrDevice := range forUserID {
|
for keyID, keyOrDevice := range forUserID {
|
||||||
switch key := keyOrDevice.CrossSigningBody.(type) {
|
switch key := keyOrDevice.CrossSigningBody.(type) {
|
||||||
case *gomatrixserverlib.CrossSigningKey:
|
case *fclient.CrossSigningKey:
|
||||||
if key.UserID == req.UserID {
|
if key.UserID == req.UserID {
|
||||||
if _, ok := selfSignatures[userID]; !ok {
|
if _, ok := selfSignatures[userID]; !ok {
|
||||||
selfSignatures[userID] = map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
selfSignatures[userID] = map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
}
|
}
|
||||||
selfSignatures[userID][keyID] = keyOrDevice
|
selfSignatures[userID][keyID] = keyOrDevice
|
||||||
} else {
|
} else {
|
||||||
if _, ok := otherSignatures[userID]; !ok {
|
if _, ok := otherSignatures[userID]; !ok {
|
||||||
otherSignatures[userID] = map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
otherSignatures[userID] = map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
}
|
}
|
||||||
otherSignatures[userID][keyID] = keyOrDevice
|
otherSignatures[userID][keyID] = keyOrDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
case *gomatrixserverlib.DeviceKeys:
|
case *fclient.DeviceKeys:
|
||||||
if key.UserID == req.UserID {
|
if key.UserID == req.UserID {
|
||||||
if _, ok := selfSignatures[userID]; !ok {
|
if _, ok := selfSignatures[userID]; !ok {
|
||||||
selfSignatures[userID] = map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
selfSignatures[userID] = map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
}
|
}
|
||||||
selfSignatures[userID][keyID] = keyOrDevice
|
selfSignatures[userID][keyID] = keyOrDevice
|
||||||
} else {
|
} else {
|
||||||
if _, ok := otherSignatures[userID]; !ok {
|
if _, ok := otherSignatures[userID]; !ok {
|
||||||
otherSignatures[userID] = map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice{}
|
otherSignatures[userID] = map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice{}
|
||||||
}
|
}
|
||||||
otherSignatures[userID][keyID] = keyOrDevice
|
otherSignatures[userID][keyID] = keyOrDevice
|
||||||
}
|
}
|
||||||
@ -354,7 +355,7 @@ func (a *UserInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
|||||||
|
|
||||||
func (a *UserInternalAPI) processSelfSignatures(
|
func (a *UserInternalAPI) processSelfSignatures(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
signatures map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice,
|
signatures map[string]map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice,
|
||||||
) error {
|
) error {
|
||||||
// Here we will process:
|
// Here we will process:
|
||||||
// * The user signing their own devices using their self-signing key
|
// * The user signing their own devices using their self-signing key
|
||||||
@ -363,7 +364,7 @@ func (a *UserInternalAPI) processSelfSignatures(
|
|||||||
for targetUserID, forTargetUserID := range signatures {
|
for targetUserID, forTargetUserID := range signatures {
|
||||||
for targetKeyID, signature := range forTargetUserID {
|
for targetKeyID, signature := range forTargetUserID {
|
||||||
switch sig := signature.CrossSigningBody.(type) {
|
switch sig := signature.CrossSigningBody.(type) {
|
||||||
case *gomatrixserverlib.CrossSigningKey:
|
case *fclient.CrossSigningKey:
|
||||||
for keyID := range sig.Keys {
|
for keyID := range sig.Keys {
|
||||||
split := strings.SplitN(string(keyID), ":", 2)
|
split := strings.SplitN(string(keyID), ":", 2)
|
||||||
if len(split) > 1 && gomatrixserverlib.KeyID(split[1]) == targetKeyID {
|
if len(split) > 1 && gomatrixserverlib.KeyID(split[1]) == targetKeyID {
|
||||||
@ -381,7 +382,7 @@ func (a *UserInternalAPI) processSelfSignatures(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case *gomatrixserverlib.DeviceKeys:
|
case *fclient.DeviceKeys:
|
||||||
for originUserID, forOriginUserID := range sig.Signatures {
|
for originUserID, forOriginUserID := range sig.Signatures {
|
||||||
for originKeyID, originSig := range forOriginUserID {
|
for originKeyID, originSig := range forOriginUserID {
|
||||||
if err := a.KeyDatabase.StoreCrossSigningSigsForTarget(
|
if err := a.KeyDatabase.StoreCrossSigningSigsForTarget(
|
||||||
@ -403,7 +404,7 @@ func (a *UserInternalAPI) processSelfSignatures(
|
|||||||
|
|
||||||
func (a *UserInternalAPI) processOtherSignatures(
|
func (a *UserInternalAPI) processOtherSignatures(
|
||||||
ctx context.Context, userID string, queryRes *api.QueryKeysResponse,
|
ctx context.Context, userID string, queryRes *api.QueryKeysResponse,
|
||||||
signatures map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.CrossSigningForKeyOrDevice,
|
signatures map[string]map[gomatrixserverlib.KeyID]fclient.CrossSigningForKeyOrDevice,
|
||||||
) error {
|
) error {
|
||||||
// Here we will process:
|
// Here we will process:
|
||||||
// * A user signing someone else's master keys using their user-signing keys
|
// * A user signing someone else's master keys using their user-signing keys
|
||||||
@ -411,7 +412,7 @@ func (a *UserInternalAPI) processOtherSignatures(
|
|||||||
for targetUserID, forTargetUserID := range signatures {
|
for targetUserID, forTargetUserID := range signatures {
|
||||||
for _, signature := range forTargetUserID {
|
for _, signature := range forTargetUserID {
|
||||||
switch sig := signature.CrossSigningBody.(type) {
|
switch sig := signature.CrossSigningBody.(type) {
|
||||||
case *gomatrixserverlib.CrossSigningKey:
|
case *fclient.CrossSigningKey:
|
||||||
// Find the local copy of the master key. We'll use this to be
|
// Find the local copy of the master key. We'll use this to be
|
||||||
// sure that the supplied stanza matches the key that we think it
|
// sure that the supplied stanza matches the key that we think it
|
||||||
// should be.
|
// should be.
|
||||||
@ -509,13 +510,13 @@ func (a *UserInternalAPI) crossSigningKeysFromDatabase(
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch keyType {
|
switch keyType {
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeMaster:
|
case fclient.CrossSigningKeyPurposeMaster:
|
||||||
res.MasterKeys[targetUserID] = key
|
res.MasterKeys[targetUserID] = key
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
case fclient.CrossSigningKeyPurposeSelfSigning:
|
||||||
res.SelfSigningKeys[targetUserID] = key
|
res.SelfSigningKeys[targetUserID] = key
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeUserSigning:
|
case fclient.CrossSigningKeyPurposeUserSigning:
|
||||||
res.UserSigningKeys[targetUserID] = key
|
res.UserSigningKeys[targetUserID] = key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,21 +535,21 @@ func (a *UserInternalAPI) QuerySignatures(ctx context.Context, req *api.QuerySig
|
|||||||
|
|
||||||
for targetPurpose, targetKey := range keyMap {
|
for targetPurpose, targetKey := range keyMap {
|
||||||
switch targetPurpose {
|
switch targetPurpose {
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeMaster:
|
case fclient.CrossSigningKeyPurposeMaster:
|
||||||
if res.MasterKeys == nil {
|
if res.MasterKeys == nil {
|
||||||
res.MasterKeys = map[string]gomatrixserverlib.CrossSigningKey{}
|
res.MasterKeys = map[string]fclient.CrossSigningKey{}
|
||||||
}
|
}
|
||||||
res.MasterKeys[targetUserID] = targetKey
|
res.MasterKeys[targetUserID] = targetKey
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
case fclient.CrossSigningKeyPurposeSelfSigning:
|
||||||
if res.SelfSigningKeys == nil {
|
if res.SelfSigningKeys == nil {
|
||||||
res.SelfSigningKeys = map[string]gomatrixserverlib.CrossSigningKey{}
|
res.SelfSigningKeys = map[string]fclient.CrossSigningKey{}
|
||||||
}
|
}
|
||||||
res.SelfSigningKeys[targetUserID] = targetKey
|
res.SelfSigningKeys[targetUserID] = targetKey
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeUserSigning:
|
case fclient.CrossSigningKeyPurposeUserSigning:
|
||||||
if res.UserSigningKeys == nil {
|
if res.UserSigningKeys == nil {
|
||||||
res.UserSigningKeys = map[string]gomatrixserverlib.CrossSigningKey{}
|
res.UserSigningKeys = map[string]fclient.CrossSigningKey{}
|
||||||
}
|
}
|
||||||
res.UserSigningKeys[targetUserID] = targetKey
|
res.UserSigningKeys[targetUserID] = targetKey
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -508,12 +509,12 @@ func (u *DeviceListUpdater) processServerUser(ctx context.Context, serverName go
|
|||||||
}
|
}
|
||||||
uploadRes := &api.PerformUploadDeviceKeysResponse{}
|
uploadRes := &api.PerformUploadDeviceKeysResponse{}
|
||||||
if res.MasterKey != nil {
|
if res.MasterKey != nil {
|
||||||
if err = sanityCheckKey(*res.MasterKey, userID, gomatrixserverlib.CrossSigningKeyPurposeMaster); err == nil {
|
if err = sanityCheckKey(*res.MasterKey, userID, fclient.CrossSigningKeyPurposeMaster); err == nil {
|
||||||
uploadReq.MasterKey = *res.MasterKey
|
uploadReq.MasterKey = *res.MasterKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if res.SelfSigningKey != nil {
|
if res.SelfSigningKey != nil {
|
||||||
if err = sanityCheckKey(*res.SelfSigningKey, userID, gomatrixserverlib.CrossSigningKeyPurposeSelfSigning); err == nil {
|
if err = sanityCheckKey(*res.SelfSigningKey, userID, fclient.CrossSigningKeyPurposeSelfSigning); err == nil {
|
||||||
uploadReq.SelfSigningKey = *res.SelfSigningKey
|
uploadReq.SelfSigningKey = *res.SelfSigningKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +528,7 @@ func (u *DeviceListUpdater) processServerUser(ctx context.Context, serverName go
|
|||||||
return defaultWaitTime, nil
|
return defaultWaitTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *DeviceListUpdater) updateDeviceList(res *gomatrixserverlib.RespUserDevices) error {
|
func (u *DeviceListUpdater) updateDeviceList(res *fclient.RespUserDevices) error {
|
||||||
ctx := context.Background() // we've got the keys, don't time out when persisting them to the database.
|
ctx := context.Background() // we've got the keys, don't time out when persisting them to the database.
|
||||||
keys := make([]api.DeviceMessage, len(res.Devices))
|
keys := make([]api.DeviceMessage, len(res.Devices))
|
||||||
existingKeys := make([]api.DeviceMessage, len(res.Devices))
|
existingKeys := make([]api.DeviceMessage, len(res.Devices))
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
@ -135,10 +136,10 @@ func (t *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
return t.fn(req)
|
return t.fn(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFedClient(tripper func(*http.Request) (*http.Response, error)) *gomatrixserverlib.FederationClient {
|
func newFedClient(tripper func(*http.Request) (*http.Response, error)) *fclient.FederationClient {
|
||||||
_, pkey, _ := ed25519.GenerateKey(nil)
|
_, pkey, _ := ed25519.GenerateKey(nil)
|
||||||
fedClient := gomatrixserverlib.NewFederationClient(
|
fedClient := fclient.NewFederationClient(
|
||||||
[]*gomatrixserverlib.SigningIdentity{
|
[]*fclient.SigningIdentity{
|
||||||
{
|
{
|
||||||
ServerName: gomatrixserverlib.ServerName("example.test"),
|
ServerName: gomatrixserverlib.ServerName("example.test"),
|
||||||
KeyID: gomatrixserverlib.KeyID("ed25519:test"),
|
KeyID: gomatrixserverlib.KeyID("ed25519:test"),
|
||||||
@ -146,8 +147,8 @@ func newFedClient(tripper func(*http.Request) (*http.Response, error)) *gomatrix
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
fedClient.Client = *gomatrixserverlib.NewClient(
|
fedClient.Client = *fclient.NewClient(
|
||||||
gomatrixserverlib.WithTransport(&roundTripper{tripper}),
|
fclient.WithTransport(&roundTripper{tripper}),
|
||||||
)
|
)
|
||||||
return fedClient
|
return fedClient
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@ -229,9 +230,9 @@ func (a *UserInternalAPI) PerformMarkAsStaleIfNeeded(ctx context.Context, req *a
|
|||||||
func (a *UserInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) error {
|
func (a *UserInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) error {
|
||||||
var respMu sync.Mutex
|
var respMu sync.Mutex
|
||||||
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
||||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.MasterKeys = make(map[string]fclient.CrossSigningKey)
|
||||||
res.SelfSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.SelfSigningKeys = make(map[string]fclient.CrossSigningKey)
|
||||||
res.UserSigningKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.UserSigningKeys = make(map[string]fclient.CrossSigningKey)
|
||||||
res.Failures = make(map[string]interface{})
|
res.Failures = make(map[string]interface{})
|
||||||
|
|
||||||
// make a map from domain to device keys
|
// make a map from domain to device keys
|
||||||
@ -362,7 +363,7 @@ func (a *UserInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReque
|
|||||||
if len(sigMap) == 0 {
|
if len(sigMap) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var deviceKey gomatrixserverlib.DeviceKeys
|
var deviceKey fclient.DeviceKeys
|
||||||
if err = json.Unmarshal(key, &deviceKey); err != nil {
|
if err = json.Unmarshal(key, &deviceKey); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -415,7 +416,7 @@ func (a *UserInternalAPI) queryRemoteKeys(
|
|||||||
ctx context.Context, timeout time.Duration, res *api.QueryKeysResponse,
|
ctx context.Context, timeout time.Duration, res *api.QueryKeysResponse,
|
||||||
domainToDeviceKeys map[string]map[string][]string, domainToCrossSigningKeys map[string]map[string]struct{},
|
domainToDeviceKeys map[string]map[string][]string, domainToCrossSigningKeys map[string]map[string]struct{},
|
||||||
) {
|
) {
|
||||||
resultCh := make(chan *gomatrixserverlib.RespQueryKeys, len(domainToDeviceKeys))
|
resultCh := make(chan *fclient.RespQueryKeys, len(domainToDeviceKeys))
|
||||||
// allows us to wait until all federation servers have been poked
|
// allows us to wait until all federation servers have been poked
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
// mutex for writing directly to res (e.g failures)
|
// mutex for writing directly to res (e.g failures)
|
||||||
@ -450,7 +451,7 @@ func (a *UserInternalAPI) queryRemoteKeys(
|
|||||||
close(resultCh)
|
close(resultCh)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
processResult := func(result *gomatrixserverlib.RespQueryKeys) {
|
processResult := func(result *fclient.RespQueryKeys) {
|
||||||
respMu.Lock()
|
respMu.Lock()
|
||||||
defer respMu.Unlock()
|
defer respMu.Unlock()
|
||||||
for userID, nest := range result.DeviceKeys {
|
for userID, nest := range result.DeviceKeys {
|
||||||
@ -483,7 +484,7 @@ func (a *UserInternalAPI) queryRemoteKeys(
|
|||||||
|
|
||||||
func (a *UserInternalAPI) queryRemoteKeysOnServer(
|
func (a *UserInternalAPI) queryRemoteKeysOnServer(
|
||||||
ctx context.Context, serverName string, devKeys map[string][]string, crossSigningKeys map[string]struct{},
|
ctx context.Context, serverName string, devKeys map[string][]string, crossSigningKeys map[string]struct{},
|
||||||
wg *sync.WaitGroup, respMu *sync.Mutex, timeout time.Duration, resultCh chan<- *gomatrixserverlib.RespQueryKeys,
|
wg *sync.WaitGroup, respMu *sync.Mutex, timeout time.Duration, resultCh chan<- *fclient.RespQueryKeys,
|
||||||
res *api.QueryKeysResponse,
|
res *api.QueryKeysResponse,
|
||||||
) {
|
) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/internal/pushrules"
|
"github.com/matrix-org/dendrite/internal/pushrules"
|
||||||
@ -203,7 +204,7 @@ type KeyDatabase interface {
|
|||||||
// MarkDeviceListStale sets the stale bit for this user to isStale.
|
// MarkDeviceListStale sets the stale bit for this user to isStale.
|
||||||
MarkDeviceListStale(ctx context.Context, userID string, isStale bool) error
|
MarkDeviceListStale(ctx context.Context, userID string, isStale bool) error
|
||||||
|
|
||||||
CrossSigningKeysForUser(ctx context.Context, userID string) (map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey, error)
|
CrossSigningKeysForUser(ctx context.Context, userID string) (map[fclient.CrossSigningKeyPurpose]fclient.CrossSigningKey, error)
|
||||||
CrossSigningKeysDataForUser(ctx context.Context, userID string) (types.CrossSigningKeyMap, error)
|
CrossSigningKeysDataForUser(ctx context.Context, userID string) (types.CrossSigningKeyMap, error)
|
||||||
CrossSigningSigsForTarget(ctx context.Context, originUserID, targetUserID string, targetKeyID gomatrixserverlib.KeyID) (types.CrossSigningSigMap, error)
|
CrossSigningSigsForTarget(ctx context.Context, originUserID, targetUserID string, targetKeyID gomatrixserverlib.KeyID) (types.CrossSigningSigMap, error)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/userapi/types"
|
"github.com/matrix-org/dendrite/userapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
var crossSigningKeysSchema = `
|
var crossSigningKeysSchema = `
|
||||||
@ -89,7 +90,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *crossSigningKeysStatements) UpsertCrossSigningKeysForUser(
|
func (s *crossSigningKeysStatements) UpsertCrossSigningKeysForUser(
|
||||||
ctx context.Context, txn *sql.Tx, userID string, keyType gomatrixserverlib.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes,
|
ctx context.Context, txn *sql.Tx, userID string, keyType fclient.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes,
|
||||||
) error {
|
) error {
|
||||||
keyTypeInt, ok := types.KeyTypePurposeToInt[keyType]
|
keyTypeInt, ok := types.KeyTypePurposeToInt[keyType]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
@ -1026,17 +1027,17 @@ func (d *KeyDatabase) DeleteDeviceKeys(ctx context.Context, userID string, devic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CrossSigningKeysForUser returns the latest known cross-signing keys for a user, if any.
|
// CrossSigningKeysForUser returns the latest known cross-signing keys for a user, if any.
|
||||||
func (d *KeyDatabase) CrossSigningKeysForUser(ctx context.Context, userID string) (map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey, error) {
|
func (d *KeyDatabase) CrossSigningKeysForUser(ctx context.Context, userID string) (map[fclient.CrossSigningKeyPurpose]fclient.CrossSigningKey, error) {
|
||||||
keyMap, err := d.CrossSigningKeysTable.SelectCrossSigningKeysForUser(ctx, nil, userID)
|
keyMap, err := d.CrossSigningKeysTable.SelectCrossSigningKeysForUser(ctx, nil, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("d.CrossSigningKeysTable.SelectCrossSigningKeysForUser: %w", err)
|
return nil, fmt.Errorf("d.CrossSigningKeysTable.SelectCrossSigningKeysForUser: %w", err)
|
||||||
}
|
}
|
||||||
results := map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.CrossSigningKey{}
|
results := map[fclient.CrossSigningKeyPurpose]fclient.CrossSigningKey{}
|
||||||
for purpose, key := range keyMap {
|
for purpose, key := range keyMap {
|
||||||
keyID := gomatrixserverlib.KeyID("ed25519:" + key.Encode())
|
keyID := gomatrixserverlib.KeyID("ed25519:" + key.Encode())
|
||||||
result := gomatrixserverlib.CrossSigningKey{
|
result := fclient.CrossSigningKey{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{purpose},
|
Usage: []fclient.CrossSigningKeyPurpose{purpose},
|
||||||
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
||||||
keyID: key,
|
keyID: key,
|
||||||
},
|
},
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
"github.com/matrix-org/dendrite/userapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/userapi/types"
|
"github.com/matrix-org/dendrite/userapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
var crossSigningKeysSchema = `
|
var crossSigningKeysSchema = `
|
||||||
@ -88,7 +89,7 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *crossSigningKeysStatements) UpsertCrossSigningKeysForUser(
|
func (s *crossSigningKeysStatements) UpsertCrossSigningKeysForUser(
|
||||||
ctx context.Context, txn *sql.Tx, userID string, keyType gomatrixserverlib.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes,
|
ctx context.Context, txn *sql.Tx, userID string, keyType fclient.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes,
|
||||||
) error {
|
) error {
|
||||||
keyTypeInt, ok := types.KeyTypePurposeToInt[keyType]
|
keyTypeInt, ok := types.KeyTypePurposeToInt[keyType]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/userapi/types"
|
"github.com/matrix-org/dendrite/userapi/types"
|
||||||
@ -181,7 +182,7 @@ type StaleDeviceLists interface {
|
|||||||
|
|
||||||
type CrossSigningKeys interface {
|
type CrossSigningKeys interface {
|
||||||
SelectCrossSigningKeysForUser(ctx context.Context, txn *sql.Tx, userID string) (r types.CrossSigningKeyMap, err error)
|
SelectCrossSigningKeysForUser(ctx context.Context, txn *sql.Tx, userID string) (r types.CrossSigningKeyMap, err error)
|
||||||
UpsertCrossSigningKeysForUser(ctx context.Context, txn *sql.Tx, userID string, keyType gomatrixserverlib.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes) error
|
UpsertCrossSigningKeysForUser(ctx context.Context, txn *sql.Tx, userID string, keyType fclient.CrossSigningKeyPurpose, keyData gomatrixserverlib.Base64Bytes) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CrossSigningSigs interface {
|
type CrossSigningSigs interface {
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -29,22 +30,22 @@ const (
|
|||||||
|
|
||||||
// KeyTypePurposeToInt maps a purpose to an integer, which is used in the
|
// KeyTypePurposeToInt maps a purpose to an integer, which is used in the
|
||||||
// database to reduce the amount of space taken up by this column.
|
// database to reduce the amount of space taken up by this column.
|
||||||
var KeyTypePurposeToInt = map[gomatrixserverlib.CrossSigningKeyPurpose]int16{
|
var KeyTypePurposeToInt = map[fclient.CrossSigningKeyPurpose]int16{
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeMaster: 1,
|
fclient.CrossSigningKeyPurposeMaster: 1,
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeSelfSigning: 2,
|
fclient.CrossSigningKeyPurposeSelfSigning: 2,
|
||||||
gomatrixserverlib.CrossSigningKeyPurposeUserSigning: 3,
|
fclient.CrossSigningKeyPurposeUserSigning: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyTypeIntToPurpose maps an integer to a purpose, which is used in the
|
// KeyTypeIntToPurpose maps an integer to a purpose, which is used in the
|
||||||
// database to reduce the amount of space taken up by this column.
|
// database to reduce the amount of space taken up by this column.
|
||||||
var KeyTypeIntToPurpose = map[int16]gomatrixserverlib.CrossSigningKeyPurpose{
|
var KeyTypeIntToPurpose = map[int16]fclient.CrossSigningKeyPurpose{
|
||||||
1: gomatrixserverlib.CrossSigningKeyPurposeMaster,
|
1: fclient.CrossSigningKeyPurposeMaster,
|
||||||
2: gomatrixserverlib.CrossSigningKeyPurposeSelfSigning,
|
2: fclient.CrossSigningKeyPurposeSelfSigning,
|
||||||
3: gomatrixserverlib.CrossSigningKeyPurposeUserSigning,
|
3: fclient.CrossSigningKeyPurposeUserSigning,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map of purpose -> public key
|
// Map of purpose -> public key
|
||||||
type CrossSigningKeyMap map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.Base64Bytes
|
type CrossSigningKeyMap map[fclient.CrossSigningKeyPurpose]gomatrixserverlib.Base64Bytes
|
||||||
|
|
||||||
// Map of user ID -> key ID -> signature
|
// Map of user ID -> key ID -> signature
|
||||||
type CrossSigningSigMap map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes
|
type CrossSigningSigMap map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/userapi/producers"
|
"github.com/matrix-org/dendrite/userapi/producers"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
@ -87,7 +88,7 @@ func MustMakeInternalAPI(t *testing.T, opts apiTestOpts, dbType test.DBType, pub
|
|||||||
t.Fatalf("failed to create key DB: %s", err)
|
t.Fatalf("failed to create key DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Global.SigningIdentity = gomatrixserverlib.SigningIdentity{
|
cfg.Global.SigningIdentity = fclient.SigningIdentity{
|
||||||
ServerName: sName,
|
ServerName: sName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user