From 8722f7bf0661ba3b5840f1d7505e8c5eb1d961d7 Mon Sep 17 00:00:00 2001 From: Mikhail Savochkin Date: Tue, 6 Nov 2018 17:51:21 +0600 Subject: [PATCH] Added generic configuration file --- CHANGELOG | 4 + VERSION | 2 +- config.darwin.yaml | 3 + config.linux.yaml | 3 + config.windows.yaml | 5 + lib/conf.go | 69 +++++++++ lib/conf_darwin.go | 12 ++ lib/conf_test.go | 296 +++++++++++++++++++++++++++++++++++++ lib/configuration.go | 42 ------ lib/dht_callbacks_test.go | 57 +++---- lib/p2p.go | 12 +- lib/p2p_test.go | 69 +++------ lib/packet_handler_test.go | 2 - lib/tuntap_darwin.go | 5 - lib/utils_test.go | 2 - 15 files changed, 437 insertions(+), 146 deletions(-) create mode 100644 config.darwin.yaml create mode 100644 config.linux.yaml create mode 100644 config.windows.yaml create mode 100644 lib/conf.go create mode 100644 lib/conf_darwin.go create mode 100644 lib/conf_test.go delete mode 100644 lib/configuration.go diff --git a/CHANGELOG b/CHANGELOG index 5ed966a4..c87ba410 100644 --- a/CHANGELOG +++ b/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) diff --git a/VERSION b/VERSION index 8104cabd..42ed2d77 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.1.0 +8.1.1 \ No newline at end of file diff --git a/config.darwin.yaml b/config.darwin.yaml new file mode 100644 index 00000000..a74c4a46 --- /dev/null +++ b/config.darwin.yaml @@ -0,0 +1,3 @@ +iptool: /sbin/ifconfig +pmtu: false +mtu: 1500 \ No newline at end of file diff --git a/config.linux.yaml b/config.linux.yaml new file mode 100644 index 00000000..e7579580 --- /dev/null +++ b/config.linux.yaml @@ -0,0 +1,3 @@ +iptool: /sbin/ip +pmtu: false +mtu: 1500 \ No newline at end of file diff --git a/config.windows.yaml b/config.windows.yaml new file mode 100644 index 00000000..2d0bbe04 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/conf.go b/lib/conf.go new file mode 100644 index 00000000..0f75e581 --- /dev/null +++ b/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 +} diff --git a/lib/conf_darwin.go b/lib/conf_darwin.go new file mode 100644 index 00000000..bea5c49f --- /dev/null +++ b/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 +) diff --git a/lib/conf_test.go b/lib/conf_test.go new file mode 100644 index 00000000..3fc71c62 --- /dev/null +++ b/lib/conf_test.go @@ -0,0 +1,296 @@ +package ptp + +import ( + "io/ioutil" + "testing" +) + +func Test_conf_readConf(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + filepath string + } + + d1 := []byte("-") + ioutil.WriteFile("/tmp/test-yaml-config-p2p-bad", d1, 0777) + + d2 := []byte("iptool: /sbin/ip") + ioutil.WriteFile("/tmp/test-yaml-config-p2p-ok", d2, 0777) + + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + {"empty filepath", fields{}, args{""}, true}, + {"wrong filepath", fields{}, args{"/"}, true}, + {"bad yaml", fields{}, args{"/tmp/test-yaml-config-p2p-bad"}, true}, + {"normal yaml", fields{}, args{"/tmp/test-yaml-config-p2p-ok"}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if err := c.readConf(tt.args.filepath); (err != nil) != tt.wantErr { + t.Errorf("conf.readConf() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func Test_conf_getIPTool(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + preset string + } + + c1 := new(conf) + c1.readConf("/") + + f1 := fields{ + IPTool: c1.IPTool, + TAPTool: c1.TAPTool, + INFFile: c1.INFFile, + MTU: c1.MTU, + PMTU: c1.PMTU, + } + + tests := []struct { + name string + fields fields + args args + want string + }{ + {"empty string test", fields{}, args{}, ""}, + {"default value", f1, args{""}, c1.IPTool}, + {"preset value", f1, args{"preset-val"}, "preset-val"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if got := c.getIPTool(tt.args.preset); got != tt.want { + t.Errorf("conf.getIPTool() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_conf_getTAPTool(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + preset string + } + + c1 := new(conf) + c1.readConf("/") + + f1 := fields{ + IPTool: c1.IPTool, + TAPTool: c1.TAPTool, + INFFile: c1.INFFile, + MTU: c1.MTU, + PMTU: c1.PMTU, + } + + tests := []struct { + name string + fields fields + args args + want string + }{ + {"empty string test", fields{}, args{}, ""}, + {"default value", f1, args{""}, c1.TAPTool}, + {"preset value", f1, args{"preset-val"}, "preset-val"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if got := c.getTAPTool(tt.args.preset); got != tt.want { + t.Errorf("conf.getTAPTool() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_conf_getINFFile(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + preset string + } + + c1 := new(conf) + c1.readConf("/") + + f1 := fields{ + IPTool: c1.IPTool, + TAPTool: c1.TAPTool, + INFFile: c1.INFFile, + MTU: c1.MTU, + PMTU: c1.PMTU, + } + + tests := []struct { + name string + fields fields + args args + want string + }{ + {"empty string test", fields{}, args{}, ""}, + {"default value", f1, args{""}, c1.INFFile}, + {"preset value", f1, args{"preset-val"}, "preset-val"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if got := c.getINFFile(tt.args.preset); got != tt.want { + t.Errorf("conf.getINFFile() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_conf_getMTU(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + preset int + } + + c1 := new(conf) + c1.readConf("/") + + f1 := fields{ + IPTool: c1.IPTool, + TAPTool: c1.TAPTool, + INFFile: c1.INFFile, + MTU: c1.MTU, + PMTU: c1.PMTU, + } + + tests := []struct { + name string + fields fields + args args + want int + }{ + {"empty string test", fields{}, args{}, 0}, + {"default value", f1, args{0}, c1.MTU}, + {"preset value", f1, args{256}, 256}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if got := c.getMTU(tt.args.preset); got != tt.want { + t.Errorf("conf.getMTU() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_conf_getPMTU(t *testing.T) { + type fields struct { + IPTool string + TAPTool string + INFFile string + MTU int + PMTU bool + } + type args struct { + preset bool + } + + c1 := new(conf) + c1.readConf("/") + + f1 := fields{ + IPTool: c1.IPTool, + TAPTool: c1.TAPTool, + INFFile: c1.INFFile, + MTU: c1.MTU, + PMTU: c1.PMTU, + } + + tests := []struct { + name string + fields fields + args args + want bool + }{ + {"empty pmtu val", fields{}, args{}, false}, + {"default value", f1, args{false}, false}, + {"preset value", f1, args{true}, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &conf{ + IPTool: tt.fields.IPTool, + TAPTool: tt.fields.TAPTool, + INFFile: tt.fields.INFFile, + MTU: tt.fields.MTU, + PMTU: tt.fields.PMTU, + } + if got := c.getPMTU(tt.args.preset); got != tt.want { + t.Errorf("conf.getPMTU() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/lib/configuration.go b/lib/configuration.go deleted file mode 100644 index 1939bdeb..00000000 --- a/lib/configuration.go +++ /dev/null @@ -1,42 +0,0 @@ -package ptp - -import ( - "fmt" - "io/ioutil" - - yaml "gopkg.in/yaml.v2" -) - -type Configuration struct { - IPTool string `yaml:"iptool"` // Network interface configuration tool - AddTap string `yaml:"addtap"` // Path to addtap.bat - InfFile string `yaml:"inffile"` // Path to deltap.bat -} - -func (y *Configuration) GetIPTool() string { - return y.IPTool -} - -func (y *Configuration) GetAddTap() string { - return y.AddTap -} - -func (y *Configuration) GetInfFile() string { - return y.InfFile -} - -func (y *Configuration) Read() error { - // TODO: Remove hard-coded path - yamlFile, err := ioutil.ReadFile(ConfigDir + "/p2p/config.yaml") - if err != nil { - Log(Debug, "Failed to load config: %v", err) - y.IPTool = "/sbin/ip" - y.AddTap = "C:\\Program Files\\TAP-Windows\\bin\\tapinstall.exe" - y.InfFile = "C:\\Program Files\\TAP-Windows\\driver\\OemVista.inf" - } - err = yaml.Unmarshal(yamlFile, y) - if err != nil { - return fmt.Errorf("Failed to parse config: %v", err) - } - return nil -} diff --git a/lib/dht_callbacks_test.go b/lib/dht_callbacks_test.go index 1306a261..3784c7e4 100644 --- a/lib/dht_callbacks_test.go +++ b/lib/dht_callbacks_test.go @@ -10,7 +10,6 @@ import ( func TestPeerToPeer_setupTCPCallbacks(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -39,7 +38,7 @@ func TestPeerToPeer_setupTCPCallbacks(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -65,7 +64,6 @@ func TestPeerToPeer_setupTCPCallbacks(t *testing.T) { func TestPeerToPeer_packetBadProxy(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -98,7 +96,7 @@ func TestPeerToPeer_packetBadProxy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -126,7 +124,6 @@ func TestPeerToPeer_packetBadProxy(t *testing.T) { func TestPeerToPeer_packetConnect(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -162,7 +159,7 @@ func TestPeerToPeer_packetConnect(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -190,7 +187,6 @@ func TestPeerToPeer_packetConnect(t *testing.T) { func TestPeerToPeer_packetDHCP(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -226,7 +222,7 @@ func TestPeerToPeer_packetDHCP(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -254,7 +250,6 @@ func TestPeerToPeer_packetDHCP(t *testing.T) { func TestPeerToPeer_packetError(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -291,7 +286,7 @@ func TestPeerToPeer_packetError(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -319,7 +314,6 @@ func TestPeerToPeer_packetError(t *testing.T) { func TestPeerToPeer_packetFind(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -415,7 +409,7 @@ func TestPeerToPeer_packetFind(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -443,7 +437,6 @@ func TestPeerToPeer_packetFind(t *testing.T) { func TestPeerToPeer_packetForward(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -476,7 +469,7 @@ func TestPeerToPeer_packetForward(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -504,7 +497,6 @@ func TestPeerToPeer_packetForward(t *testing.T) { func TestPeerToPeer_packetNode(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -566,7 +558,7 @@ func TestPeerToPeer_packetNode(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -594,7 +586,6 @@ func TestPeerToPeer_packetNode(t *testing.T) { func TestPeerToPeer_packetNotify(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -627,7 +618,7 @@ func TestPeerToPeer_packetNotify(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -655,7 +646,6 @@ func TestPeerToPeer_packetNotify(t *testing.T) { func TestPeerToPeer_packetPing(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -688,7 +678,7 @@ func TestPeerToPeer_packetPing(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -716,7 +706,6 @@ func TestPeerToPeer_packetPing(t *testing.T) { func TestPeerToPeer_packetProxy(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -785,7 +774,7 @@ func TestPeerToPeer_packetProxy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -813,7 +802,6 @@ func TestPeerToPeer_packetProxy(t *testing.T) { func TestPeerToPeer_packetRequestProxy(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -871,7 +859,7 @@ func TestPeerToPeer_packetRequestProxy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -899,7 +887,6 @@ func TestPeerToPeer_packetRequestProxy(t *testing.T) { func TestPeerToPeer_packetReportProxy(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -932,7 +919,7 @@ func TestPeerToPeer_packetReportProxy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -960,7 +947,6 @@ func TestPeerToPeer_packetReportProxy(t *testing.T) { func TestPeerToPeer_packetRegisterProxy(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -995,7 +981,7 @@ func TestPeerToPeer_packetRegisterProxy(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1023,7 +1009,6 @@ func TestPeerToPeer_packetRegisterProxy(t *testing.T) { func TestPeerToPeer_packetReportLoad(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1056,7 +1041,7 @@ func TestPeerToPeer_packetReportLoad(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1084,7 +1069,6 @@ func TestPeerToPeer_packetReportLoad(t *testing.T) { func TestPeerToPeer_packetState(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1158,7 +1142,7 @@ func TestPeerToPeer_packetState(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1186,7 +1170,6 @@ func TestPeerToPeer_packetState(t *testing.T) { func TestPeerToPeer_packetStop(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1219,7 +1202,7 @@ func TestPeerToPeer_packetStop(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1247,7 +1230,6 @@ func TestPeerToPeer_packetStop(t *testing.T) { func TestPeerToPeer_packetUnknown(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1302,7 +1284,7 @@ func TestPeerToPeer_packetUnknown(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1330,7 +1312,6 @@ func TestPeerToPeer_packetUnknown(t *testing.T) { func TestPeerToPeer_packetUnsupported(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1365,7 +1346,7 @@ func TestPeerToPeer_packetUnsupported(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, diff --git a/lib/p2p.go b/lib/p2p.go index 7fac9594..972b8c78 100644 --- a/lib/p2p.go +++ b/lib/p2p.go @@ -17,7 +17,7 @@ var UsePMTU = false // PeerToPeer - Main structure type PeerToPeer struct { - Config Configuration // Network interface configuration tool + //Config Configuration // Network interface configuration tool UDPSocket *Network // Peer-to-peer interconnection socket LocalIPs []net.IP // List of IPs available in the system Dht *DHTClient // DHT Client @@ -70,11 +70,11 @@ func (p *PeerToPeer) AssignInterface(interfaceName string) error { } // Extract necessary information from config file - err = p.Config.Read() - if err != nil { - Log(Error, "Failed to extract information from config file: %v", err) - return err - } + // err = p.Config.Read() + // if err != nil { + // Log(Error, "Failed to extract information from config file: %v", err) + // return err + // } err = p.Interface.Open() if err != nil { diff --git a/lib/p2p_test.go b/lib/p2p_test.go index 5a0b92c6..57b695b0 100644 --- a/lib/p2p_test.go +++ b/lib/p2p_test.go @@ -9,7 +9,6 @@ import ( func TestPeerToPeer_AssignInterface(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -73,7 +72,6 @@ func TestPeerToPeer_AssignInterface(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -101,7 +99,6 @@ func TestPeerToPeer_AssignInterface(t *testing.T) { func TestPeerToPeer_ListenInterface(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -130,7 +127,6 @@ func TestPeerToPeer_ListenInterface(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -158,7 +154,6 @@ func TestPeerToPeer_ListenInterface(t *testing.T) { func TestPeerToPeer_IsDeviceExists(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -191,7 +186,6 @@ func TestPeerToPeer_IsDeviceExists(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -219,7 +213,6 @@ func TestPeerToPeer_IsDeviceExists(t *testing.T) { func TestPeerToPeer_GenerateDeviceName(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -252,7 +245,6 @@ func TestPeerToPeer_GenerateDeviceName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -280,7 +272,6 @@ func TestPeerToPeer_GenerateDeviceName(t *testing.T) { func TestPeerToPeer_IsIPv4(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -313,7 +304,6 @@ func TestPeerToPeer_IsIPv4(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -369,7 +359,6 @@ func TestNew(t *testing.T) { func TestPeerToPeer_ReadDHT(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -398,7 +387,6 @@ func TestPeerToPeer_ReadDHT(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -426,7 +414,6 @@ func TestPeerToPeer_ReadDHT(t *testing.T) { func TestPeerToPeer_waitForRemotePort(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -455,7 +442,7 @@ func TestPeerToPeer_waitForRemotePort(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -483,7 +470,6 @@ func TestPeerToPeer_waitForRemotePort(t *testing.T) { func TestPeerToPeer_PrepareInterfaces(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -517,7 +503,7 @@ func TestPeerToPeer_PrepareInterfaces(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -545,7 +531,6 @@ func TestPeerToPeer_PrepareInterfaces(t *testing.T) { func TestPeerToPeer_attemptPortForward(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -579,7 +564,7 @@ func TestPeerToPeer_attemptPortForward(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -607,7 +592,6 @@ func TestPeerToPeer_attemptPortForward(t *testing.T) { func TestPeerToPeer_Init(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -636,7 +620,7 @@ func TestPeerToPeer_Init(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -664,7 +648,6 @@ func TestPeerToPeer_Init(t *testing.T) { func TestPeerToPeer_validateMac(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -697,7 +680,7 @@ func TestPeerToPeer_validateMac(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -725,7 +708,6 @@ func TestPeerToPeer_validateMac(t *testing.T) { func TestPeerToPeer_validateInterfaceName(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -759,7 +741,7 @@ func TestPeerToPeer_validateInterfaceName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -792,7 +774,6 @@ func TestPeerToPeer_validateInterfaceName(t *testing.T) { func TestPeerToPeer_setupHandlers(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -821,7 +802,7 @@ func TestPeerToPeer_setupHandlers(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -849,7 +830,6 @@ func TestPeerToPeer_setupHandlers(t *testing.T) { func TestPeerToPeer_RequestIP(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -885,7 +865,7 @@ func TestPeerToPeer_RequestIP(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -921,7 +901,6 @@ func TestPeerToPeer_RequestIP(t *testing.T) { func TestPeerToPeer_ReportIP(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -958,7 +937,7 @@ func TestPeerToPeer_ReportIP(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -994,7 +973,6 @@ func TestPeerToPeer_ReportIP(t *testing.T) { func TestPeerToPeer_Run(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1023,7 +1001,7 @@ func TestPeerToPeer_Run(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1051,7 +1029,6 @@ func TestPeerToPeer_Run(t *testing.T) { func TestPeerToPeer_checkLastDHTUpdate(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1080,7 +1057,7 @@ func TestPeerToPeer_checkLastDHTUpdate(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1108,7 +1085,6 @@ func TestPeerToPeer_checkLastDHTUpdate(t *testing.T) { func TestPeerToPeer_removeStoppedPeers(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1137,7 +1113,7 @@ func TestPeerToPeer_removeStoppedPeers(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1165,7 +1141,6 @@ func TestPeerToPeer_removeStoppedPeers(t *testing.T) { func TestPeerToPeer_checkProxies(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1194,7 +1169,7 @@ func TestPeerToPeer_checkProxies(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1222,7 +1197,6 @@ func TestPeerToPeer_checkProxies(t *testing.T) { func TestPeerToPeer_checkPeers(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1251,7 +1225,7 @@ func TestPeerToPeer_checkPeers(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1279,7 +1253,6 @@ func TestPeerToPeer_checkPeers(t *testing.T) { func TestPeerToPeer_PrepareIntroductionMessage(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1314,7 +1287,7 @@ func TestPeerToPeer_PrepareIntroductionMessage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1347,7 +1320,6 @@ func TestPeerToPeer_PrepareIntroductionMessage(t *testing.T) { func TestPeerToPeer_WriteToDevice(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1382,7 +1354,7 @@ func TestPeerToPeer_WriteToDevice(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1410,7 +1382,6 @@ func TestPeerToPeer_WriteToDevice(t *testing.T) { func TestPeerToPeer_ParseIntroString(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1444,7 +1415,7 @@ func TestPeerToPeer_ParseIntroString(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1477,7 +1448,6 @@ func TestPeerToPeer_ParseIntroString(t *testing.T) { func TestPeerToPeer_SendTo(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1512,7 +1482,7 @@ func TestPeerToPeer_SendTo(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, @@ -1545,7 +1515,6 @@ func TestPeerToPeer_SendTo(t *testing.T) { func TestPeerToPeer_Close(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -1574,7 +1543,7 @@ func TestPeerToPeer_Close(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, + UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, diff --git a/lib/packet_handler_test.go b/lib/packet_handler_test.go index f077b5c4..6c23c7e9 100644 --- a/lib/packet_handler_test.go +++ b/lib/packet_handler_test.go @@ -8,7 +8,6 @@ import ( func TestPeerToPeer_HandleXpeerPingMessage(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -58,7 +57,6 @@ func TestPeerToPeer_HandleXpeerPingMessage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht, diff --git a/lib/tuntap_darwin.go b/lib/tuntap_darwin.go index 444eaf4d..58d5f4ec 100644 --- a/lib/tuntap_darwin.go +++ b/lib/tuntap_darwin.go @@ -11,11 +11,6 @@ import ( "os/exec" ) -const ( - ConfigDir string = "/usr/local/etc" - DefaultMTU int = 1500 -) - func GetDeviceBase() string { return "tun" } diff --git a/lib/utils_test.go b/lib/utils_test.go index e377046d..1d6c283a 100644 --- a/lib/utils_test.go +++ b/lib/utils_test.go @@ -183,7 +183,6 @@ func TestSrvLookup(t *testing.T) { func TestPeerToPeer_FindNetworkAddresses(t *testing.T) { type fields struct { - Config Configuration UDPSocket *Network LocalIPs []net.IP Dht *DHTClient @@ -212,7 +211,6 @@ func TestPeerToPeer_FindNetworkAddresses(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &PeerToPeer{ - Config: tt.fields.Config, UDPSocket: tt.fields.UDPSocket, LocalIPs: tt.fields.LocalIPs, Dht: tt.fields.Dht,