test drop in replacement of jsoniter

Signed-off-by: 6543 <6543@obermui.de>
This commit is contained in:
6543 2020-12-21 15:33:53 +01:00
parent a85051ca9d
commit 3dd0b89d0f
No known key found for this signature in database
GPG key ID: A1CA74D27FD13271
122 changed files with 350 additions and 245 deletions

View file

@ -16,7 +16,6 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"github.com/matrix-org/dendrite/appservice/storage" "github.com/matrix-org/dendrite/appservice/storage"
"github.com/matrix-org/dendrite/appservice/types" "github.com/matrix-org/dendrite/appservice/types"
@ -26,9 +25,12 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// OutputRoomEventConsumer consumes events that originated in the room server. // OutputRoomEventConsumer consumes events that originated in the room server.
type OutputRoomEventConsumer struct { type OutputRoomEventConsumer struct {
roomServerConsumer *internal.ContinualConsumer roomServerConsumer *internal.ContinualConsumer

View file

@ -1,15 +1,17 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/appservice/api"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux. // AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux.
func AddRoutes(a api.AppServiceQueryAPI, internalAPIMux *mux.Router) { func AddRoutes(a api.AppServiceQueryAPI, internalAPIMux *mux.Router) {
internalAPIMux.Handle( internalAPIMux.Handle(

View file

@ -18,10 +18,11 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"time" "time"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -64,6 +65,8 @@ const (
invalidTxnID = -2 invalidTxnID = -2
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type eventsStatements struct { type eventsStatements struct {
selectEventsByApplicationServiceIDStmt *sql.Stmt selectEventsByApplicationServiceIDStmt *sql.Stmt
countEventsByApplicationServiceIDStmt *sql.Stmt countEventsByApplicationServiceIDStmt *sql.Stmt

View file

@ -18,11 +18,12 @@ package sqlite3
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"time" "time"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -65,6 +66,8 @@ const (
invalidTxnID = -2 invalidTxnID = -2
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type eventsStatements struct { type eventsStatements struct {
db *sql.DB db *sql.DB
writer sqlutil.Writer writer sqlutil.Writer

View file

@ -17,7 +17,6 @@ package workers
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"fmt" "fmt"
"math" "math"
"net/http" "net/http"
@ -28,6 +27,8 @@ import (
"github.com/matrix-org/dendrite/appservice/types" "github.com/matrix-org/dendrite/appservice/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"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -36,6 +37,8 @@ var (
transactionBatchSize = 50 transactionBatchSize = 50
// Timeout for sending a single transaction to an application service. // Timeout for sending a single transaction to an application service.
transactionTimeout = time.Second * 60 transactionTimeout = time.Second * 60
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
// SetupTransactionWorkers spawns a separate goroutine for each application // SetupTransactionWorkers spawns a separate goroutine for each application

View file

@ -16,17 +16,20 @@ package auth
import ( import (
"context" "context"
"encoding/json"
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"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/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Type represents an auth type // Type represents an auth type
// https://matrix.org/docs/spec/client_server/r0.6.1#authentication-types // https://matrix.org/docs/spec/client_server/r0.6.1#authentication-types
type Type interface { type Type interface {

View file

@ -2,7 +2,6 @@ package auth
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"testing" "testing"
@ -62,7 +61,7 @@ func TestUserInteractivePasswordLogin(t *testing.T) {
UserID: fmt.Sprintf("@alice:%s", serverName), UserID: fmt.Sprintf("@alice:%s", serverName),
} }
// valid password requests // valid password requests
testCases := []json.RawMessage{ testCases := [][]byte{
// deprecated form // deprecated form
[]byte(`{ []byte(`{
"auth": { "auth": {
@ -101,7 +100,7 @@ func TestUserInteractivePasswordBadLogin(t *testing.T) {
} }
// invalid password requests // invalid password requests
testCases := []struct { testCases := []struct {
body json.RawMessage body []byte
wantRes util.JSONResponse wantRes util.JSONResponse
}{ }{
{ {

View file

@ -15,15 +15,18 @@
package httputil package httputil
import ( import (
"encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"unicode/utf8" "unicode/utf8"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if // UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if
// there was a problem unmarshalling. Calling this function consumes the request body. // there was a problem unmarshalling. Calling this function consumes the request body.
func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse { func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse {

View file

@ -15,10 +15,13 @@
package jsonerror package jsonerror
import ( import (
"encoding/json"
"testing" "testing"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
func TestLimitExceeded(t *testing.T) { func TestLimitExceeded(t *testing.T) {
e := LimitExceeded("too fast", 5000) e := LimitExceeded("too fast", 5000)
jsonBytes, err := json.Marshal(&e) jsonBytes, err := json.Marshal(&e)

View file

@ -15,13 +15,15 @@
package producers package producers
import ( import (
"encoding/json" "github.com/matrix-org/dendrite/internal/eventutil"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal/eventutil" jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// SyncAPIProducer produces events for the sync API server to consume // SyncAPIProducer produces events for the sync API server to consume
type SyncAPIProducer struct { type SyncAPIProducer struct {
Topic string Topic string

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -53,7 +52,7 @@ func GetAccountData(
return util.ErrorResponse(fmt.Errorf("userAPI.QueryAccountData: %w", err)) return util.ErrorResponse(fmt.Errorf("userAPI.QueryAccountData: %w", err))
} }
var data json.RawMessage var data []byte
var ok bool var ok bool
if roomID != "" { if roomID != "" {
data, ok = dataRes.RoomAccountData[roomID][dataType] data, ok = dataRes.RoomAccountData[roomID][dataType]
@ -118,7 +117,7 @@ func SaveAccountData(
UserID: userID, UserID: userID,
DataType: dataType, DataType: dataType,
RoomID: roomID, RoomID: roomID,
AccountData: json.RawMessage(body), AccountData: []byte(body),
} }
dataRes := api.InputAccountDataResponse{} dataRes := api.InputAccountDataResponse{}
if err := userAPI.InputAccountData(req.Context(), &dataReq, &dataRes); err != nil { if err := userAPI.InputAccountData(req.Context(), &dataReq, &dataRes); err != nil {

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"time" "time"
@ -27,8 +26,8 @@ import (
) )
type uploadKeysRequest struct { type uploadKeysRequest struct {
DeviceKeys json.RawMessage `json:"device_keys"` DeviceKeys []byte `json:"device_keys"`
OneTimeKeys map[string]json.RawMessage `json:"one_time_keys"` OneTimeKeys map[string][]byte `json:"one_time_keys"`
} }
func UploadKeys(req *http.Request, keyAPI api.KeyInternalAPI, device *userapi.Device) util.JSONResponse { func UploadKeys(req *http.Request, keyAPI api.KeyInternalAPI, device *userapi.Device) util.JSONResponse {

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"

View file

@ -19,7 +19,6 @@ import (
"context" "context"
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -205,7 +204,7 @@ func saveTagData(
UserID: userID, UserID: userID,
RoomID: roomID, RoomID: roomID,
DataType: "m.tag", DataType: "m.tag",
AccountData: json.RawMessage(newTagData), AccountData: []byte(newTagData),
} }
dataRes := api.InputAccountDataResponse{} dataRes := api.InputAccountDataResponse{}
return userAPI.InputAccountData(req.Context(), &dataReq, &dataRes) return userAPI.InputAccountData(req.Context(), &dataReq, &dataRes)

View file

@ -15,11 +15,9 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"strings" "strings"
"github.com/gorilla/mux"
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"
"github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth"
@ -37,8 +35,13 @@ import (
"github.com/matrix-org/dendrite/userapi/storage/accounts" "github.com/matrix-org/dendrite/userapi/storage/accounts"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests. // to clients which need to make outbound HTTP requests.
// //
@ -480,7 +483,7 @@ func Setup(
r0mux.Handle("/pushrules/", r0mux.Handle("/pushrules/",
httputil.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse { httputil.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse {
// TODO: Implement push rules API // TODO: Implement push rules API
res := json.RawMessage(`{ res := []byte(`{
"global": { "global": {
"content": [], "content": [],
"override": [], "override": [],

View file

@ -13,7 +13,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/httputil"
@ -39,7 +38,7 @@ func SendToDevice(
} }
var httpReq struct { var httpReq struct {
Messages map[string]map[string]json.RawMessage `json:"messages"` Messages map[string]map[string][]byte `json:"messages"`
} }
resErr := httputil.UnmarshalJSONRequest(req, &httpReq) resErr := httputil.UnmarshalJSONRequest(req, &httpReq)
if resErr != nil { if resErr != nil {

View file

@ -16,7 +16,6 @@ package routing
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -30,8 +29,8 @@ import (
type stateEventInStateResp struct { type stateEventInStateResp struct {
gomatrixserverlib.ClientEvent gomatrixserverlib.ClientEvent
PrevContent json.RawMessage `json:"prev_content,omitempty"` PrevContent []byte `json:"prev_content,omitempty"`
ReplacesState string `json:"replaces_state,omitempty"` ReplacesState string `json:"replaces_state,omitempty"`
} }
// OnIncomingStateRequest is called when a client makes a /rooms/{roomID}/state // OnIncomingStateRequest is called when a client makes a /rooms/{roomID}/state

View file

@ -16,7 +16,6 @@ package threepid
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"

View file

@ -16,7 +16,6 @@ package threepid
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
@ -25,8 +24,12 @@ import (
"strings" "strings"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// 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
type EmailAssociationRequest struct { type EmailAssociationRequest struct {
IDServer string `json:"id_server"` IDServer string `json:"id_server"`

View file

@ -18,7 +18,6 @@ package main
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -27,6 +26,8 @@ import (
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
) )
@ -48,6 +49,8 @@ var (
messageCount = flag.Int("message-count", 10, "The number of m.room.messsage events to generate") messageCount = flag.Int("message-count", 10, "The number of m.room.messsage events to generate")
format = flag.String("Format", "InputRoomEvent", "The output format to use for the messages: InputRoomEvent or Event") format = flag.String("Format", "InputRoomEvent", "The output format to use for the messages: InputRoomEvent or Event")
ver = flag.String("version", string(gomatrixserverlib.RoomVersionV1), "Room version to generate events as") ver = flag.String("version", string(gomatrixserverlib.RoomVersionV1), "Room version to generate events as")
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
// By default we use a private key of 0. // By default we use a private key of 0.

View file

@ -16,7 +16,6 @@ package main
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -24,6 +23,7 @@ import (
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
jsoniter "github.com/json-iterator/go"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
@ -31,6 +31,8 @@ import (
const MaintenanceInterval = time.Second * 10 const MaintenanceInterval = time.Second * 10
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type discoveredRoom struct { type discoveredRoom struct {
time time.Time time time.Time
room gomatrixserverlib.PublicRoom room gomatrixserverlib.PublicRoom

View file

@ -19,7 +19,6 @@ import (
"crypto/ed25519" "crypto/ed25519"
"crypto/tls" "crypto/tls"
"encoding/hex" "encoding/hex"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -39,8 +38,11 @@ import (
"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
gologme "github.com/gologme/log" gologme "github.com/gologme/log"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Node struct { type Node struct {
core *yggdrasil.Core core *yggdrasil.Core
config *yggdrasilconfig.NodeConfig config *yggdrasilconfig.NodeConfig

View file

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ed25519" "crypto/ed25519"
"encoding/json"
"encoding/pem" "encoding/pem"
"flag" "flag"
"fmt" "fmt"
@ -14,12 +13,16 @@ import (
"os" "os"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
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")
var requestKey = flag.String("key", "matrix_key.pem", "the private key to use when signing the request") var requestKey = flag.String("key", "matrix_key.pem", "the private key to use when signing the request")
var requestPost = flag.Bool("post", false, "send a POST request instead of GET (pipe input into stdin or type followed by Ctrl-D)") var requestPost = flag.Bool("post", false, "send a POST request instead of GET (pipe input into stdin or type followed by Ctrl-D)")
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// nolint:gocyclo // nolint:gocyclo
func main() { func main() {
flag.Parse() flag.Parse()

View file

@ -18,22 +18,21 @@ import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"encoding/json"
"net/http"
"github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/internal/test"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/inthttp" "github.com/matrix-org/dendrite/roomserver/inthttp"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
var ( var (
@ -55,6 +54,8 @@ var (
testDatabaseName = defaulting(os.Getenv("DATABASE_NAME"), "roomserver_test") testDatabaseName = defaulting(os.Getenv("DATABASE_NAME"), "roomserver_test")
// The postgres connection config for connecting to the test database. // The postgres connection config for connecting to the test database.
testDatabase = defaulting(os.Getenv("DATABASE"), fmt.Sprintf("dbname=%s binary_parameters=yes", testDatabaseName)) testDatabase = defaulting(os.Getenv("DATABASE"), fmt.Sprintf("dbname=%s binary_parameters=yes", testDatabaseName))
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
var exe = test.KafkaExecutor{ var exe = test.KafkaExecutor{

View file

@ -15,7 +15,6 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -28,6 +27,8 @@ 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"
jsoniter "github.com/json-iterator/go"
) )
var ( var (
@ -51,6 +52,8 @@ var (
testDatabaseName = test.Defaulting(os.Getenv("DATABASE_NAME"), "syncserver_test") testDatabaseName = test.Defaulting(os.Getenv("DATABASE_NAME"), "syncserver_test")
// The postgres connection config for connecting to the test database. // The postgres connection config for connecting to the test database.
testDatabase = test.Defaulting(os.Getenv("DATABASE"), fmt.Sprintf("dbname=%s sslmode=disable binary_parameters=yes", testDatabaseName)) testDatabase = test.Defaulting(os.Getenv("DATABASE"), fmt.Sprintf("dbname=%s sslmode=disable binary_parameters=yes", testDatabaseName))
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
const inputTopic = "syncserverInput" const inputTopic = "syncserverInput"

View file

@ -16,12 +16,14 @@ package api
import ( import (
"context" "context"
"encoding/json"
"time" "time"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// SendTyping sends a typing event to EDU server // SendTyping sends a typing event to EDU server
func SendTyping( func SendTyping(
ctx context.Context, eduAPI EDUServerInputAPI, userID, roomID string, ctx context.Context, eduAPI EDUServerInputAPI, userID, roomID string,

View file

@ -18,10 +18,10 @@ package input
import ( import (
"context" "context"
"encoding/json"
"time" "time"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/eduserver/cache" "github.com/matrix-org/dendrite/eduserver/cache"
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
@ -29,6 +29,8 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// EDUServerInputAPI implements api.EDUServerInputAPI // EDUServerInputAPI implements api.EDUServerInputAPI
type EDUServerInputAPI struct { type EDUServerInputAPI struct {
// Cache to store the current typing members in each room. // Cache to store the current typing members in each room.

View file

@ -1,15 +1,17 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// AddRoutes adds the EDUServerInputAPI handlers to the http.ServeMux. // AddRoutes adds the EDUServerInputAPI handlers to the http.ServeMux.
func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) { func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) {
internalAPIMux.Handle(EDUServerInputTypingEventPath, internalAPIMux.Handle(EDUServerInputTypingEventPath,

View file

@ -15,7 +15,7 @@
package routing package routing
import ( import (
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
@ -102,7 +102,7 @@ func Backfill(
} }
} }
eventJSONs := []json.RawMessage{} eventJSONs := []stdjson.RawMessage{}
for _, e := range gomatrixserverlib.ReverseTopologicalOrdering( for _, e := range gomatrixserverlib.ReverseTopologicalOrdering(
evs, evs,
gomatrixserverlib.TopologicalOrderByPrevEvents, gomatrixserverlib.TopologicalOrderByPrevEvents,

View file

@ -13,7 +13,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"

View file

@ -16,7 +16,7 @@ package routing
import ( import (
"context" "context"
"encoding/json" stdjson "encoding/json"
"net/http" "net/http"
"time" "time"
@ -45,7 +45,7 @@ func GetEvent(
return util.JSONResponse{Code: http.StatusOK, JSON: gomatrixserverlib.Transaction{ return util.JSONResponse{Code: http.StatusOK, JSON: gomatrixserverlib.Transaction{
Origin: origin, Origin: origin,
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()), OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
PDUs: []json.RawMessage{ PDUs: []stdjson.RawMessage{
event.JSON(), event.JSON(),
}, },
}} }}

View file

@ -16,7 +16,6 @@ package routing
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"time" "time"
@ -184,9 +183,9 @@ func NotaryKeys(
} }
var response struct { var response struct {
ServerKeys []json.RawMessage `json:"server_keys"` ServerKeys [][]byte `json:"server_keys"`
} }
response.ServerKeys = []json.RawMessage{} response.ServerKeys = [][]byte{}
for serverName := range req.ServerKeys { for serverName := range req.ServerKeys {
var keys *gomatrixserverlib.ServerKeys var keys *gomatrixserverlib.ServerKeys

View file

@ -13,7 +13,6 @@
package routing package routing
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"

View file

@ -17,7 +17,6 @@ package routing
import ( import (
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
eduserverAPI "github.com/matrix-org/dendrite/eduserver/api" eduserverAPI "github.com/matrix-org/dendrite/eduserver/api"
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
@ -28,8 +27,13 @@ import (
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/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Setup registers HTTP handlers with the given ServeMux. // Setup registers HTTP handlers with the given ServeMux.
// The provided publicAPIMux MUST have `UseEncodedPath()` enabled or else routes will incorrectly // The provided publicAPIMux MUST have `UseEncodedPath()` enabled or else routes will incorrectly
// path unescape twice (once from the router, once from MakeFedAPI). We need to have this enabled // path unescape twice (once from the router, once from MakeFedAPI). We need to have this enabled

View file

@ -17,7 +17,7 @@ package routing
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sync" "sync"
@ -56,7 +56,7 @@ func Send(
} }
var txnEvents struct { var txnEvents struct {
PDUs []json.RawMessage `json:"pdus"` PDUs []stdjson.RawMessage `json:"pdus"`
EDUs []gomatrixserverlib.EDU `json:"edus"` EDUs []gomatrixserverlib.EDU `json:"edus"`
} }

View file

@ -2,7 +2,7 @@ package routing
import ( import (
"context" "context"
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"reflect" "reflect"
"testing" "testing"
@ -21,7 +21,7 @@ const (
var ( var (
testRoomVersion = gomatrixserverlib.RoomVersionV1 testRoomVersion = gomatrixserverlib.RoomVersionV1
testData = []json.RawMessage{ testData = [][]byte{
[]byte(`{"auth_events":[],"content":{"creator":"@userid:kaer.morhen"},"depth":0,"event_id":"$0ok8ynDp7kjc95e3:kaer.morhen","hashes":{"sha256":"17kPoH+h0Dk4Omn7Sus0qMb6+oGcf+CZFEgDhv7UKWs"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"jP4a04f5/F10Pw95FPpdCyKAO44JOwUQ/MZOOeA/RTU1Dn+AHPMzGSaZnuGjRr/xQuADt+I3ctb5ZQfLKNzHDw"}},"state_key":"","type":"m.room.create"}`), []byte(`{"auth_events":[],"content":{"creator":"@userid:kaer.morhen"},"depth":0,"event_id":"$0ok8ynDp7kjc95e3:kaer.morhen","hashes":{"sha256":"17kPoH+h0Dk4Omn7Sus0qMb6+oGcf+CZFEgDhv7UKWs"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"jP4a04f5/F10Pw95FPpdCyKAO44JOwUQ/MZOOeA/RTU1Dn+AHPMzGSaZnuGjRr/xQuADt+I3ctb5ZQfLKNzHDw"}},"state_key":"","type":"m.room.create"}`),
[]byte(`{"auth_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}]],"content":{"membership":"join"},"depth":1,"event_id":"$LEwEu0kxrtu5fOiS:kaer.morhen","hashes":{"sha256":"B7M88PhXf3vd1LaFtjQutFu4x/w7fHD28XKZ4sAsJTo"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}]],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"p2vqmuJn7ZBRImctSaKbXCAxCcBlIjPH9JHte1ouIUGy84gpu4eLipOvSBCLL26hXfC0Zrm4WUto6Hr+ohdrCg"}},"state_key":"@userid:kaer.morhen","type":"m.room.member"}`), []byte(`{"auth_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}]],"content":{"membership":"join"},"depth":1,"event_id":"$LEwEu0kxrtu5fOiS:kaer.morhen","hashes":{"sha256":"B7M88PhXf3vd1LaFtjQutFu4x/w7fHD28XKZ4sAsJTo"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}]],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"p2vqmuJn7ZBRImctSaKbXCAxCcBlIjPH9JHte1ouIUGy84gpu4eLipOvSBCLL26hXfC0Zrm4WUto6Hr+ohdrCg"}},"state_key":"@userid:kaer.morhen","type":"m.room.member"}`),
[]byte(`{"auth_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}],["$LEwEu0kxrtu5fOiS:kaer.morhen",{"sha256":"1aKajq6DWHru1R1HJjvdWMEavkJJHGaTmPvfuERUXaA"}]],"content":{"join_rule":"public"},"depth":2,"event_id":"$SMHlqUrNhhBBRLeN:kaer.morhen","hashes":{"sha256":"vIuJQvmMjrGxshAkj1SXe0C4RqvMbv4ZADDw9pFCWqQ"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[["$LEwEu0kxrtu5fOiS:kaer.morhen",{"sha256":"1aKajq6DWHru1R1HJjvdWMEavkJJHGaTmPvfuERUXaA"}]],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"hBMsb3Qppo3RaqqAl4JyTgaiWEbW5hlckATky6PrHun+F3YM203TzG7w9clwuQU5F5pZoB1a6nw+to0hN90FAw"}},"state_key":"","type":"m.room.join_rules"}`), []byte(`{"auth_events":[["$0ok8ynDp7kjc95e3:kaer.morhen",{"sha256":"sWCi6Ckp9rDimQON+MrUlNRkyfZ2tjbPbWfg2NMB18Q"}],["$LEwEu0kxrtu5fOiS:kaer.morhen",{"sha256":"1aKajq6DWHru1R1HJjvdWMEavkJJHGaTmPvfuERUXaA"}]],"content":{"join_rule":"public"},"depth":2,"event_id":"$SMHlqUrNhhBBRLeN:kaer.morhen","hashes":{"sha256":"vIuJQvmMjrGxshAkj1SXe0C4RqvMbv4ZADDw9pFCWqQ"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[["$LEwEu0kxrtu5fOiS:kaer.morhen",{"sha256":"1aKajq6DWHru1R1HJjvdWMEavkJJHGaTmPvfuERUXaA"}]],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"hBMsb3Qppo3RaqqAl4JyTgaiWEbW5hlckATky6PrHun+F3YM203TzG7w9clwuQU5F5pZoB1a6nw+to0hN90FAw"}},"state_key":"","type":"m.room.join_rules"}`),
@ -362,7 +362,7 @@ func (c *txnFedClient) LookupMissingEvents(ctx context.Context, s gomatrixserver
return c.getMissingEvents(missing) return c.getMissingEvents(missing)
} }
func mustCreateTransaction(rsAPI api.RoomserverInternalAPI, fedClient txnFederationClient, pdus []json.RawMessage) *txnReq { func mustCreateTransaction(rsAPI api.RoomserverInternalAPI, fedClient txnFederationClient, pdus []stdjson.RawMessage) *txnReq {
t := &txnReq{ t := &txnReq{
rsAPI: rsAPI, rsAPI: rsAPI,
eduAPI: &testEDUProducer{}, eduAPI: &testEDUProducer{},
@ -445,7 +445,7 @@ func TestBasicTransaction(t *testing.T) {
} }
}, },
} }
pdus := []json.RawMessage{ pdus := []stdjson.RawMessage{
testData[len(testData)-1], // a message event testData[len(testData)-1], // a message event
} }
txn := mustCreateTransaction(rsAPI, &txnFedClient{}, pdus) txn := mustCreateTransaction(rsAPI, &txnFedClient{}, pdus)
@ -465,7 +465,7 @@ func TestTransactionFailAuthChecks(t *testing.T) {
} }
}, },
} }
pdus := []json.RawMessage{ pdus := []stdjson.RawMessage{
testData[len(testData)-1], // a message event testData[len(testData)-1], // a message event
} }
txn := mustCreateTransaction(rsAPI, &txnFedClient{}, pdus) txn := mustCreateTransaction(rsAPI, &txnFedClient{}, pdus)
@ -550,7 +550,7 @@ func TestTransactionFetchMissingPrevEvents(t *testing.T) {
}, },
} }
pdus := []json.RawMessage{ pdus := []stdjson.RawMessage{
inputEvent.JSON(), inputEvent.JSON(),
} }
txn := mustCreateTransaction(rsAPI, cli, pdus) txn := mustCreateTransaction(rsAPI, cli, pdus)
@ -713,7 +713,7 @@ func TestTransactionFetchMissingStateByStateIDs(t *testing.T) {
// /event for event B returns it // /event for event B returns it
getEvent: map[string]gomatrixserverlib.Transaction{ getEvent: map[string]gomatrixserverlib.Transaction{
eventB.EventID(): { eventB.EventID(): {
PDUs: []json.RawMessage{ PDUs: []stdjson.RawMessage{
eventB.JSON(), eventB.JSON(),
}, },
}, },
@ -735,7 +735,7 @@ func TestTransactionFetchMissingStateByStateIDs(t *testing.T) {
}, },
} }
pdus := []json.RawMessage{ pdus := []stdjson.RawMessage{
eventD.JSON(), eventD.JSON(),
} }
txn := mustCreateTransaction(rsAPI, cli, pdus) txn := mustCreateTransaction(rsAPI, cli, pdus)

View file

@ -16,7 +16,6 @@ package routing
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"net/http" "net/http"
"time" "time"

View file

@ -16,10 +16,9 @@ package consumers
import ( import (
"context" "context"
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/federationsender/queue" "github.com/matrix-org/dendrite/federationsender/queue"
"github.com/matrix-org/dendrite/federationsender/storage" "github.com/matrix-org/dendrite/federationsender/storage"
@ -27,9 +26,14 @@ 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/util" "github.com/matrix-org/util"
"github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// OutputEDUConsumer consumes events that originate in EDU server. // OutputEDUConsumer consumes events that originate in EDU server.
type OutputEDUConsumer struct { type OutputEDUConsumer struct {
typingConsumer *internal.ContinualConsumer typingConsumer *internal.ContinualConsumer
@ -131,7 +135,7 @@ func (t *OutputEDUConsumer) onSendToDeviceEvent(msg *sarama.ConsumerMessage) err
Sender: ote.Sender, Sender: ote.Sender,
Type: ote.Type, Type: ote.Type,
MessageID: util.RandomString(32), MessageID: util.RandomString(32),
Messages: map[string]map[string]json.RawMessage{ Messages: map[string]map[string]stdjson.RawMessage{
ote.UserID: { ote.UserID: {
ote.DeviceID: ote.Content, ote.DeviceID: ote.Content,
}, },

View file

@ -16,7 +16,6 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"

View file

@ -16,7 +16,6 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"

View file

@ -2,7 +2,6 @@ package internal
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"time" "time"
@ -14,9 +13,13 @@ 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/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// PerformLeaveRequest implements api.FederationSenderInternalAPI // PerformLeaveRequest implements api.FederationSenderInternalAPI
func (r *FederationSenderInternalAPI) PerformDirectoryLookup( func (r *FederationSenderInternalAPI) PerformDirectoryLookup(
ctx context.Context, ctx context.Context,

View file

@ -1,15 +1,18 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// AddRoutes adds the FederationSenderInternalAPI handlers to the http.ServeMux. // AddRoutes adds the FederationSenderInternalAPI handlers to the http.ServeMux.
// nolint:gocyclo // nolint:gocyclo
func AddRoutes(intAPI api.FederationSenderInternalAPI, internalAPIMux *mux.Router) { func AddRoutes(intAPI api.FederationSenderInternalAPI, internalAPIMux *mux.Router) {

View file

@ -16,7 +16,7 @@ package queue
import ( import (
"context" "context"
"encoding/json" stdjson "encoding/json"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -27,6 +27,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.uber.org/atomic" "go.uber.org/atomic"
@ -367,7 +368,7 @@ func (oq *destinationQueue) nextTransaction(
// Create the transaction. // Create the transaction.
t := gomatrixserverlib.Transaction{ t := gomatrixserverlib.Transaction{
PDUs: []json.RawMessage{}, PDUs: []stdjson.RawMessage{},
EDUs: []gomatrixserverlib.EDU{}, EDUs: []gomatrixserverlib.EDU{},
} }
t.Origin = oq.origin t.Origin = oq.origin
@ -390,7 +391,7 @@ func (oq *destinationQueue) nextTransaction(
if pdu == nil || pdu.pdu == nil { if pdu == nil || pdu.pdu == nil {
continue continue
} }
// Append the JSON of the event, since this is a json.RawMessage type in the // Append the JSON of the event, since this is a []byte type in the
// gomatrixserverlib.Transaction struct // gomatrixserverlib.Transaction struct
t.PDUs = append(t.PDUs, pdu.pdu.JSON()) t.PDUs = append(t.PDUs, pdu.pdu.JSON())
pduReceipts = append(pduReceipts, pdu.receipt) pduReceipts = append(pduReceipts, pdu.receipt)

View file

@ -17,7 +17,6 @@ package queue
import ( import (
"context" "context"
"crypto/ed25519" "crypto/ed25519"
"encoding/json"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -27,11 +26,15 @@ import (
"github.com/matrix-org/dendrite/federationsender/storage/shared" "github.com/matrix-org/dendrite/federationsender/storage/shared"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// OutgoingQueues is a collection of queues for sending transactions to other // OutgoingQueues is a collection of queues for sending transactions to other
// matrix servers // matrix servers
type OutgoingQueues struct { type OutgoingQueues struct {

View file

@ -24,8 +24,12 @@ 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/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Database struct { type Database struct {
DB *sql.DB DB *sql.DB
Cache caching.FederationSenderCache Cache caching.FederationSenderCache

View file

@ -17,7 +17,6 @@ package shared
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"errors" "errors"
"fmt" "fmt"

View file

@ -17,7 +17,6 @@ package shared
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"errors" "errors"
"fmt" "fmt"

2
go.mod
View file

@ -7,6 +7,7 @@ require (
github.com/gologme/log v1.2.0 github.com/gologme/log v1.2.0
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/golang-lru v0.5.4
github.com/json-iterator/go v1.1.10
github.com/lib/pq v1.8.0 github.com/lib/pq v1.8.0
github.com/libp2p/go-libp2p v0.11.0 github.com/libp2p/go-libp2p v0.11.0
github.com/libp2p/go-libp2p-circuit v0.3.1 github.com/libp2p/go-libp2p-circuit v0.3.1
@ -33,6 +34,7 @@ require (
github.com/pressly/goose v2.7.0-rc5+incompatible github.com/pressly/goose v2.7.0-rc5+incompatible
github.com/prometheus/client_golang v1.7.1 github.com/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.3 github.com/tidwall/gjson v1.6.3
github.com/tidwall/match v1.0.2 // indirect github.com/tidwall/match v1.0.2 // indirect
github.com/tidwall/sjson v1.1.2 github.com/tidwall/sjson v1.1.2

3
go.sum
View file

@ -282,6 +282,7 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
@ -607,8 +608,10 @@ github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=

View file

@ -17,16 +17,18 @@ package httputil
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
jsoniter "github.com/json-iterator/go"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// PostJSON performs a POST request with JSON on an internal HTTP API // PostJSON performs a POST request with JSON on an internal HTTP API
func PostJSON( func PostJSON(
ctx context.Context, span opentracing.Span, httpClient *http.Client, ctx context.Context, span opentracing.Span, httpClient *http.Client,

View file

@ -16,7 +16,6 @@ package api
import ( import (
"context" "context"
"encoding/json"
"strings" "strings"
"time" "time"
@ -83,7 +82,7 @@ type OneTimeKeys struct {
// The device ID of this device // The device ID of this device
DeviceID string DeviceID string
// A map of algorithm:key_id => key JSON // A map of algorithm:key_id => key JSON
KeyJSON map[string]json.RawMessage KeyJSON map[string][]byte
} }
// Split a key in KeyJSON into algorithm and key ID // Split a key in KeyJSON into algorithm and key ID
@ -142,7 +141,7 @@ type PerformClaimKeysRequest struct {
type PerformClaimKeysResponse struct { type PerformClaimKeysResponse struct {
// Map of user_id to device_id to algorithm:key_id to key JSON // Map of user_id to device_id to algorithm:key_id to key JSON
OneTimeKeys map[string]map[string]map[string]json.RawMessage OneTimeKeys map[string]map[string]map[string][]byte
// Map of remote server domain to error JSON // Map of remote server domain to error JSON
Failures map[string]interface{} Failures map[string]interface{}
// Set if there was a fatal error processing this action // Set if there was a fatal error processing this action
@ -159,7 +158,7 @@ type QueryKeysResponse struct {
// Map of remote server domain to error JSON // Map of remote server domain to error JSON
Failures map[string]interface{} Failures map[string]interface{}
// 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][]byte
// Set if there was a fatal error processing this query // Set if there was a fatal error processing this query
Error *KeyError Error *KeyError
} }

View file

@ -16,7 +16,6 @@ package internal
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"sync" "sync"

View file

@ -17,7 +17,6 @@ package internal
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -29,11 +28,15 @@ import (
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/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/tidwall/sjson" "github.com/tidwall/sjson"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type KeyInternalAPI struct { type KeyInternalAPI struct {
DB storage.Database DB storage.Database
ThisServer gomatrixserverlib.ServerName ThisServer gomatrixserverlib.ServerName
@ -80,7 +83,7 @@ func (a *KeyInternalAPI) PerformUploadKeys(ctx context.Context, req *api.Perform
} }
func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse) { func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformClaimKeysRequest, res *api.PerformClaimKeysResponse) {
res.OneTimeKeys = make(map[string]map[string]map[string]json.RawMessage) res.OneTimeKeys = make(map[string]map[string]map[string][]byte)
res.Failures = make(map[string]interface{}) res.Failures = make(map[string]interface{})
// wrap request map in a top-level by-domain map // wrap request map in a top-level by-domain map
domainToDeviceKeys := make(map[string]map[string]map[string]string) domainToDeviceKeys := make(map[string]map[string]map[string]string)
@ -108,11 +111,11 @@ func (a *KeyInternalAPI) PerformClaimKeys(ctx context.Context, req *api.PerformC
for _, key := range keys { for _, key := range keys {
_, ok := res.OneTimeKeys[key.UserID] _, ok := res.OneTimeKeys[key.UserID]
if !ok { if !ok {
res.OneTimeKeys[key.UserID] = make(map[string]map[string]json.RawMessage) res.OneTimeKeys[key.UserID] = make(map[string]map[string][]byte)
} }
_, ok = res.OneTimeKeys[key.UserID][key.DeviceID] _, ok = res.OneTimeKeys[key.UserID][key.DeviceID]
if !ok { if !ok {
res.OneTimeKeys[key.UserID][key.DeviceID] = make(map[string]json.RawMessage) res.OneTimeKeys[key.UserID][key.DeviceID] = make(map[string][]byte)
} }
for keyID, keyJSON := range key.KeyJSON { for keyID, keyJSON := range key.KeyJSON {
res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON
@ -165,9 +168,9 @@ func (a *KeyInternalAPI) claimRemoteKeys(
keysClaimed := 0 keysClaimed := 0
for result := range resultCh { for result := range resultCh {
for userID, nest := range result.OneTimeKeys { for userID, nest := range result.OneTimeKeys {
res.OneTimeKeys[userID] = make(map[string]map[string]json.RawMessage) res.OneTimeKeys[userID] = make(map[string]map[string][]byte)
for deviceID, nest2 := range nest { for deviceID, nest2 := range nest {
res.OneTimeKeys[userID][deviceID] = make(map[string]json.RawMessage) res.OneTimeKeys[userID][deviceID] = make(map[string][]byte)
for keyIDWithAlgo, otk := range nest2 { for keyIDWithAlgo, otk := range nest2 {
keyJSON, err := json.Marshal(otk) keyJSON, err := json.Marshal(otk)
if err != nil { if err != nil {
@ -220,7 +223,7 @@ func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.Query
} }
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) { func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
res.DeviceKeys = make(map[string]map[string]json.RawMessage) res.DeviceKeys = make(map[string]map[string][]byte)
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
domainToDeviceKeys := make(map[string]map[string][]string) domainToDeviceKeys := make(map[string]map[string][]string)
@ -254,7 +257,7 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
} }
if res.DeviceKeys[userID] == nil { if res.DeviceKeys[userID] == nil {
res.DeviceKeys[userID] = make(map[string]json.RawMessage) res.DeviceKeys[userID] = make(map[string][]byte)
} }
for _, dk := range deviceKeys { for _, dk := range deviceKeys {
if len(dk.KeyJSON) == 0 { if len(dk.KeyJSON) == 0 {
@ -335,7 +338,7 @@ func (a *KeyInternalAPI) queryRemoteKeys(
for result := range resultCh { for result := range resultCh {
for userID, nest := range result.DeviceKeys { for userID, nest := range result.DeviceKeys {
res.DeviceKeys[userID] = make(map[string]json.RawMessage) res.DeviceKeys[userID] = make(map[string][]byte)
for deviceID, deviceKey := range nest { for deviceID, deviceKey := range nest {
keyJSON, err := json.Marshal(deviceKey) keyJSON, err := json.Marshal(deviceKey)
if err != nil { if err != nil {
@ -432,7 +435,7 @@ func (a *KeyInternalAPI) populateResponseWithDeviceKeysFromDatabase(
return fmt.Errorf("DeviceKeysForUser %s returned no keys but wanted all keys, falling back to remote", userID) return fmt.Errorf("DeviceKeysForUser %s returned no keys but wanted all keys, falling back to remote", userID)
} }
if res.DeviceKeys[userID] == nil { if res.DeviceKeys[userID] == nil {
res.DeviceKeys[userID] = make(map[string]json.RawMessage) res.DeviceKeys[userID] = make(map[string][]byte)
} }
for _, key := range keys { for _, key := range keys {

View file

@ -15,15 +15,18 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) { func AddRoutes(internalAPIMux *mux.Router, s api.KeyInternalAPI) {
internalAPIMux.Handle(InputDeviceListUpdatePath, internalAPIMux.Handle(InputDeviceListUpdatePath,
httputil.MakeInternalAPI("inputDeviceListUpdate", func(req *http.Request) util.JSONResponse { httputil.MakeInternalAPI("inputDeviceListUpdate", func(req *http.Request) util.JSONResponse {

View file

@ -16,14 +16,16 @@ package producers
import ( import (
"context" "context"
"encoding/json"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/dendrite/keyserver/storage" "github.com/matrix-org/dendrite/keyserver/storage"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// KeyChange produces key change events for the sync API and federation sender to consume // KeyChange produces key change events for the sync API and federation sender to consume
type KeyChange struct { type KeyChange struct {
Topic string Topic string

View file

@ -16,7 +16,6 @@ package storage
import ( import (
"context" "context"
"encoding/json"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
@ -25,7 +24,7 @@ import (
type Database interface { type Database interface {
// ExistingOneTimeKeys returns a map of keyIDWithAlgorithm to key JSON for the given parameters. If no keys exist with this combination // ExistingOneTimeKeys returns a map of keyIDWithAlgorithm to key JSON for the given parameters. If no keys exist with this combination
// of user/device/key/algorithm 4-uple then it is omitted from the map. Returns an error when failing to communicate with the database. // of user/device/key/algorithm 4-uple then it is omitted from the map. Returns an error when failing to communicate with the database.
ExistingOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string]json.RawMessage, error) ExistingOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string][]byte, error)
// StoreOneTimeKeys persists the given one-time keys. // StoreOneTimeKeys persists the given one-time keys.
StoreOneTimeKeys(ctx context.Context, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error) StoreOneTimeKeys(ctx context.Context, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error)

View file

@ -17,7 +17,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"time" "time"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
@ -93,7 +92,7 @@ func NewPostgresOneTimeKeysTable(db *sql.DB) (tables.OneTimeKeys, error) {
return s, nil return s, nil
} }
func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string]json.RawMessage, error) { func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string][]byte, error) {
rows, err := s.selectKeysStmt.QueryContext(ctx, userID, deviceID) rows, err := s.selectKeysStmt.QueryContext(ctx, userID, deviceID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -105,7 +104,7 @@ func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, d
wantSet[ka] = true wantSet[ka] = true
} }
result := make(map[string]json.RawMessage) result := make(map[string][]byte)
for rows.Next() { for rows.Next() {
var keyID string var keyID string
var algorithm string var algorithm string
@ -115,7 +114,7 @@ func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, d
} }
keyIDWithAlgo := algorithm + ":" + keyID keyIDWithAlgo := algorithm + ":" + keyID
if wantSet[keyIDWithAlgo] { if wantSet[keyIDWithAlgo] {
result[keyIDWithAlgo] = json.RawMessage(keyJSONStr) result[keyIDWithAlgo] = []byte(keyJSONStr)
} }
} }
return result, rows.Err() return result, rows.Err()
@ -178,7 +177,7 @@ func (s *oneTimeKeysStatements) InsertOneTimeKeys(ctx context.Context, txn *sql.
func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey( func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey(
ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string, ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string,
) (map[string]json.RawMessage, error) { ) (map[string][]byte, error) {
var keyID string var keyID string
var keyJSON string var keyJSON string
err := sqlutil.TxStmtContext(ctx, txn, s.selectKeyByAlgorithmStmt).QueryRowContext(ctx, userID, deviceID, algorithm).Scan(&keyID, &keyJSON) err := sqlutil.TxStmtContext(ctx, txn, s.selectKeyByAlgorithmStmt).QueryRowContext(ctx, userID, deviceID, algorithm).Scan(&keyID, &keyJSON)
@ -189,7 +188,7 @@ func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey(
return nil, err return nil, err
} }
_, err = sqlutil.TxStmtContext(ctx, txn, s.deleteOneTimeKeyStmt).ExecContext(ctx, userID, deviceID, algorithm, keyID) _, err = sqlutil.TxStmtContext(ctx, txn, s.deleteOneTimeKeyStmt).ExecContext(ctx, userID, deviceID, algorithm, keyID)
return map[string]json.RawMessage{ return map[string][]byte{
algorithm + ":" + keyID: json.RawMessage(keyJSON), algorithm + ":" + keyID: []byte(keyJSON),
}, err }, err
} }

View file

@ -17,7 +17,6 @@ package shared
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
@ -34,7 +33,7 @@ type Database struct {
StaleDeviceListsTable tables.StaleDeviceLists StaleDeviceListsTable tables.StaleDeviceLists
} }
func (d *Database) ExistingOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string]json.RawMessage, error) { func (d *Database) ExistingOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string][]byte, error) {
return d.OneTimeKeysTable.SelectOneTimeKeys(ctx, userID, deviceID, keyIDsWithAlgorithms) return d.OneTimeKeysTable.SelectOneTimeKeys(ctx, userID, deviceID, keyIDsWithAlgorithms)
} }

View file

@ -17,7 +17,6 @@ package sqlite3
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"time" "time"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
@ -93,7 +92,7 @@ func NewSqliteOneTimeKeysTable(db *sql.DB) (tables.OneTimeKeys, error) {
return s, nil return s, nil
} }
func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string]json.RawMessage, error) { func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string][]byte, error) {
rows, err := s.selectKeysStmt.QueryContext(ctx, userID, deviceID) rows, err := s.selectKeysStmt.QueryContext(ctx, userID, deviceID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -105,7 +104,7 @@ func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, d
wantSet[ka] = true wantSet[ka] = true
} }
result := make(map[string]json.RawMessage) result := make(map[string][]byte)
for rows.Next() { for rows.Next() {
var keyID string var keyID string
var algorithm string var algorithm string
@ -115,7 +114,7 @@ func (s *oneTimeKeysStatements) SelectOneTimeKeys(ctx context.Context, userID, d
} }
keyIDWithAlgo := algorithm + ":" + keyID keyIDWithAlgo := algorithm + ":" + keyID
if wantSet[keyIDWithAlgo] { if wantSet[keyIDWithAlgo] {
result[keyIDWithAlgo] = json.RawMessage(keyJSONStr) result[keyIDWithAlgo] = []byte(keyJSONStr)
} }
} }
return result, rows.Err() return result, rows.Err()
@ -180,7 +179,7 @@ func (s *oneTimeKeysStatements) InsertOneTimeKeys(
func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey( func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey(
ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string, ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string,
) (map[string]json.RawMessage, error) { ) (map[string][]byte, error) {
var keyID string var keyID string
var keyJSON string var keyJSON string
err := sqlutil.TxStmtContext(ctx, txn, s.selectKeyByAlgorithmStmt).QueryRowContext(ctx, userID, deviceID, algorithm).Scan(&keyID, &keyJSON) err := sqlutil.TxStmtContext(ctx, txn, s.selectKeyByAlgorithmStmt).QueryRowContext(ctx, userID, deviceID, algorithm).Scan(&keyID, &keyJSON)
@ -197,7 +196,7 @@ func (s *oneTimeKeysStatements) SelectAndDeleteOneTimeKey(
if keyJSON == "" { if keyJSON == "" {
return nil, nil return nil, nil
} }
return map[string]json.RawMessage{ return map[string][]byte{
algorithm + ":" + keyID: json.RawMessage(keyJSON), algorithm + ":" + keyID: []byte(keyJSON),
}, err }, err
} }

View file

@ -17,19 +17,18 @@ package tables
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
type OneTimeKeys interface { type OneTimeKeys interface {
SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string]json.RawMessage, error) SelectOneTimeKeys(ctx context.Context, userID, deviceID string, keyIDsWithAlgorithms []string) (map[string][]byte, error)
CountOneTimeKeys(ctx context.Context, userID, deviceID string) (*api.OneTimeKeysCount, error) CountOneTimeKeys(ctx context.Context, userID, deviceID string) (*api.OneTimeKeysCount, error)
InsertOneTimeKeys(ctx context.Context, txn *sql.Tx, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error) InsertOneTimeKeys(ctx context.Context, txn *sql.Tx, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error)
// SelectAndDeleteOneTimeKey selects a single one time key matching the user/device/algorithm specified and returns the algo:key_id => JSON. // SelectAndDeleteOneTimeKey selects a single one time key matching the user/device/algorithm specified and returns the algo:key_id => JSON.
// Returns an empty map if the key does not exist. // Returns an empty map if the key does not exist.
SelectAndDeleteOneTimeKey(ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string) (map[string]json.RawMessage, error) SelectAndDeleteOneTimeKey(ctx context.Context, txn *sql.Tx, userID, deviceID, algorithm string) (map[string][]byte, error)
} }
type DeviceKeys interface { type DeviceKeys interface {

View file

@ -16,7 +16,6 @@ package routing
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
"mime" "mime"

View file

@ -20,18 +20,22 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/storage"
"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/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"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"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Setup registers the media API HTTP handlers // Setup registers the media API HTTP handlers
// //
// Due to Setup being used to call many other functions, a gocyclo nolint is // Due to Setup being used to call many other functions, a gocyclo nolint is

View file

@ -16,7 +16,6 @@ package acls
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net" "net"
"regexp" "regexp"
@ -24,9 +23,13 @@ import (
"sync" "sync"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type ServerACLDatabase interface { type ServerACLDatabase interface {
// GetKnownRooms returns a list of all rooms we know about. // GetKnownRooms returns a list of all rooms we know about.
GetKnownRooms(ctx context.Context) ([]string, error) GetKnownRooms(ctx context.Context) ([]string, error)

View file

@ -5,8 +5,12 @@ import (
asAPI "github.com/matrix-org/dendrite/appservice/api" asAPI "github.com/matrix-org/dendrite/appservice/api"
fsAPI "github.com/matrix-org/dendrite/federationsender/api" fsAPI "github.com/matrix-org/dendrite/federationsender/api"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// RoomserverInputAPI is used to write events to the room server. // RoomserverInputAPI is used to write events to the room server.
type RoomserverInternalAPI interface { type RoomserverInternalAPI interface {
// needed to avoid chicken and egg scenario when setting up the // needed to avoid chicken and egg scenario when setting up the

View file

@ -2,7 +2,6 @@ package api
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
asAPI "github.com/matrix-org/dendrite/appservice/api" asAPI "github.com/matrix-org/dendrite/appservice/api"

View file

@ -1,7 +1,6 @@
package api package api
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -54,7 +53,7 @@ func (p *PerformError) JSONResponse() util.JSONResponse {
return util.JSONResponse{ return util.JSONResponse{
Code: p.RemoteCode, Code: p.RemoteCode,
// TODO: Should we assert this is in fact JSON? E.g gjson parse? // TODO: Should we assert this is in fact JSON? E.g gjson parse?
JSON: json.RawMessage(p.Msg), JSON: []byte(p.Msg),
} }
default: default:
return util.ErrorResponse(p) return util.ErrorResponse(p)

View file

@ -17,7 +17,6 @@
package api package api
import ( import (
"encoding/json"
"fmt" "fmt"
"strings" "strings"

View file

@ -13,11 +13,13 @@
package auth package auth
import ( import (
"encoding/json"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// TODO: This logic should live in gomatrixserverlib // TODO: This logic should live in gomatrixserverlib
// IsServerAllowed returns true if the server is allowed to see events in the room // IsServerAllowed returns true if the server is allowed to see events in the room

View file

@ -16,7 +16,6 @@ package internal
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"time" "time"
@ -25,8 +24,12 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
asAPI "github.com/matrix-org/dendrite/appservice/api" asAPI "github.com/matrix-org/dendrite/appservice/api"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// RoomserverInternalAPIDatabase has the storage APIs needed to implement the alias API. // RoomserverInternalAPIDatabase has the storage APIs needed to implement the alias API.
type RoomserverInternalAPIDatabase interface { type RoomserverInternalAPIDatabase interface {
// Save a given room alias with the room ID it refers to. // Save a given room alias with the room ID it refers to.
@ -200,7 +203,7 @@ func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent(
if err != nil { if err != nil {
return err return err
} }
err = builder.SetContent(json.RawMessage(rawContent)) err = builder.SetContent([]byte(rawContent))
if err != nil { if err != nil {
return err return err
} }

View file

@ -17,20 +17,23 @@ package input
import ( import (
"context" "context"
"encoding/json"
"sync" "sync"
"time" "time"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal/hooks" "github.com/matrix-org/dendrite/internal/hooks"
"github.com/matrix-org/dendrite/roomserver/acls" "github.com/matrix-org/dendrite/roomserver/acls"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/roomserver/storage"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.uber.org/atomic" "go.uber.org/atomic"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Inputer struct { type Inputer struct {
DB storage.Database DB storage.Database
Producer sarama.SyncProducer Producer sarama.SyncProducer

View file

@ -16,7 +16,6 @@ package perform
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"strings" "strings"
@ -27,9 +26,13 @@ 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/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Peeker struct { type Peeker struct {
ServerName gomatrixserverlib.ServerName ServerName gomatrixserverlib.ServerName
Cfg *config.RoomServer Cfg *config.RoomServer

View file

@ -16,14 +16,17 @@ package query
import ( import (
"context" "context"
"encoding/json"
"testing" "testing"
"github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/internal/test"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// used to implement RoomserverInternalAPIEventDB to test getAuthChain // used to implement RoomserverInternalAPIEventDB to test getAuthChain
type getEventDB struct { type getEventDB struct {
eventMap map[string]*gomatrixserverlib.Event eventMap map[string]*gomatrixserverlib.Event

View file

@ -1,15 +1,18 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux. // AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
// nolint: gocyclo // nolint: gocyclo
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {

View file

@ -4,14 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ed25519" "crypto/ed25519"
"encoding/json"
"fmt" "fmt"
"os" "os"
"reflect" "reflect"
"testing" "testing"
"time" "time"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/test" "github.com/matrix-org/dendrite/internal/test"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
@ -20,6 +18,9 @@ import (
"github.com/matrix-org/dendrite/setup" "github.com/matrix-org/dendrite/setup"
"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/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -33,7 +34,8 @@ const (
) )
var ( var (
ctx = context.Background() ctx = context.Background()
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
type dummyProducer struct { type dummyProducer struct {
@ -49,7 +51,7 @@ func (p *dummyProducer) SendMessage(msg *sarama.ProducerMessage) (partition int3
return 0, 0, nil return 0, 0, nil
} }
be := msg.Value.(sarama.ByteEncoder) be := msg.Value.(sarama.ByteEncoder)
b := json.RawMessage(be) b := []byte(be)
fmt.Println("SENDING >>>>>>>> ", string(b)) fmt.Println("SENDING >>>>>>>> ", string(b))
var out api.OutputEvent var out api.OutputEvent
err = json.Unmarshal(b, &out) err = json.Unmarshal(b, &out)
@ -143,7 +145,7 @@ func mustCreateEvents(t *testing.T, roomVer gomatrixserverlib.RoomVersion, event
return return
} }
func mustLoadRawEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) []*gomatrixserverlib.HeaderedEvent { func mustLoadRawEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events [][]byte) []*gomatrixserverlib.HeaderedEvent {
t.Helper() t.Helper()
hs := make([]*gomatrixserverlib.HeaderedEvent, len(events)) hs := make([]*gomatrixserverlib.HeaderedEvent, len(events))
for i := range events { for i := range events {
@ -186,7 +188,7 @@ func mustCreateRoomserverAPI(t *testing.T) (api.RoomserverInternalAPI, *dummyPro
), dp ), dp
} }
func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []json.RawMessage) (api.RoomserverInternalAPI, *dummyProducer, []*gomatrixserverlib.HeaderedEvent) { func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events [][]byte) (api.RoomserverInternalAPI, *dummyProducer, []*gomatrixserverlib.HeaderedEvent) {
t.Helper() t.Helper()
rsAPI, dp := mustCreateRoomserverAPI(t) rsAPI, dp := mustCreateRoomserverAPI(t)
hevents := mustLoadRawEvents(t, ver, events) hevents := mustLoadRawEvents(t, ver, events)
@ -197,7 +199,7 @@ func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []js
} }
func TestOutputRedactedEvent(t *testing.T) { func TestOutputRedactedEvent(t *testing.T) {
redactionEvents := []json.RawMessage{ redactionEvents := [][]byte{
// create event // create event
[]byte(`{"auth_events":[],"content":{"creator":"@userid:kaer.morhen"},"depth":0,"event_id":"$N4us6vqqq3RjvpKd:kaer.morhen","hashes":{"sha256":"WTdrCn/YsiounXcJPsLP8xT0ZjHiO5Ov0NvXYmK2onE"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"9+5JcpaN5b5KlHYHGp6r+GoNDH98lbfzGYwjfxensa5C5D/bDACaYnMDLnhwsHOE5nxgI+jT/GV271pz6PMSBQ"}},"state_key":"","type":"m.room.create"}`), []byte(`{"auth_events":[],"content":{"creator":"@userid:kaer.morhen"},"depth":0,"event_id":"$N4us6vqqq3RjvpKd:kaer.morhen","hashes":{"sha256":"WTdrCn/YsiounXcJPsLP8xT0ZjHiO5Ov0NvXYmK2onE"},"origin":"kaer.morhen","origin_server_ts":0,"prev_events":[],"prev_state":[],"room_id":"!roomid:kaer.morhen","sender":"@userid:kaer.morhen","signatures":{"kaer.morhen":{"ed25519:auto":"9+5JcpaN5b5KlHYHGp6r+GoNDH98lbfzGYwjfxensa5C5D/bDACaYnMDLnhwsHOE5nxgI+jT/GV271pz6PMSBQ"}},"state_key":"","type":"m.room.create"}`),
// join event // join event

View file

@ -3,7 +3,6 @@ package shared
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"sort" "sort"
@ -14,6 +13,8 @@ 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/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
@ -26,6 +27,8 @@ import (
// unsigned.redacted_because - we just don't clear out the content fields yet. // unsigned.redacted_because - we just don't clear out the content fields yet.
const redactionsArePermanent = true const redactionsArePermanent = true
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Database struct { type Database struct {
DB *sql.DB DB *sql.DB
Cache caching.RoomServerCaches Cache caching.RoomServerCaches

View file

@ -18,7 +18,6 @@ package sqlite3
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"strings" "strings"

View file

@ -18,7 +18,6 @@ package sqlite3
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"strings" "strings"

View file

@ -18,7 +18,6 @@ package sqlite3
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"fmt" "fmt"
"strings" "strings"

View file

@ -28,8 +28,12 @@ import (
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/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"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// A Database is used to store room events and stream offsets. // A Database is used to store room events and stream offsets.
type Database struct { type Database struct {
shared.Database shared.Database

View file

@ -19,7 +19,6 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/json"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -27,6 +26,7 @@ import (
"strings" "strings"
"time" "time"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
fs "github.com/matrix-org/dendrite/federationsender/api" fs "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/hooks" "github.com/matrix-org/dendrite/internal/hooks"
@ -42,6 +42,8 @@ const (
constRelType = "m.reference" constRelType = "m.reference"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type EventRelationshipRequest struct { type EventRelationshipRequest struct {
EventID string `json:"event_id"` EventID string `json:"event_id"`
RoomID string `json:"room_id"` RoomID string `json:"room_id"`

View file

@ -6,7 +6,6 @@ import (
"crypto/ed25519" "crypto/ed25519"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -16,6 +15,7 @@ import (
"time" "time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/internal/hooks" "github.com/matrix-org/dendrite/internal/hooks"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
roomserver "github.com/matrix-org/dendrite/roomserver/api" roomserver "github.com/matrix-org/dendrite/roomserver/api"
@ -30,6 +30,7 @@ var (
client = &http.Client{ client = &http.Client{
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
} }
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
// Basic sanity check of MSC2836 logic. Injects a thread that looks like: // Basic sanity check of MSC2836 logic. Injects a thread that looks like:
@ -162,9 +163,9 @@ func TestMSC2836(t *testing.T) {
// make everyone joined to each other's rooms // make everyone joined to each other's rooms
nopRsAPI := &testRoomserverAPI{ nopRsAPI := &testRoomserverAPI{
userToJoinedRooms: map[string][]string{ userToJoinedRooms: map[string][]string{
alice: []string{roomID}, alice: {roomID},
bob: []string{roomID}, bob: {roomID},
charlie: []string{roomID}, charlie: {roomID},
}, },
events: map[string]*gomatrixserverlib.HeaderedEvent{ events: map[string]*gomatrixserverlib.HeaderedEvent{
eventA.EventID(): eventA, eventA.EventID(): eventA,

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"encoding/base64" "encoding/base64"
"encoding/json"
"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"

View file

@ -1,7 +1,6 @@
package inthttp package inthttp
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -9,8 +8,12 @@ import (
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/signingkeyserver/api" "github.com/matrix-org/dendrite/signingkeyserver/api"
"github.com/matrix-org/util" "github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
func AddRoutes(s api.SigningKeyServerAPI, internalAPIMux *mux.Router, cache caching.ServerKeyCache) { func AddRoutes(s api.SigningKeyServerAPI, internalAPIMux *mux.Router, cache caching.ServerKeyCache) {
internalAPIMux.Handle(ServerKeyQueryPublicKeyPath, internalAPIMux.Handle(ServerKeyQueryPublicKeyPath,
httputil.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse { httputil.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ed25519" "crypto/ed25519"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -18,8 +17,12 @@ import (
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/signingkeyserver/api" "github.com/matrix-org/dendrite/signingkeyserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
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

View file

@ -16,18 +16,21 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/sync" "github.com/matrix-org/dendrite/syncapi/sync"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// OutputClientDataConsumer consumes events that originated in the client API server. // OutputClientDataConsumer consumes events that originated in the client API server.
type OutputClientDataConsumer struct { type OutputClientDataConsumer struct {
clientAPIConsumer *internal.ContinualConsumer clientAPIConsumer *internal.ContinualConsumer

View file

@ -16,16 +16,16 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/sync" "github.com/matrix-org/dendrite/syncapi/sync"
"github.com/Shopify/sarama"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -16,9 +16,7 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
@ -27,6 +25,8 @@ import (
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/Shopify/sarama"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -15,15 +15,14 @@
package consumers package consumers
import ( import (
"encoding/json"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/eduserver/api" "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/storage" "github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/sync" "github.com/matrix-org/dendrite/syncapi/sync"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/Shopify/sarama"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -16,10 +16,8 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"sync" "sync"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/keyserver/api" "github.com/matrix-org/dendrite/keyserver/api"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
@ -27,6 +25,8 @@ import (
syncapi "github.com/matrix-org/dendrite/syncapi/sync" syncapi "github.com/matrix-org/dendrite/syncapi/sync"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/Shopify/sarama"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -16,10 +16,8 @@ package consumers
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"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"

View file

@ -15,7 +15,6 @@
package routing package routing
import ( import (
"encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -25,6 +24,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/util" "github.com/matrix-org/util"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )

View file

@ -17,7 +17,6 @@ package routing
import ( import (
"net/http" "net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
"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"
@ -26,8 +25,13 @@ import (
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/util" "github.com/matrix-org/util"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Setup configures the given mux with sync-server listeners // Setup configures the given mux with sync-server listeners
// //
// Due to Setup being used to call many other functions, a gocyclo nolint is // Due to Setup being used to call many other functions, a gocyclo nolint is

View file

@ -18,7 +18,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"

View file

@ -17,7 +17,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/storage/tables"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"

View file

@ -18,7 +18,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"

View file

@ -18,7 +18,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"sort" "sort"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"

View file

@ -17,7 +17,6 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"encoding/json"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"

Some files were not shown because too many files have changed in this diff Show more