Implement /get_missing_events (#1022)

* WIP get_missing_events work

* More WIP get_missing_events work

* First working /get_missing_events implementation

Flakey currently due to racing between /sync and /send

* Final tweaks

* Remove log lines

* Linting

* go mod tidy

* Clamp min depth to 0

* sort events by depth because sytest makes me sad

Specifically I think it's
4172585c25/lib/SyTest/Federation/Client.pm (L265)
to blame here.
This commit is contained in:
Kegsay 2020-05-12 16:24:28 +01:00 committed by GitHub
parent 32624697fd
commit ce5dfbebf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 675 additions and 198 deletions

View file

@ -17,6 +17,7 @@ package routing
import (
"fmt"
"net/http"
"sort"
"time"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
@ -275,6 +276,12 @@ func SendJoin(
}
}
// sort events deterministically by depth (lower is earlier)
// We also do this because sytest's basic federation server isn't good at using the correct
// state if these lists are randomised, resulting in flakey tests. :(
sort.Sort(eventsByDepth(stateAndAuthChainResponse.StateEvents))
sort.Sort(eventsByDepth(stateAndAuthChainResponse.AuthChainEvents))
// https://matrix.org/docs/spec/server_server/latest#put-matrix-federation-v1-send-join-roomid-eventid
return util.JSONResponse{
Code: http.StatusOK,
@ -285,3 +292,15 @@ func SendJoin(
},
}
}
type eventsByDepth []gomatrixserverlib.HeaderedEvent
func (e eventsByDepth) Len() int {
return len(e)
}
func (e eventsByDepth) Swap(i, j int) {
e[i], e[j] = e[j], e[i]
}
func (e eventsByDepth) Less(i, j int) bool {
return e[i].Depth() < e[j].Depth()
}