From 6948f5a30dbabf0659b369c1d1006d2e4e5040fe Mon Sep 17 00:00:00 2001 From: Kioubit Date: Sat, 25 Dec 2021 09:28:59 -0500 Subject: [PATCH] Support modules --- README.md | 5 ++++- config.go | 26 +++++++++++++++++++++++--- main.go | 14 ++++++++++++++ modules/example/example.go | 25 +++++++++++++++++++++++++ modules/modules.go | 21 +++++++++++++++++++++ pndp/process.go | 4 ++-- 6 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 modules/example/example.go create mode 100644 modules/modules.go diff --git a/README.md b/README.md index 6c3d6a1..a8f460e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ pndpd proxy ", commandLineRead, configRead) +} + +func configRead(s []string) { + // Prints out the contents of the config file that are relevant for this module (that are inside the example{} option) + for _, n := range s { + fmt.Println(n) + } +} + +func commandLineRead(s []string) { + // Prints out the command line options given to the program if the command starts with "example" + for _, n := range s { + fmt.Println(n) + } +} diff --git a/modules/modules.go b/modules/modules.go new file mode 100644 index 0000000..0993a9d --- /dev/null +++ b/modules/modules.go @@ -0,0 +1,21 @@ +package modules + +var ModuleList []*Module + +type Module struct { + Name string + Option string + OptionDescription string + CommandLineCallback func([]string) + ConfigCallback func([]string) +} + +func RegisterModule(name string, option string, description string, commandLineCallback func([]string), configCallback func([]string)) { + ModuleList = append(ModuleList, &Module{ + Name: name, + Option: option, + OptionDescription: description, + CommandLineCallback: commandLineCallback, + ConfigCallback: configCallback, + }) +} diff --git a/pndp/process.go b/pndp/process.go index 9b24d1b..47a2dad 100644 --- a/pndp/process.go +++ b/pndp/process.go @@ -57,7 +57,7 @@ func (obj *ResponderObj) start() { }() go respond(obj.iface, requests, ndp_ADV, nil, obj.filter, obj.autosense, obj.stopWG, obj.stopChan) go listen(obj.iface, requests, ndp_SOL, obj.stopWG, obj.stopChan) - fmt.Println("Started responder instance on interface ", obj.iface) + fmt.Println("Started responder instance on interface", obj.iface) <-obj.stopChan } @@ -128,7 +128,7 @@ func (obj *ProxyObj) start() { go listen(obj.iface2, req_iface2_adv_iface1, ndp_ADV, obj.stopWG, obj.stopChan) go respond(obj.iface1, req_iface2_adv_iface1, ndp_ADV, out_iface2_sol_questions_iface1_adv, nil, "", obj.stopWG, obj.stopChan) - fmt.Println("Started Proxy instance for interfaces: ", obj.iface1, " and ", obj.iface2) + fmt.Println("Started Proxy instance for interfaces:", obj.iface1, "and", obj.iface2) <-obj.stopChan }