Skip to content

Commit

Permalink
Merge pull request #101 from gravitl/bugfix_v0.2_misc
Browse files Browse the repository at this point in the history
fixed constant peer update issue
  • Loading branch information
afeiszli authored Apr 19, 2021
2 parents c194f84 + f8657a5 commit a0b8e25
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
75 changes: 37 additions & 38 deletions controllers/networkHttpController.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,25 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) {

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

filter := bson.M{"netid": params["networkname"]}
// prepare update model.
update := bson.D{
{"$set", bson.D{
{"addressrange", network.AddressRange},
{"displayname", network.DisplayName},
{"defaultlistenport", network.DefaultListenPort},
{"defaultpostup", network.DefaultPostUp},
{"defaultpreup", network.DefaultPostDown},
{"defaultkeepalive", network.DefaultKeepalive},
{"keyupdatetimestamp", network.KeyUpdateTimeStamp},
{"defaultsaveconfig", network.DefaultSaveConfig},
{"defaultinterface", network.DefaultInterface},
{"nodeslastmodified", network.NodesLastModified},
{"networklastmodified", network.NetworkLastModified},
{"allowmanualsignup", network.AllowManualSignUp},
{"defaultcheckininterval", network.DefaultCheckInInterval},
}},
}
filter := bson.M{"netid": params["networkname"]}
// prepare update model.
update := bson.D{
{"$set", bson.D{
{"addressrange", network.AddressRange},
{"displayname", network.DisplayName},
{"defaultlistenport", network.DefaultListenPort},
{"defaultpostup", network.DefaultPostUp},
{"defaultpostdown", network.DefaultPostDown},
{"defaultkeepalive", network.DefaultKeepalive},
{"keyupdatetimestamp", network.KeyUpdateTimeStamp},
{"defaultsaveconfig", network.DefaultSaveConfig},
{"defaultinterface", network.DefaultInterface},
{"nodeslastmodified", network.NodesLastModified},
{"networklastmodified", network.NetworkLastModified},
{"allowmanualsignup", network.AllowManualSignUp},
{"defaultcheckininterval", network.DefaultCheckInInterval},
}},
}

err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&network)

Expand Down Expand Up @@ -390,25 +390,24 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) {
if haschange {
network.SetNetworkLastModified()
}

// prepare update model.
update := bson.D{
{"$set", bson.D{
{"addressrange", network.AddressRange},
{"displayname", network.DisplayName},
{"defaultlistenport", network.DefaultListenPort},
{"defaultpostup", network.DefaultPostUp},
{"defaultpreup", network.DefaultPostDown},
{"defaultkeepalive", network.DefaultKeepalive},
{"defaultsaveconfig", network.DefaultSaveConfig},
{"defaultinterface", network.DefaultInterface},
{"nodeslastmodified", network.NodesLastModified},
{"networklastmodified", network.NetworkLastModified},
{"allowmanualsignup", network.AllowManualSignUp},
{"localrange", network.LocalRange},
{"islocal", network.IsLocal},
{"defaultcheckininterval", network.DefaultCheckInInterval},
}},
// prepare update model.
update := bson.D{
{"$set", bson.D{
{"addressrange", network.AddressRange},
{"displayname", network.DisplayName},
{"defaultlistenport", network.DefaultListenPort},
{"defaultpostup", network.DefaultPostUp},
{"defaultpostdown", network.DefaultPostDown},
{"defaultkeepalive", network.DefaultKeepalive},
{"defaultsaveconfig", network.DefaultSaveConfig},
{"defaultinterface", network.DefaultInterface},
{"nodeslastmodified", network.NodesLastModified},
{"networklastmodified", network.NetworkLastModified},
{"allowmanualsignup", network.AllowManualSignUp},
{"localrange", network.LocalRange},
{"islocal", network.IsLocal},
{"defaultcheckininterval", network.DefaultCheckInInterval},
}},
}

err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&network)
Expand Down
4 changes: 2 additions & 2 deletions controllers/nodeHttpController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion models/returnNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 4 additions & 1 deletion netclient/functions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,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.
Expand Down

0 comments on commit a0b8e25

Please sign in to comment.