Parcourir la source

Have api-host pka be specified in seconds

gabrielseibel1 il y a 1 an
Parent
commit
4828648a8a
2 fichiers modifiés avec 5 ajouts et 6 suppressions
  1. 2 3
      cli/cmd/host/update.go
  2. 3 3
      models/api_host.go

+ 2 - 3
cli/cmd/host/update.go

@@ -19,7 +19,7 @@ var (
 	mtu             int
 	isStatic        bool
 	isDefault       bool
-	keepAlive       int64
+	keepAlive       int
 )
 
 var hostUpdateCmd = &cobra.Command{
@@ -57,8 +57,7 @@ func init() {
 	hostUpdateCmd.Flags().StringVar(&name, "name", "", "Host name")
 	hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
 	hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
-	hostUpdateCmd.Flags().
-		Int64Var(&keepAlive, "keep_alive", 0, "Interval in which packets are sent to keep connections open with peers")
+	hostUpdateCmd.Flags().IntVar(&keepAlive, "keep_alive", 0, "Interval (seconds) in which packets are sent to keep connections open with peers")
 	hostUpdateCmd.Flags().BoolVar(&isStatic, "static", false, "Make Host Static ?")
 	hostUpdateCmd.Flags().BoolVar(&isDefault, "default", false, "Make Host Default ?")
 	rootCmd.AddCommand(hostUpdateCmd)

+ 3 - 3
models/api_host.go

@@ -31,7 +31,7 @@ type ApiHost struct {
 	IsRelay             bool     `json:"isrelay"               yaml:"isrelay"               bson:"isrelay"`
 	RelayedHosts        []string `json:"relay_hosts"           yaml:"relay_hosts"           bson:"relay_hosts"`
 	NatType             string   `json:"nat_type"              yaml:"nat_type"`
-	PersistentKeepalive int64    `json:"persistentkeepalive"   yaml:"persistentkeepalive"`
+	PersistentKeepalive int      `json:"persistentkeepalive"   yaml:"persistentkeepalive"`
 }
 
 // Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host
@@ -59,7 +59,7 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
 	a.Version = h.Version
 	a.IsDefault = h.IsDefault
 	a.NatType = h.NatType
-	a.PersistentKeepalive = int64(h.PersistentKeepalive)
+	a.PersistentKeepalive = int(h.PersistentKeepalive.Seconds())
 	return &a
 }
 
@@ -97,6 +97,6 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
 	h.IsDefault = a.IsDefault
 	h.NatType = currentHost.NatType
 	h.TurnEndpoint = currentHost.TurnEndpoint
-	h.PersistentKeepalive = time.Duration(a.PersistentKeepalive)
+	h.PersistentKeepalive = time.Duration(a.PersistentKeepalive) * time.Second
 	return &h
 }