Skip to content

Commit

Permalink
Filter out from-self messages in GJKR
Browse files Browse the repository at this point in the history
When we pre-process messages before executing GJKR protocol phase, we
now also remove the from-self message from the list.
  • Loading branch information
pdyraga committed Oct 25, 2024
1 parent ec297fd commit 8449f5d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
21 changes: 20 additions & 1 deletion gjkr/message_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,34 @@ func deduplicateBySender[T interface{ getSenderIndex() memberIndex }](
return result
}

// removeFromSelf filters out the from-self message from the provided message
// list.
func removeFromSelf[T interface{ getSenderIndex() memberIndex }](
selfMemberIndex memberIndex,
list []T,
) []T {
result := make([]T, 0)

for _, msg := range list {
if msg.getSenderIndex() != selfMemberIndex {
result = append(result, msg)
}
}

return result
}

func (m *symmetricKeyGeneratingMember) preProcessMessages(
ephemeralPubKeyMessages []*ephemeralPublicKeyMessage,
) []*ephemeralPublicKeyMessage {
forThisSession := filterForSession(m.sessionID, ephemeralPubKeyMessages)
deduplicated := deduplicateBySender(forThisSession)
withoutSelf := removeFromSelf(m.memberIndex, deduplicated)

inactiveMembers := findInactive(m.group.groupSize, forThisSession)
for _, ia := range inactiveMembers {
m.group.markMemberAsInactive(ia)
}

return deduplicateBySender(forThisSession)
return withoutSelf
}
28 changes: 23 additions & 5 deletions gjkr/message_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@ import (
)

func TestFilterForSession(t *testing.T) {
msg0 := &ephemeralPublicKeyMessage{sessionID: "session-2", senderIndex: 1}
msg1 := &ephemeralPublicKeyMessage{sessionID: "session-2", senderIndex: 1}
msg2 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 1}
msg3 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 2}
msg4 := &ephemeralPublicKeyMessage{sessionID: "session-2", senderIndex: 3}

filtered := filterForSession("session-1", []*ephemeralPublicKeyMessage{
msg1, msg2, msg3, msg4,
})

testutils.AssertDeepEqual(
t,
"filtered messages",
[]*ephemeralPublicKeyMessage{msg2, msg3},
filtered,
)
}

func TestRemoveFromSelf(t *testing.T) {
msg1 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 1}
msg2 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 2}
msg3 := &ephemeralPublicKeyMessage{sessionID: "session-2", senderIndex: 3}
msg3 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 3}
msg4 := &ephemeralPublicKeyMessage{sessionID: "session-1", senderIndex: 4}

filtered := filterForSession("session-1", []*ephemeralPublicKeyMessage{
msg0, msg1, msg2, msg3,
filtered := removeFromSelf(memberIndex(2), []*ephemeralPublicKeyMessage{
msg1, msg2, msg3, msg4,
})

testutils.AssertDeepEqual(
t,
"filtered messages",
[]*ephemeralPublicKeyMessage{msg1, msg2},
[]*ephemeralPublicKeyMessage{msg1, msg3, msg4},
filtered,
)
}
Expand Down

0 comments on commit 8449f5d

Please sign in to comment.