2018-07-29 00:31:23 -04:00
|
|
|
package i2ptunconf
|
|
|
|
|
|
|
|
import (
|
2018-09-12 12:52:44 -04:00
|
|
|
"io/ioutil"
|
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"
|
2018-07-29 00:31:23 -04:00
|
|
|
)
|
|
|
|
|
2018-08-16 15:27:29 -04:00
|
|
|
import (
|
|
|
|
"github.com/eyedeekay/sam-forwarder"
|
|
|
|
"github.com/eyedeekay/sam-forwarder/udp"
|
|
|
|
"github.com/zieckey/goini"
|
|
|
|
)
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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
|
2018-09-12 12:52:44 -04:00
|
|
|
Labels []string
|
2018-08-16 14:57:46 -04:00
|
|
|
Client bool
|
|
|
|
Type string
|
2018-08-09 15:42:39 -04:00
|
|
|
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-08-22 21:43:17 -04:00
|
|
|
TargetForPort443 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-07-29 00:31:23 -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
|
|
|
}
|
|
|
|
|
2018-07-29 01:07:17 -04:00
|
|
|
// Get passes directly through to goini.Get
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) Get(key string, label ...string) (string, bool) {
|
2018-09-12 13:43:18 -04:00
|
|
|
if len(c.Labels) > 0 {
|
2018-09-12 18:00:24 -04:00
|
|
|
if len(label) > 0 {
|
|
|
|
return c.config.SectionGet(label[0], key)
|
|
|
|
}
|
2018-09-12 12:52:44 -04:00
|
|
|
return c.config.SectionGet(c.Labels[0], key)
|
|
|
|
} else {
|
|
|
|
return c.config.Get(key)
|
|
|
|
}
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
|
|
|
|
2018-07-29 01:07:17 -04:00
|
|
|
// GetBool passes directly through to goini.GetBool
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetBool(key string, label ...string) (bool, bool) {
|
2018-09-12 13:43:18 -04:00
|
|
|
if len(c.Labels) > 0 {
|
2018-09-12 18:00:24 -04:00
|
|
|
if len(label) > 0 {
|
|
|
|
return c.config.SectionGetBool(label[0], key)
|
|
|
|
}
|
2018-09-12 12:52:44 -04:00
|
|
|
return c.config.SectionGetBool(c.Labels[0], key)
|
|
|
|
} else {
|
|
|
|
return c.config.GetBool(key)
|
|
|
|
}
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
|
|
|
|
2018-07-29 01:07:17 -04:00
|
|
|
// GetInt passes directly through to goini.GetInt
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInt(key string, label ...string) (int, bool) {
|
2018-09-12 13:43:18 -04:00
|
|
|
if len(c.Labels) > 0 {
|
2018-09-12 18:00:24 -04:00
|
|
|
if len(label) > 0 {
|
|
|
|
return c.config.SectionGetInt(label[0], key)
|
|
|
|
}
|
2018-09-12 12:52:44 -04:00
|
|
|
return c.config.SectionGetInt(c.Labels[0], key)
|
|
|
|
} else {
|
|
|
|
return c.config.GetInt(key)
|
|
|
|
}
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// AddAccessListMember adds a member to either the blacklist or the whitelist
|
2018-08-02 22:43:47 -04:00
|
|
|
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)
|
2018-08-02 22:43:47 -04:00
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetHost(arg, def string, label ...string) string {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("host", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetPort(arg, def string, label ...string) string {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("port", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
2018-08-22 21:43:17 -04:00
|
|
|
// GetPort443 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetPort443(arg, def string, label ...string) string {
|
2018-08-22 21:43:17 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("targetForPort.443", label...); o {
|
2018-08-22 21:43:17 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:57:46 -04:00
|
|
|
// GetType 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetType(argc, argu, argh bool, def string, label ...string) string {
|
2018-08-16 14:57:46 -04:00
|
|
|
var typ string
|
|
|
|
if argu {
|
|
|
|
typ += "udp"
|
|
|
|
}
|
|
|
|
if argc {
|
|
|
|
typ += "client"
|
2018-08-16 15:27:29 -04:00
|
|
|
c.Client = true
|
2018-08-16 14:57:46 -04:00
|
|
|
} else {
|
2018-09-08 03:57:37 -04:00
|
|
|
if argh == true {
|
|
|
|
typ += "http"
|
|
|
|
} else {
|
|
|
|
typ += "server"
|
|
|
|
}
|
2018-08-16 14:57:46 -04:00
|
|
|
}
|
|
|
|
if typ != def {
|
|
|
|
return typ
|
|
|
|
}
|
|
|
|
if c.config == nil {
|
|
|
|
return typ
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("type", label...); o {
|
2018-08-16 14:57:46 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetSAMHost(arg, def string, label ...string) string {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("samhost", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetSAMPort(arg, def string, label ...string) string {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("samport", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:42:39 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetDir(arg, def string, label ...string) string {
|
2018-08-09 15:42:39 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("dir", label...); o {
|
2018-08-09 15:42:39 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 16:27:36 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetSaveFile(arg, def bool, label ...string) bool {
|
2018-08-09 16:27:36 -04:00
|
|
|
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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetAccessListType(arg, def string, label ...string) string {
|
2018-08-09 16:27:36 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
return c.AccessListType
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetKeys(arg, def string, label ...string) string {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.Get("keys", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInLength(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("inbound.length", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-02 22:43:47 -04:00
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetOutLength(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("outbound.length", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInVariance(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("inbound.variance", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetOutVariance(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("outbound.variance", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInQuantity(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("inbound.quantity", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetOutQuantity(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("outbound.quantity", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInBackups(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("inbound.backupQuantity", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetOutBackups(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("outbound.backupQuantity", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetEncryptLeaseset(arg, def bool, label ...string) bool {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("i2cp.encryptLeaseSet", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetInAllowZeroHop(arg, def bool, label ...string) bool {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("inbound.allowZeroHop", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetOutAllowZeroHop(arg, def bool, label ...string) bool {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("outbound.allowZeroHop", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetUseCompression(arg, def bool, label ...string) bool {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("gzip", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
2018-08-14 23:02:06 -04:00
|
|
|
// GetCloseOnIdle 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetCloseOnIdle(arg, def bool, label ...string) bool {
|
2018-08-14 23:02:06 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("i2cp.closeOnIdle", label...); o {
|
2018-08-14 23:02:06 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCloseIdleTime 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetCloseIdleTime(arg, def int, label ...string) int {
|
2018-08-14 23:02:06 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("i2cp.closeIdleTime", label...); o {
|
2018-08-14 23:02:06 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetReduceOnIdle(arg, def bool, label ...string) bool {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetBool("i2cp.reduceOnIdle", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetReduceIdleTime(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("i2cp.reduceIdleTime", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
|
|
|
// 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) GetReduceIdleQuantity(arg, def int, label ...string) int {
|
2018-08-09 13:23:11 -04:00
|
|
|
if arg != def {
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 16:27:36 -04:00
|
|
|
if c.config == nil {
|
|
|
|
return arg
|
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if x, o := c.GetInt("i2cp.reduceIdleQuantity", label...); o {
|
2018-08-09 12:47:24 -04:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
return arg
|
|
|
|
}
|
2018-08-09 13:23:11 -04:00
|
|
|
|
2018-08-17 11:08:26 -04:00
|
|
|
/*
|
|
|
|
// Get 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.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) Get(arg, def int, label ...string) int {
|
2018-08-17 11:08:26 -04:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetDir sets the key save directory from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetDir(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("dir"); ok {
|
|
|
|
c.SaveDirectory = v
|
|
|
|
} else {
|
|
|
|
c.SaveDirectory = "./"
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
2018-07-30 03:25:06 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetKeys sets the key name from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetKeys(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if _, ok := c.Get("keys"); ok {
|
|
|
|
c.SaveFile = true
|
|
|
|
} else {
|
|
|
|
c.SaveFile = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-09 15:42:39 -04:00
|
|
|
|
2018-08-16 14:57:46 -04:00
|
|
|
// SetType sets the type of proxy to create from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetType(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("type"); ok {
|
|
|
|
if strings.Contains(v, "client") {
|
|
|
|
c.Client = true
|
|
|
|
}
|
|
|
|
if c.Type == "server" || c.Type == "http" || c.Type == "client" || c.Type == "udpserver" || c.Type == "udpclient" {
|
|
|
|
c.Type = v
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.Type = "server"
|
2018-08-16 14:57:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetHost sets the host to forward from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetHost(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("host"); ok {
|
|
|
|
c.TargetHost = v
|
|
|
|
} else {
|
|
|
|
c.TargetHost = "127.0.0.1"
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetPort sets the port to forward from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetPort(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("port"); ok {
|
|
|
|
c.TargetPort = v
|
|
|
|
} else {
|
|
|
|
c.TargetPort = "8081"
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-22 21:43:17 -04:00
|
|
|
// SetTargetPort443 sets the port to forward from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetTargetPort443(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("targetForPort.443"); ok {
|
|
|
|
c.TargetForPort443 = v
|
|
|
|
} else {
|
|
|
|
c.TargetForPort443 = ""
|
|
|
|
}
|
2018-08-22 21:43:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetSAMHost sets the SAM host from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetSAMHost(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("samhost"); ok {
|
|
|
|
c.SamHost = v
|
|
|
|
} else {
|
|
|
|
c.SamHost = "127.0.0.1"
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 02:17:52 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetSAMPort sets the SAM port from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetSAMPort(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("samport"); ok {
|
|
|
|
c.SamPort = v
|
|
|
|
} else {
|
|
|
|
c.SamPort = "7656"
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetTunName sets the tunnel name from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetTunName(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.Get("keys"); ok {
|
|
|
|
c.TunName = v
|
|
|
|
} else {
|
|
|
|
c.TunName = "fowarder"
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetEncryptLease tells the conf to use encrypted leasesets the from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetEncryptLease(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("i2cp.encryptLeaseSet"); ok {
|
|
|
|
c.EncryptLeaseSet = v
|
|
|
|
} else {
|
|
|
|
c.EncryptLeaseSet = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetAllowZeroHopIn sets the config to allow zero-hop tunnels
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetAllowZeroHopIn(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("inbound.allowZeroHop"); ok {
|
|
|
|
c.InAllowZeroHop = v
|
|
|
|
} else {
|
|
|
|
c.InAllowZeroHop = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetAllowZeroHopOut sets the config to allow zero-hop tunnels
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetAllowZeroHopOut(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("outbound.allowZeroHop"); ok {
|
|
|
|
c.OutAllowZeroHop = v
|
|
|
|
} else {
|
|
|
|
c.OutAllowZeroHop = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetInLength sets the inbound length from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetInLength(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("outbound.length"); ok {
|
|
|
|
c.OutLength = v
|
|
|
|
} else {
|
|
|
|
c.OutLength = 3
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetOutLength sets the outbound lenth from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetOutLength(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("inbound.length"); ok {
|
|
|
|
c.InLength = v
|
|
|
|
} else {
|
|
|
|
c.InLength = 3
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 01:17:08 -04:00
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetInQuantity sets the inbound tunnel quantity from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetInQuantity(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("inbound.quantity"); ok {
|
|
|
|
c.InQuantity = v
|
|
|
|
} else {
|
|
|
|
c.InQuantity = 5
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetOutQuantity sets the outbound tunnel quantity from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetOutQuantity(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("outbound.quantity"); ok {
|
|
|
|
c.OutQuantity = v
|
|
|
|
} else {
|
|
|
|
c.OutQuantity = 5
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetInVariance sets the inbound tunnel variance from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetInVariance(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("inbound.variance"); ok {
|
|
|
|
c.InVariance = v
|
|
|
|
} else {
|
|
|
|
c.InVariance = 0
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetOutVariance sets the outbound tunnel variance from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetOutVariance(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("outbound.variance"); ok {
|
|
|
|
c.OutVariance = v
|
|
|
|
} else {
|
|
|
|
c.OutVariance = 0
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetInBackups sets the inbound tunnel backups from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetInBackups(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("inbound.backupQuantity"); ok {
|
|
|
|
c.InBackupQuantity = v
|
|
|
|
} else {
|
|
|
|
c.InBackupQuantity = 2
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetOutBackups sets the outbound tunnel backups from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetOutBackups(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("outbound.backupQuantity"); ok {
|
|
|
|
c.OutBackupQuantity = v
|
|
|
|
} else {
|
|
|
|
c.OutBackupQuantity = 2
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetCompressed sets the compression from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetCompressed(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("gzip"); ok {
|
|
|
|
c.UseCompression = v
|
|
|
|
} else {
|
|
|
|
c.UseCompression = true
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetReduceIdle sets the config to reduce tunnels after idle time from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetReduceIdle(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("i2cp.reduceOnIdle"); ok {
|
|
|
|
c.ReduceIdle = v
|
|
|
|
} else {
|
|
|
|
c.ReduceIdle = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetReduceIdleTime sets the time to wait before reducing tunnels from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetReduceIdleTime(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("i2cp.reduceIdleTime"); ok {
|
|
|
|
c.ReduceIdleTime = v
|
|
|
|
} else {
|
|
|
|
c.ReduceIdleTime = 300000
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetReduceIdleQuantity sets the number of tunnels to reduce to from config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetReduceIdleQuantity(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("i2cp.reduceQuantity"); ok {
|
|
|
|
c.ReduceIdleQuantity = v
|
|
|
|
} else {
|
|
|
|
c.ReduceIdleQuantity = 3
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetCloseIdle sets the tunnel to automatically close on idle from the config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetCloseIdle(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("i2cp.closeOnIdle"); ok {
|
|
|
|
c.CloseIdle = v
|
|
|
|
} else {
|
|
|
|
c.CloseIdle = false
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetCloseIdleTime sets the time to wait before killing a tunnel from a config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetCloseIdleTime(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetInt("i2cp.closeIdleTime"); ok {
|
|
|
|
c.CloseIdleTime = v
|
|
|
|
} else {
|
|
|
|
c.CloseIdleTime = 300000
|
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:12:22 -04:00
|
|
|
// SetAccessListType sets the access list type from a config file
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) SetAccessListType(label ...string) {
|
2018-09-12 14:35:59 -04:00
|
|
|
if len(label) < 1 {
|
|
|
|
if v, ok := c.GetBool("i2cp.enableBlackList"); ok {
|
|
|
|
if v {
|
|
|
|
c.AccessListType = "blacklist"
|
|
|
|
}
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
2018-09-12 14:35:59 -04:00
|
|
|
if v, ok := c.GetBool("i2cp.enableAccessList"); ok {
|
|
|
|
if v {
|
|
|
|
c.AccessListType = "whitelist"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if c.AccessListType != "whitelist" && c.AccessListType != "blacklist" {
|
|
|
|
c.AccessListType = "none"
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
2018-08-16 13:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 12:52:44 -04:00
|
|
|
// SetLabels
|
|
|
|
func (c *Conf) SetLabels(iniFile string) {
|
|
|
|
if tempfile, temperr := ioutil.ReadFile(iniFile); temperr == nil {
|
|
|
|
tempstring := string(tempfile)
|
|
|
|
tempslice := strings.Split(tempstring, "\n")
|
|
|
|
for _, element := range tempslice {
|
|
|
|
trimmedelement := strings.Trim(element, "\t\n ")
|
|
|
|
if strings.HasPrefix(trimmedelement, "[") && strings.HasSuffix(trimmedelement, "]") {
|
2018-09-12 13:43:18 -04:00
|
|
|
c.Labels = append(c.Labels, strings.Trim(trimmedelement, "[]"))
|
2018-09-12 12:52:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("Found Labels:", c.Labels)
|
|
|
|
}
|
|
|
|
|
2018-08-16 13:46:22 -04:00
|
|
|
/*
|
|
|
|
// Set
|
2018-09-12 13:43:18 -04:00
|
|
|
func (c *Conf) Set(label ...string) {
|
2018-08-16 13:46:22 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// I2PINILoad loads variables from an ini file into the Conf data structure.
|
2018-09-12 14:35:59 -04:00
|
|
|
func (c *Conf) I2PINILoad(iniFile string, label ...string) error {
|
2018-08-16 13:46:22 -04:00
|
|
|
var err error
|
|
|
|
if iniFile != "none" {
|
|
|
|
c.config = goini.New()
|
|
|
|
err = c.config.ParseFile(iniFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-30 02:36:03 -04:00
|
|
|
}
|
2018-09-12 12:52:44 -04:00
|
|
|
c.SetLabels(iniFile)
|
2018-09-12 14:35:59 -04:00
|
|
|
c.SetDir(label...)
|
|
|
|
c.SetType(label...)
|
|
|
|
c.SetKeys(label...)
|
|
|
|
c.SetHost(label...)
|
|
|
|
c.SetPort(label...)
|
|
|
|
c.SetSAMHost(label...)
|
|
|
|
c.SetSAMPort(label...)
|
|
|
|
c.SetTunName(label...)
|
|
|
|
c.SetEncryptLease(label...)
|
|
|
|
c.SetAllowZeroHopIn(label...)
|
|
|
|
c.SetAllowZeroHopOut(label...)
|
|
|
|
c.SetInLength(label...)
|
|
|
|
c.SetOutLength(label...)
|
|
|
|
c.SetInQuantity(label...)
|
|
|
|
c.SetOutQuantity(label...)
|
|
|
|
c.SetInVariance(label...)
|
|
|
|
c.SetOutVariance(label...)
|
|
|
|
c.SetInBackups(label...)
|
|
|
|
c.SetOutBackups(label...)
|
|
|
|
c.SetCompressed(label...)
|
|
|
|
c.SetReduceIdle(label...)
|
|
|
|
c.SetReduceIdleTime(label...)
|
|
|
|
c.SetReduceIdleQuantity(label...)
|
|
|
|
c.SetCloseIdle(label...)
|
|
|
|
c.SetCloseIdleTime(label...)
|
|
|
|
c.SetAccessListType(label...)
|
|
|
|
c.SetTargetPort443(label...)
|
2018-09-12 12:52:44 -04:00
|
|
|
if v, ok := c.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
|
|
|
}
|
|
|
|
}
|
2018-08-14 22:22:01 -04:00
|
|
|
log.Println(c.Print())
|
2018-08-11 01:16:00 -04:00
|
|
|
}
|
2018-08-14 22:22:01 -04:00
|
|
|
return nil
|
2018-08-11 01:16:00 -04:00
|
|
|
}
|
|
|
|
|
2018-08-14 20:34:22 -04:00
|
|
|
// NewI2PBlankTunConf returns an empty but intialized tunconf
|
|
|
|
func NewI2PBlankTunConf() *Conf {
|
2018-08-14 22:22:01 -04:00
|
|
|
var c Conf
|
2018-08-14 20:34:22 -04:00
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
2018-08-11 01:16:00 -04:00
|
|
|
// NewI2PTunConf returns a Conf structure from an ini file, for modification
|
|
|
|
// before starting the tunnel
|
|
|
|
func NewI2PTunConf(iniFile string) (*Conf, error) {
|
|
|
|
var err error
|
|
|
|
var c Conf
|
2018-08-11 01:28:45 -04:00
|
|
|
if err = c.I2PINILoad(iniFile); err != nil {
|
2018-08-11 01:16:00 -04:00
|
|
|
return nil, err
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
2018-08-11 01:16:00 -04:00
|
|
|
return &c, nil
|
2018-07-29 00:52:36 -04:00
|
|
|
}
|
2018-07-29 02:13:49 -04:00
|
|
|
|
2018-08-09 13:23:11 -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-09-08 03:57:37 -04:00
|
|
|
samforwarder.SetType(config.Type),
|
2018-08-09 02:44:38 -04:00
|
|
|
samforwarder.SetSaveFile(config.SaveFile),
|
2018-08-09 15:42:39 -04:00
|
|
|
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),
|
2018-08-14 22:22:01 -04:00
|
|
|
samforwarder.SetReduceIdleTimeMs(config.ReduceIdleTime),
|
2018-08-09 02:55:21 -04:00
|
|
|
samforwarder.SetReduceIdleQuantity(config.ReduceIdleQuantity),
|
|
|
|
samforwarder.SetCloseIdle(config.CloseIdle),
|
2018-08-14 22:41:53 -04:00
|
|
|
samforwarder.SetCloseIdleTimeMs(config.CloseIdleTime),
|
2018-08-09 02:44:38 -04:00
|
|
|
samforwarder.SetAccessListType(config.AccessListType),
|
|
|
|
samforwarder.SetAccessList(config.AccessList),
|
2018-08-24 00:52:36 -04:00
|
|
|
//samforwarder.SetTargetForPort443(config.TargetForPort443),
|
2018-08-02 22:35:41 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-08-17 11:08:26 -04:00
|
|
|
// NewSAMForwarderFromConfig generates a new SAMForwarder from a config file
|
|
|
|
func NewSAMForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarder.SAMForwarder, error) {
|
|
|
|
if iniFile != "none" {
|
|
|
|
config, err := NewI2PTunConf(iniFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-17 11:24:52 -04:00
|
|
|
if SamHost != "" && SamHost != "127.0.0.1" && SamHost != "localhost" {
|
|
|
|
config.SamHost = config.GetSAMHost(SamHost, config.SamHost)
|
|
|
|
}
|
|
|
|
if SamPort != "" && SamPort != "7656" {
|
|
|
|
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
|
|
|
|
}
|
2018-08-17 11:08:26 -04:00
|
|
|
return NewSAMForwarderFromConf(config)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-08-16 12:20:23 -04:00
|
|
|
// NewSAMClientForwarderFromConf generates a SAMforwarder from *i2ptunconf.Conf
|
|
|
|
func NewSAMClientForwarderFromConf(config *Conf) (*samforwarder.SAMClientForwarder, error) {
|
|
|
|
if config != nil {
|
|
|
|
return samforwarder.NewSAMClientForwarderFromOptions(
|
|
|
|
samforwarder.SetClientSaveFile(config.SaveFile),
|
|
|
|
samforwarder.SetClientFilePath(config.SaveDirectory),
|
|
|
|
samforwarder.SetClientHost(config.TargetHost),
|
|
|
|
samforwarder.SetClientPort(config.TargetPort),
|
|
|
|
samforwarder.SetClientSAMHost(config.SamHost),
|
|
|
|
samforwarder.SetClientSAMPort(config.SamPort),
|
|
|
|
samforwarder.SetClientName(config.TunName),
|
|
|
|
samforwarder.SetClientInLength(config.InLength),
|
|
|
|
samforwarder.SetClientOutLength(config.OutLength),
|
|
|
|
samforwarder.SetClientInVariance(config.InVariance),
|
|
|
|
samforwarder.SetClientOutVariance(config.OutVariance),
|
|
|
|
samforwarder.SetClientInQuantity(config.InQuantity),
|
|
|
|
samforwarder.SetClientOutQuantity(config.OutQuantity),
|
|
|
|
samforwarder.SetClientInBackups(config.InBackupQuantity),
|
|
|
|
samforwarder.SetClientOutBackups(config.OutBackupQuantity),
|
|
|
|
samforwarder.SetClientEncrypt(config.EncryptLeaseSet),
|
|
|
|
samforwarder.SetClientAllowZeroIn(config.InAllowZeroHop),
|
|
|
|
samforwarder.SetClientAllowZeroOut(config.OutAllowZeroHop),
|
|
|
|
samforwarder.SetClientCompress(config.UseCompression),
|
|
|
|
samforwarder.SetClientReduceIdle(config.ReduceIdle),
|
|
|
|
samforwarder.SetClientReduceIdleTimeMs(config.ReduceIdleTime),
|
|
|
|
samforwarder.SetClientReduceIdleQuantity(config.ReduceIdleQuantity),
|
|
|
|
samforwarder.SetClientCloseIdle(config.CloseIdle),
|
|
|
|
samforwarder.SetClientCloseIdleTimeMs(config.CloseIdleTime),
|
|
|
|
samforwarder.SetClientAccessListType(config.AccessListType),
|
|
|
|
samforwarder.SetClientAccessList(config.AccessList),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-08-16 19:32:50 -04:00
|
|
|
// NewSAMClientForwarderFromConfig generates a new SAMForwarder from a config file
|
|
|
|
func NewSAMClientForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarder.SAMClientForwarder, error) {
|
|
|
|
if iniFile != "none" {
|
|
|
|
config, err := NewI2PTunConf(iniFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-17 11:24:52 -04:00
|
|
|
if SamHost != "" && SamHost != "127.0.0.1" && SamHost != "localhost" {
|
|
|
|
config.SamHost = config.GetSAMHost(SamHost, config.SamHost)
|
|
|
|
}
|
|
|
|
if SamPort != "" && SamPort != "7656" {
|
|
|
|
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
|
|
|
|
}
|
2018-08-16 19:32:50 -04:00
|
|
|
return NewSAMClientForwarderFromConf(config)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:23:11 -04:00
|
|
|
// 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),
|
2018-08-09 15:42:39 -04:00
|
|
|
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),
|
2018-08-14 22:22:01 -04:00
|
|
|
samforwarderudp.SetReduceIdleTimeMs(config.ReduceIdleTime),
|
2018-08-09 02:55:21 -04:00
|
|
|
samforwarderudp.SetReduceIdleQuantity(config.ReduceIdleQuantity),
|
|
|
|
samforwarderudp.SetCloseIdle(config.CloseIdle),
|
2018-08-14 22:41:53 -04:00
|
|
|
samforwarderudp.SetCloseIdleTimeMs(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
|
|
|
|
}
|
2018-08-16 14:25:31 -04:00
|
|
|
|
2018-08-17 11:08:26 -04:00
|
|
|
// NewSAMSSUForwarderFromConfig generates a new SAMSSUForwarder from a config file
|
|
|
|
func NewSAMSSUForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarderudp.SAMSSUForwarder, error) {
|
|
|
|
if iniFile != "none" {
|
|
|
|
config, err := NewI2PTunConf(iniFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-17 11:24:52 -04:00
|
|
|
if SamHost != "" && SamHost != "127.0.0.1" && SamHost != "localhost" {
|
|
|
|
config.SamHost = config.GetSAMHost(SamHost, config.SamHost)
|
|
|
|
}
|
|
|
|
if SamPort != "" && SamPort != "7656" {
|
|
|
|
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
|
|
|
|
}
|
2018-08-17 11:08:26 -04:00
|
|
|
return NewSAMSSUForwarderFromConf(config)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:25:31 -04:00
|
|
|
// NewSAMSSUClientForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
|
2018-08-16 16:17:41 -04:00
|
|
|
func NewSAMSSUClientForwarderFromConf(config *Conf) (*samforwarderudp.SAMSSUClientForwarder, error) {
|
2018-08-16 14:25:31 -04:00
|
|
|
if config != nil {
|
2018-08-16 16:17:41 -04:00
|
|
|
return samforwarderudp.NewSAMSSUClientForwarderFromOptions(
|
|
|
|
samforwarderudp.SetClientSaveFile(config.SaveFile),
|
|
|
|
samforwarderudp.SetClientFilePath(config.SaveDirectory),
|
|
|
|
samforwarderudp.SetClientHost(config.TargetHost),
|
|
|
|
samforwarderudp.SetClientPort(config.TargetPort),
|
|
|
|
samforwarderudp.SetClientSAMHost(config.SamHost),
|
|
|
|
samforwarderudp.SetClientSAMPort(config.SamPort),
|
|
|
|
samforwarderudp.SetClientName(config.TunName),
|
|
|
|
samforwarderudp.SetClientInLength(config.InLength),
|
|
|
|
samforwarderudp.SetClientOutLength(config.OutLength),
|
|
|
|
samforwarderudp.SetClientInVariance(config.InVariance),
|
|
|
|
samforwarderudp.SetClientOutVariance(config.OutVariance),
|
|
|
|
samforwarderudp.SetClientInQuantity(config.InQuantity),
|
|
|
|
samforwarderudp.SetClientOutQuantity(config.OutQuantity),
|
|
|
|
samforwarderudp.SetClientInBackups(config.InBackupQuantity),
|
|
|
|
samforwarderudp.SetClientOutBackups(config.OutBackupQuantity),
|
|
|
|
samforwarderudp.SetClientEncrypt(config.EncryptLeaseSet),
|
|
|
|
samforwarderudp.SetClientAllowZeroIn(config.InAllowZeroHop),
|
|
|
|
samforwarderudp.SetClientAllowZeroOut(config.OutAllowZeroHop),
|
|
|
|
samforwarderudp.SetClientCompress(config.UseCompression),
|
|
|
|
samforwarderudp.SetClientReduceIdle(config.ReduceIdle),
|
|
|
|
samforwarderudp.SetClientReduceIdleTimeMs(config.ReduceIdleTime),
|
|
|
|
samforwarderudp.SetClientReduceIdleQuantity(config.ReduceIdleQuantity),
|
|
|
|
samforwarderudp.SetClientCloseIdle(config.CloseIdle),
|
|
|
|
samforwarderudp.SetClientCloseIdleTimeMs(config.CloseIdleTime),
|
|
|
|
samforwarderudp.SetClientAccessListType(config.AccessListType),
|
|
|
|
samforwarderudp.SetClientAccessList(config.AccessList),
|
2018-08-16 14:25:31 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
2018-08-17 11:08:26 -04:00
|
|
|
|
|
|
|
// NewSAMSSUClientForwarderFromConfig generates a new SAMSSUForwarder from a config file
|
|
|
|
func NewSAMSSUClientForwarderFromConfig(iniFile, SamHost, SamPort string) (*samforwarderudp.SAMSSUClientForwarder, error) {
|
|
|
|
if iniFile != "none" {
|
|
|
|
config, err := NewI2PTunConf(iniFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-08-17 11:24:52 -04:00
|
|
|
if SamHost != "" && SamHost != "127.0.0.1" && SamHost != "localhost" {
|
|
|
|
config.SamHost = config.GetSAMHost(SamHost, config.SamHost)
|
|
|
|
}
|
|
|
|
if SamPort != "" && SamPort != "7656" {
|
|
|
|
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
|
|
|
|
}
|
2018-08-17 11:08:26 -04:00
|
|
|
return NewSAMSSUClientForwarderFromConf(config)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|