Browse Source

changed stuff to make it work

worker-9 4 years ago
parent
commit
9b37940c1a
2 changed files with 30 additions and 9 deletions
  1. 26 5
      models/node.go
  2. 4 4
      netclient/wireguard/kernel.go

+ 26 - 5
models/node.go

@@ -57,7 +57,7 @@ type Node struct {
 	IsIngressGateway    string   `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
 	IsIngressGateway    string   `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
 	EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
 	EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
 	IngressGatewayRange string   `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
 	IngressGatewayRange string   `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
-	IsStatic	        string   `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
+	IsStatic            string   `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
 	UDPHolePunch        string   `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
 	UDPHolePunch        string   `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
 	PullChanges         string   `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
 	PullChanges         string   `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
 	DNSOn               string   `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
 	DNSOn               string   `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
@@ -70,6 +70,24 @@ type Node struct {
 	IPForwarding        string   `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
 	IPForwarding        string   `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
 }
 }
 
 
+func (node *Node) SetDefaulIsPending() {
+	if node.IsPending == "" {
+		node.IsPending = "no"
+	}
+}
+
+func (node *Node) SetDefaultEgressGateway() {
+	if node.IsEgressGateway == "" {
+		node.IsEgressGateway = "no"
+	}
+}
+
+func (node *Node) SetDefaultIngressGateway() {
+	if node.IsIngressGateway == "" {
+		node.IsIngressGateway = "no"
+	}
+}
+
 func (node *Node) SetDefaultAction() {
 func (node *Node) SetDefaultAction() {
 	if node.Action == "" {
 	if node.Action == "" {
 		node.Action = NODE_NOOP
 		node.Action = NODE_NOOP
@@ -235,6 +253,9 @@ func (node *Node) SetDefaults() {
 	node.SetID()
 	node.SetID()
 	node.SetIsServerDefault()
 	node.SetIsServerDefault()
 	node.SetIsStaticDefault()
 	node.SetIsStaticDefault()
+	node.SetDefaultEgressGateway()
+	node.SetDefaultIngressGateway()
+	node.SetDefaulIsPending()
 	node.KeyUpdateTimeStamp = time.Now().Unix()
 	node.KeyUpdateTimeStamp = time.Now().Unix()
 }
 }
 
 
@@ -242,10 +263,10 @@ func (newNode *Node) Fill(currentNode *Node) {
 	if newNode.ID == "" {
 	if newNode.ID == "" {
 		newNode.ID = currentNode.ID
 		newNode.ID = currentNode.ID
 	}
 	}
-	if newNode.Address == ""  && newNode.IsStatic != "yes"{
+	if newNode.Address == "" && newNode.IsStatic != "yes" {
 		newNode.Address = currentNode.Address
 		newNode.Address = currentNode.Address
 	}
 	}
-	if newNode.Address6 == ""  && newNode.IsStatic != "yes"{
+	if newNode.Address6 == "" && newNode.IsStatic != "yes" {
 		newNode.Address6 = currentNode.Address6
 		newNode.Address6 = currentNode.Address6
 	}
 	}
 	if newNode.LocalAddress == "" {
 	if newNode.LocalAddress == "" {
@@ -254,7 +275,7 @@ func (newNode *Node) Fill(currentNode *Node) {
 	if newNode.Name == "" {
 	if newNode.Name == "" {
 		newNode.Name = currentNode.Name
 		newNode.Name = currentNode.Name
 	}
 	}
-	if newNode.ListenPort == 0  && newNode.IsStatic != "yes"{
+	if newNode.ListenPort == 0 && newNode.IsStatic != "yes" {
 		newNode.ListenPort = currentNode.ListenPort
 		newNode.ListenPort = currentNode.ListenPort
 	}
 	}
 	if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
 	if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
@@ -262,7 +283,7 @@ func (newNode *Node) Fill(currentNode *Node) {
 	} else {
 	} else {
 		newNode.KeyUpdateTimeStamp = time.Now().Unix()
 		newNode.KeyUpdateTimeStamp = time.Now().Unix()
 	}
 	}
-	if newNode.Endpoint == ""  && newNode.IsStatic != "yes"{
+	if newNode.Endpoint == "" && newNode.IsStatic != "yes" {
 		newNode.Endpoint = currentNode.Endpoint
 		newNode.Endpoint = currentNode.Endpoint
 	}
 	}
 	if newNode.PostUp == "" {
 	if newNode.PostUp == "" {

+ 4 - 4
netclient/wireguard/kernel.go

@@ -80,10 +80,10 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 	nodeport = int(node.ListenPort)
 	nodeport = int(node.ListenPort)
 
 
 	conf := wgtypes.Config{}
 	conf := wgtypes.Config{}
-	if nodecfg.UDPHolePunch == "yes" &&  
-	nodecfg.IsServer == "no"  &&    
-	nodecfg.IsIngressGateway == "no" && 
-	nodecfg.IsStatic != "yes" {
+	if nodecfg.UDPHolePunch == "yes" &&
+		nodecfg.IsServer == "no" &&
+		nodecfg.IsIngressGateway != "yes" &&
+		nodecfg.IsStatic != "yes" {
 		conf = wgtypes.Config{
 		conf = wgtypes.Config{
 			PrivateKey:   &key,
 			PrivateKey:   &key,
 			ReplacePeers: true,
 			ReplacePeers: true,