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
0d2555ea
Commit
0d2555ea
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Add multilookup to ud bindings
parent
eee99cdd
No related branches found
No related tags found
2 merge requests
!510
Release
,
!382
Xx 4184/multilookup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/ud.go
+115
-0
115 additions, 0 deletions
bindings/ud.go
with
115 additions
and
0 deletions
bindings/ud.go
+
115
−
0
View file @
0d2555ea
...
@@ -9,6 +9,7 @@ package bindings
...
@@ -9,6 +9,7 @@ package bindings
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/single"
"gitlab.com/elixxir/client/single"
...
@@ -420,6 +421,120 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback,
...
@@ -420,6 +421,120 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback,
return
json
.
Marshal
(
sr
)
return
json
.
Marshal
(
sr
)
}
}
////////////////////////////////////////////////////////////////////////////////
// User Discovery Lookup //
////////////////////////////////////////////////////////////////////////////////
// UdMultiLookupCallback contains the callback called by MultiLookupUD that returns the
// contacts which match the passed in IDs.
//
// Parameters:
// - contactListJSON - the JSON marshalled bytes of []contact.Contact, or nil
// if an error occurs.
//
// JSON Example:
// {
// "<xxc(2)F8dL9EC6gy+RMJuk3R+Au6eGExo02Wfio5cacjBcJRwDEgB7Ugdw/BAr6RkCABkWAFV1c2VybmFtZTA7c4LzV05sG+DMt+rFB0NIJg==xxc>",
// "<xxc(2)eMhAi/pYkW5jCmvKE5ZaTglQb+fTo1D8NxVitr5CCFADEgB7Ugdw/BAr6RoCABkWAFV1c2VybmFtZTE7fElAa7z3IcrYrrkwNjMS2w==xxc>",
// "<xxc(2)d7RJTu61Vy1lDThDMn8rYIiKSe1uXA/RCvvcIhq5Yg4DEgB7Ugdw/BAr6RsCABkWAFV1c2VybmFtZTI7N3XWrxIUpR29atpFMkcR6A==xxc>"
// }
// - err - any errors that occurred in the multilookup.
type
UdMultiLookupCallback
interface
{
Callback
(
contactListJSON
[]
byte
,
err
error
)
}
type
lookupResp
struct
{
id
*
id
.
ID
contact
contact
.
Contact
err
error
}
// MultiLookupUD returns the public key of all passed in IDs as known by the
// user discovery system or returns by the timeout.
//
// Parameters:
// - e2eID - e2e object ID in the tracker
// - udContact - the marshalled bytes of the contact.Contact object
// - lookupIds - JSON marshalled list of []*id.ID object for the users that
// MultiLookupUD will look up.
// - singleRequestParams - the JSON marshalled bytes of single.RequestParams
//
// Returns:
// - []byte - the JSON marshalled bytes of the SingleUseSendReport object,
// which can be passed into Cmix.WaitForRoundResult to see if the send
// succeeded.
func
MultiLookupUD
(
e2eID
int
,
udContact
[]
byte
,
cb
UdMultiLookupCallback
,
lookupIds
[]
byte
,
singleRequestParamsJSON
[]
byte
)
error
{
// Get user from singleton
user
,
err
:=
e2eTrackerSingleton
.
get
(
e2eID
)
if
err
!=
nil
{
return
err
}
c
,
err
:=
contact
.
Unmarshal
(
udContact
)
if
err
!=
nil
{
return
err
}
var
idList
[]
*
id
.
ID
err
=
json
.
Unmarshal
(
lookupIds
,
&
idList
)
if
err
!=
nil
{
return
err
}
var
p
single
.
RequestParams
err
=
json
.
Unmarshal
(
singleRequestParamsJSON
,
&
p
)
if
err
!=
nil
{
return
err
}
respCh
:=
make
(
chan
lookupResp
,
len
(
idList
))
for
_
,
uid
:=
range
idList
{
localID
:=
uid
.
DeepCopy
()
callback
:=
func
(
c
contact
.
Contact
,
err
error
)
{
respCh
<-
lookupResp
{
id
:
localID
,
contact
:
c
,
err
:
err
,
}
}
go
func
()
{
_
,
_
,
err
:=
ud
.
Lookup
(
user
.
api
,
c
,
callback
,
localID
,
p
)
if
err
!=
nil
{
respCh
<-
lookupResp
{
id
:
localID
,
contact
:
contact
.
Contact
{},
err
:
err
,
}
}
}()
}
go
func
()
{
var
contactList
[]
contact
.
Contact
var
errorString
string
for
numReturned
:=
0
;
numReturned
<
len
(
idList
);
numReturned
++
{
response
:=
<-
respCh
if
response
.
err
!=
nil
{
contactList
=
append
(
contactList
,
response
.
contact
)
}
else
{
errorString
=
errorString
+
fmt
.
Sprintf
(
"Failed to lookup id %s: %+v"
,
response
.
id
,
response
.
err
)
}
}
marshalled
,
err
:=
json
.
Marshal
(
contactList
)
if
err
!=
nil
{
cb
.
Callback
(
nil
,
err
)
}
else
{
cb
.
Callback
(
marshalled
,
errors
.
New
(
errorString
))
}
}()
return
nil
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// User Discovery Search //
// User Discovery Search //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
...
...
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