From 5530f16e3ff6f3cfeb8767341616a6704085eee4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 27 Mar 2020 14:32:38 +0000 Subject: [PATCH] Rely on EventBuilder in gmsl to generate the event IDs for us --- clientapi/routing/createroom.go | 10 +--------- clientapi/routing/joinroom.go | 10 +--------- cmd/create-room-events/main.go | 3 +-- common/events.go | 13 +------------ federationapi/routing/threepid.go | 11 +---------- go.mod | 2 +- go.sum | 2 ++ roomserver/alias/alias.go | 11 +---------- 8 files changed, 9 insertions(+), 53 deletions(-) diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index fb96fe01b..ef11e8b3e 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -379,16 +379,8 @@ func buildEvent( return nil, err } builder.AuthEvents = refs - eventID := "" - eventIDFormat, err := roomVersion.EventIDFormat() - if err != nil { - return nil, err - } - if eventIDFormat == gomatrixserverlib.EventIDFormatV1 { - eventID = fmt.Sprintf("$%s:%s", util.RandomString(16), cfg.Matrix.ServerName) - } event, err := builder.Build( - eventID, evTime, cfg.Matrix.ServerName, cfg.Matrix.KeyID, + evTime, cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, roomVersion, ) if err != nil { diff --git a/clientapi/routing/joinroom.go b/clientapi/routing/joinroom.go index a73e25e66..745b4eecc 100644 --- a/clientapi/routing/joinroom.go +++ b/clientapi/routing/joinroom.go @@ -342,16 +342,8 @@ func (r joinRoomReq) joinRoomUsingServer(roomID string, server gomatrixserverlib }, nil } - eventIDFormat, err := respMakeJoin.RoomVersion.EventIDFormat() - if err != nil { - return nil, err - } - eventID := "" - if eventIDFormat == gomatrixserverlib.EventIDFormatV1 { - eventID = fmt.Sprintf("$%s:%s", util.RandomString(16), r.cfg.Matrix.ServerName) - } event, err := respMakeJoin.JoinEvent.Build( - eventID, r.evTime, r.cfg.Matrix.ServerName, r.cfg.Matrix.KeyID, + r.evTime, r.cfg.Matrix.ServerName, r.cfg.Matrix.KeyID, r.cfg.Matrix.PrivateKey, respMakeJoin.RoomVersion, ) if err != nil { diff --git a/cmd/create-room-events/main.go b/cmd/create-room-events/main.go index 623890ba3..ebce953ce 100644 --- a/cmd/create-room-events/main.go +++ b/cmd/create-room-events/main.go @@ -103,13 +103,12 @@ func main() { // Build an event and write the event to the output. func buildAndOutput() gomatrixserverlib.EventReference { eventID++ - id := fmt.Sprintf("$%d:%s", eventID, *serverName) now = time.Unix(0, 0) name := gomatrixserverlib.ServerName(*serverName) key := gomatrixserverlib.KeyID(*keyID) event, err := b.Build( - id, now, name, key, privateKey, + now, name, key, privateKey, gomatrixserverlib.RoomVersionV1, ) if err != nil { diff --git a/common/events.go b/common/events.go index 19c929f94..90eef19aa 100644 --- a/common/events.go +++ b/common/events.go @@ -17,14 +17,12 @@ package common import ( "context" "errors" - "fmt" "time" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/util" ) // ErrRoomNoExists is returned when trying to lookup the state of a room that @@ -51,17 +49,8 @@ func BuildEvent( return nil, err } - eventID := "" - eventIDFormat, err := queryRes.RoomVersion.EventIDFormat() - if err != nil { - return nil, err - } - if eventIDFormat == gomatrixserverlib.EventIDFormatV1 { - eventID = fmt.Sprintf("$%s:%s", util.RandomString(16), cfg.Matrix.ServerName) - } - event, err := builder.Build( - eventID, evTime, cfg.Matrix.ServerName, cfg.Matrix.KeyID, + evTime, cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, queryRes.RoomVersion, ) if err != nil { diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index ff0473f95..da7174730 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -18,7 +18,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "net/http" "time" @@ -310,16 +309,8 @@ func buildMembershipEvent( } builder.AuthEvents = refs - eventID := "" - eventIDFormat, err := queryRes.RoomVersion.EventIDFormat() - if err != nil { - return nil, err - } - if eventIDFormat == gomatrixserverlib.EventIDFormatV1 { - eventID = fmt.Sprintf("$%s:%s", util.RandomString(16), cfg.Matrix.ServerName) - } event, err := builder.Build( - eventID, time.Now(), cfg.Matrix.ServerName, cfg.Matrix.KeyID, + time.Now(), cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, queryRes.RoomVersion, ) diff --git a/go.mod b/go.mod index 533032b0c..83ba461f4 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/matrix-org/go-http-js-libp2p v0.0.0-20200318135427-31631a9ef51f github.com/matrix-org/go-sqlite3-js v0.0.0-20200304164012-aa524245b658 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 - github.com/matrix-org/gomatrixserverlib v0.0.0-20200327141825-4c04d7773f61 + github.com/matrix-org/gomatrixserverlib v0.0.0-20200327143012-be83dab84222 github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 github.com/mattn/go-sqlite3 v2.0.2+incompatible diff --git a/go.sum b/go.sum index e22b064c6..38f0b400a 100644 --- a/go.sum +++ b/go.sum @@ -168,6 +168,8 @@ github.com/matrix-org/gomatrixserverlib v0.0.0-20200327141230-2e491c5d6d12 h1:le github.com/matrix-org/gomatrixserverlib v0.0.0-20200327141230-2e491c5d6d12/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= github.com/matrix-org/gomatrixserverlib v0.0.0-20200327141825-4c04d7773f61 h1:9ctc7P784fnLURt+5PV04cpbpX9o6qZRHATmXS75w7c= github.com/matrix-org/gomatrixserverlib v0.0.0-20200327141825-4c04d7773f61/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200327143012-be83dab84222 h1:b8u7o03EGemkblBgAvwtpCjVXKwzBZ794uCco/Urv6Y= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200327143012-be83dab84222/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 h1:osLoFdOy+ChQqVUn2PeTDETFftVkl4w9t/OW18g3lnk= github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1/go.mod h1:cXoYQIENbdWIQHt1SyCo6Bl3C3raHwJ0wgVrXHSqf+A= github.com/matrix-org/util v0.0.0-20171127121716-2e2df66af2f5 h1:W7l5CP4V7wPyPb4tYE11dbmeAOwtFQBTW0rf4OonOS8= diff --git a/roomserver/alias/alias.go b/roomserver/alias/alias.go index 809086f09..032b8da1c 100644 --- a/roomserver/alias/alias.go +++ b/roomserver/alias/alias.go @@ -17,7 +17,6 @@ package alias import ( "context" "encoding/json" - "fmt" "net/http" "time" @@ -250,17 +249,9 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent( } // Build the event - eventID := "" - eventIDFormat, err := roomVersion.EventIDFormat() - if err != nil { - return err - } - if eventIDFormat == gomatrixserverlib.EventIDFormatV1 { - eventID = fmt.Sprintf("$%s:%s", util.RandomString(16), r.Cfg.Matrix.ServerName) - } now := time.Now() event, err := builder.Build( - eventID, now, r.Cfg.Matrix.ServerName, r.Cfg.Matrix.KeyID, + now, r.Cfg.Matrix.ServerName, r.Cfg.Matrix.KeyID, r.Cfg.Matrix.PrivateKey, roomVersion, ) if err != nil {