SpoofDPI/config/config.go

60 lines
1023 B
Go
Raw Normal View History

2022-01-03 07:24:39 +00:00
package config
2021-12-29 17:08:30 +00:00
import (
"errors"
"log"
"strings"
"sync"
2022-01-03 15:13:42 +00:00
"runtime"
2021-12-29 17:08:30 +00:00
)
type Config struct {
SrcIp string
SrcPort string
DNS string
2022-01-03 15:13:42 +00:00
OS string
2021-12-29 17:08:30 +00:00
Debug bool
}
var config *Config
var once sync.Once
var err error
func tokenizeAddress(srcAddress string) (string, string, error) {
tokens := strings.Split(srcAddress, ":")
if len(tokens) < 2 {
return "", "", errors.New("Error while parsing source address: invalid format.")
}
ip := tokens[0]
port := tokens[1]
return ip, port, nil
}
2022-01-03 15:13:42 +00:00
func InitConfig(srcAddress string, dns string, debug bool) error {
2021-12-29 17:08:30 +00:00
err = nil
once.Do(func() {
ip, port, err := tokenizeAddress(srcAddress)
if err != nil {
log.Fatal(err)
return
}
config = &Config{
SrcIp : ip,
SrcPort : port,
DNS : dns,
2022-01-03 15:13:42 +00:00
OS : runtime.GOOS,
2021-12-29 17:08:30 +00:00
Debug : debug,
}
})
return err
}
2022-01-03 07:24:39 +00:00
func GetConfig() (*Config) {
2021-12-29 17:08:30 +00:00
return config
}