remove GetNodeByIDOrMacAddress

This commit is contained in:
afeiszli
2022-02-01 21:50:11 -05:00
parent 0c502baa14
commit c8154ffa5d
7 changed files with 38 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"log"
"os"
"runtime"
"strings"
@@ -155,7 +156,6 @@ func Pull(network string, manual bool) (*models.Node, error) {
if err != nil {
return nil, err
}
node := cfg.Node
//servercfg := cfg.Server
@@ -171,6 +171,9 @@ func Pull(network string, manual bool) (*models.Node, error) {
var ctx context.Context
if cfg.Node.IsServer != "yes" {
log.Println("DELETE ME: server addr - " + cfg.Server.GRPCAddress)
log.Println("DELETE ME: server ssl - " + cfg.Server.GRPCSSL)
conn, err := grpc.Dial(cfg.Server.GRPCAddress,
ncutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
if err != nil {
@@ -185,7 +188,9 @@ func Pull(network string, manual bool) (*models.Node, error) {
ncutils.PrintLog("Failed to authenticate: "+err.Error(), 1)
return nil, err
}
log.Println("DELETE ME: node - " + node.Name)
log.Println("DELETE ME: node - " + node.Network)
log.Println("DELETE ME: node - " + node.Address)
data, err := json.Marshal(&node)
if err != nil {
ncutils.PrintLog("Failed to parse node config: "+err.Error(), 1)
@@ -197,10 +202,15 @@ func Pull(network string, manual bool) (*models.Node, error) {
Type: nodepb.NODE_TYPE,
}
log.Println("DELETE ME: checkpoint 3")
readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header))
if err != nil {
return nil, err
}
log.Println("DELETE ME: checkpoint 3.5")
if err = json.Unmarshal([]byte(readres.Data), &resNode); err != nil {
return nil, err
}
@@ -225,6 +235,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
if err != nil {
return &resNode, err
}
if resNode.IsServer != "yes" {
if wcclient == nil || ctx == nil {
return &cfg.Node, errors.New("issue initializing gRPC client")

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"os/signal"
"runtime"
@@ -449,7 +450,9 @@ func UpdateKeys(cfg *config.ClientConfig, client mqtt.Client) error {
// Checkin -- go routine that checks for public or local ip changes, publishes changes
// if there are no updates, simply "pings" the server as a checkin
func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
log.Println("DELETE ME: starting checkin")
for {
log.Println("DELETE ME: running checkin")
select {
case <-ctx.Done():
ncutils.Log("Checkin cancelled")
@@ -489,6 +492,7 @@ func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
PublishNodeUpdate(cfg)
}
}
log.Println("DELETE ME: run hell0")
Hello(cfg, network)
// ncutils.Log("Checkin complete")
}
@@ -514,6 +518,7 @@ func Hello(cfg *config.ClientConfig, network string) {
if err := publish(cfg, fmt.Sprintf("ping/%s", cfg.Node.ID), []byte("hello world!")); err != nil {
ncutils.Log(fmt.Sprintf("error publishing ping, %v", err))
}
log.Println("DELETE ME: ran hello")
}
func publish(cfg *config.ClientConfig, dest string, msg []byte) error {