mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-12 08:04:25 +08:00
removing peer cache
This commit is contained in:
parent
80dfdaa8fb
commit
7c4e8b2b4a
3 changed files with 14 additions and 23 deletions
|
@ -199,7 +199,7 @@ func GetNodePeers(networkName string, excludeRelayed bool) ([]models.Node, error
|
||||||
if len(endpointarr) == 2 {
|
if len(endpointarr) == 2 {
|
||||||
port, err := strconv.Atoi(endpointarr[1])
|
port, err := strconv.Atoi(endpointarr[1])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
peer.Endpoint = endpointarr[0]
|
// peer.Endpoint = endpointarr[0]
|
||||||
peer.ListenPort = int32(port)
|
peer.ListenPort = int32(port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ func GetPeersList(networkName string, excludeRelayed bool, relayedNodeAddr strin
|
||||||
if err == nil && peerNode.UDPHolePunch == "yes" {
|
if err == nil && peerNode.UDPHolePunch == "yes" {
|
||||||
for _, nodepeer := range nodepeers {
|
for _, nodepeer := range nodepeers {
|
||||||
if nodepeer.Address == peerNode.Address {
|
if nodepeer.Address == peerNode.Address {
|
||||||
peerNode.Endpoint = nodepeer.Endpoint
|
// peerNode.Endpoint = nodepeer.Endpoint
|
||||||
peerNode.ListenPort = nodepeer.ListenPort
|
peerNode.ListenPort = nodepeer.ListenPort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -171,9 +170,6 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
|
|
||||||
if cfg.Node.IsServer != "yes" {
|
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,
|
conn, err := grpc.Dial(cfg.Server.GRPCAddress,
|
||||||
ncutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
|
ncutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -188,9 +184,6 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
||||||
ncutils.PrintLog("Failed to authenticate: "+err.Error(), 1)
|
ncutils.PrintLog("Failed to authenticate: "+err.Error(), 1)
|
||||||
return nil, err
|
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)
|
data, err := json.Marshal(&node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ncutils.PrintLog("Failed to parse node config: "+err.Error(), 1)
|
ncutils.PrintLog("Failed to parse node config: "+err.Error(), 1)
|
||||||
|
@ -202,15 +195,11 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
||||||
Type: nodepb.NODE_TYPE,
|
Type: nodepb.NODE_TYPE,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("DELETE ME: checkpoint 3")
|
|
||||||
|
|
||||||
readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header))
|
readres, err := wcclient.ReadNode(ctx, req, grpc.Header(&header))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("DELETE ME: checkpoint 3.5")
|
|
||||||
|
|
||||||
if err = json.Unmarshal([]byte(readres.Data), &resNode); err != nil {
|
if err = json.Unmarshal([]byte(readres.Data), &resNode); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -312,10 +311,12 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// see if cache hit, if so skip
|
// see if cache hit, if so skip
|
||||||
var currentMessage = read(peerUpdate.Network, lastPeerUpdate)
|
/*
|
||||||
if currentMessage == string(data) {
|
var currentMessage = read(peerUpdate.Network, lastPeerUpdate)
|
||||||
return
|
if currentMessage == string(data) {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
*/
|
||||||
insert(peerUpdate.Network, lastPeerUpdate, string(data))
|
insert(peerUpdate.Network, lastPeerUpdate, string(data))
|
||||||
ncutils.Log("update peer handler")
|
ncutils.Log("update peer handler")
|
||||||
|
|
||||||
|
@ -450,9 +451,7 @@ func UpdateKeys(cfg *config.ClientConfig, client mqtt.Client) error {
|
||||||
// Checkin -- go routine that checks for public or local ip changes, publishes changes
|
// 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
|
// if there are no updates, simply "pings" the server as a checkin
|
||||||
func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
|
func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
|
||||||
log.Println("DELETE ME: starting checkin")
|
|
||||||
for {
|
for {
|
||||||
log.Println("DELETE ME: running checkin")
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ncutils.Log("Checkin cancelled")
|
ncutils.Log("Checkin cancelled")
|
||||||
|
@ -492,7 +491,6 @@ func Checkin(ctx context.Context, cfg *config.ClientConfig, network string) {
|
||||||
PublishNodeUpdate(cfg)
|
PublishNodeUpdate(cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println("DELETE ME: run hell0")
|
|
||||||
Hello(cfg, network)
|
Hello(cfg, network)
|
||||||
// ncutils.Log("Checkin complete")
|
// ncutils.Log("Checkin complete")
|
||||||
}
|
}
|
||||||
|
@ -517,8 +515,13 @@ func PublishNodeUpdate(cfg *config.ClientConfig) {
|
||||||
func Hello(cfg *config.ClientConfig, network string) {
|
func Hello(cfg *config.ClientConfig, network string) {
|
||||||
if err := publish(cfg, fmt.Sprintf("ping/%s", cfg.Node.ID), []byte("hello world!")); err != nil {
|
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))
|
ncutils.Log(fmt.Sprintf("error publishing ping, %v", err))
|
||||||
|
ncutils.Log("running pull on " + cfg.Node.Network + " to reconnect")
|
||||||
|
_, err := Pull(cfg.Node.Network, true)
|
||||||
|
if err != nil {
|
||||||
|
ncutils.Log("could not run pull on " + cfg.Node.Network + ", error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Println("DELETE ME: ran hello")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func publish(cfg *config.ClientConfig, dest string, msg []byte) error {
|
func publish(cfg *config.ClientConfig, dest string, msg []byte) error {
|
||||||
|
@ -547,7 +550,6 @@ func publish(cfg *config.ClientConfig, dest string, msg []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseNetworkFromTopic(topic string) string {
|
func parseNetworkFromTopic(topic string) string {
|
||||||
log.Println("DELETE ME: topic - " + topic)
|
|
||||||
return strings.Split(topic, "/")[1]
|
return strings.Split(topic, "/")[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue