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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
33534691
Commit
33534691
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add documentation
parent
1a5df79a
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/triggers.go
+31
-7
31 additions, 7 deletions
network/triggers.go
with
31 additions
and
7 deletions
network/triggers.go
+
31
−
7
View file @
33534691
...
...
@@ -50,19 +50,38 @@ func NewTriggers() *Triggers {
return
nil
}
func
(
t
*
Triggers
)
Lookup
(
identityFp
,
ecrMsgContents
[]
byte
)
([]
*
Trigger
,
bool
)
{
// Lookup will see if a trigger exists for the given preimage and message
// contents. It will do this by trial hashing the preimages in the map with
// the received message contents, until either a match to the
// received identity fingerprint is received or it has exhausted the map.
// If a match is found, this means the message received is for the client,
// and that one or multiple triggers exist to process this message.
// These triggers are returned to the caller along with the a true boolean.
// If the map has been exhausted with no matches found, it returns nil and false.
// todo: reorganize this interface. Lookup needs to be called
// by handleMessage, which should not have access to the other
// state modifying methods below. Possible options include:
// - privatizing the state-changing methods
// - leaking lookup on this layer and migrating the state modifiation methods
// a layer down in a sepearate package
func
(
t
*
Triggers
)
Lookup
(
receivedIdentityFp
,
ecrMsgContents
[]
byte
)
(
triggers
[]
*
Trigger
,
forMe
bool
)
{
t
.
RLock
()
defer
t
.
RUnlock
()
for
preimage
,
trigger
s
:=
range
t
.
triggers
{
for
preimage
,
trigger
List
:=
range
t
.
triggers
{
preimageBytes
,
err
:=
unmarshalPreimage
(
preimage
)
if
err
!=
nil
{
// fixme: panic here, this error would mean bad data is in the map
// fixme: panic here?, An error here would mean there's a bad
// key-value pair in the map (specifically the preimage-key is bad,
// as it should be base64 encoded).
}
if
fingerprint2
.
CheckIdentityFP
(
identityFp
,
ecrMsgContents
,
preimageBytes
)
{
return
triggers
,
true
// fixme, there probably needs to be a small refactor.
// Terminology and variable names are being used misused. For example:
// phrases like tag, preimage and identityFP are being used
// interchangeably in the code and it's getting unwieldy.
if
fingerprint2
.
CheckIdentityFP
(
receivedIdentityFp
,
ecrMsgContents
,
preimageBytes
)
{
return
triggerList
,
true
}
}
...
...
@@ -133,10 +152,15 @@ func (t *Triggers) RemoveTrigger(preimage []byte,
}
// fixme: maybe make preimage a type or struct and place this in primitives?
// marshalPreimage is a helper which encodes the preimage byte data to
// a base64 encoded string.
func
marshalPreimage
(
pi
[]
byte
)
string
{
return
base64
.
StdEncoding
.
EncodeToString
(
pi
)
}
// unmarshalPreimage is a helper which decodes the preimage base64 string to
// bytes.
func
unmarshalPreimage
(
data
string
)
([]
byte
,
error
)
{
decoded
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
data
)
if
err
!=
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