Skip to content

Commit

Permalink
Added generic configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
crioto committed Nov 6, 2018
1 parent c76b2e6 commit 8722f7b
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 146 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,5 +1,9 @@
# Change Log

## [8.1.1] 11/06/2018

* Dynamic IP reconfiguration using `set` command (#1125)

## [8.1.0] 11/05/2018

* Implemented latency measurement for peers (#445)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
8.1.0
8.1.1
3 changes: 3 additions & 0 deletions config.darwin.yaml
@@ -0,0 +1,3 @@
iptool: /sbin/ifconfig
pmtu: false
mtu: 1500
3 changes: 3 additions & 0 deletions config.linux.yaml
@@ -0,0 +1,3 @@
iptool: /sbin/ip
pmtu: false
mtu: 1500
5 changes: 5 additions & 0 deletions config.windows.yaml
@@ -0,0 +1,5 @@
iptool: netsh.exe
taptool: C:\\Program Files\\TAP-Windows\\bin\\tapinstall.exe
inf_file: C:\\Program Files\\TAP-Windows\\driver\\OemVista.inf
pmtu: false
mtu: 1500
69 changes: 69 additions & 0 deletions lib/conf.go
@@ -0,0 +1,69 @@
package ptp

import (
"fmt"
"io/ioutil"

yaml "gopkg.in/yaml.v2"
)

type conf struct {
IPTool string `yaml:"iptool"`
TAPTool string `yaml:"taptool"`
INFFile string `yaml:"inf_file"`
MTU int `yaml:"mtu"`
PMTU bool `yaml:"pmtu"`
}

func (c *conf) readConf(filepath string) error {
yamlFile, err := ioutil.ReadFile(filepath)
if err != nil {
Log(Debug, "Failed to load config: %v", err)
c.IPTool = DefaultIPTool
c.TAPTool = DefaultTAPTool
c.INFFile = DefaultINFFile
c.MTU = DefaultMTU
c.PMTU = DefaultPMTU
return fmt.Errorf("Failed to load configuration file from %s: %s", filepath, err.Error())
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
return fmt.Errorf("Failed to parse config: %v", err)
}
return nil
}

func (c *conf) getIPTool(preset string) string {
if preset != "" {
return preset
}
return c.IPTool
}

func (c *conf) getTAPTool(preset string) string {
if preset != "" {
return preset
}
return c.TAPTool
}

func (c *conf) getINFFile(preset string) string {
if preset != "" {
return preset
}
return c.INFFile
}

func (c *conf) getMTU(preset int) int {
if preset != 0 {
return preset
}
return c.MTU
}

func (c *conf) getPMTU(preset bool) bool {
if preset {
return preset
}
return c.PMTU
}
12 changes: 12 additions & 0 deletions lib/conf_darwin.go
@@ -0,0 +1,12 @@
// +build darwin

package ptp

// Platform specific defaults
const (
DefaultIPTool = "/sbin/ifconfig" // Default network interface configuration tool for Darwin OS
DefaultTAPTool = "" // Default path to TAP configuration tool on Windows OS
DefaultINFFile = "" // Default path to TAP INF file used by Windows OS
DefaultMTU = 1500 // Default MTU value
DefaultPMTU = false // Default PMTU switch
)

0 comments on commit 8722f7b

Please sign in to comment.