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
f4b33116
Commit
f4b33116
authored
2 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add GetNDF for gateways to the API
parent
9ee3aee2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!510
Release
,
!297
Add GetNDF for gateways to the API
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/getndf.go
+17
-20
17 additions, 20 deletions
cmd/getndf.go
xxdk/ndf.go
+42
-0
42 additions, 0 deletions
xxdk/ndf.go
with
59 additions
and
20 deletions
cmd/getndf.go
+
17
−
20
View file @
f4b33116
...
...
@@ -13,18 +13,18 @@ import (
"github.com/spf13/cobra"
jww
"github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"gitlab.com/elixxir/comms/client"
// "gitlab.com/elixxir/crypto/contact"
// "gitlab.com/elixxir/client/interfaces/message"
// "gitlab.com/elixxir/client/switchboard"
// "gitlab.com/elixxir/client/ud"
// "gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/comms/client"
"gitlab.com/xx_network/comms/connect"
//"time"
pb
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/utils"
)
...
...
@@ -99,38 +99,35 @@ var getNDFCmd = &cobra.Command{
opensslCertDL
)
}
params
:=
connect
.
GetDefaultHostParams
()
params
.
AuthEnabled
=
false
comms
,
_
:=
client
.
NewClientComms
(
nil
,
nil
,
nil
,
nil
)
// Gateway lookup
if
gwHost
!=
""
{
host
,
_
:=
connect
.
NewHost
(
&
id
.
TempGateway
,
gwHost
,
cert
,
params
)
dummyID
:=
ephemeral
.
ReservedIDs
[
0
]
pollMsg
:=
&
pb
.
GatewayPoll
{
Partial
:
&
pb
.
NDFHash
{
Hash
:
nil
,
},
LastUpdate
:
uint64
(
0
),
ReceptionID
:
dummyID
[
:
],
ClientVersion
:
[]
byte
(
xxdk
.
SEMVER
),
}
resp
,
err
:=
comms
.
SendPoll
(
host
,
pollMsg
)
resp
,
err
:=
xxdk
.
DownloadNdfFromGateway
(
gwHost
,
cert
)
fmt
.
Printf
(
"%s"
,
resp
.
PartialNDF
.
Ndf
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Unable to poll %s for NDF:"
+
" %+v"
,
gwHost
,
err
)
jww
.
FATAL
.
Panicf
(
"%v"
,
err
)
}
fmt
.
Printf
(
"%s"
,
resp
.
PartialNDF
.
Ndf
)
return
}
if
permHost
!=
""
{
// Establish parameters for gRPC
params
:=
connect
.
GetDefaultHostParams
()
params
.
AuthEnabled
=
false
// Construct client's gRPC comms object
comms
,
_
:=
client
.
NewClientComms
(
nil
,
nil
,
nil
,
nil
)
// Establish host for scheduling server
host
,
_
:=
connect
.
NewHost
(
&
id
.
Permissioning
,
permHost
,
cert
,
params
)
// Construct a dummy message
pollMsg
:=
&
pb
.
NDFHash
{
Hash
:
[]
byte
(
"DummyUserRequest"
),
}
// Send request to scheduling and get response
resp
,
err
:=
comms
.
RequestNdf
(
host
,
pollMsg
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Unable to ask %s for NDF:"
+
...
...
This diff is collapsed.
Click to expand it.
xxdk/ndf.go
+
42
−
0
View file @
f4b33116
...
...
@@ -11,14 +11,56 @@ import (
"encoding/base64"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/comms/client"
pb
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/tls"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"google.golang.org/protobuf/proto"
"io/ioutil"
"net/http"
)
// DownloadNdfFromGateway will download an NDF from a gateway on the cMix network.
// It will take the given address and certificate and send a request to a gateway
// for an NDF over HTTP/2 using the xx network's gRPC implementation.
func
DownloadNdfFromGateway
(
address
string
,
cert
[]
byte
)
(
*
pb
.
GatewayPollResponse
,
error
)
{
// Establish parameters for gRPC
params
:=
connect
.
GetDefaultHostParams
()
params
.
AuthEnabled
=
false
// Construct client's gRPC comms object
comms
,
err
:=
client
.
NewClientComms
(
nil
,
nil
,
nil
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
// Construct a host off of the gateway to connect to
host
,
err
:=
connect
.
NewHost
(
&
id
.
TempGateway
,
address
,
cert
,
params
)
if
err
!=
nil
{
return
nil
,
err
}
// Construct a Poll message with dummy data.
// All that's needed is the NDF
dummyID
:=
ephemeral
.
ReservedIDs
[
0
]
pollMsg
:=
&
pb
.
GatewayPoll
{
Partial
:
&
pb
.
NDFHash
{
Hash
:
nil
,
},
LastUpdate
:
uint64
(
0
),
ReceptionID
:
dummyID
[
:
],
ClientVersion
:
[]
byte
(
SEMVER
),
}
// Send poll request and receive response containing NDF
return
comms
.
SendPoll
(
host
,
pollMsg
)
}
// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL.
// The NDF is processed into a protobuf containing a signature that is verified
// using the cert string passed in. The NDF is returned as marshaled byte data
...
...
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