Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
23cee627
Commit
23cee627
authored
Mar 10, 2023
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Make the send tracking code clearer
parent
2dce69c4
No related branches found
No related tags found
2 merge requests
!564
Clean up the send tracking code, and properly mark DMs as delivered
,
!515
Release
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
dm/client.go
+5
-5
5 additions, 5 deletions
dm/client.go
dm/interfaces.go
+6
-0
6 additions, 0 deletions
dm/interfaces.go
dm/receiver.go
+22
-6
22 additions, 6 deletions
dm/receiver.go
dm/sendTracker.go
+25
-11
25 additions, 11 deletions
dm/sendTracker.go
dm/sendTracker_test.go
+4
-0
4 additions, 0 deletions
dm/sendTracker_test.go
with
62 additions
and
22 deletions
dm/client.go
+
5
−
5
View file @
23cee627
...
...
@@ -81,19 +81,19 @@ func NewDMClient(myID *codename.PrivateIdentity, receiver EventModel,
}
// Register the listener
dmc
.
register
(
receiver
,
dmc
.
st
.
CheckIfSent
)
dmc
.
register
(
receiver
,
dmc
.
st
)
return
dmc
}
// Register registers a listener for direct messages.
func
(
dc
*
dmClient
)
register
(
apiReceiver
EventModel
,
checkSent
messageReceiveFunc
)
error
{
tracker
SendTracker
)
error
{
beginningOfTime
:=
time
.
Time
{}
r
:=
&
receiver
{
c
:
dc
,
api
:
apiReceiver
,
checkSent
:
checkSent
,
sendTracker
:
tracker
,
}
// Initialize Send Tracking
...
...
This diff is collapsed.
Click to expand it.
dm/interfaces.go
+
6
−
0
View file @
23cee627
...
...
@@ -277,4 +277,10 @@ type SendTracker interface {
//CheckIfSent checks if the given message was a sent message
CheckIfSent
(
messageID
cryptoMessage
.
ID
,
r
rounds
.
Round
)
bool
//Delivered marks a message delivered
Delivered
(
msgID
cryptoMessage
.
ID
,
round
rounds
.
Round
)
bool
//StopTracking stops tracking a message
StopTracking
(
msgID
cryptoMessage
.
ID
,
round
rounds
.
Round
)
bool
}
This diff is collapsed.
Click to expand it.
dm/receiver.go
+
22
−
6
View file @
23cee627
...
...
@@ -31,7 +31,7 @@ import (
type
receiver
struct
{
c
*
dmClient
api
EventModel
checkSent
messageReceiveFunc
sendTracker
SendTracker
}
type
dmProcessor
struct
{
...
...
@@ -78,7 +78,9 @@ func (dp *dmProcessor) Process(msg format.Message,
msgID
:=
message
.
DeriveDirectMessageID
(
myID
,
directMsg
)
// Check if we sent the message and ignore triggering if we sent
if
dp
.
r
.
checkSent
(
msgID
,
round
)
{
// This will happen when DM'ing with oneself, but the receive self
// processor will update the status to delivered, so we do nothing here.
if
dp
.
r
.
sendTracker
.
CheckIfSent
(
msgID
,
round
)
{
return
}
...
...
@@ -172,8 +174,22 @@ func (sp *selfProcessor) Process(msg format.Message,
msgID
:=
message
.
DeriveDirectMessageID
(
partnerID
,
directMsg
)
// Check if we sent the message and ignore triggering if we sent
if
sp
.
r
.
checkSent
(
msgID
,
round
)
{
// Check if we sent the message and ignore triggering if we
// sent, but mark the message as delivered
if
sp
.
r
.
sendTracker
.
CheckIfSent
(
msgID
,
round
)
{
go
func
()
{
ok
:=
sp
.
r
.
sendTracker
.
Delivered
(
msgID
,
round
)
if
!
ok
{
jww
.
WARN
.
Printf
(
"[DM] Couldn't mark delivered"
+
": %s %v)"
,
msgID
,
round
)
}
sp
.
r
.
sendTracker
.
StopTracking
(
msgID
,
round
)
if
!
ok
{
jww
.
WARN
.
Printf
(
"[DM] Coulnd't StopTracking: "
+
"%s, %v"
,
msgID
,
round
)
}
}()
return
}
...
...
This diff is collapsed.
Click to expand it.
dm/sendTracker.go
+
25
−
11
View file @
23cee627
...
...
@@ -319,20 +319,39 @@ func (st *sendTracker) handleSendFailed(uuid uint64) (*tracked, error) {
}
// CheckIfSent is used when a message is received to check if the message was
// sent by this user. If it was, the correct signal is sent to the event model
// and the function returns true, notifying the caller to not process the
// message.
// sent by this user.
func
(
st
*
sendTracker
)
CheckIfSent
(
messageID
message
.
ID
,
round
rounds
.
Round
)
bool
{
st
.
mux
.
RLock
()
// Skip if already added
defer
st
.
mux
.
RUnlock
()
_
,
existsMessage
:=
st
.
byMessageID
[
messageID
]
st
.
mux
.
RUnlock
()
return
existsMessage
}
// Delivered calls the event model update function to tell it that this
// message was delivered. (after this is called successfully, it is safe to
// stop tracking this message).
// returns true if the update sent status func was called.
func
(
st
*
sendTracker
)
Delivered
(
messageID
message
.
ID
,
round
rounds
.
Round
)
bool
{
st
.
mux
.
RLock
()
defer
st
.
mux
.
RUnlock
()
msgData
,
existsMessage
:=
st
.
byMessageID
[
messageID
]
if
!
existsMessage
{
return
false
}
ts
:=
message
.
MutateTimestamp
(
round
.
Timestamps
[
states
.
QUEUED
],
messageID
)
st
.
updateStatus
(
msgData
.
UUID
,
messageID
,
ts
,
round
,
Sent
)
return
true
}
// StopTracking deletes this message id/round combination from the
// send tracking. returns true if it was removed, false otherwise.
func
(
st
*
sendTracker
)
StopTracking
(
messageID
message
.
ID
,
round
rounds
.
Round
)
bool
{
st
.
mux
.
Lock
()
defer
st
.
mux
.
Unlock
()
msgData
,
existsMessage
:=
st
.
byMessageID
[
messageID
]
...
...
@@ -359,11 +378,6 @@ func (st *sendTracker) CheckIfSent(
}
}
ts
:=
message
.
MutateTimestamp
(
round
.
Timestamps
[
states
.
QUEUED
],
messageID
)
go
st
.
updateStatus
(
msgData
.
UUID
,
messageID
,
ts
,
round
,
Sent
)
if
err
:=
st
.
storeSent
();
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"failed to store the updated sent list: %+v"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
dm/sendTracker_test.go
+
4
−
0
View file @
23cee627
...
...
@@ -84,6 +84,8 @@ func TestSendTracker_MessageReceive(t *testing.T) {
require
.
NoError
(
t
,
err
)
process
=
st
.
CheckIfSent
(
mid
,
r
)
st
.
Delivered
(
mid
,
r
)
st
.
StopTracking
(
mid
,
r
)
require
.
True
(
t
,
process
)
directMessage2
:=
&
DirectMessage
{
...
...
@@ -102,6 +104,8 @@ func TestSendTracker_MessageReceive(t *testing.T) {
require
.
NoError
(
t
,
err
)
process
=
st
.
CheckIfSent
(
mid
,
r
)
require
.
True
(
t
,
process
)
st
.
Delivered
(
mid
,
r
)
st
.
StopTracking
(
mid
,
r
)
}
// Test failedSend function, confirming that data is stored appropriately and
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment