mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
This commit is contained in:
parent
9fa39263c0
commit
72285b2659
306 changed files with 2117 additions and 1934 deletions
|
@ -20,8 +20,8 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/relayapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -30,9 +30,9 @@ import (
|
|||
// This endpoint can be extracted into a separate relay server service.
|
||||
func GetTransactionFromRelay(
|
||||
httpReq *http.Request,
|
||||
fedReq *gomatrixserverlib.FederationRequest,
|
||||
fedReq *fclient.FederationRequest,
|
||||
relayAPI api.RelayInternalAPI,
|
||||
userID gomatrixserverlib.UserID,
|
||||
userID spec.UserID,
|
||||
) util.JSONResponse {
|
||||
logrus.Infof("Processing relay_txn for %s", userID.Raw())
|
||||
|
||||
|
|
|
@ -26,16 +26,17 @@ import (
|
|||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createQuery(
|
||||
userID gomatrixserverlib.UserID,
|
||||
userID spec.UserID,
|
||||
prevEntry fclient.RelayEntry,
|
||||
) gomatrixserverlib.FederationRequest {
|
||||
) fclient.FederationRequest {
|
||||
var federationPathPrefixV1 = "/_matrix/federation/v1"
|
||||
path := federationPathPrefixV1 + "/relay_txn/" + userID.Raw()
|
||||
request := gomatrixserverlib.NewFederationRequest("GET", userID.Domain(), "relay", path)
|
||||
request := fclient.NewFederationRequest("GET", userID.Domain(), "relay", path)
|
||||
request.SetContent(prevEntry)
|
||||
|
||||
return request
|
||||
|
@ -49,7 +50,7 @@ func TestGetEmptyDatabaseReturnsNothing(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
transaction := createTransaction()
|
||||
|
@ -82,7 +83,7 @@ func TestGetInvalidPrevEntryFails(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
transaction := createTransaction()
|
||||
|
@ -107,7 +108,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
transaction := createTransaction()
|
||||
|
@ -116,7 +117,7 @@ func TestGetReturnsSavedTransaction(t *testing.T) {
|
|||
|
||||
err = db.AssociateTransactionWithDestinations(
|
||||
context.Background(),
|
||||
map[gomatrixserverlib.UserID]struct{}{
|
||||
map[spec.UserID]struct{}{
|
||||
*userID: {},
|
||||
},
|
||||
transaction.TransactionID,
|
||||
|
@ -157,7 +158,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
transaction := createTransaction()
|
||||
|
@ -166,7 +167,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||
|
||||
err = db.AssociateTransactionWithDestinations(
|
||||
context.Background(),
|
||||
map[gomatrixserverlib.UserID]struct{}{
|
||||
map[spec.UserID]struct{}{
|
||||
*userID: {},
|
||||
},
|
||||
transaction.TransactionID,
|
||||
|
@ -179,7 +180,7 @@ func TestGetReturnsMultipleSavedTransactions(t *testing.T) {
|
|||
|
||||
err = db.AssociateTransactionWithDestinations(
|
||||
context.Background(),
|
||||
map[gomatrixserverlib.UserID]struct{}{
|
||||
map[spec.UserID]struct{}{
|
||||
*userID: {},
|
||||
},
|
||||
transaction2.TransactionID,
|
||||
|
|
|
@ -26,6 +26,8 @@ import (
|
|||
relayInternal "github.com/matrix-org/dendrite/relayapi/internal"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -44,7 +46,7 @@ func Setup(
|
|||
|
||||
v1fedmux.Handle("/send_relay/{txnID}/{userID}", MakeRelayAPI(
|
||||
"send_relay_transaction", "", cfg.Matrix.IsLocalServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||
func(httpReq *http.Request, request *fclient.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||
logrus.Infof("Handling send_relay from: %s", request.Origin())
|
||||
if !relayAPI.RelayingEnabled() {
|
||||
logrus.Warnf("Dropping send_relay from: %s", request.Origin())
|
||||
|
@ -53,7 +55,7 @@ func Setup(
|
|||
}
|
||||
}
|
||||
|
||||
userID, err := gomatrixserverlib.NewUserID(vars["userID"], false)
|
||||
userID, err := spec.NewUserID(vars["userID"], false)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
|
@ -69,7 +71,7 @@ func Setup(
|
|||
|
||||
v1fedmux.Handle("/relay_txn/{userID}", MakeRelayAPI(
|
||||
"get_relay_transaction", "", cfg.Matrix.IsLocalServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||
func(httpReq *http.Request, request *fclient.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||
logrus.Infof("Handling relay_txn from: %s", request.Origin())
|
||||
if !relayAPI.RelayingEnabled() {
|
||||
logrus.Warnf("Dropping relay_txn from: %s", request.Origin())
|
||||
|
@ -78,7 +80,7 @@ func Setup(
|
|||
}
|
||||
}
|
||||
|
||||
userID, err := gomatrixserverlib.NewUserID(vars["userID"], false)
|
||||
userID, err := spec.NewUserID(vars["userID"], false)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
|
@ -92,13 +94,13 @@ func Setup(
|
|||
|
||||
// MakeRelayAPI makes an http.Handler that checks matrix relay authentication.
|
||||
func MakeRelayAPI(
|
||||
metricsName string, serverName gomatrixserverlib.ServerName,
|
||||
isLocalServerName func(gomatrixserverlib.ServerName) bool,
|
||||
metricsName string, serverName spec.ServerName,
|
||||
isLocalServerName func(spec.ServerName) bool,
|
||||
keyRing gomatrixserverlib.JSONVerifier,
|
||||
f func(*http.Request, *gomatrixserverlib.FederationRequest, map[string]string) util.JSONResponse,
|
||||
f func(*http.Request, *fclient.FederationRequest, map[string]string) util.JSONResponse,
|
||||
) http.Handler {
|
||||
h := func(req *http.Request) util.JSONResponse {
|
||||
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
|
||||
fedReq, errResp := fclient.VerifyHTTPRequest(
|
||||
req, time.Now(), serverName, isLocalServerName, keyRing,
|
||||
)
|
||||
if fedReq == nil {
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/relayapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -30,10 +31,10 @@ import (
|
|||
// This endpoint can be extracted into a separate relay server service.
|
||||
func SendTransactionToRelay(
|
||||
httpReq *http.Request,
|
||||
fedReq *gomatrixserverlib.FederationRequest,
|
||||
fedReq *fclient.FederationRequest,
|
||||
relayAPI api.RelayInternalAPI,
|
||||
txnID gomatrixserverlib.TransactionID,
|
||||
userID gomatrixserverlib.UserID,
|
||||
userID spec.UserID,
|
||||
) util.JSONResponse {
|
||||
logrus.Infof("Processing send_relay for %s", userID.Raw())
|
||||
|
||||
|
|
|
@ -26,11 +26,13 @@ import (
|
|||
"github.com/matrix-org/dendrite/relayapi/storage/shared"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
testOrigin = gomatrixserverlib.ServerName("kaer.morhen")
|
||||
testOrigin = spec.ServerName("kaer.morhen")
|
||||
)
|
||||
|
||||
func createTransaction() gomatrixserverlib.Transaction {
|
||||
|
@ -43,15 +45,15 @@ func createTransaction() gomatrixserverlib.Transaction {
|
|||
}
|
||||
|
||||
func createFederationRequest(
|
||||
userID gomatrixserverlib.UserID,
|
||||
userID spec.UserID,
|
||||
txnID gomatrixserverlib.TransactionID,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
destination gomatrixserverlib.ServerName,
|
||||
origin spec.ServerName,
|
||||
destination spec.ServerName,
|
||||
content interface{},
|
||||
) gomatrixserverlib.FederationRequest {
|
||||
) fclient.FederationRequest {
|
||||
var federationPathPrefixV1 = "/_matrix/federation/v1"
|
||||
path := federationPathPrefixV1 + "/send_relay/" + string(txnID) + "/" + userID.Raw()
|
||||
request := gomatrixserverlib.NewFederationRequest("PUT", origin, destination, path)
|
||||
request := fclient.NewFederationRequest("PUT", origin, destination, path)
|
||||
request.SetContent(content)
|
||||
|
||||
return request
|
||||
|
@ -65,7 +67,7 @@ func TestForwardEmptyReturnsOk(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
txn := createTransaction()
|
||||
|
@ -88,7 +90,7 @@ func TestForwardBadJSONReturnsError(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
type BadData struct {
|
||||
|
@ -117,7 +119,7 @@ func TestForwardTooManyPDUsReturnsError(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
type BadData struct {
|
||||
|
@ -151,7 +153,7 @@ func TestForwardTooManyEDUsReturnsError(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
type BadData struct {
|
||||
|
@ -161,7 +163,7 @@ func TestForwardTooManyEDUsReturnsError(t *testing.T) {
|
|||
Field: []gomatrixserverlib.EDU{},
|
||||
}
|
||||
for i := 0; i < 101; i++ {
|
||||
content.Field = append(content.Field, gomatrixserverlib.EDU{Type: gomatrixserverlib.MTyping})
|
||||
content.Field = append(content.Field, gomatrixserverlib.EDU{Type: spec.MTyping})
|
||||
}
|
||||
assert.Greater(t, len(content.Field), 100)
|
||||
|
||||
|
@ -185,7 +187,7 @@ func TestUniqueTransactionStoredInDatabase(t *testing.T) {
|
|||
RelayQueueJSON: testDB,
|
||||
}
|
||||
httpReq := &http.Request{}
|
||||
userID, err := gomatrixserverlib.NewUserID("@local:domain", false)
|
||||
userID, err := spec.NewUserID("@local:domain", false)
|
||||
assert.NoError(t, err, "Invalid userID")
|
||||
|
||||
txn := createTransaction()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue