mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
s/StateKey/StateKeyTuple
This commit is contained in:
parent
dbd6ad2ad5
commit
2720aba81f
|
|
@ -120,7 +120,7 @@ func (ae *authEvents) ThirdPartyInvite(stateKey string) (*gomatrixserverlib.Even
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ae *authEvents) lookupEventWithEmptyStateKey(typeNID int64) *gomatrixserverlib.Event {
|
func (ae *authEvents) lookupEventWithEmptyStateKey(typeNID int64) *gomatrixserverlib.Event {
|
||||||
eventNID, ok := ae.state.lookup(types.StateKey{typeNID, types.EmptyStateKeyNID})
|
eventNID, ok := ae.state.lookup(types.StateKeyTuple{typeNID, types.EmptyStateKeyNID})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ func (ae *authEvents) lookupEvent(typeNID int64, stateKey string) *gomatrixserve
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
eventNID, ok := ae.state.lookup(types.StateKey{typeNID, stateKeyNID})
|
eventNID, ok := ae.state.lookup(types.StateKeyTuple{typeNID, stateKeyNID})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -182,27 +182,27 @@ func loadAuthEvents(
|
||||||
}
|
}
|
||||||
|
|
||||||
// stateKeysNeeded works out which numeric state keys we need to authenticate some events.
|
// stateKeysNeeded works out which numeric state keys we need to authenticate some events.
|
||||||
func stateKeysNeeded(stateNIDMap idMap, stateNeeded gomatrixserverlib.StateNeeded) []types.StateKey {
|
func stateKeysNeeded(stateNIDMap idMap, stateNeeded gomatrixserverlib.StateNeeded) []types.StateKeyTuple {
|
||||||
var keys []types.StateKey
|
var keys []types.StateKeyTuple
|
||||||
if stateNeeded.Create {
|
if stateNeeded.Create {
|
||||||
keys = append(keys, types.StateKey{types.MRoomCreateNID, types.EmptyStateKeyNID})
|
keys = append(keys, types.StateKeyTuple{types.MRoomCreateNID, types.EmptyStateKeyNID})
|
||||||
}
|
}
|
||||||
if stateNeeded.PowerLevels {
|
if stateNeeded.PowerLevels {
|
||||||
keys = append(keys, types.StateKey{types.MRoomPowerLevelsNID, types.EmptyStateKeyNID})
|
keys = append(keys, types.StateKeyTuple{types.MRoomPowerLevelsNID, types.EmptyStateKeyNID})
|
||||||
}
|
}
|
||||||
if stateNeeded.JoinRules {
|
if stateNeeded.JoinRules {
|
||||||
keys = append(keys, types.StateKey{types.MRoomJoinRulesNID, types.EmptyStateKeyNID})
|
keys = append(keys, types.StateKeyTuple{types.MRoomJoinRulesNID, types.EmptyStateKeyNID})
|
||||||
}
|
}
|
||||||
for _, member := range stateNeeded.Member {
|
for _, member := range stateNeeded.Member {
|
||||||
stateKeyNID, ok := stateNIDMap.lookup(member)
|
stateKeyNID, ok := stateNIDMap.lookup(member)
|
||||||
if ok {
|
if ok {
|
||||||
keys = append(keys, types.StateKey{types.MRoomMemberNID, stateKeyNID})
|
keys = append(keys, types.StateKeyTuple{types.MRoomMemberNID, stateKeyNID})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, token := range stateNeeded.ThirdPartyInvite {
|
for _, token := range stateNeeded.ThirdPartyInvite {
|
||||||
stateKeyNID, ok := stateNIDMap.lookup(token)
|
stateKeyNID, ok := stateNIDMap.lookup(token)
|
||||||
if ok {
|
if ok {
|
||||||
keys = append(keys, types.StateKey{types.MRoomThirdPartyInviteNID, stateKeyNID})
|
keys = append(keys, types.StateKeyTuple{types.MRoomThirdPartyInviteNID, stateKeyNID})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keys
|
return keys
|
||||||
|
|
@ -238,16 +238,16 @@ func newStateEntryMap(stateEntries []types.StateEntry) stateEntryMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup an entry in the event map.
|
// lookup an entry in the event map.
|
||||||
func (m stateEntryMap) lookup(stateKey types.StateKey) (eventNID int64, ok bool) {
|
func (m stateEntryMap) lookup(stateKey types.StateKeyTuple) (eventNID int64, ok bool) {
|
||||||
// Since the list is sorted we can implement this using binary search.
|
// Since the list is sorted we can implement this using binary search.
|
||||||
// This is faster than using a hash map.
|
// This is faster than using a hash map.
|
||||||
// We don't have to worry about pathological cases because the keys are fixed
|
// We don't have to worry about pathological cases because the keys are fixed
|
||||||
// size and are controlled by us.
|
// size and are controlled by us.
|
||||||
list := []types.StateEntry(m)
|
list := []types.StateEntry(m)
|
||||||
i := sort.Search(len(list), func(i int) bool {
|
i := sort.Search(len(list), func(i int) bool {
|
||||||
return !list[i].StateKey.LessThan(stateKey)
|
return !list[i].StateKeyTuple.LessThan(stateKey)
|
||||||
})
|
})
|
||||||
if i < len(list) && list[i].StateKey == stateKey {
|
if i < len(list) && list[i].StateKeyTuple == stateKey {
|
||||||
ok = true
|
ok = true
|
||||||
eventNID = list[i].EventNID
|
eventNID = list[i].EventNID
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,17 @@ type PartitionOffset struct {
|
||||||
Offset int64
|
Offset int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// A StateKey is a pair of a numeric event type and a numeric state key.
|
// A StateKeyTuple is a pair of a numeric event type and a numeric state key.
|
||||||
// It is used to lookup state entries.
|
// It is used to lookup state entries.
|
||||||
type StateKey struct {
|
type StateKeyTuple struct {
|
||||||
// The numeric ID for the event type.
|
// The numeric ID for the event type.
|
||||||
EventTypeNID int64
|
EventTypeNID int64
|
||||||
// The numeric ID for the state key or 0 if the event is not a state event.
|
// The numeric ID for the state key.
|
||||||
EventStateKeyNID int64
|
EventStateKeyNID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// LessThan returns true if this state key is less than the other state key.
|
// LessThan returns true if this state key is less than the other state key.
|
||||||
func (a StateKey) LessThan(b StateKey) bool {
|
func (a StateKeyTuple) LessThan(b StateKeyTuple) bool {
|
||||||
if a.EventTypeNID != b.EventTypeNID {
|
if a.EventTypeNID != b.EventTypeNID {
|
||||||
return a.EventTypeNID < b.EventTypeNID
|
return a.EventTypeNID < b.EventTypeNID
|
||||||
}
|
}
|
||||||
|
|
@ -32,15 +32,15 @@ func (a StateKey) LessThan(b StateKey) bool {
|
||||||
|
|
||||||
// A StateEntry is an entry in the room state of a matrix room.
|
// A StateEntry is an entry in the room state of a matrix room.
|
||||||
type StateEntry struct {
|
type StateEntry struct {
|
||||||
StateKey
|
StateKeyTuple
|
||||||
// The numeric ID for the event.
|
// The numeric ID for the event.
|
||||||
EventNID int64
|
EventNID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// LessThan returns true if this state entry is less than the other state entry.
|
// LessThan returns true if this state entry is less than the other state entry.
|
||||||
func (a StateEntry) LessThan(b StateEntry) bool {
|
func (a StateEntry) LessThan(b StateEntry) bool {
|
||||||
if a.StateKey != b.StateKey {
|
if a.StateKeyTuple != b.StateKeyTuple {
|
||||||
return a.StateKey.LessThan(b.StateKey)
|
return a.StateKeyTuple.LessThan(b.StateKeyTuple)
|
||||||
}
|
}
|
||||||
return a.EventNID < b.EventNID
|
return a.EventNID < b.EventNID
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue