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/dendrite/federationapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
)
|
||||
|
||||
var nidMutex sync.Mutex
|
||||
|
|
@ -31,28 +32,28 @@ var nid = int64(0)
|
|||
|
||||
type InMemoryFederationDatabase struct {
|
||||
dbMutex sync.Mutex
|
||||
pendingPDUServers map[gomatrixserverlib.ServerName]struct{}
|
||||
pendingEDUServers map[gomatrixserverlib.ServerName]struct{}
|
||||
blacklistedServers map[gomatrixserverlib.ServerName]struct{}
|
||||
assumedOffline map[gomatrixserverlib.ServerName]struct{}
|
||||
pendingPDUServers map[spec.ServerName]struct{}
|
||||
pendingEDUServers map[spec.ServerName]struct{}
|
||||
blacklistedServers map[spec.ServerName]struct{}
|
||||
assumedOffline map[spec.ServerName]struct{}
|
||||
pendingPDUs map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent
|
||||
pendingEDUs map[*receipt.Receipt]*gomatrixserverlib.EDU
|
||||
associatedPDUs map[gomatrixserverlib.ServerName]map[*receipt.Receipt]struct{}
|
||||
associatedEDUs map[gomatrixserverlib.ServerName]map[*receipt.Receipt]struct{}
|
||||
relayServers map[gomatrixserverlib.ServerName][]gomatrixserverlib.ServerName
|
||||
associatedPDUs map[spec.ServerName]map[*receipt.Receipt]struct{}
|
||||
associatedEDUs map[spec.ServerName]map[*receipt.Receipt]struct{}
|
||||
relayServers map[spec.ServerName][]spec.ServerName
|
||||
}
|
||||
|
||||
func NewInMemoryFederationDatabase() *InMemoryFederationDatabase {
|
||||
return &InMemoryFederationDatabase{
|
||||
pendingPDUServers: make(map[gomatrixserverlib.ServerName]struct{}),
|
||||
pendingEDUServers: make(map[gomatrixserverlib.ServerName]struct{}),
|
||||
blacklistedServers: make(map[gomatrixserverlib.ServerName]struct{}),
|
||||
assumedOffline: make(map[gomatrixserverlib.ServerName]struct{}),
|
||||
pendingPDUServers: make(map[spec.ServerName]struct{}),
|
||||
pendingEDUServers: make(map[spec.ServerName]struct{}),
|
||||
blacklistedServers: make(map[spec.ServerName]struct{}),
|
||||
assumedOffline: make(map[spec.ServerName]struct{}),
|
||||
pendingPDUs: make(map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent),
|
||||
pendingEDUs: make(map[*receipt.Receipt]*gomatrixserverlib.EDU),
|
||||
associatedPDUs: make(map[gomatrixserverlib.ServerName]map[*receipt.Receipt]struct{}),
|
||||
associatedEDUs: make(map[gomatrixserverlib.ServerName]map[*receipt.Receipt]struct{}),
|
||||
relayServers: make(map[gomatrixserverlib.ServerName][]gomatrixserverlib.ServerName),
|
||||
associatedPDUs: make(map[spec.ServerName]map[*receipt.Receipt]struct{}),
|
||||
associatedEDUs: make(map[spec.ServerName]map[*receipt.Receipt]struct{}),
|
||||
relayServers: make(map[spec.ServerName][]spec.ServerName),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +89,7 @@ func (d *InMemoryFederationDatabase) StoreJSON(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingPDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
limit int,
|
||||
) (pdus map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
d.dbMutex.Lock()
|
||||
|
|
@ -112,7 +113,7 @@ func (d *InMemoryFederationDatabase) GetPendingPDUs(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingEDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
limit int,
|
||||
) (edus map[*receipt.Receipt]*gomatrixserverlib.EDU, err error) {
|
||||
d.dbMutex.Lock()
|
||||
|
|
@ -136,7 +137,7 @@ func (d *InMemoryFederationDatabase) GetPendingEDUs(
|
|||
|
||||
func (d *InMemoryFederationDatabase) AssociatePDUWithDestinations(
|
||||
ctx context.Context,
|
||||
destinations map[gomatrixserverlib.ServerName]struct{},
|
||||
destinations map[spec.ServerName]struct{},
|
||||
dbReceipt *receipt.Receipt,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
|
|
@ -158,7 +159,7 @@ func (d *InMemoryFederationDatabase) AssociatePDUWithDestinations(
|
|||
|
||||
func (d *InMemoryFederationDatabase) AssociateEDUWithDestinations(
|
||||
ctx context.Context,
|
||||
destinations map[gomatrixserverlib.ServerName]struct{},
|
||||
destinations map[spec.ServerName]struct{},
|
||||
dbReceipt *receipt.Receipt,
|
||||
eduType string,
|
||||
expireEDUTypes map[string]time.Duration,
|
||||
|
|
@ -182,7 +183,7 @@ func (d *InMemoryFederationDatabase) AssociateEDUWithDestinations(
|
|||
|
||||
func (d *InMemoryFederationDatabase) CleanPDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
receipts []*receipt.Receipt,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
|
|
@ -199,7 +200,7 @@ func (d *InMemoryFederationDatabase) CleanPDUs(
|
|||
|
||||
func (d *InMemoryFederationDatabase) CleanEDUs(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
receipts []*receipt.Receipt,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
|
|
@ -216,7 +217,7 @@ func (d *InMemoryFederationDatabase) CleanEDUs(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingPDUCount(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) (int64, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -230,7 +231,7 @@ func (d *InMemoryFederationDatabase) GetPendingPDUCount(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingEDUCount(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) (int64, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -244,11 +245,11 @@ func (d *InMemoryFederationDatabase) GetPendingEDUCount(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingPDUServerNames(
|
||||
ctx context.Context,
|
||||
) ([]gomatrixserverlib.ServerName, error) {
|
||||
) ([]spec.ServerName, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
||||
servers := []gomatrixserverlib.ServerName{}
|
||||
servers := []spec.ServerName{}
|
||||
for server := range d.pendingPDUServers {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
|
@ -257,11 +258,11 @@ func (d *InMemoryFederationDatabase) GetPendingPDUServerNames(
|
|||
|
||||
func (d *InMemoryFederationDatabase) GetPendingEDUServerNames(
|
||||
ctx context.Context,
|
||||
) ([]gomatrixserverlib.ServerName, error) {
|
||||
) ([]spec.ServerName, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
||||
servers := []gomatrixserverlib.ServerName{}
|
||||
servers := []spec.ServerName{}
|
||||
for server := range d.pendingEDUServers {
|
||||
servers = append(servers, server)
|
||||
}
|
||||
|
|
@ -269,7 +270,7 @@ func (d *InMemoryFederationDatabase) GetPendingEDUServerNames(
|
|||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) AddServerToBlacklist(
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -279,7 +280,7 @@ func (d *InMemoryFederationDatabase) AddServerToBlacklist(
|
|||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) RemoveServerFromBlacklist(
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -292,12 +293,12 @@ func (d *InMemoryFederationDatabase) RemoveAllServersFromBlacklist() error {
|
|||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
||||
d.blacklistedServers = make(map[gomatrixserverlib.ServerName]struct{})
|
||||
d.blacklistedServers = make(map[spec.ServerName]struct{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) IsServerBlacklisted(
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) (bool, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -312,7 +313,7 @@ func (d *InMemoryFederationDatabase) IsServerBlacklisted(
|
|||
|
||||
func (d *InMemoryFederationDatabase) SetServerAssumedOffline(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -323,7 +324,7 @@ func (d *InMemoryFederationDatabase) SetServerAssumedOffline(
|
|||
|
||||
func (d *InMemoryFederationDatabase) RemoveServerAssumedOffline(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -338,13 +339,13 @@ func (d *InMemoryFederationDatabase) RemoveAllServersAssumedOffine(
|
|||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
||||
d.assumedOffline = make(map[gomatrixserverlib.ServerName]struct{})
|
||||
d.assumedOffline = make(map[spec.ServerName]struct{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) IsServerAssumedOffline(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
) (bool, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -359,12 +360,12 @@ func (d *InMemoryFederationDatabase) IsServerAssumedOffline(
|
|||
|
||||
func (d *InMemoryFederationDatabase) P2PGetRelayServersForServer(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
) ([]gomatrixserverlib.ServerName, error) {
|
||||
serverName spec.ServerName,
|
||||
) ([]spec.ServerName, error) {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
||||
knownRelayServers := []gomatrixserverlib.ServerName{}
|
||||
knownRelayServers := []spec.ServerName{}
|
||||
if relayServers, ok := d.relayServers[serverName]; ok {
|
||||
knownRelayServers = relayServers
|
||||
}
|
||||
|
|
@ -374,8 +375,8 @@ func (d *InMemoryFederationDatabase) P2PGetRelayServersForServer(
|
|||
|
||||
func (d *InMemoryFederationDatabase) P2PAddRelayServersForServer(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
relayServers []gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
relayServers []spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -401,8 +402,8 @@ func (d *InMemoryFederationDatabase) P2PAddRelayServersForServer(
|
|||
|
||||
func (d *InMemoryFederationDatabase) P2PRemoveRelayServersForServer(
|
||||
ctx context.Context,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
relayServers []gomatrixserverlib.ServerName,
|
||||
serverName spec.ServerName,
|
||||
relayServers []spec.ServerName,
|
||||
) error {
|
||||
d.dbMutex.Lock()
|
||||
defer d.dbMutex.Unlock()
|
||||
|
|
@ -426,7 +427,7 @@ func (d *InMemoryFederationDatabase) P2PRemoveRelayServersForServer(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) FetchKeys(ctx context.Context, requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
||||
func (d *InMemoryFederationDatabase) FetchKeys(ctx context.Context, requests map[gomatrixserverlib.PublicKeyLookupRequest]spec.Timestamp) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -446,11 +447,11 @@ func (d *InMemoryFederationDatabase) GetJoinedHosts(ctx context.Context, roomID
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) GetAllJoinedHosts(ctx context.Context) ([]gomatrixserverlib.ServerName, error) {
|
||||
func (d *InMemoryFederationDatabase) GetAllJoinedHosts(ctx context.Context) ([]spec.ServerName, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) GetJoinedHostsForRooms(ctx context.Context, roomIDs []string, excludeSelf, excludeBlacklisted bool) ([]gomatrixserverlib.ServerName, error) {
|
||||
func (d *InMemoryFederationDatabase) GetJoinedHostsForRooms(ctx context.Context, roomIDs []string, excludeSelf, excludeBlacklisted bool) ([]spec.ServerName, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -458,19 +459,19 @@ func (d *InMemoryFederationDatabase) RemoveAllServersAssumedOffline(ctx context.
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) P2PRemoveAllRelayServersForServer(ctx context.Context, serverName gomatrixserverlib.ServerName) error {
|
||||
func (d *InMemoryFederationDatabase) P2PRemoveAllRelayServersForServer(ctx context.Context, serverName spec.ServerName) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) AddOutboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
func (d *InMemoryFederationDatabase) AddOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) RenewOutboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
func (d *InMemoryFederationDatabase) RenewOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) GetOutboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string) (*types.OutboundPeek, error) {
|
||||
func (d *InMemoryFederationDatabase) GetOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string) (*types.OutboundPeek, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -478,15 +479,15 @@ func (d *InMemoryFederationDatabase) GetOutboundPeeks(ctx context.Context, roomI
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) AddInboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
func (d *InMemoryFederationDatabase) AddInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) RenewInboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
func (d *InMemoryFederationDatabase) RenewInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) GetInboundPeek(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID, peekID string) (*types.InboundPeek, error) {
|
||||
func (d *InMemoryFederationDatabase) GetInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string) (*types.InboundPeek, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
@ -494,11 +495,11 @@ func (d *InMemoryFederationDatabase) GetInboundPeeks(ctx context.Context, roomID
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) UpdateNotaryKeys(ctx context.Context, serverName gomatrixserverlib.ServerName, serverKeys gomatrixserverlib.ServerKeys) error {
|
||||
func (d *InMemoryFederationDatabase) UpdateNotaryKeys(ctx context.Context, serverName spec.ServerName, serverKeys gomatrixserverlib.ServerKeys) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *InMemoryFederationDatabase) GetNotaryKeys(ctx context.Context, serverName gomatrixserverlib.ServerName, optKeyIDs []gomatrixserverlib.KeyID) ([]gomatrixserverlib.ServerKeys, error) {
|
||||
func (d *InMemoryFederationDatabase) GetNotaryKeys(ctx context.Context, serverName spec.ServerName, optKeyIDs []gomatrixserverlib.KeyID) ([]gomatrixserverlib.ServerKeys, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue