Skip to content
Snippets Groups Projects
Commit f4b33116 authored by Josh Brooks's avatar Josh Brooks
Browse files

Add GetNDF for gateways to the API

parent 9ee3aee2
No related branches found
No related tags found
2 merge requests!510Release,!297Add GetNDF for gateways to the API
......@@ -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:"+
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment