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
d7d9b93e
Commit
d7d9b93e
authored
4 years ago
by
Benjamin Wenger
Browse files
Options
Downloads
Patches
Plain Diff
fixed the process for checking if messages are properly submitted to cmix
parent
d1635b97
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ud/addFact.go
+4
-4
4 additions, 4 deletions
ud/addFact.go
ud/addFact_test.go
+2
-2
2 additions, 2 deletions
ud/addFact_test.go
ud/lookup.go
+40
-25
40 additions, 25 deletions
ud/lookup.go
ud/search.go
+35
-25
35 additions, 25 deletions
ud/search.go
with
81 additions
and
56 deletions
ud/addFact.go
+
4
−
4
View file @
d7d9b93e
...
...
@@ -9,6 +9,7 @@ import (
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
)
type
addFactComms
interface
{
...
...
@@ -16,10 +17,11 @@ type addFactComms interface {
}
func
(
m
*
Manager
)
SendRegisterFact
(
fact
fact
.
Fact
)
(
*
pb
.
FactRegisterResponse
,
error
)
{
return
m
.
addFact
(
fact
,
m
.
comms
)
uid
:=
m
.
storage
.
User
()
.
GetCryptographicIdentity
()
.
GetUserID
()
return
m
.
addFact
(
fact
,
uid
,
m
.
comms
)
}
func
(
m
*
Manager
)
addFact
(
inFact
fact
.
Fact
,
aFC
addFactComms
)
(
*
pb
.
FactRegisterResponse
,
error
)
{
func
(
m
*
Manager
)
addFact
(
inFact
fact
.
Fact
,
uid
*
id
.
ID
,
aFC
addFactComms
)
(
*
pb
.
FactRegisterResponse
,
error
)
{
if
!
m
.
IsRegistered
()
{
return
nil
,
errors
.
New
(
"Failed to add fact: "
+
"client is not registered"
)
...
...
@@ -40,8 +42,6 @@ func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterR
return
&
pb
.
FactRegisterResponse
{},
err
}
uid
:=
m
.
storage
.
User
()
.
GetCryptographicIdentity
()
.
GetUserID
()
// Create our Fact Removal Request message data
remFactMsg
:=
pb
.
FactRegisterRequest
{
UID
:
uid
.
Marshal
(),
...
...
This diff is collapsed.
Click to expand it.
ud/addFact_test.go
+
2
−
2
View file @
d7d9b93e
...
...
@@ -53,9 +53,9 @@ func TestAddFact(t *testing.T) {
// This way we don't need to run UDB just to check that this
// function works.
tafc
:=
testAFC
{}
uid
:=
&
id
.
ID
{}
// Run addFact and see if it returns without an error!
_
,
err
=
m
.
addFact
(
f
,
&
tafc
)
_
,
err
=
m
.
addFact
(
f
,
uid
,
&
tafc
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
This diff is collapsed.
Click to expand it.
ud/lookup.go
+
40
−
25
View file @
d7d9b93e
package
ud
import
(
"fmt"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
...
...
@@ -22,7 +23,6 @@ func (m *Manager) lookupProcess(c chan message.Receive, quitCh <-chan struct{})
return
case
response
:=
<-
c
:
// Unmarshal the message
lookupResponse
:=
&
LookupResponse
{}
if
err
:=
proto
.
Unmarshal
(
response
.
Payload
,
lookupResponse
);
err
!=
nil
{
...
...
@@ -101,7 +101,8 @@ func (m *Manager) Lookup(uid *id.ID, callback lookupCallback, timeout time.Durat
// Subtract a millisecond to ensure this timeout will trigger before the
// one below
m
.
net
.
GetInstance
()
.
GetRoundEvents
()
.
AddRoundEventChan
(
round
,
roundFailChan
,
timeout
-
1
*
time
.
Millisecond
,
states
.
FAILED
)
roundFailChan
,
timeout
-
1
*
time
.
Millisecond
,
states
.
FAILED
,
states
.
COMPLETED
)
}
// Start the go routine which will trigger the callback
...
...
@@ -111,30 +112,44 @@ func (m *Manager) Lookup(uid *id.ID, callback lookupCallback, timeout time.Durat
var
err
error
var
c
contact
.
Contact
select
{
// Return an error if the round fails
case
<-
roundFailChan
:
err
=
errors
.
New
(
"One or more rounds failed to resolve; "
+
"lookup not delivered"
)
// Return an error if the timeout is reached
case
<-
timer
.
C
:
err
=
errors
.
New
(
"Response from User Discovery did not come "
+
"before timeout"
)
// Return the contact if one is returned
case
response
:=
<-
responseChan
:
if
response
.
Error
!=
""
{
err
=
errors
.
Errorf
(
"User Discovery returned an error on "
+
"lookup: %s"
,
response
.
Error
)
}
else
{
pubkey
:=
m
.
grp
.
NewIntFromBytes
(
response
.
PubKey
)
c
=
contact
.
Contact
{
ID
:
uid
,
DhPubKey
:
pubkey
,
OwnershipProof
:
nil
,
Facts
:
nil
,
done
:=
false
for
!
done
{
select
{
// Return an error if the round fails
case
fail
:=
<-
roundFailChan
:
if
states
.
Round
(
fail
.
RoundInfo
.
State
)
==
states
.
FAILED
{
fType
:=
""
if
fail
.
TimedOut
{
fType
=
"timeout"
}
else
{
fType
=
fmt
.
Sprintf
(
"round failure: %v"
,
fail
.
RoundInfo
.
ID
)
}
err
=
errors
.
Errorf
(
"One or more rounds (%v) failed to "
+
"resolve due to: %s; search not delivered"
,
rounds
,
fType
)
done
=
true
}
// Return an error if the timeout is reached
case
<-
timer
.
C
:
err
=
errors
.
New
(
"Response from User Discovery did not come "
+
"before timeout"
)
done
=
true
// Return the contact if one is returned
case
response
:=
<-
responseChan
:
if
response
.
Error
!=
""
{
err
=
errors
.
Errorf
(
"User Discovery returned an error on "
+
"lookup: %s"
,
response
.
Error
)
}
else
{
pubkey
:=
m
.
grp
.
NewIntFromBytes
(
response
.
PubKey
)
c
=
contact
.
Contact
{
ID
:
uid
,
DhPubKey
:
pubkey
,
OwnershipProof
:
nil
,
Facts
:
nil
,
}
}
done
=
true
}
}
...
...
This diff is collapsed.
Click to expand it.
ud/search.go
+
35
−
25
View file @
d7d9b93e
...
...
@@ -104,7 +104,8 @@ func (m *Manager) Search(list fact.FactList, callback searchCallback, timeout ti
// Subtract a millisecond to ensure this timeout will trigger before the
// one below
m
.
net
.
GetInstance
()
.
GetRoundEvents
()
.
AddRoundEventChan
(
round
,
roundFailChan
,
timeout
-
1
*
time
.
Millisecond
,
states
.
FAILED
)
roundFailChan
,
timeout
-
1
*
time
.
Millisecond
,
states
.
FAILED
,
states
.
COMPLETED
)
}
// Start the go routine which will trigger the callback
...
...
@@ -114,33 +115,42 @@ func (m *Manager) Search(list fact.FactList, callback searchCallback, timeout ti
var
err
error
var
c
[]
contact
.
Contact
select
{
// Return an error if the round fails
case
fail
:=
<-
roundFailChan
:
fType
:=
""
if
fail
.
TimedOut
{
fType
=
"timeout"
}
else
{
fType
=
fmt
.
Sprintf
(
"round failure: %v"
,
fail
.
RoundInfo
.
ID
)
}
err
=
errors
.
Errorf
(
"One or more rounds (%v) failed to "
+
"resolve due to: %s; search not delivered"
,
rounds
,
fType
)
// Return an error if the timeout is reached
case
<-
timer
.
C
:
err
=
errors
.
New
(
"Response from User Discovery did not come "
+
"before timeout"
)
// Return the contacts if one is returned
case
response
:=
<-
responseChan
:
if
response
.
Error
!=
""
{
err
=
errors
.
Errorf
(
"User Discovery returned an error on "
+
"search: %s"
,
response
.
Error
)
}
else
{
c
,
err
=
m
.
parseContacts
(
response
.
Contacts
,
factMap
)
done
:=
false
for
!
done
{
select
{
// Return an error if the round fails
case
fail
:=
<-
roundFailChan
:
if
states
.
Round
(
fail
.
RoundInfo
.
State
)
==
states
.
FAILED
{
fType
:=
""
if
fail
.
TimedOut
{
fType
=
"timeout"
}
else
{
fType
=
fmt
.
Sprintf
(
"round failure: %v"
,
fail
.
RoundInfo
.
ID
)
}
err
=
errors
.
Errorf
(
"One or more rounds (%v) failed to "
+
"resolve due to: %s; search not delivered"
,
rounds
,
fType
)
done
=
true
}
// Return an error if the timeout is reached
case
<-
timer
.
C
:
err
=
errors
.
New
(
"Response from User Discovery did not come "
+
"before timeout"
)
done
=
true
// Return the contacts if one is returned
case
response
:=
<-
responseChan
:
if
response
.
Error
!=
""
{
err
=
errors
.
Errorf
(
"User Discovery returned an error on "
+
"search: %s"
,
response
.
Error
)
}
else
{
c
,
err
=
m
.
parseContacts
(
response
.
Contacts
,
factMap
)
}
done
=
true
}
}
// Delete the response channel from the map
m
.
inProgressSearchMux
.
Lock
()
delete
(
m
.
inProgressSearch
,
commID
)
...
...
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