Files
sam-forwarder/config/tunconf.go

820 lines
24 KiB
Go
Raw Normal View History

package i2ptunconf
import (
2018-08-09 02:58:53 -04:00
"github.com/eyedeekay/sam-forwarder"
"github.com/eyedeekay/sam-forwarder/udp"
2018-07-29 00:52:36 -04:00
"github.com/zieckey/goini"
2018-07-30 02:44:36 -04:00
"log"
2018-08-09 15:19:50 -04:00
"strconv"
2018-07-29 00:52:36 -04:00
"strings"
)
// Conf is a tructure containing an ini config, with some functions to help
// when you use it for in conjunction with command-line flags
2018-07-29 00:52:36 -04:00
type Conf struct {
config *goini.INI
SaveDirectory string
2018-08-09 02:44:38 -04:00
SaveFile bool
2018-07-29 00:52:36 -04:00
TargetHost string
TargetPort string
2018-07-29 02:13:49 -04:00
SamHost string
SamPort string
2018-07-29 00:52:36 -04:00
TunName string
2018-08-09 02:55:21 -04:00
EncryptLeaseSet bool
InAllowZeroHop bool
OutAllowZeroHop bool
InLength int
OutLength int
InQuantity int
OutQuantity int
InVariance int
OutVariance int
InBackupQuantity int
OutBackupQuantity int
UseCompression bool
ReduceIdle bool
ReduceIdleTime int
ReduceIdleQuantity int
CloseIdle bool
CloseIdleTime int
2018-08-09 02:44:38 -04:00
AccessListType string
AccessList []string
2018-07-29 00:52:36 -04:00
}
2018-08-09 15:19:07 -04:00
func (c *Conf) accesslisttype() string {
if c.AccessListType == "whitelist" {
return "i2cp.enableAccessList=true"
} else if c.AccessListType == "blacklist" {
return "i2cp.enableBlackList=true"
} else if c.AccessListType == "none" {
return ""
}
return ""
}
func (c *Conf) accesslist() string {
if c.AccessListType != "" && len(c.AccessList) > 0 {
r := ""
for _, s := range c.AccessList {
r += s + ","
}
return "i2cp.accessList=" + strings.TrimSuffix(r, ",")
}
return ""
}
// Print returns and prints a formatted list of configured tunnel settings.
func (c *Conf) Print() []string {
2018-08-09 15:19:50 -04:00
confstring := []string{
"inbound.length=" + strconv.Itoa(c.InLength),
"outbound.length=" + strconv.Itoa(c.OutLength),
"inbound.lengthVariance=" + strconv.Itoa(c.InVariance),
"outbound.lengthVariance=" + strconv.Itoa(c.OutVariance),
"inbound.backupQuantity=" + strconv.Itoa(c.InBackupQuantity),
"outbound.backupQuantity=" + strconv.Itoa(c.OutBackupQuantity),
"inbound.quantity=" + strconv.Itoa(c.InQuantity),
"outbound.quantity=" + strconv.Itoa(c.OutQuantity),
"inbound.allowZeroHop=" + strconv.FormatBool(c.InAllowZeroHop),
"outbound.allowZeroHop=" + strconv.FormatBool(c.OutAllowZeroHop),
"i2cp.encryptLeaseSet=" + strconv.FormatBool(c.EncryptLeaseSet),
"i2cp.gzip=" + strconv.FormatBool(c.UseCompression),
"i2cp.reduceOnIdle=" + strconv.FormatBool(c.ReduceIdle),
"i2cp.reduceIdleTime=" + strconv.Itoa(c.ReduceIdleTime),
"i2cp.reduceQuantity=" + strconv.Itoa(c.ReduceIdleQuantity),
"i2cp.closeOnIdle=" + strconv.FormatBool(c.CloseIdle),
"i2cp.closeIdleTime=" + strconv.Itoa(c.CloseIdleTime),
c.accesslisttype(),
c.accesslist(),
}
2018-08-09 15:19:07 -04:00
log.Println(confstring)
2018-08-09 15:19:50 -04:00
return confstring
2018-07-29 00:52:36 -04:00
}
// Get passes directly through to goini.Get
2018-07-29 00:52:36 -04:00
func (c *Conf) Get(key string) (string, bool) {
return c.config.Get(key)
}
// GetBool passes directly through to goini.GetBool
2018-07-29 00:52:36 -04:00
func (c *Conf) GetBool(key string) (bool, bool) {
return c.config.GetBool(key)
}
// GetInt passes directly through to goini.GetInt
2018-07-29 00:52:36 -04:00
func (c *Conf) GetInt(key string) (int, bool) {
return c.config.GetInt(key)
}
// AddAccessListMember adds a member to either the blacklist or the whitelist
func (c *Conf) AddAccessListMember(key string) {
2018-08-09 02:44:38 -04:00
for _, item := range c.AccessList {
2018-08-03 01:17:08 -04:00
if item == key {
return
}
}
2018-08-09 02:44:38 -04:00
c.AccessList = append(c.AccessList, key)
}
// GetHost takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetHost(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("host"); o {
return x
}
return arg
}
// GetPort takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetPort(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("port"); o {
return x
}
return arg
}
// GetSAMHost takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetSAMHost(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samhost"); o {
return x
}
return arg
}
// GetSAMPort takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetSAMPort(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samport"); o {
return x
}
return arg
}
// GetDir takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetDir(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("dir"); o {
return x
}
return arg
}
// GetSaveFile takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetSaveFile(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
return c.SaveFile
}
// GetAccessListType takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetAccessListType(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
return c.AccessListType
}
// GetKeys takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetKeys(arg, def string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("keys"); o {
return x
}
return arg
}
// GetInLength takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetInLength(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.length"); o {
return x
}
return arg
}
// GetOutLength takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetOutLength(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.length"); o {
return x
}
return arg
}
// GetInVariance takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetInVariance(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.variance"); o {
return x
}
return arg
}
// GetOutVariance takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetOutVariance(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.variance"); o {
return x
}
return arg
}
// GetInQuantity takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetInQuantity(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.quantity"); o {
return x
}
return arg
}
// GetOutQuantity takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetOutQuantity(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.quantity"); o {
return x
}
return arg
}
// GetInBackups takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetInBackups(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.backupQuantity"); o {
return x
}
return arg
}
// GetOutBackups takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetOutBackups(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.backupQuantity"); o {
return x
}
return arg
}
// GetEncryptLeaseset takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetEncryptLeaseset(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.encryptLeaseSet"); o {
return x
}
return arg
}
// GetInAllowZeroHop takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetInAllowZeroHop(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("inbound.allowZeroHop"); o {
return x
}
return arg
}
// GetOutAllowZeroHop takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetOutAllowZeroHop(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("outbound.allowZeroHop"); o {
return x
}
return arg
}
// GetUseCompression takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetUseCompression(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("gzip"); o {
return x
}
return arg
}
// GetReduceOnIdle takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetReduceOnIdle(arg, def bool) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.reduceOnIdle"); o {
return x
}
return arg
}
// GetReduceIdleTime takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetReduceIdleTime(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleTime"); o {
return x
}
return arg
}
// GetReduceIdleQuantity takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetReduceIdleQuantity(arg, def int) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleQuantity"); o {
return x
}
return arg
}
// NewI2PTunConf returns a Conf structure from an ini file, for modification
// before starting the tunnel
2018-07-29 00:52:36 -04:00
func NewI2PTunConf(iniFile string) (*Conf, error) {
var err error
2018-07-29 02:13:49 -04:00
var c Conf
2018-07-30 02:44:36 -04:00
c.config = goini.New()
2018-07-29 00:52:36 -04:00
if iniFile != "none" {
2018-07-30 02:44:36 -04:00
err = c.config.ParseFile(iniFile)
2018-07-29 00:52:36 -04:00
if err != nil {
return nil, err
}
2018-07-30 03:25:06 -04:00
if v, ok := c.config.Get("dir"); ok {
c.SaveDirectory = v
} else {
c.SaveDirectory = "./"
}
2018-07-30 03:51:35 -04:00
if _, ok := c.config.Get("keys"); ok {
2018-08-09 02:44:38 -04:00
c.SaveFile = true
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:44:38 -04:00
c.SaveFile = false
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.Get("host"); ok {
2018-07-30 02:17:52 -04:00
c.TargetHost = strings.Replace(v, ":", "", -1)
2018-07-29 02:13:49 -04:00
} else {
c.TargetHost = "127.0.0.1"
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.Get("port"); ok {
2018-07-30 02:17:52 -04:00
c.TargetPort = strings.Replace(v, ":", "", -1)
2018-07-29 02:13:49 -04:00
} else {
c.TargetPort = "8081"
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.Get("samhost"); ok {
2018-07-30 02:32:58 -04:00
c.SamHost = strings.Replace(v, ":", "", -1)
2018-07-30 02:17:52 -04:00
} else {
2018-07-30 02:32:58 -04:00
c.SamHost = "127.0.0.1"
2018-07-30 02:17:52 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.Get("samport"); ok {
2018-07-30 02:32:58 -04:00
c.SamPort = strings.Replace(v, ":", "", -1)
2018-07-30 02:17:52 -04:00
} else {
2018-07-30 02:32:58 -04:00
c.SamPort = "7656"
2018-07-30 02:17:52 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.Get("keys"); ok {
2018-07-29 00:52:36 -04:00
c.TunName = v
2018-07-29 02:13:49 -04:00
} else {
c.TunName = "fowarder"
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("i2cp.encryptLeaseSet"); ok {
2018-08-09 02:55:21 -04:00
c.EncryptLeaseSet = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.EncryptLeaseSet = false
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("inbound.allowZeroHop"); ok {
2018-08-09 02:55:21 -04:00
c.InAllowZeroHop = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.InAllowZeroHop = false
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("outbound.allowZeroHop"); ok {
2018-08-09 02:55:21 -04:00
c.OutAllowZeroHop = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.OutAllowZeroHop = false
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("inbound.length"); ok {
2018-08-09 02:55:21 -04:00
c.InLength = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.InLength = 3
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("outbound.length"); ok {
2018-08-09 02:55:21 -04:00
c.OutLength = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.OutLength = 3
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("inbound.quantity"); ok {
2018-08-09 02:55:21 -04:00
c.InQuantity = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.InQuantity = 5
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("outbound.quantity"); ok {
2018-08-09 02:55:21 -04:00
c.OutQuantity = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.OutQuantity = 5
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("inbound.variance"); ok {
2018-08-09 02:55:21 -04:00
c.InVariance = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.InVariance = 0
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("outbound.variance"); ok {
2018-08-09 02:55:21 -04:00
c.OutVariance = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.OutVariance = 0
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("inbound.backupQuantity"); ok {
2018-08-09 02:55:21 -04:00
c.InBackupQuantity = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.InBackupQuantity = 2
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("outbound.backupQuantity"); ok {
2018-08-09 02:55:21 -04:00
c.OutBackupQuantity = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.OutBackupQuantity = 2
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("gzip"); ok {
2018-08-09 02:55:21 -04:00
c.UseCompression = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.UseCompression = true
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("i2cp.reduceOnIdle"); ok {
2018-08-09 02:55:21 -04:00
c.ReduceIdle = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.ReduceIdle = false
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("i2cp.reduceIdleTime"); ok {
2018-08-09 02:55:21 -04:00
c.ReduceIdleTime = (v / 1000) / 60
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.ReduceIdleTime = (6 * 60) * 1000
2018-07-29 00:52:36 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetInt("i2cp.reduceQuantity"); ok {
2018-08-09 02:55:21 -04:00
c.ReduceIdleQuantity = v
2018-07-29 02:13:49 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.ReduceIdleQuantity = 3
2018-07-29 00:52:36 -04:00
}
2018-07-29 02:13:49 -04:00
2018-08-03 01:17:08 -04:00
if v, ok := c.config.GetBool("i2cp.closeOnIdle"); ok {
2018-08-09 02:55:21 -04:00
c.CloseIdle = v
2018-08-03 01:17:08 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.CloseIdle = false
2018-08-03 01:17:08 -04:00
}
if v, ok := c.config.GetInt("i2cp.closeIdleTime"); ok {
2018-08-09 02:55:21 -04:00
c.CloseIdleTime = (v / 2000) / 60
2018-08-03 01:17:08 -04:00
} else {
2018-08-09 02:55:21 -04:00
c.CloseIdleTime = (6 * 60) * 2000
2018-08-03 01:17:08 -04:00
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("i2cp.enableBlackList"); ok {
2018-07-29 00:52:36 -04:00
if v {
2018-08-09 02:44:38 -04:00
c.AccessListType = "blacklist"
2018-07-29 00:52:36 -04:00
}
}
2018-07-30 02:44:36 -04:00
if v, ok := c.config.GetBool("i2cp.enableAccessList"); ok {
2018-07-29 00:52:36 -04:00
if v {
2018-08-09 02:44:38 -04:00
c.AccessListType = "whitelist"
2018-07-29 00:52:36 -04:00
}
}
2018-08-09 02:44:38 -04:00
if c.AccessListType != "whitelist" && c.AccessListType != "blacklist" {
c.AccessListType = "none"
2018-07-30 02:36:03 -04:00
}
2018-08-09 02:55:21 -04:00
if v, ok := c.config.Get("i2cp.accessList"); ok {
2018-07-29 00:52:36 -04:00
csv := strings.Split(v, ",")
for _, z := range csv {
2018-08-09 02:44:38 -04:00
c.AccessList = append(c.AccessList, z)
2018-07-29 00:52:36 -04:00
}
}
return &c, nil
}
return nil, nil
}
2018-07-29 02:13:49 -04:00
// NewSAMForwarderFromConf generates a SAMforwarder from *i2ptunconf.Conf
2018-08-02 22:35:41 -04:00
func NewSAMForwarderFromConf(config *Conf) (*samforwarder.SAMForwarder, error) {
if config != nil {
return samforwarder.NewSAMForwarderFromOptions(
2018-08-09 02:44:38 -04:00
samforwarder.SetSaveFile(config.SaveFile),
samforwarder.SetFilePath(config.SaveDirectory),
2018-08-02 22:35:41 -04:00
samforwarder.SetHost(config.TargetHost),
samforwarder.SetPort(config.TargetPort),
samforwarder.SetSAMHost(config.SamHost),
samforwarder.SetSAMPort(config.SamPort),
samforwarder.SetName(config.TunName),
2018-08-09 02:55:21 -04:00
samforwarder.SetInLength(config.InLength),
samforwarder.SetOutLength(config.OutLength),
samforwarder.SetInVariance(config.InVariance),
samforwarder.SetOutVariance(config.OutVariance),
samforwarder.SetInQuantity(config.InQuantity),
samforwarder.SetOutQuantity(config.OutQuantity),
samforwarder.SetInBackups(config.InBackupQuantity),
samforwarder.SetOutBackups(config.OutBackupQuantity),
samforwarder.SetEncrypt(config.EncryptLeaseSet),
samforwarder.SetAllowZeroIn(config.InAllowZeroHop),
samforwarder.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarder.SetCompress(config.UseCompression),
samforwarder.SetReduceIdle(config.ReduceIdle),
samforwarder.SetReduceIdleTime(config.ReduceIdleTime),
samforwarder.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarder.SetCloseIdle(config.CloseIdle),
samforwarder.SetCloseIdleTime(config.CloseIdleTime),
2018-08-09 02:44:38 -04:00
samforwarder.SetAccessListType(config.AccessListType),
samforwarder.SetAccessList(config.AccessList),
2018-08-02 22:35:41 -04:00
)
}
return nil, nil
}
// NewSAMForwarderFromConfig generates a new SAMForwarder from a config file
2018-07-29 02:13:49 -04:00
func NewSAMForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarder.SAMForwarder, error) {
if iniFile != "none" {
config, err := NewI2PTunConf(iniFile)
if err != nil {
return nil, err
}
return samforwarder.NewSAMForwarderFromOptions(
2018-08-09 02:44:38 -04:00
samforwarder.SetSaveFile(config.SaveFile),
samforwarder.SetFilePath(config.SaveDirectory),
2018-07-29 02:13:49 -04:00
samforwarder.SetHost(config.TargetHost),
samforwarder.SetPort(config.TargetPort),
samforwarder.SetSAMHost(config.SamHost),
samforwarder.SetSAMPort(config.SamPort),
samforwarder.SetName(config.TunName),
2018-08-09 02:55:21 -04:00
samforwarder.SetInLength(config.InLength),
samforwarder.SetOutLength(config.OutLength),
samforwarder.SetInVariance(config.InVariance),
samforwarder.SetOutVariance(config.OutVariance),
samforwarder.SetInQuantity(config.InQuantity),
samforwarder.SetOutQuantity(config.OutQuantity),
samforwarder.SetInBackups(config.InBackupQuantity),
samforwarder.SetOutBackups(config.OutBackupQuantity),
samforwarder.SetEncrypt(config.EncryptLeaseSet),
samforwarder.SetAllowZeroIn(config.InAllowZeroHop),
samforwarder.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarder.SetCompress(config.UseCompression),
samforwarder.SetReduceIdle(config.ReduceIdle),
samforwarder.SetReduceIdleTime(config.ReduceIdleTime),
samforwarder.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarder.SetCloseIdle(config.CloseIdle),
samforwarder.SetCloseIdleTime(config.CloseIdleTime),
2018-08-09 02:44:38 -04:00
samforwarder.SetAccessListType(config.AccessListType),
samforwarder.SetAccessList(config.AccessList),
2018-07-29 02:13:49 -04:00
)
}
return nil, nil
}
2018-07-30 19:26:31 -04:00
// NewSAMSSUForwarderFromConfig generates a new SAMSSUForwarder from a config file
2018-07-30 19:26:31 -04:00
func NewSAMSSUForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarderudp.SAMSSUForwarder, error) {
if iniFile != "none" {
config, err := NewI2PTunConf(iniFile)
if err != nil {
return nil, err
}
return samforwarderudp.NewSAMSSUForwarderFromOptions(
2018-08-09 02:44:38 -04:00
samforwarderudp.SetSaveFile(config.SaveFile),
samforwarderudp.SetFilePath(config.SaveDirectory),
2018-07-30 19:26:31 -04:00
samforwarderudp.SetHost(config.TargetHost),
samforwarderudp.SetPort(config.TargetPort),
samforwarderudp.SetSAMHost(config.SamHost),
samforwarderudp.SetSAMPort(config.SamPort),
samforwarderudp.SetName(config.TunName),
2018-08-09 02:55:21 -04:00
samforwarderudp.SetInLength(config.InLength),
samforwarderudp.SetOutLength(config.OutLength),
samforwarderudp.SetInVariance(config.InVariance),
samforwarderudp.SetOutVariance(config.OutVariance),
samforwarderudp.SetInQuantity(config.InQuantity),
samforwarderudp.SetOutQuantity(config.OutQuantity),
samforwarderudp.SetInBackups(config.InBackupQuantity),
samforwarderudp.SetOutBackups(config.OutBackupQuantity),
samforwarderudp.SetEncrypt(config.EncryptLeaseSet),
samforwarderudp.SetAllowZeroIn(config.InAllowZeroHop),
samforwarderudp.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarderudp.SetCompress(config.UseCompression),
samforwarderudp.SetReduceIdle(config.ReduceIdle),
samforwarderudp.SetReduceIdleTime(config.ReduceIdleTime),
samforwarderudp.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarderudp.SetCloseIdle(config.CloseIdle),
samforwarderudp.SetCloseIdleTime(config.CloseIdleTime),
2018-08-09 02:44:38 -04:00
samforwarderudp.SetAccessListType(config.AccessListType),
samforwarderudp.SetAccessList(config.AccessList),
2018-08-02 22:35:41 -04:00
)
}
return nil, nil
}
// NewSAMSSUForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
2018-08-02 22:35:41 -04:00
func NewSAMSSUForwarderFromConf(config *Conf) (*samforwarderudp.SAMSSUForwarder, error) {
if config != nil {
return samforwarderudp.NewSAMSSUForwarderFromOptions(
2018-08-09 02:44:38 -04:00
samforwarderudp.SetSaveFile(config.SaveFile),
samforwarderudp.SetFilePath(config.SaveDirectory),
2018-08-02 22:35:41 -04:00
samforwarderudp.SetHost(config.TargetHost),
samforwarderudp.SetPort(config.TargetPort),
samforwarderudp.SetSAMHost(config.SamHost),
samforwarderudp.SetSAMPort(config.SamPort),
samforwarderudp.SetName(config.TunName),
2018-08-09 02:55:21 -04:00
samforwarderudp.SetInLength(config.InLength),
samforwarderudp.SetOutLength(config.OutLength),
samforwarderudp.SetInVariance(config.InVariance),
samforwarderudp.SetOutVariance(config.OutVariance),
samforwarderudp.SetInQuantity(config.InQuantity),
samforwarderudp.SetOutQuantity(config.OutQuantity),
samforwarderudp.SetInBackups(config.InBackupQuantity),
samforwarderudp.SetOutBackups(config.OutBackupQuantity),
samforwarderudp.SetEncrypt(config.EncryptLeaseSet),
samforwarderudp.SetAllowZeroIn(config.InAllowZeroHop),
samforwarderudp.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarderudp.SetCompress(config.UseCompression),
samforwarderudp.SetReduceIdle(config.ReduceIdle),
samforwarderudp.SetReduceIdleTime(config.ReduceIdleTime),
samforwarderudp.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarderudp.SetCloseIdle(config.CloseIdle),
samforwarderudp.SetCloseIdleTime(config.CloseIdleTime),
2018-08-09 02:44:38 -04:00
samforwarderudp.SetAccessListType(config.AccessListType),
samforwarderudp.SetAccessList(config.AccessList),
2018-07-30 19:26:31 -04:00
)
}
return nil, nil
}