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
|
@ -22,7 +22,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"nhooyr.io/websocket"
|
||||
|
||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||
|
@ -91,17 +91,17 @@ func createTransport(s *pineconeSessions.Sessions) *http.Transport {
|
|||
|
||||
func CreateClient(
|
||||
s *pineconeSessions.Sessions,
|
||||
) *gomatrixserverlib.Client {
|
||||
return gomatrixserverlib.NewClient(
|
||||
gomatrixserverlib.WithTransport(createTransport(s)),
|
||||
) *fclient.Client {
|
||||
return fclient.NewClient(
|
||||
fclient.WithTransport(createTransport(s)),
|
||||
)
|
||||
}
|
||||
|
||||
func CreateFederationClient(
|
||||
cfg *config.Dendrite, s *pineconeSessions.Sessions,
|
||||
) *gomatrixserverlib.FederationClient {
|
||||
return gomatrixserverlib.NewFederationClient(
|
||||
) *fclient.FederationClient {
|
||||
return fclient.NewFederationClient(
|
||||
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/federationapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/util"
|
||||
|
||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||
|
@ -32,14 +33,14 @@ type PineconeRoomProvider struct {
|
|||
r *pineconeRouter.Router
|
||||
s *pineconeSessions.Sessions
|
||||
fedSender api.FederationInternalAPI
|
||||
fedClient *gomatrixserverlib.FederationClient
|
||||
fedClient *fclient.FederationClient
|
||||
}
|
||||
|
||||
func NewPineconeRoomProvider(
|
||||
r *pineconeRouter.Router,
|
||||
s *pineconeSessions.Sessions,
|
||||
fedSender api.FederationInternalAPI,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
fedClient *fclient.FederationClient,
|
||||
) *PineconeRoomProvider {
|
||||
p := &PineconeRoomProvider{
|
||||
r: r,
|
||||
|
@ -50,7 +51,7 @@ func NewPineconeRoomProvider(
|
|||
return p
|
||||
}
|
||||
|
||||
func (p *PineconeRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
||||
func (p *PineconeRoomProvider) Rooms() []fclient.PublicRoom {
|
||||
list := map[gomatrixserverlib.ServerName]struct{}{}
|
||||
for k := range defaults.DefaultServerNames {
|
||||
list[k] = struct{}{}
|
||||
|
@ -67,14 +68,14 @@ func (p *PineconeRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
|||
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
||||
// Returns a list of public rooms.
|
||||
func bulkFetchPublicRoomsFromServers(
|
||||
ctx context.Context, fedClient *gomatrixserverlib.FederationClient,
|
||||
ctx context.Context, fedClient *fclient.FederationClient,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
homeservers map[gomatrixserverlib.ServerName]struct{},
|
||||
) (publicRooms []gomatrixserverlib.PublicRoom) {
|
||||
) (publicRooms []fclient.PublicRoom) {
|
||||
limit := 200
|
||||
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
||||
// 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
|
||||
done := make(chan bool)
|
||||
// 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"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/util"
|
||||
|
||||
pineconeRouter "github.com/matrix-org/pinecone/router"
|
||||
|
@ -38,7 +39,7 @@ type PineconeUserProvider struct {
|
|||
r *pineconeRouter.Router
|
||||
s *pineconeSessions.Sessions
|
||||
userAPI userapi.QuerySearchProfilesAPI
|
||||
fedClient *gomatrixserverlib.FederationClient
|
||||
fedClient *fclient.FederationClient
|
||||
}
|
||||
|
||||
const PublicURL = "/_matrix/p2p/profiles"
|
||||
|
@ -47,7 +48,7 @@ func NewPineconeUserProvider(
|
|||
r *pineconeRouter.Router,
|
||||
s *pineconeSessions.Sessions,
|
||||
userAPI userapi.QuerySearchProfilesAPI,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
fedClient *fclient.FederationClient,
|
||||
) *PineconeUserProvider {
|
||||
p := &PineconeUserProvider{
|
||||
r: r,
|
||||
|
@ -94,7 +95,7 @@ func (p *PineconeUserProvider) QuerySearchProfiles(ctx context.Context, req *use
|
|||
// Returns a list of user profiles.
|
||||
func bulkFetchUserDirectoriesFromServers(
|
||||
ctx context.Context, req *userapi.QuerySearchProfilesRequest,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
fedClient *fclient.FederationClient,
|
||||
homeservers map[gomatrixserverlib.ServerName]struct{},
|
||||
) (profiles []authtypes.Profile) {
|
||||
jsonBody, err := json.Marshal(req)
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
)
|
||||
|
||||
type yggroundtripper struct {
|
||||
|
@ -17,7 +17,7 @@ func (y *yggroundtripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
return y.inner.RoundTrip(req)
|
||||
}
|
||||
|
||||
func (n *Node) CreateClient() *gomatrixserverlib.Client {
|
||||
func (n *Node) CreateClient() *fclient.Client {
|
||||
tr := &http.Transport{}
|
||||
tr.RegisterProtocol(
|
||||
"matrix", &yggroundtripper{
|
||||
|
@ -31,14 +31,14 @@ func (n *Node) CreateClient() *gomatrixserverlib.Client {
|
|||
},
|
||||
},
|
||||
)
|
||||
return gomatrixserverlib.NewClient(
|
||||
gomatrixserverlib.WithTransport(tr),
|
||||
return fclient.NewClient(
|
||||
fclient.WithTransport(tr),
|
||||
)
|
||||
}
|
||||
|
||||
func (n *Node) CreateFederationClient(
|
||||
cfg *config.Dendrite,
|
||||
) *gomatrixserverlib.FederationClient {
|
||||
) *fclient.FederationClient {
|
||||
tr := &http.Transport{}
|
||||
tr.RegisterProtocol(
|
||||
"matrix", &yggroundtripper{
|
||||
|
@ -52,8 +52,8 @@ func (n *Node) CreateFederationClient(
|
|||
},
|
||||
},
|
||||
)
|
||||
return gomatrixserverlib.NewFederationClient(
|
||||
return fclient.NewFederationClient(
|
||||
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/federationapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
type YggdrasilRoomProvider struct {
|
||||
node *yggconn.Node
|
||||
fedSender api.FederationInternalAPI
|
||||
fedClient *gomatrixserverlib.FederationClient
|
||||
fedClient *fclient.FederationClient
|
||||
}
|
||||
|
||||
func NewYggdrasilRoomProvider(
|
||||
node *yggconn.Node, fedSender api.FederationInternalAPI, fedClient *gomatrixserverlib.FederationClient,
|
||||
node *yggconn.Node, fedSender api.FederationInternalAPI, fedClient *fclient.FederationClient,
|
||||
) *YggdrasilRoomProvider {
|
||||
p := &YggdrasilRoomProvider{
|
||||
node: node,
|
||||
|
@ -42,7 +43,7 @@ func NewYggdrasilRoomProvider(
|
|||
return p
|
||||
}
|
||||
|
||||
func (p *YggdrasilRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
||||
func (p *YggdrasilRoomProvider) Rooms() []fclient.PublicRoom {
|
||||
return bulkFetchPublicRoomsFromServers(
|
||||
context.Background(), p.fedClient,
|
||||
gomatrixserverlib.ServerName(p.node.DerivedServerName()),
|
||||
|
@ -53,14 +54,14 @@ func (p *YggdrasilRoomProvider) Rooms() []gomatrixserverlib.PublicRoom {
|
|||
// bulkFetchPublicRoomsFromServers fetches public rooms from the list of homeservers.
|
||||
// Returns a list of public rooms.
|
||||
func bulkFetchPublicRoomsFromServers(
|
||||
ctx context.Context, fedClient *gomatrixserverlib.FederationClient,
|
||||
ctx context.Context, fedClient *fclient.FederationClient,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
homeservers []gomatrixserverlib.ServerName,
|
||||
) (publicRooms []gomatrixserverlib.PublicRoom) {
|
||||
) (publicRooms []fclient.PublicRoom) {
|
||||
limit := 200
|
||||
// follow pipeline semantics, see https://blog.golang.org/pipelines for more info.
|
||||
// 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
|
||||
done := make(chan bool)
|
||||
// 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/setup/jetstream"
|
||||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/appservice"
|
||||
|
@ -96,9 +96,9 @@ func main() {
|
|||
}
|
||||
|
||||
// create DNS cache
|
||||
var dnsCache *gomatrixserverlib.DNSCache
|
||||
var dnsCache *fclient.DNSCache
|
||||
if cfg.Global.DNSCache.Enabled {
|
||||
dnsCache = gomatrixserverlib.NewDNSCache(
|
||||
dnsCache = fclient.NewDNSCache(
|
||||
cfg.Global.DNSCache.CacheSize,
|
||||
cfg.Global.DNSCache.CacheLifetime,
|
||||
)
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
|
||||
"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")
|
||||
|
@ -49,8 +50,8 @@ func main() {
|
|||
}
|
||||
|
||||
serverName := gomatrixserverlib.ServerName(*requestFrom)
|
||||
client := gomatrixserverlib.NewFederationClient(
|
||||
[]*gomatrixserverlib.SigningIdentity{
|
||||
client := fclient.NewFederationClient(
|
||||
[]*fclient.SigningIdentity{
|
||||
{
|
||||
ServerName: serverName,
|
||||
KeyID: gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue