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
60e0ed72
Commit
60e0ed72
authored
Aug 28, 2020
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Add threads rough draft
parent
831ea7a5
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
io/threads.go
+146
-0
146 additions, 0 deletions
io/threads.go
with
146 additions
and
0 deletions
io/threads.go
0 → 100644
+
146
−
0
View file @
60e0ed72
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2019 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package
io
// threads.go handles all the long running network processing threads in client
import
(
"gitlab.com/elixxir/client/context"
"time"
)
// Interface for stopping a goroutine
type
Stoppable
interface
{
Close
(
timeout
time
.
Duration
)
}
// ChanStop allows stopping a single goroutine using a channel
type
ChanStop
struct
{
name
string
quit
chan
bool
}
// Close signals thread to time out and closes.
func
(
c
ChanStop
)
Close
(
timeout
time
.
Duration
)
{
timer
:=
time
.
NewTimer
(
timeout
)
select
{
case
<-
timer
:
jww
.
ERROR
.
Printf
(
"goroutine failed to Close: %s"
,
c
.
name
)
case
<-
c
.
quit
:
return
}
}
// StartTrackNetwork starts a single TrackNetwork thread and returns a stoppable
// structure
func
StartTrackNetwork
(
ctx
*
context
.
Context
)
Stoppable
{
stopper
:=
ChanStop
{
name
:
"TrackNetwork"
quit
:
make
(
chan
bool
),
}
go
TrackNetwork
(
ctx
,
stopper
.
quit
)
return
stopper
}
// TrackNetwork polls the network to get updated on the state of nodes, the
// round status, and informs the client when messages can be retrieved.
func
TrackNetwork
(
ctx
*
context
.
Context
,
quitCh
chan
bool
)
{
ticker
:=
timer
.
NewTicker
(
ctx
.
GetTrackNetworkPeriod
())
done
:=
false
for
!
done
{
select
{
case
<-
quitCh
:
done
=
true
case
<-
ticker
:
trackNetwork
(
ctx
)
}
}
}
func
trackNetwork
(
ctx
)
{
gateway
,
err
:=
ctx
.
Session
.
GetNodeKeys
()
.
GetGatewayForSending
()
if
err
!=
nil
{
//...
}
network
:=
ctx
.
GetNetwork
()
ndf
,
err
:=
network
.
PollNDF
(
ctx
,
gateway
)
if
err
!=
nil
{
// ....
}
newNodes
,
removedNodes
:=
network
.
UpdateNDF
(
ndf
)
for
_
,
n
:=
range
newNodes
{
network
.
addNodeCh
<-
n
}
for
_
,
n
:=
range
removedNodes
{
network
.
removeNodeCh
<-
n
}
rounds
,
err
=
network
.
UpdateRounds
(
ctx
,
ndf
)
if
err
!=
nil
{
// ...
}
err
=
rounds
.
GetKnownRound
()
.
MaskedRange
(
gateway
,
network
.
CheckRoundsFunction
)
if
err
!=
nil
{
// ...
}
}
func
StartProcessHistoricalRounds
(
ctx
*
context
.
Context
)
Stoppable
{
stopper
:=
ChanStop
{
name
:
"ProcessHistoricalRounds"
quit
:
make
(
chan
bool
),
}
go
ProcessHistoricalRounds
(
ctx
,
stopper
.
quit
)
return
stopper
}
func
ProcessHistoricalRounds
(
ctx
*
context
.
Context
,
quitCh
chan
bool
)
{
ticker
:=
timer
.
NewTicker
(
ctx
.
GetTrackNetworkPeriod
())
var
rounds
[]
RoundID
done
:=
false
for
!
done
{
shouldProcess
:=
false
select
{
case
<-
quitCh
:
done
=
true
case
<-
ticker
:
if
len
(
rounds
)
>
0
{
shouldProcess
=
true
}
case
rid
:=
<-
ctx
.
GetHistoricalRoundsCh
()
:
rounds
=
append
(
rounds
,
rid
)
if
len
(
rounds
)
>
ctx
.
GetSendSize
()
{
shouldProcess
=
true
}
}
if
!
shouldProcess
{
continue
}
var
roundInfos
[]
*
RoundInfo
roundInfos
:=
processHistoricalRounds
(
ctx
,
rounds
)
rounds
:=
make
([]
RoundID
)
for
_
,
ri
:=
range
roundInfos
{
ctx
.
GetMessagesCh
()
<-
ri
}
}
}
func
processHistoricalRounds
(
ctx
*
context
.
Context
,
rids
[]
RoundID
)
[]
*
RoundInfo
{
// for loop over rids?
network
:=
ctx
.
GetNetwork
()
gw
:=
network
.
GetGateway
()
ris
:=
gw
.
GetHistoricalRounds
(
ctx
.
GetRoundList
())
return
ris
}
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