removing peer cache

This commit is contained in:
afeiszli 2022-02-01 23:30:10 -05:00
parent 80dfdaa8fb
commit 7c4e8b2b4a
3 changed files with 14 additions and 23 deletions

View file

@ -199,7 +199,7 @@ func GetNodePeers(networkName string, excludeRelayed bool) ([]models.Node, error
if len(endpointarr) == 2 {
port, err := strconv.Atoi(endpointarr[1])
if err == nil {
peer.Endpoint = endpointarr[0]
// peer.Endpoint = endpointarr[0]
peer.ListenPort = int32(port)
}
}
@ -253,7 +253,7 @@ func GetPeersList(networkName string, excludeRelayed bool, relayedNodeAddr strin
if err == nil && peerNode.UDPHolePunch == "yes" {
for _, nodepeer := range nodepeers {
if nodepeer.Address == peerNode.Address {
peerNode.Endpoint = nodepeer.Endpoint
// peerNode.Endpoint = nodepeer.Endpoint
peerNode.ListenPort = nodepeer.ListenPort
}
}

View file

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"log"
"os"
"runtime"
"strings"
@ -171,9 +170,6 @@ 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 {
@ -188,9 +184,6 @@ 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)
@ -202,15 +195,11 @@ 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
}

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"os/signal"
"runtime"
@ -312,10 +311,12 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
return
}
// see if cache hit, if so skip
var currentMessage = read(peerUpdate.Network, lastPeerUpdate)
if currentMessage == string(data) {
return
}
/*
var currentMessage = read(peerUpdate.Network, lastPeerUpdate)
if currentMessage == string(data) {
return
}
*/
insert(peerUpdate.Network, lastPeerUpdate, string(data))
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
// 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")
@ -492,7 +491,6 @@ 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")
}
@ -517,8 +515,13 @@ func PublishNodeUpdate(cfg *config.ClientConfig) {
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))
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 {
@ -547,7 +550,6 @@ func publish(cfg *config.ClientConfig, dest string, msg []byte) error {
}
func parseNetworkFromTopic(topic string) string {
log.Println("DELETE ME: topic - " + topic)
return strings.Split(topic, "/")[1]
}