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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
3152ba00
Commit
3152ba00
authored
Jan 28, 2021
by
Richard T. Carback III
Browse files
Options
Downloads
Patches
Plain Diff
Add initial getndf command
parent
b0a563db
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/getndf.go
+91
-0
91 additions, 0 deletions
cmd/getndf.go
with
91 additions
and
0 deletions
cmd/getndf.go
0 → 100644
+
91
−
0
View file @
3152ba00
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
// Package cmd initializes the CLI and config parsers as well as the logger.
package
cmd
import
(
"fmt"
"github.com/spf13/cobra"
jww
"github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
// "gitlab.com/elixxir/client/interfaces/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/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/utils"
)
const
opensslCertDL
=
(
"openssl s_client -showcerts -connect ip:port < "
+
"/dev/null 2>&1 | openssl x509 -outform PEM > certfile.pem"
)
// getNDFCmd user discovery subcommand, allowing user lookup and registration for
// allowing others to search.
// This basically runs a client for these functions with the UD module enabled.
// Normally, clients don't need it so it is not loaded for the rest of the
// commands.
var
getNDFCmd
=
&
cobra
.
Command
{
Use
:
"getndf"
,
Short
:
(
"Download the network definition file from the network "
+
"and print it."
),
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
gwHost
:=
viper
.
GetString
(
"gwhost"
)
certPath
:=
viper
.
GetString
(
"cert"
)
// Load the certificate
var
cert
[]
byte
if
certPath
!=
""
{
cert
,
_
=
utils
.
ReadFile
(
certPath
)
}
if
len
(
cert
)
==
0
{
jww
.
FATAL
.
Panicf
(
"Could not load a certificate, "
+
"provide a certificate file with --cert.
\n\n
"
+
"You can download a cert using openssl:
\n\n
%s"
,
opensslCertDL
)
}
params
:=
connect
.
GetDefaultHostParams
()
params
.
AuthEnabled
=
false
comms
,
_
:=
client
.
NewClientComms
(
nil
,
nil
,
nil
,
nil
)
host
,
_
:=
connect
.
NewHost
(
&
id
.
TempGateway
,
gwHost
,
cert
,
params
)
pollMsg
:=
&
pb
.
GatewayPoll
{
Partial
:
&
pb
.
NDFHash
{
Hash
:
nil
,
},
LastUpdate
:
uint64
(
0
),
ClientID
:
id
.
DummyUser
.
Marshal
(),
}
resp
,
err
:=
comms
.
SendPoll
(
host
,
pollMsg
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Unable to poll %s for NDF: %+v"
,
gwHost
,
err
)
return
}
fmt
.
Printf
(
"%s"
,
resp
.
PartialNDF
.
Ndf
)
},
}
func
init
()
{
getNDFCmd
.
Flags
()
.
StringP
(
"gwhost"
,
""
,
""
,
"Poll this gateway host:port for the NDF"
)
viper
.
BindPFlag
(
"gwhost"
,
getNDFCmd
.
Flags
()
.
Lookup
(
"gwhost"
))
getNDFCmd
.
Flags
()
.
StringP
(
"cert"
,
""
,
""
,
"Check with the TLS certificate at this path"
)
viper
.
BindPFlag
(
"cert"
,
getNDFCmd
.
Flags
()
.
Lookup
(
"cert"
))
rootCmd
.
AddCommand
(
getNDFCmd
)
}
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