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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,15 +15,18 @@
package httputil
import (
"encoding/json"
"io/ioutil"
"net/http"
"unicode/utf8"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"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
// there was a problem unmarshalling. Calling this function consumes the request body.
func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,7 +13,6 @@
package routing
import (
"encoding/json"
"net/http"
"github.com/matrix-org/dendrite/clientapi/httputil"
@ -39,7 +38,7 @@ func SendToDevice(
}
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)
if resErr != nil {

View file

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

View file

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

View file

@ -16,7 +16,6 @@ package threepid
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
@ -25,8 +24,12 @@ import (
"strings"
"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
type EmailAssociationRequest struct {
IDServer string `json:"id_server"`

View file

@ -18,7 +18,6 @@ package main
import (
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"os"
@ -27,6 +26,8 @@ import (
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
"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")
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")
json = jsoniter.ConfigCompatibleWithStandardLibrary
)
// By default we use a private key of 0.

View file

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

View file

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

View file

@ -5,7 +5,6 @@ import (
"bytes"
"context"
"crypto/ed25519"
"encoding/json"
"encoding/pem"
"flag"
"fmt"
@ -14,12 +13,16 @@ import (
"os"
"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 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 json = jsoniter.ConfigCompatibleWithStandardLibrary
// nolint:gocyclo
func main() {
flag.Parse()

View file

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

View file

@ -15,7 +15,6 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
@ -28,6 +27,8 @@ import (
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
)
var (
@ -51,6 +52,8 @@ var (
testDatabaseName = test.Defaulting(os.Getenv("DATABASE_NAME"), "syncserver_test")
// 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))
json = jsoniter.ConfigCompatibleWithStandardLibrary
)
const inputTopic = "syncserverInput"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,6 @@
package routing
import (
"encoding/json"
"net/http"
"time"
@ -184,9 +183,9 @@ func NotaryKeys(
}
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 {
var keys *gomatrixserverlib.ServerKeys

View file

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

View file

@ -17,7 +17,6 @@ package routing
import (
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
eduserverAPI "github.com/matrix-org/dendrite/eduserver/api"
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
@ -28,8 +27,13 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"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.
// 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

View file

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

View file

@ -2,7 +2,7 @@ package routing
import (
"context"
"encoding/json"
stdjson "encoding/json"
"fmt"
"reflect"
"testing"
@ -21,7 +21,7 @@ const (
var (
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":[["$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"}`),
@ -362,7 +362,7 @@ func (c *txnFedClient) LookupMissingEvents(ctx context.Context, s gomatrixserver
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{
rsAPI: rsAPI,
eduAPI: &testEDUProducer{},
@ -445,7 +445,7 @@ func TestBasicTransaction(t *testing.T) {
}
},
}
pdus := []json.RawMessage{
pdus := []stdjson.RawMessage{
testData[len(testData)-1], // a message event
}
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
}
txn := mustCreateTransaction(rsAPI, &txnFedClient{}, pdus)
@ -550,7 +550,7 @@ func TestTransactionFetchMissingPrevEvents(t *testing.T) {
},
}
pdus := []json.RawMessage{
pdus := []stdjson.RawMessage{
inputEvent.JSON(),
}
txn := mustCreateTransaction(rsAPI, cli, pdus)
@ -713,7 +713,7 @@ func TestTransactionFetchMissingStateByStateIDs(t *testing.T) {
// /event for event B returns it
getEvent: map[string]gomatrixserverlib.Transaction{
eventB.EventID(): {
PDUs: []json.RawMessage{
PDUs: []stdjson.RawMessage{
eventB.JSON(),
},
},
@ -735,7 +735,7 @@ func TestTransactionFetchMissingStateByStateIDs(t *testing.T) {
},
}
pdus := []json.RawMessage{
pdus := []stdjson.RawMessage{
eventD.JSON(),
}
txn := mustCreateTransaction(rsAPI, cli, pdus)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,15 +1,18 @@
package inthttp
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/httputil"
"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.
// nolint:gocyclo
func AddRoutes(intAPI api.FederationSenderInternalAPI, internalAPIMux *mux.Router) {

View file

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

View file

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

View file

@ -24,8 +24,12 @@ import (
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type Database struct {
DB *sql.DB
Cache caching.FederationSenderCache

View file

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

View file

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

2
go.mod
View file

@ -7,6 +7,7 @@ require (
github.com/gologme/log v1.2.0
github.com/gorilla/mux v1.8.0
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/libp2p/go-libp2p v0.11.0
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/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.3
github.com/tidwall/match v1.0.2 // indirect
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/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.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
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/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/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-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
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 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
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.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=

View file

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

View file

@ -16,7 +16,6 @@ package api
import (
"context"
"encoding/json"
"strings"
"time"
@ -83,7 +82,7 @@ type OneTimeKeys struct {
// The device ID of this device
DeviceID string
// 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
@ -142,7 +141,7 @@ type PerformClaimKeysRequest struct {
type PerformClaimKeysResponse struct {
// 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
Failures map[string]interface{}
// 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
Failures map[string]interface{}
// 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
Error *KeyError
}

View file

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

View file

@ -17,7 +17,6 @@ package internal
import (
"bytes"
"context"
"encoding/json"
"fmt"
"sync"
"time"
@ -29,11 +28,15 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type KeyInternalAPI struct {
DB storage.Database
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) {
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{})
// wrap request map in a top-level by-domain map
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 {
_, ok := res.OneTimeKeys[key.UserID]
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]
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 {
res.OneTimeKeys[key.UserID][key.DeviceID][keyID] = keyJSON
@ -165,9 +168,9 @@ func (a *KeyInternalAPI) claimRemoteKeys(
keysClaimed := 0
for result := range resultCh {
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 {
res.OneTimeKeys[userID][deviceID] = make(map[string]json.RawMessage)
res.OneTimeKeys[userID][deviceID] = make(map[string][]byte)
for keyIDWithAlgo, otk := range nest2 {
keyJSON, err := json.Marshal(otk)
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) {
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
res.DeviceKeys = make(map[string]map[string][]byte)
res.Failures = make(map[string]interface{})
// make a map from domain to device keys
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 {
res.DeviceKeys[userID] = make(map[string]json.RawMessage)
res.DeviceKeys[userID] = make(map[string][]byte)
}
for _, dk := range deviceKeys {
if len(dk.KeyJSON) == 0 {
@ -335,7 +338,7 @@ func (a *KeyInternalAPI) queryRemoteKeys(
for result := range resultCh {
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 {
keyJSON, err := json.Marshal(deviceKey)
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)
}
if res.DeviceKeys[userID] == nil {
res.DeviceKeys[userID] = make(map[string]json.RawMessage)
res.DeviceKeys[userID] = make(map[string][]byte)
}
for _, key := range keys {

View file

@ -15,15 +15,18 @@
package inthttp
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/keyserver/api"
"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) {
internalAPIMux.Handle(InputDeviceListUpdatePath,
httputil.MakeInternalAPI("inputDeviceListUpdate", func(req *http.Request) util.JSONResponse {

View file

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

View file

@ -16,7 +16,6 @@ package storage
import (
"context"
"encoding/json"
"github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/gomatrixserverlib"
@ -25,7 +24,7 @@ import (
type Database interface {
// 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.
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(ctx context.Context, keys api.OneTimeKeys) (*api.OneTimeKeysCount, error)

View file

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

View file

@ -17,7 +17,6 @@ package shared
import (
"context"
"database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/keyserver/api"
@ -34,7 +33,7 @@ type Database struct {
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)
}

View file

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

View file

@ -17,19 +17,18 @@ package tables
import (
"context"
"database/sql"
"encoding/json"
"github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/gomatrixserverlib"
)
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)
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.
// 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 {

View file

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

View file

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

View file

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

View file

@ -5,8 +5,12 @@ import (
asAPI "github.com/matrix-org/dendrite/appservice/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.
type RoomserverInternalAPI interface {
// needed to avoid chicken and egg scenario when setting up the

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,6 @@ package internal
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
@ -25,8 +24,12 @@ import (
"github.com/matrix-org/gomatrixserverlib"
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.
type RoomserverInternalAPIDatabase interface {
// Save a given room alias with the room ID it refers to.
@ -200,7 +203,7 @@ func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent(
if err != nil {
return err
}
err = builder.SetContent(json.RawMessage(rawContent))
err = builder.SetContent([]byte(rawContent))
if err != nil {
return err
}

View file

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

View file

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

View file

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

View file

@ -1,15 +1,18 @@
package inthttp
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/roomserver/api"
"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.
// nolint: gocyclo
func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {

View file

@ -4,14 +4,12 @@ import (
"bytes"
"context"
"crypto/ed25519"
"encoding/json"
"fmt"
"os"
"reflect"
"testing"
"time"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/test"
"github.com/matrix-org/dendrite/roomserver/api"
@ -20,6 +18,9 @@ import (
"github.com/matrix-org/dendrite/setup"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
"github.com/Shopify/sarama"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
)
@ -33,7 +34,8 @@ const (
)
var (
ctx = context.Background()
ctx = context.Background()
json = jsoniter.ConfigCompatibleWithStandardLibrary
)
type dummyProducer struct {
@ -49,7 +51,7 @@ func (p *dummyProducer) SendMessage(msg *sarama.ProducerMessage) (partition int3
return 0, 0, nil
}
be := msg.Value.(sarama.ByteEncoder)
b := json.RawMessage(be)
b := []byte(be)
fmt.Println("SENDING >>>>>>>> ", string(b))
var out api.OutputEvent
err = json.Unmarshal(b, &out)
@ -143,7 +145,7 @@ func mustCreateEvents(t *testing.T, roomVer gomatrixserverlib.RoomVersion, event
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()
hs := make([]*gomatrixserverlib.HeaderedEvent, len(events))
for i := range events {
@ -186,7 +188,7 @@ func mustCreateRoomserverAPI(t *testing.T) (api.RoomserverInternalAPI, *dummyPro
), 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()
rsAPI, dp := mustCreateRoomserverAPI(t)
hevents := mustLoadRawEvents(t, ver, events)
@ -197,7 +199,7 @@ func mustSendEvents(t *testing.T, ver gomatrixserverlib.RoomVersion, events []js
}
func TestOutputRedactedEvent(t *testing.T) {
redactionEvents := []json.RawMessage{
redactionEvents := [][]byte{
// 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"}`),
// join event

View file

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

View file

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

View file

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

View file

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

View file

@ -28,8 +28,12 @@ import (
"github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
"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.
type Database struct {
shared.Database

View file

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

View file

@ -6,7 +6,6 @@ import (
"crypto/ed25519"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
@ -16,6 +15,7 @@ import (
"time"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/matrix-org/dendrite/internal/hooks"
"github.com/matrix-org/dendrite/internal/httputil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
@ -30,6 +30,7 @@ var (
client = &http.Client{
Timeout: 10 * time.Second,
}
json = jsoniter.ConfigCompatibleWithStandardLibrary
)
// 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
nopRsAPI := &testRoomserverAPI{
userToJoinedRooms: map[string][]string{
alice: []string{roomID},
bob: []string{roomID},
charlie: []string{roomID},
alice: {roomID},
bob: {roomID},
charlie: {roomID},
},
events: map[string]*gomatrixserverlib.HeaderedEvent{
eventA.EventID(): eventA,

View file

@ -5,7 +5,6 @@ import (
"context"
"database/sql"
"encoding/base64"
"encoding/json"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/setup/config"

View file

@ -1,7 +1,6 @@
package inthttp
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
@ -9,8 +8,12 @@ import (
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/signingkeyserver/api"
"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) {
internalAPIMux.Handle(ServerKeyQueryPublicKeyPath,
httputil.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {

View file

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/ed25519"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
@ -18,8 +17,12 @@ import (
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/signingkeyserver/api"
"github.com/matrix-org/gomatrixserverlib"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type server struct {
name gomatrixserverlib.ServerName // server name
validity time.Duration // key validity duration from now

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,10 +16,8 @@ package consumers
import (
"context"
"encoding/json"
"fmt"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"

View file

@ -15,7 +15,6 @@
package routing
import (
"encoding/json"
"io/ioutil"
"net/http"
@ -25,6 +24,7 @@ import (
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
"github.com/tidwall/gjson"
)

View file

@ -17,7 +17,6 @@ package routing
import (
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
@ -26,8 +25,13 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"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
//
// Due to Setup being used to call many other functions, a gocyclo nolint is

View file

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

View file

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

View file

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

View file

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

View file

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

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