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
d20e8577
Commit
d20e8577
authored
Feb 17, 2021
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
fixed getRoundResults
parent
84e0502a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/messages.go
+82
-46
82 additions, 46 deletions
api/messages.go
with
82 additions
and
46 deletions
api/messages.go
+
82
−
46
View file @
d20e8577
...
...
@@ -19,21 +19,31 @@ import (
)
type
RoundEventCallback
interface
{
Report
(
rid
,
state
int
,
timedOut
bool
)
bool
Report
(
succeeded
,
timedout
bool
,
rounds
map
[
id
.
Round
]
RoundResult
)
}
type
RoundResult
uint
const
(
TimeOut
RoundResult
=
iota
Failed
Succeeded
)
func
(
c
*
Client
)
GetRoundResults
(
roundList
[]
id
.
Round
,
roundCallback
RoundEventCallback
,
timeout
time
.
Duration
)
error
{
}
// Adjudicates on the rounds requested. Checks if they are older rounds or in progress rounds.
// Sends updates on the rounds with callbacks
func
(
c
*
Client
)
RegisterMessageDelivery
(
roundList
[]
id
.
Round
,
roundCallback
RoundEventCallback
,
timeoutMS
int
)
error
{
func
(
c
*
Client
)
getRoundResults
(
roundList
[]
id
.
Round
,
roundCallback
RoundEventCallback
,
timeout
time
.
Duration
,
sendResults
chan
ds
.
EventReturn
,
)
error
{
// Get the oldest round in the buffer
networkInstance
:=
c
.
network
.
GetInstance
()
timeout
:=
time
.
Duration
(
timeoutMS
)
*
time
.
Millisecond
/*check message delivery*/
sendResults
:=
make
(
chan
ds
.
EventReturn
,
len
(
roundList
))
roundEvents
:=
c
.
GetRoundEvents
()
rndEventObjs
:=
make
([]
*
ds
.
EventCallback
,
len
(
roundList
))
numResults
:=
0
// Generate a message
historicalRequest
:=
&
pb
.
HistoricalRounds
{
...
...
@@ -41,53 +51,79 @@ func (c *Client) RegisterMessageDelivery(roundList []id.Round, roundCallback Ro
}
oldestRound
:=
networkInstance
.
GetOldestRoundID
()
for
i
,
rnd
:=
range
roundList
{
rounds
:=
make
(
map
[
id
.
Round
]
RoundResult
)
succeeded
:=
true
for
_
,
rnd
:=
range
roundList
{
rounds
[
rnd
]
=
TimeOut
roundInfo
,
err
:=
networkInstance
.
GetRound
(
rnd
)
if
err
!=
nil
{
if
err
==
nil
{
if
states
.
Round
(
roundInfo
.
State
)
==
states
.
COMPLETED
{
rounds
[
rnd
]
=
Succeeded
}
else
if
states
.
Round
(
roundInfo
.
State
)
==
states
.
FAILED
{
rounds
[
rnd
]
=
Failed
succeeded
=
false
}
else
{
roundEvents
.
AddRoundEventChan
(
rnd
,
sendResults
,
timeout
-
time
.
Millisecond
,
states
.
COMPLETED
,
states
.
FAILED
)
numResults
++
}
}
else
{
jww
.
DEBUG
.
Printf
(
"Failed to ger round [%d] in buffer: %v"
,
rnd
,
err
)
// Update oldest round (buffer may have updated externally)
oldestRound
=
networkInstance
.
GetOldestRoundID
()
}
oldestRound
:=
networkInstance
.
GetOldestRoundID
()
if
rnd
<
oldestRound
{
// If round is older that oldest round in our buffer
// Add it to the historical round request (performed later)
historicalRequest
.
Rounds
=
append
(
historicalRequest
.
Rounds
,
uint64
(
rnd
))
numResults
++
}
else
{
// If the round is in the buffer, and done (completed or failed) send the results
// through the channel
if
roundInfo
!=
nil
&&
(
states
.
Round
(
roundInfo
.
State
)
==
states
.
COMPLETED
||
states
.
Round
(
roundInfo
.
State
)
==
states
.
FAILED
)
{
sendResults
<-
ds
.
EventReturn
{
RoundInfo
:
roundInfo
,
roundEvents
.
AddRoundEventChan
(
rnd
,
sendResults
,
timeout
-
time
.
Millisecond
,
states
.
COMPLETED
,
states
.
FAILED
)
numResults
++
}
continue
}
// If it is still in progress, create a monitoring channel
rndEventObjs
[
i
]
=
roundEvents
.
AddRoundEventChan
(
rnd
,
sendResults
,
timeout
,
states
.
COMPLETED
,
states
.
FAILED
)
}
}
//request historical rounds if any are needed
if
len
(
historicalRequest
.
Rounds
)
>
0
{
// Find out what happened to old (historical) rounds
historicalReport
:=
make
(
chan
ds
.
EventReturn
,
len
(
historicalRequest
.
Rounds
)
)
go
c
.
getHistoricalRounds
(
historicalRequest
,
networkInstance
,
historicalReport
)
go
c
.
getHistoricalRounds
(
historicalRequest
,
networkInstance
,
sendResults
)
}
// Determine the success of all rounds requested
go
func
()
{
//create the results timer
timer
:=
time
.
NewTimer
(
timeout
)
for
{
//if we know about all rounds, return
if
numResults
==
0
{
roundCallback
.
Report
(
succeeded
,
true
,
rounds
)
return
}
//wait for info about rounds or the timeout to occur
select
{
case
<-
timer
.
C
:
roundCallback
.
Report
(
false
,
true
,
rounds
)
return
case
roundReport
:=
<-
sendResults
:
ri
:=
roundReport
.
RoundInfo
roundCallback
.
Report
(
int
(
ri
.
ID
),
int
(
ri
.
State
),
roundReport
.
TimedOut
)
case
roundReport
:=
<-
historicalReport
:
ri
:=
roundReport
.
RoundInfo
roundCallback
.
Report
(
int
(
ri
.
ID
),
int
(
ri
.
State
),
roundReport
.
TimedOut
)
numResults
--
// skip if the round is nil (unknown from historical rounds)
// they default to timed out, so correct behavior is preserved
if
roundReport
.
RoundInfo
==
nil
||
roundReport
.
TimedOut
{
succeeded
=
false
}
else
{
//if available, denote the result
if
states
.
Round
(
roundReport
.
RoundInfo
.
State
)
==
states
.
COMPLETED
{
rounds
[
id
.
Round
(
roundReport
.
RoundInfo
.
ID
)]
=
Succeeded
}
else
{
rounds
[
id
.
Round
(
roundReport
.
RoundInfo
.
ID
)]
=
Failed
succeeded
=
false
}
}
}
}
}()
...
...
@@ -121,8 +157,8 @@ func (c *Client) getHistoricalRounds(msg *pb.HistoricalRounds,
// Process historical rounds, sending back to the caller thread
for
_
,
ri
:=
range
resp
.
Rounds
{
sendResults
<-
ds
.
EventReturn
{
RoundInfo
:
ri
,
TimedOut
:
false
,
ri
,
false
,
}
}
}
\ No newline at end of file
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