snip tunconf into reasonable chunks.

This commit is contained in:
idk
2018-09-13 18:14:22 -04:00
parent fe92d3c89e
commit 124b22e986
18 changed files with 781 additions and 764 deletions

View File

@ -90,7 +90,7 @@ gendoc:
@echo "------" >> USAGE.md
@echo "" >> USAGE.md
@echo '```' >> USAGE.md
./bin/$(appname) -h 2>> USAGE.md; true
./bin/$(appname) -help 2>> USAGE.md; true
@echo '```' >> USAGE.md
@echo "" >> USAGE.md
@echo "$(samcatd) - Router-independent tunnel management for i2p" >> USAGE.md

View File

@ -177,12 +177,12 @@ figure I give it a web interface to configure stuff with.
TLS configuration is experimental.
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlua1usACgkQ11wDs5te
FOEpaAf+LDscldudy5jnWD/v3zfj8NCQHGzkeRA6/LO5Q4kc5BooNiBVY+V0W1Et
UnKSCUpWN7v2sQ0TfYb+y9mm8oTcSPSX/8ryv41xZeH/k6ifxnZnDFn0SSqXjoQt
EJLZ5czL+je+SR3cJMvcGdOnzffn1kneIZjOOIEFjqq3IkcrcJz1m7kEfWupPRUu
xkTHOUMbU3nzdzJx5VtX+6gm5KCOo+42rBz45L7yo8stHbxAzvqOTX+BBU2SZNk8
b7nGao9G4s/f82RISuhwnw9ymtQ8soKp/AxJcGztVO8Bdqq2wM1ZNqGSg6jTrasi
SAzJDk1v8jDfzhgzyEA+pGCompnUkw==
=9+UQ
iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlua4ToACgkQ11wDs5te
FOGRHwgAixwCa/+D+vj7y41BrgO5UtpWCnL8evdY5ksrHiK0FdbQk+0wE/BA2CVU
kG4rgKDsjXyG5RL7hgkIEnA8Qpkpdd7XEWWDThgo/CslAkgRfkBJUsc7mbpfRtD1
dJCgMC2P8BgNxlArYfcoVqM1LiaE8a3X1IQaaJRgldohKcQC0qhPRb5wMyOmMwoA
jkdrxL3cKaXOJIDPSIlMFLsTuVevsVpigqMNncMrsUgQNT5M2GGMvzAoGYtcLo1L
uxsZqT0ECPbjh7vevGpIuGDCg6PflfLw877fAigQ0z2zZ7uo5zfuBt+hkkDhRrem
m2uaQiGN5F+fUHw61ohdnAbyATyPRg==
=ZrjA
-----END PGP SIGNATURE-----

64
config/access.go Normal file
View File

@ -0,0 +1,64 @@
package i2ptunconf
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
return c.AccessListType
}
// SetAccessListType sets the access list type from a config file
func (c *Conf) SetAccessListType(label ...string) {
if v, ok := c.GetBool("i2cp.enableBlackList", label...); ok {
if v {
c.AccessListType = "blacklist"
}
}
if v, ok := c.GetBool("i2cp.enableAccessList", label...); ok {
if v {
c.AccessListType = "whitelist"
}
}
if c.AccessListType != "whitelist" && c.AccessListType != "blacklist" {
c.AccessListType = "none"
}
}
// AddAccessListMember adds a member to either the blacklist or the whitelist
func (c *Conf) AddAccessListMember(key string) {
for _, item := range c.AccessList {
if item == key {
return
}
}
c.AccessList = append(c.AccessList, key)
}
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 ""
}

53
config/backups.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.backupQuantity", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.backupQuantity", label...); o {
return x
}
return arg
}
// SetInBackups sets the inbound tunnel backups from config file
func (c *Conf) SetInBackups(label ...string) {
if v, ok := c.GetInt("inbound.backupQuantity", label...); ok {
c.InBackupQuantity = v
} else {
c.InBackupQuantity = 2
}
}
// SetOutBackups sets the outbound tunnel backups from config file
func (c *Conf) SetOutBackups(label ...string) {
if v, ok := c.GetInt("outbound.backupQuantity", label...); ok {
c.OutBackupQuantity = v
} else {
c.OutBackupQuantity = 2
}
}

27
config/compress.go Normal file
View File

@ -0,0 +1,27 @@
package i2ptunconf
// 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("gzip", label...); o {
return x
}
return arg
}
// SetCompressed sets the compression from the config file
func (c *Conf) SetCompressed(label ...string) {
if v, ok := c.GetBool("gzip", label...); ok {
c.UseCompression = v
} else {
c.UseCompression = true
}
}

27
config/dir.go Normal file
View File

@ -0,0 +1,27 @@
package i2ptunconf
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("dir", label...); o {
return x
}
return arg
}
// SetDir sets the key save directory from the config file
func (c *Conf) SetDir(label ...string) {
if v, ok := c.Get("dir", label...); ok {
c.SaveDirectory = v
} else {
c.SaveDirectory = "./"
}
}

53
config/hostport.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("host", label...); 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("port", label...); o {
return x
}
return arg
}
// SetHost sets the host to forward from the config file
func (c *Conf) SetHost(label ...string) {
if v, ok := c.Get("host", label...); ok {
c.TargetHost = v
} else {
c.TargetHost = "127.0.0.1"
}
}
// SetPort sets the port to forward from the config file
func (c *Conf) SetPort(label ...string) {
if v, ok := c.Get("port", label...); ok {
c.TargetPort = v
} else {
c.TargetPort = "8081"
}
}

27
config/leasesets.go Normal file
View File

@ -0,0 +1,27 @@
package i2ptunconf
// 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.encryptLeaseSet", label...); o {
return x
}
return arg
}
// SetEncryptLease tells the conf to use encrypted leasesets the from the config file
func (c *Conf) SetEncryptLease(label ...string) {
if v, ok := c.GetBool("i2cp.encryptLeaseSet", label...); ok {
c.EncryptLeaseSet = v
} else {
c.EncryptLeaseSet = false
}
}

53
config/length.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.length", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.length", label...); o {
return x
}
return arg
}
// SetInLength sets the inbound length from the config file
func (c *Conf) SetInLength(label ...string) {
if v, ok := c.GetInt("outbound.length", label...); ok {
c.OutLength = v
} else {
c.OutLength = 3
}
}
// SetOutLength sets the outbound lenth from the config file
func (c *Conf) SetOutLength(label ...string) {
if v, ok := c.GetInt("inbound.length", label...); ok {
c.InLength = v
} else {
c.InLength = 3
}
}

50
config/name.go Normal file
View File

@ -0,0 +1,50 @@
package i2ptunconf
// 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
return c.SaveFile
}
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("keys", label...); o {
return x
}
return arg
}
// SetKeys sets the key name from the config file
func (c *Conf) SetKeys(label ...string) {
if _, ok := c.Get("keys", label...); ok {
c.SaveFile = true
} else {
c.SaveFile = false
}
}
// SetTunName sets the tunnel name from the config file
func (c *Conf) SetTunName(label ...string) {
if v, ok := c.Get("keys", label...); ok {
c.TunName = v
} else {
c.TunName = "fowarder"
}
}

53
config/quantity.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.quantity", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.quantity", label...); o {
return x
}
return arg
}
// SetInQuantity sets the inbound tunnel quantity from config file
func (c *Conf) SetInQuantity(label ...string) {
if v, ok := c.GetInt("inbound.quantity", label...); ok {
c.InQuantity = v
} else {
c.InQuantity = 5
}
}
// SetOutQuantity sets the outbound tunnel quantity from config file
func (c *Conf) SetOutQuantity(label ...string) {
if v, ok := c.GetInt("outbound.quantity", label...); ok {
c.OutQuantity = v
} else {
c.OutQuantity = 5
}
}

131
config/reduceclose.go Normal file
View File

@ -0,0 +1,131 @@
package i2ptunconf
// 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.reduceOnIdle", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleTime", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleQuantity", label...); o {
return x
}
return arg
}
// 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.
func (c *Conf) GetCloseOnIdle(arg, def bool, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.closeOnIdle", label...); o {
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.
func (c *Conf) GetCloseIdleTime(arg, def int, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.closeIdleTime", label...); o {
return x
}
return arg
}
// SetReduceIdle sets the config to reduce tunnels after idle time from config file
func (c *Conf) SetReduceIdle(label ...string) {
if v, ok := c.GetBool("i2cp.reduceOnIdle", label...); ok {
c.ReduceIdle = v
} else {
c.ReduceIdle = false
}
}
// SetReduceIdleTime sets the time to wait before reducing tunnels from config file
func (c *Conf) SetReduceIdleTime(label ...string) {
if v, ok := c.GetInt("i2cp.reduceIdleTime", label...); ok {
c.ReduceIdleTime = v
} else {
c.ReduceIdleTime = 300000
}
}
// SetReduceIdleQuantity sets the number of tunnels to reduce to from config file
func (c *Conf) SetReduceIdleQuantity(label ...string) {
if v, ok := c.GetInt("i2cp.reduceQuantity", label...); ok {
c.ReduceIdleQuantity = v
} else {
c.ReduceIdleQuantity = 3
}
}
// SetCloseIdle sets the tunnel to automatically close on idle from the config file
func (c *Conf) SetCloseIdle(label ...string) {
if v, ok := c.GetBool("i2cp.closeOnIdle", label...); ok {
c.CloseIdle = v
} else {
c.CloseIdle = false
}
}
// SetCloseIdleTime sets the time to wait before killing a tunnel from a config file
func (c *Conf) SetCloseIdleTime(label ...string) {
if v, ok := c.GetInt("i2cp.closeIdleTime", label...); ok {
c.CloseIdleTime = v
} else {
c.CloseIdleTime = 300000
}
}

53
config/samhostport.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samhost", label...); 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samport", label...); o {
return x
}
return arg
}
// SetSAMHost sets the SAM host from the config file
func (c *Conf) SetSAMHost(label ...string) {
if v, ok := c.Get("samhost", label...); ok {
c.SamHost = v
} else {
c.SamHost = "127.0.0.1"
}
}
// SetSAMPort sets the SAM port from the config file
func (c *Conf) SetSAMPort(label ...string) {
if v, ok := c.Get("samport", label...); ok {
c.SamPort = v
} else {
c.SamPort = "7656"
}
}

27
config/tls.go Normal file
View File

@ -0,0 +1,27 @@
package i2ptunconf
// 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.
func (c *Conf) GetPort443(arg, def string, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("targetForPort.443", label...); o {
return x
}
return arg
}
// SetTargetPort443 sets the port to forward from the config file
func (c *Conf) SetTargetPort443(label ...string) {
if v, ok := c.Get("targetForPort.443", label...); ok {
c.TargetForPort443 = v
} else {
c.TargetForPort443 = ""
}
}

View File

@ -50,28 +50,6 @@ type Conf struct {
AccessList []string
}
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 {
confstring := []string{
@ -136,483 +114,6 @@ func (c *Conf) GetInt(key string, label ...string) (int, bool) {
}
}
// AddAccessListMember adds a member to either the blacklist or the whitelist
func (c *Conf) AddAccessListMember(key string) {
for _, item := range c.AccessList {
if item == key {
return
}
}
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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("host", label...); 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("port", label...); o {
return x
}
return arg
}
// 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.
func (c *Conf) GetPort443(arg, def string, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("targetForPort.443", label...); o {
return x
}
return arg
}
// 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.
func (c *Conf) GetType(argc, argu, argh bool, def string, label ...string) string {
var typ string
if argu {
typ += "udp"
}
if argc {
typ += "client"
c.Client = true
} else {
if argh == true {
typ += "http"
} else {
typ += "server"
}
}
if typ != def {
return typ
}
if c.config == nil {
return typ
}
if x, o := c.Get("type", label...); o {
return x
}
return def
}
// 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samhost", label...); 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("samport", label...); 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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("dir", label...); 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, label ...string) 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, label ...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, label ...string) string {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.Get("keys", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.length", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.length", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.variance", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.variance", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.quantity", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.quantity", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.backupQuantity", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.backupQuantity", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.encryptLeaseSet", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("inbound.allowZeroHop", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("outbound.allowZeroHop", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("gzip", label...); o {
return x
}
return arg
}
// 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.
func (c *Conf) GetCloseOnIdle(arg, def bool, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.closeOnIdle", label...); o {
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.
func (c *Conf) GetCloseIdleTime(arg, def int, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.closeIdleTime", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("i2cp.reduceOnIdle", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleTime", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("i2cp.reduceIdleQuantity", label...); o {
return x
}
return arg
}
/*
// 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
@ -623,262 +124,6 @@ func (c *Conf) Get(arg, def int, label ...string) int {
}
*/
// SetDir sets the key save directory from the config file
func (c *Conf) SetDir(label ...string) {
if v, ok := c.Get("dir", label...); ok {
c.SaveDirectory = v
} else {
c.SaveDirectory = "./"
}
}
// SetKeys sets the key name from the config file
func (c *Conf) SetKeys(label ...string) {
if _, ok := c.Get("keys", label...); ok {
c.SaveFile = true
} else {
c.SaveFile = false
}
}
// SetType sets the type of proxy to create from the config file
func (c *Conf) SetType(label ...string) {
if v, ok := c.Get("type", label...); 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"
}
}
// SetHost sets the host to forward from the config file
func (c *Conf) SetHost(label ...string) {
if v, ok := c.Get("host", label...); ok {
c.TargetHost = v
} else {
c.TargetHost = "127.0.0.1"
}
}
// SetPort sets the port to forward from the config file
func (c *Conf) SetPort(label ...string) {
if v, ok := c.Get("port", label...); ok {
c.TargetPort = v
} else {
c.TargetPort = "8081"
}
}
// SetTargetPort443 sets the port to forward from the config file
func (c *Conf) SetTargetPort443(label ...string) {
if v, ok := c.Get("targetForPort.443", label...); ok {
c.TargetForPort443 = v
} else {
c.TargetForPort443 = ""
}
}
// SetSAMHost sets the SAM host from the config file
func (c *Conf) SetSAMHost(label ...string) {
if v, ok := c.Get("samhost", label...); ok {
c.SamHost = v
} else {
c.SamHost = "127.0.0.1"
}
}
// SetSAMPort sets the SAM port from the config file
func (c *Conf) SetSAMPort(label ...string) {
if v, ok := c.Get("samport", label...); ok {
c.SamPort = v
} else {
c.SamPort = "7656"
}
}
// SetTunName sets the tunnel name from the config file
func (c *Conf) SetTunName(label ...string) {
if v, ok := c.Get("keys", label...); ok {
c.TunName = v
} else {
c.TunName = "fowarder"
}
}
// SetEncryptLease tells the conf to use encrypted leasesets the from the config file
func (c *Conf) SetEncryptLease(label ...string) {
if v, ok := c.GetBool("i2cp.encryptLeaseSet", label...); ok {
c.EncryptLeaseSet = v
} else {
c.EncryptLeaseSet = false
}
}
// SetAllowZeroHopIn sets the config to allow zero-hop tunnels
func (c *Conf) SetAllowZeroHopIn(label ...string) {
if v, ok := c.GetBool("inbound.allowZeroHop", label...); ok {
c.InAllowZeroHop = v
} else {
c.InAllowZeroHop = false
}
}
// SetAllowZeroHopOut sets the config to allow zero-hop tunnels
func (c *Conf) SetAllowZeroHopOut(label ...string) {
if v, ok := c.GetBool("outbound.allowZeroHop", label...); ok {
c.OutAllowZeroHop = v
} else {
c.OutAllowZeroHop = false
}
}
// SetInLength sets the inbound length from the config file
func (c *Conf) SetInLength(label ...string) {
if v, ok := c.GetInt("outbound.length", label...); ok {
c.OutLength = v
} else {
c.OutLength = 3
}
}
// SetOutLength sets the outbound lenth from the config file
func (c *Conf) SetOutLength(label ...string) {
if v, ok := c.GetInt("inbound.length", label...); ok {
c.InLength = v
} else {
c.InLength = 3
}
}
// SetInQuantity sets the inbound tunnel quantity from config file
func (c *Conf) SetInQuantity(label ...string) {
if v, ok := c.GetInt("inbound.quantity", label...); ok {
c.InQuantity = v
} else {
c.InQuantity = 5
}
}
// SetOutQuantity sets the outbound tunnel quantity from config file
func (c *Conf) SetOutQuantity(label ...string) {
if v, ok := c.GetInt("outbound.quantity", label...); ok {
c.OutQuantity = v
} else {
c.OutQuantity = 5
}
}
// SetInVariance sets the inbound tunnel variance from config file
func (c *Conf) SetInVariance(label ...string) {
if v, ok := c.GetInt("inbound.variance", label...); ok {
c.InVariance = v
} else {
c.InVariance = 0
}
}
// SetOutVariance sets the outbound tunnel variance from config file
func (c *Conf) SetOutVariance(label ...string) {
if v, ok := c.GetInt("outbound.variance", label...); ok {
c.OutVariance = v
} else {
c.OutVariance = 0
}
}
// SetInBackups sets the inbound tunnel backups from config file
func (c *Conf) SetInBackups(label ...string) {
if v, ok := c.GetInt("inbound.backupQuantity", label...); ok {
c.InBackupQuantity = v
} else {
c.InBackupQuantity = 2
}
}
// SetOutBackups sets the outbound tunnel backups from config file
func (c *Conf) SetOutBackups(label ...string) {
if v, ok := c.GetInt("outbound.backupQuantity", label...); ok {
c.OutBackupQuantity = v
} else {
c.OutBackupQuantity = 2
}
}
// SetCompressed sets the compression from the config file
func (c *Conf) SetCompressed(label ...string) {
if v, ok := c.GetBool("gzip", label...); ok {
c.UseCompression = v
} else {
c.UseCompression = true
}
}
// SetReduceIdle sets the config to reduce tunnels after idle time from config file
func (c *Conf) SetReduceIdle(label ...string) {
if v, ok := c.GetBool("i2cp.reduceOnIdle", label...); ok {
c.ReduceIdle = v
} else {
c.ReduceIdle = false
}
}
// SetReduceIdleTime sets the time to wait before reducing tunnels from config file
func (c *Conf) SetReduceIdleTime(label ...string) {
if v, ok := c.GetInt("i2cp.reduceIdleTime", label...); ok {
c.ReduceIdleTime = v
} else {
c.ReduceIdleTime = 300000
}
}
// SetReduceIdleQuantity sets the number of tunnels to reduce to from config file
func (c *Conf) SetReduceIdleQuantity(label ...string) {
if v, ok := c.GetInt("i2cp.reduceQuantity", label...); ok {
c.ReduceIdleQuantity = v
} else {
c.ReduceIdleQuantity = 3
}
}
// SetCloseIdle sets the tunnel to automatically close on idle from the config file
func (c *Conf) SetCloseIdle(label ...string) {
if v, ok := c.GetBool("i2cp.closeOnIdle", label...); ok {
c.CloseIdle = v
} else {
c.CloseIdle = false
}
}
// SetCloseIdleTime sets the time to wait before killing a tunnel from a config file
func (c *Conf) SetCloseIdleTime(label ...string) {
if v, ok := c.GetInt("i2cp.closeIdleTime", label...); ok {
c.CloseIdleTime = v
} else {
c.CloseIdleTime = 300000
}
}
// SetAccessListType sets the access list type from a config file
func (c *Conf) SetAccessListType(label ...string) {
if v, ok := c.GetBool("i2cp.enableBlackList", label...); ok {
if v {
c.AccessListType = "blacklist"
}
}
if v, ok := c.GetBool("i2cp.enableAccessList", label...); ok {
if v {
c.AccessListType = "whitelist"
}
}
if c.AccessListType != "whitelist" && c.AccessListType != "blacklist" {
c.AccessListType = "none"
}
}
// SetLabels
func (c *Conf) SetLabels(iniFile string) {
if tempfile, temperr := ioutil.ReadFile(iniFile); temperr == nil {

48
config/type.go Normal file
View File

@ -0,0 +1,48 @@
package i2ptunconf
import "strings"
// 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.
func (c *Conf) GetType(argc, argu, argh bool, def string, label ...string) string {
var typ string
if argu {
typ += "udp"
}
if argc {
typ += "client"
c.Client = true
} else {
if argh == true {
typ += "http"
} else {
typ += "server"
}
}
if typ != def {
return typ
}
if c.config == nil {
return typ
}
if x, o := c.Get("type", label...); o {
return x
}
return def
}
// SetType sets the type of proxy to create from the config file
func (c *Conf) SetType(label ...string) {
if v, ok := c.Get("type", label...); 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"
}
}

53
config/variance.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("inbound.variance", label...); 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, label ...string) int {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetInt("outbound.variance", label...); o {
return x
}
return arg
}
// SetInVariance sets the inbound tunnel variance from config file
func (c *Conf) SetInVariance(label ...string) {
if v, ok := c.GetInt("inbound.variance", label...); ok {
c.InVariance = v
} else {
c.InVariance = 0
}
}
// SetOutVariance sets the outbound tunnel variance from config file
func (c *Conf) SetOutVariance(label ...string) {
if v, ok := c.GetInt("outbound.variance", label...); ok {
c.OutVariance = v
} else {
c.OutVariance = 0
}
}

53
config/zerohops.go Normal file
View File

@ -0,0 +1,53 @@
package i2ptunconf
// 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("inbound.allowZeroHop", label...); 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, label ...string) bool {
if arg != def {
return arg
}
if c.config == nil {
return arg
}
if x, o := c.GetBool("outbound.allowZeroHop", label...); o {
return x
}
return arg
}
// SetAllowZeroHopIn sets the config to allow zero-hop tunnels
func (c *Conf) SetAllowZeroHopIn(label ...string) {
if v, ok := c.GetBool("inbound.allowZeroHop", label...); ok {
c.InAllowZeroHop = v
} else {
c.InAllowZeroHop = false
}
}
// SetAllowZeroHopOut sets the config to allow zero-hop tunnels
func (c *Conf) SetAllowZeroHopOut(label ...string) {
if v, ok := c.GetBool("outbound.allowZeroHop", label...); ok {
c.OutAllowZeroHop = v
} else {
c.OutAllowZeroHop = false
}
}