From 529a511a792403343924761073d0f61d05abc5c6 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 19 Apr 2021 10:49:52 -0400 Subject: [PATCH 1/2] fixed constant peer update issue --- controllers/common.go | 2 +- controllers/networkHttpController.go | 4 ++-- controllers/nodeHttpController.go | 4 ++-- models/network.go | 2 +- models/returnNode.go | 2 +- netclient/functions/common.go | 5 ++++- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/controllers/common.go b/controllers/common.go index ffa830c69..a062f599f 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -204,7 +204,7 @@ func UpdateNode(nodechange models.Node, node models.Node) (models.Node, error) { {"expdatetime", node.ExpirationDateTime}, {"endpoint", node.Endpoint}, {"postup", node.PostUp}, - {"preup", node.PostDown}, + {"postdown", node.PostDown}, {"macaddress", node.MacAddress}, {"localaddress", node.LocalAddress}, {"persistentkeepalive", node.PersistentKeepalive}, diff --git a/controllers/networkHttpController.go b/controllers/networkHttpController.go index fa470ad08..6f36ea336 100644 --- a/controllers/networkHttpController.go +++ b/controllers/networkHttpController.go @@ -225,7 +225,7 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) { {"displayname", network.DisplayName}, {"defaultlistenport", network.DefaultListenPort}, {"defaultpostup", network.DefaultPostUp}, - {"defaultpreup", network.DefaultPostDown}, + {"defaultpostdown", network.DefaultPostDown}, {"defaultkeepalive", network.DefaultKeepalive}, {"keyupdatetimestamp", network.KeyUpdateTimeStamp}, {"defaultsaveconfig", network.DefaultSaveConfig}, @@ -395,7 +395,7 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) { {"displayname", network.DisplayName}, {"defaultlistenport", network.DefaultListenPort}, {"defaultpostup", network.DefaultPostUp}, - {"defaultpreup", network.DefaultPostDown}, + {"defaultpostdown", network.DefaultPostDown}, {"defaultkeepalive", network.DefaultKeepalive}, {"defaultsaveconfig", network.DefaultSaveConfig}, {"defaultinterface", network.DefaultInterface}, diff --git a/controllers/nodeHttpController.go b/controllers/nodeHttpController.go index dfc6a33c4..1152afd97 100644 --- a/controllers/nodeHttpController.go +++ b/controllers/nodeHttpController.go @@ -686,7 +686,7 @@ func deleteGateway(w http.ResponseWriter, r *http.Request) { update := bson.D{ {"$set", bson.D{ {"postup", nodechange.PostUp}, - {"preup", nodechange.PostDown}, + {"postdown", nodechange.PostDown}, {"isgateway", nodechange.IsGateway}, {"gatewayrange", nodechange.GatewayRange}, {"lastmodified", nodechange.LastModified}, @@ -703,7 +703,7 @@ func deleteGateway(w http.ResponseWriter, r *http.Request) { return } - err = SetNetworkNodesLastModified(params["networkname"]) + err = SetNetworkNodesLastModified(params["network"]) if err != nil { returnErrorResponse(w,r,formatError(err, "internal")) return diff --git a/models/network.go b/models/network.go index 1a461e42c..4183f9baa 100644 --- a/models/network.go +++ b/models/network.go @@ -18,7 +18,7 @@ type Network struct { DefaultInterface string `json:"defaultinterface" bson:"defaultinterface"` DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,numeric,min=1024,max=65535"` DefaultPostUp string `json:"defaultpostup" bson:"defaultpostup"` - DefaultPostDown string `json:"defaultpreup" bson:"defaultpreup"` + DefaultPostDown string `json:"defaultpostdown" bson:"defaultpostdown"` KeyUpdateTimeStamp int64 `json:"keyupdatetimestamp" bson:"keyupdatetimestamp"` DefaultKeepalive int32 `json:"defaultkeepalive" bson:"defaultkeepalive" validate: "omitempty,numeric,max=1000"` DefaultSaveConfig *bool `json:"defaultsaveconfig" bson:"defaultsaveconfig"` diff --git a/models/returnNode.go b/models/returnNode.go index 2061605c9..df87c5ea7 100644 --- a/models/returnNode.go +++ b/models/returnNode.go @@ -12,7 +12,7 @@ type ReturnNode struct { PublicKey string `json:"publickey" bson:"publickey" validate:"base64"` Endpoint string `json:"endpoint" bson:"endpoint" validate:"required,ipv4"` PostUp string `json:"postup" bson:"postup"` - PostDown string `json:"preup" bson:"preup"` + PostDown string `json:"postdown" bson:"postdown"` PersistentKeepalive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"` SaveConfig *bool `json:"saveconfig" bson:"saveconfig"` Interface string `json:"interface" bson:"interface"` diff --git a/netclient/functions/common.go b/netclient/functions/common.go index 24b57720f..70783809b 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -1090,8 +1090,11 @@ func CheckIn(network string) error { if err != nil { fmt.Println("ERROR DELETING INTERFACE: " + currentiface) } - } err = setWGConfig(network) + if err != nil { + log.Printf("Error updating interface: %v", err) + } + } } if checkinres.Checkinresponse.Needconfigupdate { From bf072895be921b49dabff214a05281f230f3ef2c Mon Sep 17 00:00:00 2001 From: afeiszli Date: Mon, 19 Apr 2021 11:02:59 -0400 Subject: [PATCH 2/2] updating tests --- group_test.go | 8 ++++---- test/group_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/group_test.go b/group_test.go index 50bc65f04..674ac2a81 100644 --- a/group_test.go +++ b/group_test.go @@ -495,19 +495,19 @@ func TestUpdateNetwork(t *testing.T) { assert.Nil(t, err, err) assert.Equal(t, network.DefaultPostUp, returnedNetwork.DefaultPostUp) }) - t.Run("UpdatePreUP", func(t *testing.T) { + t.Run("UpdatePostDown", func(t *testing.T) { type Network struct { - DefaultPreUp string + DefaultPostDown string } var network Network - network.DefaultPreUp = "test string" + network.DefaultPostDown = "test string" response, err := api(t, network, http.MethodPut, "http://localhost:8081/api/networks/skynet", "secretkey") assert.Nil(t, err, err) assert.Equal(t, http.StatusOK, response.StatusCode) defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&returnedNetwork) assert.Nil(t, err, err) - assert.Equal(t, network.DefaultPreUp, returnedNetwork.DefaultPreUp) + assert.Equal(t, network.DefaultPostDown, returnedNetwork.DefaultPostDown) }) t.Run("UpdateKeepAlive", func(t *testing.T) { type Network struct { diff --git a/test/group_test.go b/test/group_test.go index 68699ad0c..1b81dc1df 100644 --- a/test/group_test.go +++ b/test/group_test.go @@ -523,7 +523,7 @@ func TestUpdatenetwork(t *testing.T) { assert.Nil(t, err, err) assert.Equal(t, network.DefaultPostUp, returnedNetwork.DefaultPostUp) }) - t.Run("UpdatePreUp", func(t *testing.T) { + t.Run("UpdatePostDown", func(t *testing.T) { // -------needs fixing ------ // mismatch in models.Network between struc name and json/bson name // does not get updated.