Storagenode online confirmation ping (#1144)

* initial commit of dashboard connection tools

* Currently working against default configs

* Update configs and remove hardcoded addresses

* Update config handling

* adds external address param for tunneling nodes

* remove unnecessary address check logic
This commit is contained in:
Dylan Lott 2019-01-25 10:46:09 -07:00 committed by GitHub
parent 7bed8050aa
commit 1385a2d6bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 20 deletions

View File

@ -131,7 +131,7 @@ type Inspector struct {
// and the overlay cache
func NewInspector(address, path string) (*Inspector, error) {
ctx := context.Background()
identity, err := identity.Config{
id, err := identity.Config{
CertPath: fmt.Sprintf("%s/ca.cert", path),
KeyPath: fmt.Sprintf("%s/ca.key", path),
}.Load()
@ -140,14 +140,14 @@ func NewInspector(address, path string) (*Inspector, error) {
return &Inspector{}, ErrIdentity.Wrap(err)
}
tc := transport.NewClient(identity)
tc := transport.NewClient(id)
conn, err := tc.DialAddress(ctx, address)
if err != nil {
return &Inspector{}, ErrInspectorDial.Wrap(err)
}
return &Inspector{
identity: identity,
identity: id,
kadclient: pb.NewKadInspectorClient(conn),
overlayclient: pb.NewOverlayInspectorClient(conn),
statdbclient: pb.NewStatDBInspectorClient(conn),

View File

@ -23,6 +23,7 @@ import (
"storj.io/storj/internal/fpath"
"storj.io/storj/pkg/cfgstruct"
"storj.io/storj/pkg/identity"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/piecestore/psclient"
"storj.io/storj/pkg/piecestore/psserver/psdb"
@ -41,6 +42,11 @@ type StorageNodeFlags struct {
storagenode.Config
}
// Inspector holds the kad client for node inspection
type Inspector struct {
kad pb.KadInspectorClient
}
var (
rootCmd = &cobra.Command{
Use: "storagenode",
@ -77,7 +83,9 @@ var (
setupCfg StorageNodeFlags
dashboardCfg struct {
Address string `default:":28967" help:"address for dashboard service"`
Address string `default:":28967" help:"address for dashboard service"`
ExternalAddress string `default:":28967" help:"address that your node is listening on if using a tunneling service"`
BootstrapAddr string `default:"bootstrap.storj.io:8888" help:"address of server the storage node was bootstrapped against"`
}
diagCfg struct {
@ -339,26 +347,15 @@ func dashCmd(cmd *cobra.Command, args []string) (err error) {
zap.S().Info("Node ID: ", ident.ID)
}
// address of node to create client connection
address := dashboardCfg.Address
if dashboardCfg.Address == "" {
if runCfg.Server.Address == "" {
return fmt.Errorf("Storage Node address isn't specified")
}
address = runCfg.Server.Address
}
tc := transport.NewClient(ident)
n := &pb.Node{
Address: &pb.NodeAddress{
Address: address,
Address: dashboardCfg.Address,
Transport: 0,
},
Type: pb.NodeType_STORAGE,
}
// create new client
lc, err := psclient.NewLiteClient(ctx, tc, n)
if err != nil {
return err
@ -369,6 +366,11 @@ func dashCmd(cmd *cobra.Command, args []string) (err error) {
return err
}
online, err := getConnectionStatus(ctx, tc, ident)
if err != nil {
zap.S().Error("error getting connection status %s", err.Error())
}
for {
data, err := stream.Recv()
if err == io.EOF {
@ -387,7 +389,7 @@ func dashCmd(cmd *cobra.Command, args []string) (err error) {
fmt.Fprintf(color.Output, "Node ID: %s\n", color.YellowString(data.GetNodeId()))
if data.GetConnection() {
if online {
fmt.Fprintf(color.Output, "%s ", color.GreenString("ONLINE"))
} else {
fmt.Fprintf(color.Output, "%s ", color.RedString("OFFLINE"))
@ -456,6 +458,49 @@ func clr() {
}
}
func getConnectionStatus(ctx context.Context, tc transport.Client, id *identity.FullIdentity) (bool, error) {
bn := &pb.Node{
Address: &pb.NodeAddress{
Address: dashboardCfg.BootstrapAddr,
Transport: 0,
},
Type: pb.NodeType_BOOTSTRAP,
}
inspector, err := newInspectorClient(ctx, tc, bn)
if err != nil {
return false, err
}
resp, err := inspector.kad.PingNode(ctx, &pb.PingNodeRequest{
Id: id.ID,
Address: dashboardCfg.ExternalAddress,
})
if err != nil {
zap.S().Error(err)
return false, err
}
if resp.GetOk() {
return true, err
}
return false, err
}
func newInspectorClient(ctx context.Context, tc transport.Client, bn *pb.Node) (*Inspector, error) {
conn, err := tc.DialNode(ctx, bn)
if err != nil {
return &Inspector{}, err
}
return &Inspector{
kad: pb.NewKadInspectorClient(conn),
}, nil
}
func main() {
process.Exec(rootCmd)
}

0
cmd/storagenode/pkg Normal file
View File

2
go.mod
View File

@ -113,7 +113,7 @@ require (
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
golang.org/x/sys v0.0.0-20190108104531-7fbe1cd0fcc2
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372
golang.org/x/tools v0.0.0-20190124215303-cc6a436ffe6b
google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f // indirect
google.golang.org/grpc v1.18.0
gopkg.in/Shopify/sarama.v1 v1.18.0 // indirect

4
go.sum
View File

@ -373,8 +373,8 @@ golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 h1:JG/0uqcGdTNgq7FdU+61l5P
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1 h1:dzEuQYa6+a3gROnSlgly5ERUm4SZKJt+dh+4iSbO+bI=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372 h1:zWPUEY/PjVHT+zO3L8OfkjrtIjf55joTxn/RQP/AjOI=
golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190124215303-cc6a436ffe6b h1:QhDb4isMLF+1hiAgAqj1YPRPQh+eAqwfG6wJzp57Iuo=
golang.org/x/tools v0.0.0-20190124215303-cc6a436ffe6b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/api v0.0.0-20180818000503-e21acd801f91/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20180826000528-7954115fcf34/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=