mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Merge branch 'master' into kegan/backfill-logging
This commit is contained in:
commit
cb8dd816df
9 changed files with 11 additions and 118 deletions
|
@ -205,13 +205,11 @@ func (n *Node) SessionCount() int {
|
||||||
|
|
||||||
func (n *Node) KnownNodes() []gomatrixserverlib.ServerName {
|
func (n *Node) KnownNodes() []gomatrixserverlib.ServerName {
|
||||||
nodemap := map[string]struct{}{
|
nodemap := map[string]struct{}{
|
||||||
"b5ae50589e50991dd9dd7d59c5c5f7a4521e8da5b603b7f57076272abc58b374": {},
|
//"b5ae50589e50991dd9dd7d59c5c5f7a4521e8da5b603b7f57076272abc58b374": {},
|
||||||
|
}
|
||||||
|
for _, peer := range n.core.GetSwitchPeers() {
|
||||||
|
nodemap[hex.EncodeToString(peer.SigPublicKey[:])] = struct{}{}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
for _, peer := range n.core.GetSwitchPeers() {
|
|
||||||
nodemap[hex.EncodeToString(peer.PublicKey[:])] = struct{}{}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
n.sessions.Range(func(_, v interface{}) bool {
|
n.sessions.Range(func(_, v interface{}) bool {
|
||||||
session, ok := v.(quic.Session)
|
session, ok := v.(quic.Session)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -40,6 +40,7 @@ func GetUserDevices(
|
||||||
response := gomatrixserverlib.RespUserDevices{
|
response := gomatrixserverlib.RespUserDevices{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
StreamID: res.StreamID,
|
StreamID: res.StreamID,
|
||||||
|
Devices: []gomatrixserverlib.RespUserDevice{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dev := range res.Devices {
|
for _, dev := range res.Devices {
|
||||||
|
|
|
@ -232,7 +232,7 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
|
||||||
// If we successfully performed a send_join above then the other
|
// If we successfully performed a send_join above then the other
|
||||||
// server now thinks we're a part of the room. Send the newly
|
// server now thinks we're a part of the room. Send the newly
|
||||||
// returned state to the roomserver to update our local view.
|
// returned state to the roomserver to update our local view.
|
||||||
if err = roomserverAPI.SendEventWithRewrite(
|
if err = roomserverAPI.SendEventWithState(
|
||||||
ctx, r.rsAPI,
|
ctx, r.rsAPI,
|
||||||
respState,
|
respState,
|
||||||
event.Headered(respMakeJoin.RoomVersion),
|
event.Headered(respMakeJoin.RoomVersion),
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -37,7 +37,7 @@ require (
|
||||||
github.com/tidwall/sjson v1.1.1
|
github.com/tidwall/sjson v1.1.1
|
||||||
github.com/uber/jaeger-client-go v2.25.0+incompatible
|
github.com/uber/jaeger-client-go v2.25.0+incompatible
|
||||||
github.com/uber/jaeger-lib v2.2.0+incompatible
|
github.com/uber/jaeger-lib v2.2.0+incompatible
|
||||||
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200806125501-cd4685a3b4de
|
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20201006093556-760d9a7fd5ee
|
||||||
go.uber.org/atomic v1.6.0
|
go.uber.org/atomic v1.6.0
|
||||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
||||||
gopkg.in/h2non/bimg.v1 v1.1.4
|
gopkg.in/h2non/bimg.v1 v1.1.4
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -851,8 +851,8 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
|
||||||
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
|
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
|
||||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||||
github.com/yggdrasil-network/yggdrasil-extras v0.0.0-20200525205615-6c8a4a2e8855/go.mod h1:xQdsh08Io6nV4WRnOVTe6gI8/2iTvfLDQ0CYa5aMt+I=
|
github.com/yggdrasil-network/yggdrasil-extras v0.0.0-20200525205615-6c8a4a2e8855/go.mod h1:xQdsh08Io6nV4WRnOVTe6gI8/2iTvfLDQ0CYa5aMt+I=
|
||||||
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200806125501-cd4685a3b4de h1:p91aw0Mvol825U+5bvV9BBPl+HQxIczj7wxIOxZs70M=
|
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20201006093556-760d9a7fd5ee h1:Kot820OfxWfYrk5di5f4S5s0jXXrQj8w8BG5826HAv4=
|
||||||
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20200806125501-cd4685a3b4de/go.mod h1:d+Nz6SPeG6kmeSPFL0cvfWfgwEql75fUnZiAONgvyBE=
|
github.com/yggdrasil-network/yggdrasil-go v0.3.15-0.20201006093556-760d9a7fd5ee/go.mod h1:d+Nz6SPeG6kmeSPFL0cvfWfgwEql75fUnZiAONgvyBE=
|
||||||
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA=
|
go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA=
|
||||||
|
|
|
@ -35,10 +35,6 @@ const (
|
||||||
// KindBackfill event extend the contiguous graph going backwards.
|
// KindBackfill event extend the contiguous graph going backwards.
|
||||||
// They always have state.
|
// They always have state.
|
||||||
KindBackfill = 3
|
KindBackfill = 3
|
||||||
// KindRewrite events are used when rewriting the head of the room
|
|
||||||
// graph with entirely new state. The output events generated will
|
|
||||||
// be state events rather than timeline events.
|
|
||||||
KindRewrite = 4
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DoNotSendToOtherServers tells us not to send the event to other matrix
|
// DoNotSendToOtherServers tells us not to send the event to other matrix
|
||||||
|
|
|
@ -80,99 +80,6 @@ func SendEventWithState(
|
||||||
return SendInputRoomEvents(ctx, rsAPI, ires)
|
return SendInputRoomEvents(ctx, rsAPI, ires)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendEventWithRewrite writes an event with KindNew to the roomserver along
|
|
||||||
// with a number of rewrite and outlier events for state and auth events
|
|
||||||
// respectively.
|
|
||||||
func SendEventWithRewrite(
|
|
||||||
ctx context.Context, rsAPI RoomserverInternalAPI, state *gomatrixserverlib.RespState,
|
|
||||||
event gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool,
|
|
||||||
) error {
|
|
||||||
isCurrentState := map[string]struct{}{}
|
|
||||||
for _, se := range state.StateEvents {
|
|
||||||
isCurrentState[se.EventID()] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
authAndStateEvents, err := state.Events()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var ires []InputRoomEvent
|
|
||||||
var stateIDs []string
|
|
||||||
|
|
||||||
// This function generates three things:
|
|
||||||
// A - A set of "rewrite" events, which will form the newly rewritten
|
|
||||||
// state before the event, which includes every rewrite event that
|
|
||||||
// came before it in its state
|
|
||||||
// B - A set of "outlier" events, which are auth events but not part
|
|
||||||
// of the rewritten state
|
|
||||||
// C - A "new" event, which include all of the rewrite events in its
|
|
||||||
// state
|
|
||||||
for _, authOrStateEvent := range authAndStateEvents {
|
|
||||||
if authOrStateEvent.StateKey() == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if haveEventIDs[authOrStateEvent.EventID()] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if event.StateKey() == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// We will handle an event as if it's an outlier if one of the
|
|
||||||
// following conditions is true:
|
|
||||||
storeAsOutlier := false
|
|
||||||
if _, ok := isCurrentState[authOrStateEvent.EventID()]; !ok {
|
|
||||||
// The event is an auth event and isn't a part of the state set.
|
|
||||||
// We'll send it as an outlier because we need it to be stored
|
|
||||||
// in case something is referring to it as an auth event.
|
|
||||||
storeAsOutlier = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if storeAsOutlier {
|
|
||||||
ires = append(ires, InputRoomEvent{
|
|
||||||
Kind: KindOutlier,
|
|
||||||
Event: authOrStateEvent.Headered(event.RoomVersion),
|
|
||||||
AuthEventIDs: authOrStateEvent.AuthEventIDs(),
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the event isn't an outlier then we'll instead send it as a
|
|
||||||
// rewrite event, so that it'll form part of the rewritten state.
|
|
||||||
// These events will go through the membership and latest event
|
|
||||||
// updaters and we will generate output events, but they will be
|
|
||||||
// flagged as non-current (i.e. didn't just happen) events.
|
|
||||||
// Each of these rewrite events includes all of the rewrite events
|
|
||||||
// that came before in their StateEventIDs.
|
|
||||||
ires = append(ires, InputRoomEvent{
|
|
||||||
Kind: KindRewrite,
|
|
||||||
Event: authOrStateEvent.Headered(event.RoomVersion),
|
|
||||||
AuthEventIDs: authOrStateEvent.AuthEventIDs(),
|
|
||||||
HasState: true,
|
|
||||||
StateEventIDs: stateIDs,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add the event ID into the StateEventIDs of all subsequent
|
|
||||||
// rewrite events, and the new event.
|
|
||||||
stateIDs = append(stateIDs, authOrStateEvent.EventID())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the final event as a new event, which will generate
|
|
||||||
// a timeline output event for it. All of the rewrite events
|
|
||||||
// that came before will be sent as StateEventIDs, forming a
|
|
||||||
// new clean state before the event.
|
|
||||||
ires = append(ires, InputRoomEvent{
|
|
||||||
Kind: KindNew,
|
|
||||||
Event: event,
|
|
||||||
AuthEventIDs: event.AuthEventIDs(),
|
|
||||||
HasState: true,
|
|
||||||
StateEventIDs: stateIDs,
|
|
||||||
})
|
|
||||||
|
|
||||||
return SendInputRoomEvents(ctx, rsAPI, ires)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendInputRoomEvents to the roomserver.
|
// SendInputRoomEvents to the roomserver.
|
||||||
func SendInputRoomEvents(
|
func SendInputRoomEvents(
|
||||||
ctx context.Context, rsAPI RoomserverInternalAPI, ires []InputRoomEvent,
|
ctx context.Context, rsAPI RoomserverInternalAPI, ires []InputRoomEvent,
|
||||||
|
|
|
@ -136,15 +136,6 @@ func (r *Inputer) processRoomEvent(
|
||||||
return event.EventID(), rejectionErr
|
return event.EventID(), rejectionErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Kind == api.KindRewrite {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"event_id": event.EventID(),
|
|
||||||
"type": event.Type(),
|
|
||||||
"room": event.RoomID(),
|
|
||||||
}).Debug("Stored rewrite")
|
|
||||||
return event.EventID(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = r.updateLatestEvents(
|
if err = r.updateLatestEvents(
|
||||||
ctx, // context
|
ctx, // context
|
||||||
roomInfo, // room info for the room being updated
|
roomInfo, // room info for the room being updated
|
||||||
|
|
|
@ -238,7 +238,7 @@ func TestOutputRedactedEvent(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This tests that rewriting state via KindRewrite works correctly.
|
// This tests that rewriting state works correctly.
|
||||||
// This creates a small room with a create/join/name state, then replays it
|
// This creates a small room with a create/join/name state, then replays it
|
||||||
// with a new room name. We expect the output events to contain the original events,
|
// with a new room name. We expect the output events to contain the original events,
|
||||||
// followed by a single OutputNewRoomEvent with RewritesState set to true with the
|
// followed by a single OutputNewRoomEvent with RewritesState set to true with the
|
||||||
|
@ -344,7 +344,7 @@ func TestOutputRewritesState(t *testing.T) {
|
||||||
for i := 0; i < len(rewriteEvents)-1; i++ {
|
for i := 0; i < len(rewriteEvents)-1; i++ {
|
||||||
ev := rewriteEvents[i]
|
ev := rewriteEvents[i]
|
||||||
inputEvents = append(inputEvents, api.InputRoomEvent{
|
inputEvents = append(inputEvents, api.InputRoomEvent{
|
||||||
Kind: api.KindRewrite,
|
Kind: api.KindOutlier,
|
||||||
Event: ev,
|
Event: ev,
|
||||||
AuthEventIDs: ev.AuthEventIDs(),
|
AuthEventIDs: ev.AuthEventIDs(),
|
||||||
HasState: true,
|
HasState: true,
|
||||||
|
|
Loading…
Reference in a new issue