mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +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
86 changed files with 493 additions and 414 deletions
|
@ -32,7 +32,7 @@ import (
|
|||
"time"
|
||||
|
||||
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"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
|
@ -54,42 +54,42 @@ const HTTPServerTimeout = time.Minute * 5
|
|||
|
||||
// CreateClient creates a new client (normally used for media fetch requests).
|
||||
// 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 {
|
||||
return gomatrixserverlib.NewClient(
|
||||
gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
||||
return fclient.NewClient(
|
||||
fclient.WithTransport(noOpHTTPTransport),
|
||||
)
|
||||
}
|
||||
opts := []gomatrixserverlib.ClientOption{
|
||||
gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||
gomatrixserverlib.WithWellKnownSRVLookups(true),
|
||||
opts := []fclient.ClientOption{
|
||||
fclient.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||
fclient.WithWellKnownSRVLookups(true),
|
||||
}
|
||||
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()))
|
||||
return client
|
||||
}
|
||||
|
||||
// CreateFederationClient creates a new federation client. Should only be called
|
||||
// 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()
|
||||
if cfg.Global.DisableFederation {
|
||||
return gomatrixserverlib.NewFederationClient(
|
||||
identities, gomatrixserverlib.WithTransport(noOpHTTPTransport),
|
||||
return fclient.NewFederationClient(
|
||||
identities, fclient.WithTransport(noOpHTTPTransport),
|
||||
)
|
||||
}
|
||||
opts := []gomatrixserverlib.ClientOption{
|
||||
gomatrixserverlib.WithTimeout(time.Minute * 5),
|
||||
gomatrixserverlib.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||
gomatrixserverlib.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
|
||||
opts := []fclient.ClientOption{
|
||||
fclient.WithTimeout(time.Minute * 5),
|
||||
fclient.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
|
||||
fclient.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
|
||||
}
|
||||
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...,
|
||||
)
|
||||
client.SetUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString()))
|
||||
|
|
|
@ -8,13 +8,14 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
)
|
||||
|
||||
type Global struct {
|
||||
// Signing identity contains the server name, private key and key ID of
|
||||
// the deployment.
|
||||
gomatrixserverlib.SigningIdentity `yaml:",inline"`
|
||||
fclient.SigningIdentity `yaml:",inline"`
|
||||
|
||||
// The secondary server names, used for virtual hosting.
|
||||
VirtualHosts []*VirtualHost `yaml:"-"`
|
||||
|
@ -167,7 +168,7 @@ func (c *Global) VirtualHostForHTTPHost(serverName gomatrixserverlib.ServerName)
|
|||
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() {
|
||||
if id.ServerName == serverName {
|
||||
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)
|
||||
}
|
||||
|
||||
func (c *Global) SigningIdentities() []*gomatrixserverlib.SigningIdentity {
|
||||
identities := make([]*gomatrixserverlib.SigningIdentity, 0, len(c.VirtualHosts)+1)
|
||||
func (c *Global) SigningIdentities() []*fclient.SigningIdentity {
|
||||
identities := make([]*fclient.SigningIdentity, 0, len(c.VirtualHosts)+1)
|
||||
identities = append(identities, &c.SigningIdentity)
|
||||
for _, v := range c.VirtualHosts {
|
||||
identities = append(identities, &v.SigningIdentity)
|
||||
|
@ -188,7 +189,7 @@ func (c *Global) SigningIdentities() []*gomatrixserverlib.SigningIdentity {
|
|||
type VirtualHost struct {
|
||||
// Signing identity contains the server name, private key and key ID of
|
||||
// the virtual host.
|
||||
gomatrixserverlib.SigningIdentity `yaml:",inline"`
|
||||
fclient.SigningIdentity `yaml:",inline"`
|
||||
|
||||
// Path to the private key. If not specified, the default global private key
|
||||
// will be used instead.
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
@ -275,7 +276,7 @@ func Test_SigningIdentityFor(t *testing.T) {
|
|||
name string
|
||||
virtualHosts []*VirtualHost
|
||||
serverName gomatrixserverlib.ServerName
|
||||
want *gomatrixserverlib.SigningIdentity
|
||||
want *fclient.SigningIdentity
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -290,23 +291,23 @@ func Test_SigningIdentityFor(t *testing.T) {
|
|||
{
|
||||
name: "found identity",
|
||||
serverName: gomatrixserverlib.ServerName("main"),
|
||||
want: &gomatrixserverlib.SigningIdentity{ServerName: "main"},
|
||||
want: &fclient.SigningIdentity{ServerName: "main"},
|
||||
},
|
||||
{
|
||||
name: "identity found on virtual hosts",
|
||||
serverName: gomatrixserverlib.ServerName("vh2"),
|
||||
virtualHosts: []*VirtualHost{
|
||||
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"}},
|
||||
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh2"}},
|
||||
{SigningIdentity: fclient.SigningIdentity{ServerName: "vh1"}},
|
||||
{SigningIdentity: fclient.SigningIdentity{ServerName: "vh2"}},
|
||||
},
|
||||
want: &gomatrixserverlib.SigningIdentity{ServerName: "vh2"},
|
||||
want: &fclient.SigningIdentity{ServerName: "vh2"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := &Global{
|
||||
VirtualHosts: tt.virtualHosts,
|
||||
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "main",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
)
|
||||
|
||||
// Monolith represents an instantiation of all dependencies required to build
|
||||
|
@ -41,8 +42,8 @@ import (
|
|||
type Monolith struct {
|
||||
Config *config.Dendrite
|
||||
KeyRing *gomatrixserverlib.KeyRing
|
||||
Client *gomatrixserverlib.Client
|
||||
FedClient *gomatrixserverlib.FederationClient
|
||||
Client *fclient.Client
|
||||
FedClient *fclient.FederationClient
|
||||
|
||||
AppserviceAPI appserviceAPI.AppServiceInternalAPI
|
||||
FederationAPI federationAPI.FederationInternalAPI
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
|
@ -85,7 +86,7 @@ type EventRelationshipResponse struct {
|
|||
}
|
||||
|
||||
type MSC2836EventRelationshipsResponse struct {
|
||||
gomatrixserverlib.MSC2836EventRelationshipsResponse
|
||||
fclient.MSC2836EventRelationshipsResponse
|
||||
ParsedEvents []*gomatrixserverlib.Event
|
||||
ParsedAuthChain []*gomatrixserverlib.Event
|
||||
}
|
||||
|
@ -399,7 +400,7 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
|
|||
serversToQuery := rc.getServersForEventID(parentID)
|
||||
var result *MSC2836EventRelationshipsResponse
|
||||
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,
|
||||
Direction: "down",
|
||||
Limit: 100,
|
||||
|
@ -486,7 +487,7 @@ func walkThread(
|
|||
|
||||
// MSC2836EventRelationships performs an /event_relationships request to a remote server
|
||||
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,
|
||||
DepthFirst: rc.req.DepthFirst,
|
||||
Direction: rc.req.Direction,
|
||||
|
@ -653,7 +654,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
|
|||
messageEvents = append(messageEvents, ev)
|
||||
}
|
||||
}
|
||||
respState := gomatrixserverlib.RespState{
|
||||
respState := fclient.RespState{
|
||||
AuthEvents: res.AuthChain,
|
||||
StateEvents: stateEvents,
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
userapi "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/tidwall/gjson"
|
||||
)
|
||||
|
@ -48,8 +49,8 @@ const (
|
|||
)
|
||||
|
||||
type MSC2946ClientResponse struct {
|
||||
Rooms []gomatrixserverlib.MSC2946Room `json:"rooms"`
|
||||
NextBatch string `json:"next_batch,omitempty"`
|
||||
Rooms []fclient.MSC2946Room `json:"rooms"`
|
||||
NextBatch string `json:"next_batch,omitempty"`
|
||||
}
|
||||
|
||||
// Enable this MSC
|
||||
|
@ -222,7 +223,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||
}
|
||||
}
|
||||
|
||||
var discoveredRooms []gomatrixserverlib.MSC2946Room
|
||||
var discoveredRooms []fclient.MSC2946Room
|
||||
|
||||
var cache *paginationInfo
|
||||
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)
|
||||
var discoveredChildEvents []gomatrixserverlib.MSC2946StrippedEvent
|
||||
var discoveredChildEvents []fclient.MSC2946StrippedEvent
|
||||
|
||||
// If we know about this room and the caller is authorised (joined/world_readable) then pull
|
||||
// events locally
|
||||
|
@ -306,7 +307,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||
|
||||
pubRoom := w.publicRoomsChunk(rv.roomID)
|
||||
|
||||
discoveredRooms = append(discoveredRooms, gomatrixserverlib.MSC2946Room{
|
||||
discoveredRooms = append(discoveredRooms, fclient.MSC2946Room{
|
||||
PublicRoom: *pubRoom,
|
||||
RoomType: roomType,
|
||||
ChildrenState: events,
|
||||
|
@ -379,7 +380,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||
}
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: gomatrixserverlib.MSC2946SpacesResponse{
|
||||
JSON: fclient.MSC2946SpacesResponse{
|
||||
Room: discoveredRooms[0],
|
||||
Children: discoveredRooms[1:],
|
||||
},
|
||||
|
@ -402,7 +403,7 @@ func (w *walker) stateEvent(roomID, evType, stateKey string) *gomatrixserverlib.
|
|||
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)
|
||||
if err != nil {
|
||||
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
|
||||
// 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
|
||||
if w.caller == 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
|
||||
if res.Room.ChildrenState == nil {
|
||||
res.Room.ChildrenState = []gomatrixserverlib.MSC2946StrippedEvent{}
|
||||
res.Room.ChildrenState = []fclient.MSC2946StrippedEvent{}
|
||||
}
|
||||
for i := 0; i < len(res.Children); i++ {
|
||||
child := res.Children[i]
|
||||
if child.ChildrenState == nil {
|
||||
child.ChildrenState = []gomatrixserverlib.MSC2946StrippedEvent{}
|
||||
child.ChildrenState = []fclient.MSC2946StrippedEvent{}
|
||||
}
|
||||
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.
|
||||
func (w *walker) childReferences(roomID string) ([]gomatrixserverlib.MSC2946StrippedEvent, error) {
|
||||
func (w *walker) childReferences(roomID string) ([]fclient.MSC2946StrippedEvent, error) {
|
||||
createTuple := gomatrixserverlib.StateKeyTuple{
|
||||
EventType: gomatrixserverlib.MRoomCreate,
|
||||
StateKey: "",
|
||||
|
@ -678,12 +679,12 @@ func (w *walker) childReferences(roomID string) ([]gomatrixserverlib.MSC2946Stri
|
|||
// escape the `.`s so gjson doesn't think it's nested
|
||||
roomType := gjson.GetBytes(res.StateEvents[createTuple].Content(), strings.ReplaceAll(ConstCreateEventContentKey, ".", `\.`)).Str
|
||||
if roomType != ConstCreateEventContentValueSpace {
|
||||
return []gomatrixserverlib.MSC2946StrippedEvent{}, nil
|
||||
return []fclient.MSC2946StrippedEvent{}, nil
|
||||
}
|
||||
}
|
||||
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 {
|
||||
content := gjson.ParseBytes(ev.Content())
|
||||
// only return events that have a `via` key as per MSC1772
|
||||
|
@ -720,11 +721,11 @@ func (s set) isSet(val string) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
func stripped(ev *gomatrixserverlib.Event) *gomatrixserverlib.MSC2946StrippedEvent {
|
||||
func stripped(ev *gomatrixserverlib.Event) *fclient.MSC2946StrippedEvent {
|
||||
if ev.StateKey() == nil {
|
||||
return nil
|
||||
}
|
||||
return &gomatrixserverlib.MSC2946StrippedEvent{
|
||||
return &fclient.MSC2946StrippedEvent{
|
||||
Type: ev.Type(),
|
||||
StateKey: *ev.StateKey(),
|
||||
Content: ev.Content(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue