Skip to content
Snippets Groups Projects
Commit 224a30c4 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'Josh/GetNdfApi' into 'release'

Add GetNDF for gateways to the API

See merge request !297
parents ff4c8ab5 23ed9e39
No related branches found
No related tags found
2 merge requests!510Release,!297Add GetNDF for gateways to the API
...@@ -13,18 +13,18 @@ import ( ...@@ -13,18 +13,18 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.com/elixxir/comms/client"
// "gitlab.com/elixxir/crypto/contact" // "gitlab.com/elixxir/crypto/contact"
// "gitlab.com/elixxir/client/interfaces/message" // "gitlab.com/elixxir/client/interfaces/message"
// "gitlab.com/elixxir/client/switchboard" // "gitlab.com/elixxir/client/switchboard"
// "gitlab.com/elixxir/client/ud" // "gitlab.com/elixxir/client/ud"
// "gitlab.com/elixxir/primitives/fact" // "gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/comms/client"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
//"time" //"time"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/utils" "gitlab.com/xx_network/primitives/utils"
) )
...@@ -99,38 +99,34 @@ var getNDFCmd = &cobra.Command{ ...@@ -99,38 +99,34 @@ var getNDFCmd = &cobra.Command{
opensslCertDL) opensslCertDL)
} }
params := connect.GetDefaultHostParams()
params.AuthEnabled = false
comms, _ := client.NewClientComms(nil, nil, nil, nil)
// Gateway lookup // Gateway lookup
if gwHost != "" { if gwHost != "" {
host, _ := connect.NewHost(&id.TempGateway, gwHost, ndfJSon, err := xxdk.DownloadNdfFromGateway(gwHost, cert)
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)
if err != nil { if err != nil {
jww.FATAL.Panicf("Unable to poll %s for NDF:"+ jww.FATAL.Panicf("%v", err)
" %+v",
gwHost, err)
} }
fmt.Printf("%s", resp.PartialNDF.Ndf) fmt.Printf("%s", ndfJSon)
return return
} }
if permHost != "" { 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, host, _ := connect.NewHost(&id.Permissioning, permHost,
cert, params) cert, params)
// Construct a dummy message
pollMsg := &pb.NDFHash{ pollMsg := &pb.NDFHash{
Hash: []byte("DummyUserRequest"), Hash: []byte("DummyUserRequest"),
} }
// Send request to scheduling and get response
resp, err := comms.RequestNdf(host, pollMsg) resp, err := comms.RequestNdf(host, pollMsg)
if err != nil { if err != nil {
jww.FATAL.Panicf("Unable to ask %s for NDF:"+ jww.FATAL.Panicf("Unable to ask %s for NDF:"+
......
...@@ -11,14 +11,62 @@ import ( ...@@ -11,14 +11,62 @@ import (
"encoding/base64" "encoding/base64"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/comms/client"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/comms/signature" "gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/tls" "gitlab.com/xx_network/crypto/tls"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"io/ioutil" "io/ioutil"
"net/http" "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.
// This returns a JSON marshalled version of the NDF.
func DownloadNdfFromGateway(address string, cert []byte) (
[]byte, 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
resp, err := comms.SendPoll(host, pollMsg)
if err != nil {
return nil, err
}
return resp.PartialNDF.Ndf, nil
}
// DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL. // DownloadAndVerifySignedNdfWithUrl retrieves the NDF from a specified URL.
// The NDF is processed into a protobuf containing a signature that is verified // 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 // 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