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
06a9fdb6
Commit
06a9fdb6
authored
Mar 23, 2022
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
filling in details of tracker
parent
f55ed1c7
No related branches found
No related tags found
4 merge requests
!510
Release
,
!207
WIP: Client Restructure
,
!203
Symmetric broadcast
,
!187
Xx 3829/triggers
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
network/identity/tracker.go
+97
-53
97 additions, 53 deletions
network/identity/tracker.go
with
97 additions
and
53 deletions
network/identity/tracker.go
+
97
−
53
View file @
06a9fdb6
...
@@ -9,6 +9,10 @@ package identity
...
@@ -9,6 +9,10 @@ package identity
import
(
import
(
"encoding/json"
"encoding/json"
"os"
"sync"
"time"
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces"
...
@@ -20,9 +24,6 @@ import (
...
@@ -20,9 +24,6 @@ import (
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/netTime"
"sort"
"sync"
"time"
)
)
const
validityGracePeriod
=
5
*
time
.
Minute
const
validityGracePeriod
=
5
*
time
.
Minute
...
@@ -32,8 +33,11 @@ const TimestampKey = "IDTrackingTimestamp"
...
@@ -32,8 +33,11 @@ const TimestampKey = "IDTrackingTimestamp"
const
TimestampStoreVersion
=
0
const
TimestampStoreVersion
=
0
const
ephemeralStoppable
=
"EphemeralCheck"
const
ephemeralStoppable
=
"EphemeralCheck"
const
addressSpaceSizeChanTag
=
"ephemeralTracker"
const
addressSpaceSizeChanTag
=
"ephemeralTracker"
var
Forever
time
.
Time
=
time
.
Time
{}
var
Forever
time
.
Time
=
time
.
Time
{}
const
trackedIDChanSize
=
1000
const
deleteIDChanSize
=
1000
type
Tracker
struct
{
type
Tracker
struct
{
tracked
[]
trackedID
tracked
[]
trackedID
...
@@ -41,6 +45,8 @@ type Tracker struct{
...
@@ -41,6 +45,8 @@ type Tracker struct{
session
*
storage
.
Session
session
*
storage
.
Session
newIdentity
chan
trackedID
newIdentity
chan
trackedID
deleteIdentity
chan
*
id
.
ID
deleteIdentity
chan
*
id
.
ID
addrSpace
*
address
.
Space
mux
*
sync
.
Mutex
}
}
type
trackedID
struct
{
type
trackedID
struct
{
...
@@ -51,12 +57,32 @@ type trackedID struct{
...
@@ -51,12 +57,32 @@ type trackedID struct{
Persistent
bool
Persistent
bool
}
}
func
NewTracker
(
session
*
storage
.
Session
,
addrSpace
*
address
.
Space
)
*
Tracker
{
func
NewTracker
(
session
*
storage
.
Session
,
addrSpace
*
address
.
Space
,
kv
*
versioned
.
KV
)
*
Tracker
{
//intilization
//intilization
t
:=
&
Tracker
{
tracked
:
make
([]
trackedID
,
0
),
session
:
session
,
newIdentity
:
make
(
chan
trackedID
,
trackedIDChanSize
),
deleteIdentity
:
make
(
chan
*
id
.
ID
,
deleteIDChanSize
),
addrSpace
:
addrSpace
,
mux
:
&
sync
.
Mutex
{},
}
//loading
//loading
err
:=
t
.
load
()
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
//if load fails, make a new
//if load fails, make a new
t
.
store
=
receptionID
.
NewStore
(
session
.
GetKV
())
}
else
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"unable to create new Tracker: %+v"
,
err
)
}
else
{
t
.
store
=
receptionID
.
LoadStore
(
session
.
GetKV
())
}
//check if there is an old timestamp, recreate the basic ID from it
//check if there is an old timestamp, recreate the basic ID from it
//initilize the ephemeral identiies system
//initilize the ephemeral identiies system
return
t
}
}
//make the GetIdentities call on the ephemerals system public on this
//make the GetIdentities call on the ephemerals system public on this
...
@@ -70,8 +96,6 @@ func (tracker Tracker)StartProcessies() stoppable.Stoppable {
...
@@ -70,8 +96,6 @@ func (tracker Tracker)StartProcessies() stoppable.Stoppable {
return
stop
return
stop
}
}
// AddIdentity adds an identity to be tracked
// AddIdentity adds an identity to be tracked
func
(
tracker
*
Tracker
)
AddIdentity
(
id
*
id
.
ID
,
validUntil
time
.
Time
,
persistent
bool
)
{
func
(
tracker
*
Tracker
)
AddIdentity
(
id
*
id
.
ID
,
validUntil
time
.
Time
,
persistent
bool
)
{
tracker
.
newIdentity
<-
trackedID
{
tracker
.
newIdentity
<-
trackedID
{
...
@@ -287,6 +311,8 @@ func generateIdentitiesOverRange(lastGeneration, generateThrough time.Time,
...
@@ -287,6 +311,8 @@ func generateIdentitiesOverRange(lastGeneration, generateThrough time.Time,
}
}
func
(
tracker
*
Tracker
)
save
()
{
func
(
tracker
*
Tracker
)
save
()
{
t
.
mux
.
Lock
()
defer
t
.
mux
.
Unlock
()
persistant
:=
make
([]
trackedID
,
0
,
len
(
tracker
.
tracked
))
persistant
:=
make
([]
trackedID
,
0
,
len
(
tracker
.
tracked
))
for
i
:=
range
tracker
.
tracked
{
for
i
:=
range
tracker
.
tracked
{
...
@@ -299,20 +325,38 @@ func (tracker *Tracker)save(){
...
@@ -299,20 +325,38 @@ func (tracker *Tracker)save(){
return
return
}
}
data
,
err
:=
json
.
Marshal
(
&
persistant
)
data
,
err
:=
json
.
Marshal
(
&
persistant
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"
Fai
le
d
to marshal
the
tracked
users"
)
jww
.
FATAL
.
Panicf
(
"
unab
le to marshal tracked
ID list: %+v"
,
err
)
}
}
obj
:=
&
versioned
.
Object
{
obj
:=
&
versioned
.
Object
{
Version
:
,
Version
:
TrackerListVersion
,
Timestamp
:
netTime
.
Now
(),
Timestamp
:
netTime
.
Now
(),
Data
:
data
,
Data
:
data
,
}
}
err
=
tracker
.
session
.
GetKV
()
.
Set
(
TrackerListKey
,
TrackerListVersion
,
obj
)
err
=
tracker
.
session
.
GetKV
()
.
Set
(
TrackerListKey
,
TrackerListVersion
,
obj
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"unable to save trackedID list: %+v"
,
err
)
}
}
func
(
t
*
Tracker
)
load
()
error
{
t
.
mux
.
Lock
()
defer
t
.
mux
.
Unlock
()
obj
,
err
:=
t
.
session
.
GetKV
()
.
Get
(
TrackerListKey
,
TrackerListVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to store the tracked users"
)
return
err
}
}
trackedID
:=
make
([]
trackedID
,
0
)
err
=
json
.
Unmarshal
(
obj
.
Data
,
trackedID
)
if
err
!=
nil
{
return
err
}
t
.
tracked
=
trackedID
return
nil
}
}
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