mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-09-11 15:22:46 +00:00
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
This commit is contained in:
parent
9fa39263c0
commit
72285b2659
306 changed files with 2117 additions and 1934 deletions
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
)
|
||||
|
||||
// defaultExpiry for EDUs if not listed below
|
||||
|
@ -32,8 +33,8 @@ var defaultExpiry = time.Hour * 24
|
|||
// defaultExpireEDUTypes contains EDUs which can/should be expired after a given time
|
||||
// if the target server isn't reachable for some reason.
|
||||
var defaultExpireEDUTypes = map[string]time.Duration{
|
||||
gomatrixserverlib.MTyping: time.Minute,
|
||||
gomatrixserverlib.MPresence: time.Minute * 10,
|
||||
spec.MTyping: time.Minute,
|
||||
spec.MPresence: time.Minute * 10,
|
||||
}
|
||||
|
||||
// AssociateEDUWithDestination creates an association that the
|
||||
|
@ -41,7 +42,7 @@ var defaultExpireEDUTypes = map[string]time.Duration{
|
|||
// to which servers.
|
||||
func (d *Database) AssociateEDUWithDestinations(
|
||||
ctx context.Context,
|
||||
destinations map[gomatrixserverlib.ServerName]struct{},
|
||||
destinations map[spec.ServerName]struct{},
|
||||
dbReceipt *receipt.Receipt,
|
||||
eduType string,
|
||||
expireEDUTypes map[string]time.Duration,
|
||||
|
@ -49,14 +50,14 @@ func (d *Database) AssociateEDUWithDestinations(
|
|||
if expireEDUTypes == nil {
|
||||
expireEDUTypes = defaultExpireEDUTypes
|
||||
}
|
||||
expiresAt := gomatrixserverlib.AsTimestamp(time.Now().Add(defaultExpiry))
|
||||
expiresAt := spec.AsTimestamp(time.Now().Add(defaultExpiry))
|
||||
if duration, ok := expireEDUTypes[eduType]; ok {
|
||||
// Keep EDUs for at least x minutes before deleting them
|
||||
expiresAt = gomatrixserverlib.AsTimestamp(time.Now().Add(duration))
|
||||
expiresAt = spec.AsTimestamp(time.Now().Add(duration))
|
||||
}
|
||||
// We forcibly set m.direct_to_device and m.device_list_update events
|
||||
// to 0, as we always want them to be delivered. (required for E2EE)
|
||||
if eduType == gomatrixserverlib.MDirectToDevice || eduType == gomatrixserverlib.MDeviceListUpdate {
|
||||
if eduType == spec.MDirectToDevice || eduType == spec.MDeviceListUpdate {
|
||||
expiresAt = 0
|
||||
}
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
|
@ -79,7 +80,7 @@ func (d *Database) AssociateEDUWithDestinations(
|
|||
// the next pending transaction, up to the limit specified.
|
||||
func (d *Database) GetPendingEDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
limit int,
|
||||
) (
|
||||
edus map[*receipt.Receipt]*gomatrixserverlib.EDU,
|
||||
|
@ -126,7 +127,7 @@ func (d *Database) GetPendingEDUs(
|
|||
// transaction was sent successfully.
|
||||
func (d *Database) CleanEDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
receipts []*receipt.Receipt,
|
||||
) error {
|
||||
if len(receipts) == 0 {
|
||||
|
@ -169,7 +170,7 @@ func (d *Database) CleanEDUs(
|
|||
// waiting to be sent.
|
||||
func (d *Database) GetPendingEDUServerNames(
|
||||
ctx context.Context,
|
||||
) ([]gomatrixserverlib.ServerName, error) {
|
||||
) ([]spec.ServerName, error) {
|
||||
return d.FederationQueueEDUs.SelectQueueEDUServerNames(ctx, nil)
|
||||
}
|
||||
|
||||
|
@ -177,7 +178,7 @@ func (d *Database) GetPendingEDUServerNames(
|
|||
func (d *Database) DeleteExpiredEDUs(ctx context.Context) error {
|
||||
var jsonNIDs []int64
|
||||
err := d.Writer.Do(d.DB, nil, func(txn *sql.Tx) (err error) {
|
||||
expiredBefore := gomatrixserverlib.AsTimestamp(time.Now())
|
||||
expiredBefore := spec.AsTimestamp(time.Now())
|
||||
jsonNIDs, err = d.FederationQueueEDUs.SelectExpiredEDUs(ctx, txn, expiredBefore)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue