Start work on supporting TLS for tunnels, begin by switching all optional args to the interface instead of the concrete type
This commit is contained in:
@ -47,17 +47,17 @@ func (f *Conf) print() []string {
|
||||
"outbound.backupQuantity=" + fmt.Sprintf("%d", f.OutBackupQuantity),
|
||||
"inbound.quantity=" + fmt.Sprintf("%d", f.InQuantity),
|
||||
"outbound.quantity=" + fmt.Sprintf("%d", f.OutQuantity),
|
||||
"inbound.allowZeroHop=" + fmt.Sprintf("%b", f.InAllowZeroHop),
|
||||
"outbound.allowZeroHop=" + fmt.Sprintf("%b", f.OutAllowZeroHop),
|
||||
"i2cp.fastRecieve=" + fmt.Sprintf("%b", f.FastRecieve),
|
||||
"i2cp.gzip=" + fmt.Sprintf("%b", f.UseCompression),
|
||||
"i2cp.reduceOnIdle=" + fmt.Sprintf("%b", f.ReduceIdle),
|
||||
"i2cp.reduceIdleTime=" + fmt.Sprintf("%d", f.ReduceIdleTime),
|
||||
"inbound.allowZeroHop=" + fmt.Sprintf("%v", f.InAllowZeroHop),
|
||||
"outbound.allowZeroHop=" + fmt.Sprintf("%v", f.OutAllowZeroHop),
|
||||
"i2cp.fastRecieve=" + fmt.Sprintf("%v", f.FastRecieve),
|
||||
"i2cp.gzip=" + fmt.Sprintf("%v", f.UseCompression),
|
||||
"i2cp.reduceOnIdle=" + fmt.Sprintf("%v", f.ReduceIdle),
|
||||
"i2cp.reduceIdleTime=" + fmt.Sprintf("%v", f.ReduceIdleTime),
|
||||
"i2cp.reduceQuantity=" + fmt.Sprintf("%d", f.ReduceIdleQuantity),
|
||||
"i2cp.closeOnIdle=" + fmt.Sprintf("%b", f.CloseIdle),
|
||||
"i2cp.closeOnIdle=" + fmt.Sprintf("%v", f.CloseIdle),
|
||||
"i2cp.closeIdleTime=" + fmt.Sprintf("%d", f.CloseIdleTime),
|
||||
"i2cp.messageReliability=" + f.MessageReliability,
|
||||
"i2cp.encryptLeaseSet=" + fmt.Sprintf("%b", f.EncryptLeaseSet),
|
||||
"i2cp.encryptLeaseSet=" + fmt.Sprintf("%v", f.EncryptLeaseSet),
|
||||
"i2cp.leaseSetEncType=" + fmt.Sprintf("%s", f.LeaseSetEncType),
|
||||
lsk, lspk, lspsk,
|
||||
f.accesslisttype(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
package i2ptunconf
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@ -66,6 +67,8 @@ type Conf struct {
|
||||
exists bool `default:false`
|
||||
UserName string `default:""`
|
||||
Password string `default:""`
|
||||
UseTLS bool `default:false`
|
||||
TLSConf *tls.Config
|
||||
LoadedKeys i2pkeys.I2PKeys
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ i2cp.enableBlackList = false
|
||||
[sam-forwarder-tcp-server]
|
||||
type = server
|
||||
host = 127.0.0.1
|
||||
port = 8081
|
||||
port = 7669
|
||||
inbound.length = 2
|
||||
outbound.length = 2
|
||||
keys = tcpserver
|
||||
|
@ -3,52 +3,54 @@ package samforwarder
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
)
|
||||
|
||||
//ClientOption is a SAMClientForwarder Option
|
||||
type ClientOption func(*SAMClientForwarder) error
|
||||
type ClientOption func(samtunnel.SAMTunnel) error
|
||||
|
||||
//SetClientFilePath sets the host of the SAMClientForwarder's SAM bridge
|
||||
func SetClientFilePath(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.FilePath = s
|
||||
func SetClientFilePath(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().FilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientSaveFile tells the router to save the tunnel keys long-term
|
||||
func SetClientSaveFile(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.SaveFile = b
|
||||
func SetClientSaveFile(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SaveFile = b
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientHost sets the host of the SAMClientForwarder's SAM bridge
|
||||
func SetClientHost(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.TargetHost = s
|
||||
func SetClientHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TargetHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientDestination sets the destination to forwarder SAMClientForwarder's to
|
||||
func SetClientDestination(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.ClientDest = s
|
||||
func SetClientDestination(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ClientDest = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientPort sets the port of the SAMClientForwarder's SAM bridge using a string
|
||||
func SetClientPort(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid TCP Client Target Port %s; non-number ", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.TargetPort = s
|
||||
c.Config().TargetPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -56,22 +58,22 @@ func SetClientPort(s string) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientSAMHost sets the host of the SAMClientForwarder's SAM bridge
|
||||
func SetClientSAMHost(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.SamHost = s
|
||||
func SetClientSAMHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SamHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientSAMPort sets the port of the SAMClientForwarder's SAM bridge using a string
|
||||
func SetClientSAMPort(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientSAMPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.SamPort = s
|
||||
c.Config().SamPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -79,40 +81,40 @@ func SetClientSAMPort(s string) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientName sets the host of the SAMClientForwarder's SAM bridge
|
||||
func SetClientName(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.TunName = s
|
||||
func SetClientName(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TunName = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSigType sets the type of the forwarder server
|
||||
func SetClientSigType(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientSigType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "" {
|
||||
c.Conf.SigType = ""
|
||||
c.Config().SigType = ""
|
||||
} else if s == "DSA_SHA1" {
|
||||
c.Conf.SigType = "DSA_SHA1"
|
||||
c.Config().SigType = "DSA_SHA1"
|
||||
} else if s == "ECDSA_SHA256_P256" {
|
||||
c.Conf.SigType = "ECDSA_SHA256_P256"
|
||||
c.Config().SigType = "ECDSA_SHA256_P256"
|
||||
} else if s == "ECDSA_SHA384_P384" {
|
||||
c.Conf.SigType = "ECDSA_SHA384_P384"
|
||||
c.Config().SigType = "ECDSA_SHA384_P384"
|
||||
} else if s == "ECDSA_SHA512_P521" {
|
||||
c.Conf.SigType = "ECDSA_SHA512_P521"
|
||||
c.Config().SigType = "ECDSA_SHA512_P521"
|
||||
} else if s == "EdDSA_SHA512_Ed25519" {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
} else {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientInLength sets the number of hops inbound
|
||||
func SetClientInLength(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientInLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.InLength = u
|
||||
c.Config().InLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -120,10 +122,10 @@ func SetClientInLength(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutLength sets the number of hops outbound
|
||||
func SetClientOutLength(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientOutLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.OutLength = u
|
||||
c.Config().OutLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel length")
|
||||
@ -131,10 +133,10 @@ func SetClientOutLength(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInVariance sets the variance of a number of hops inbound
|
||||
func SetClientInVariance(i int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientInVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.InVariance = i
|
||||
c.Config().InVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -142,10 +144,10 @@ func SetClientInVariance(i int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutVariance sets the variance of a number of hops outbound
|
||||
func SetClientOutVariance(i int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientOutVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.OutVariance = i
|
||||
c.Config().OutVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel variance")
|
||||
@ -153,10 +155,10 @@ func SetClientOutVariance(i int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInQuantity sets the inbound tunnel quantity
|
||||
func SetClientInQuantity(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientInQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.InQuantity = u
|
||||
c.Config().InQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel quantity")
|
||||
@ -164,10 +166,10 @@ func SetClientInQuantity(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutQuantity sets the outbound tunnel quantity
|
||||
func SetClientOutQuantity(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientOutQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.OutQuantity = u
|
||||
c.Config().OutQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel quantity")
|
||||
@ -175,10 +177,10 @@ func SetClientOutQuantity(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInBackups sets the inbound tunnel backups
|
||||
func SetClientInBackups(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientInBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.InBackupQuantity = u
|
||||
c.Config().InBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel backup quantity")
|
||||
@ -186,10 +188,10 @@ func SetClientInBackups(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutBackups sets the inbound tunnel backups
|
||||
func SetClientOutBackups(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientOutBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.OutBackupQuantity = u
|
||||
c.Config().OutBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel backup quantity")
|
||||
@ -197,115 +199,115 @@ func SetClientOutBackups(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientEncrypt tells the router to use an encrypted leaseset
|
||||
func SetClientEncrypt(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientEncrypt(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.EncryptLeaseSet = true
|
||||
c.Config().EncryptLeaseSet = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.EncryptLeaseSet = false
|
||||
c.Config().EncryptLeaseSet = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetKey sets
|
||||
func SetClientLeaseSetKey(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.LeaseSetKey = s
|
||||
func SetClientLeaseSetKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetPrivateKey sets
|
||||
func SetClientLeaseSetPrivateKey(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.LeaseSetPrivateKey = s
|
||||
func SetClientLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetPrivateSigningKey sets
|
||||
func SetClientLeaseSetPrivateSigningKey(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.LeaseSetPrivateSigningKey = s
|
||||
func SetClientLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateSigningKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientMessageReliability sets
|
||||
func SetClientMessageReliability(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.MessageReliability = s
|
||||
func SetClientMessageReliability(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().MessageReliability = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientAllowZeroIn tells the tunnel to accept zero-hop peers
|
||||
func SetClientAllowZeroIn(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.InAllowZeroHop = true
|
||||
c.Config().InAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.InAllowZeroHop = false
|
||||
c.Config().InAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientAllowZeroOut tells the tunnel to accept zero-hop peers
|
||||
func SetClientAllowZeroOut(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.OutAllowZeroHop = true
|
||||
c.Config().OutAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.OutAllowZeroHop = false
|
||||
c.Config().OutAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientFastRecieve tells clients use the i2cp.fastRecieve option
|
||||
func SetClientFastRecieve(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientFastRecieve(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.FastRecieve = true
|
||||
c.Config().FastRecieve = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.FastRecieve = false
|
||||
c.Config().FastRecieve = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientCompress tells clients to use compression
|
||||
func SetClientCompress(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientCompress(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.UseCompression = true
|
||||
c.Config().UseCompression = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.UseCompression = false
|
||||
c.Config().UseCompression = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientReduceIdle tells the connection to reduce it's tunnels during extended idle time.
|
||||
func SetClientReduceIdle(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientReduceIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.ReduceIdle = true
|
||||
c.Config().ReduceIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.ReduceIdle = false
|
||||
c.Config().ReduceIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientReduceIdleTime sets the time to wait before reducing tunnels to idle levels
|
||||
func SetClientReduceIdleTime(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetClientReduceIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.ReduceIdleTime = (u * 60) * 1000
|
||||
c.Config().ReduceIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
|
||||
@ -313,11 +315,11 @@ func SetClientReduceIdleTime(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
|
||||
func SetClientReduceIdleTimeMs(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetClientReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.ReduceIdleTime = u
|
||||
c.Config().ReduceIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -325,10 +327,10 @@ func SetClientReduceIdleTimeMs(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
|
||||
func SetClientReduceIdleQuantity(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientReduceIdleQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 5 {
|
||||
c.Conf.ReduceIdleQuantity = u
|
||||
c.Config().ReduceIdleQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce tunnel quantity")
|
||||
@ -336,23 +338,23 @@ func SetClientReduceIdleQuantity(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientCloseIdle tells the connection to close it's tunnels during extended idle time.
|
||||
func SetClientCloseIdle(b bool) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientCloseIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.CloseIdle = true
|
||||
c.Config().CloseIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.CloseIdle = false
|
||||
c.Config().CloseIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientCloseIdleTime sets the time to wait before closing tunnels to idle levels
|
||||
func SetClientCloseIdleTime(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetClientCloseIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.CloseIdleTime = (u * 60) * 1000
|
||||
c.Config().CloseIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
|
||||
@ -360,11 +362,11 @@ func SetClientCloseIdleTime(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
|
||||
func SetClientCloseIdleTimeMs(u int) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetClientCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.CloseIdleTime = u
|
||||
c.Config().CloseIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -372,19 +374,19 @@ func SetClientCloseIdleTimeMs(u int) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientAccessListType tells the system to treat the accessList as a allowlist
|
||||
func SetClientAccessListType(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientAccessListType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "allowlist" {
|
||||
c.Conf.AccessListType = "allowlist"
|
||||
c.Config().AccessListType = "allowlist"
|
||||
return nil
|
||||
} else if s == "blocklist" {
|
||||
c.Conf.AccessListType = "blocklist"
|
||||
c.Config().AccessListType = "blocklist"
|
||||
return nil
|
||||
} else if s == "none" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
} else if s == "" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid Access list type(allowlist, blocklist, none)")
|
||||
@ -392,11 +394,11 @@ func SetClientAccessListType(s string) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientAccessList tells the system to treat the accessList as a allowlist
|
||||
func SetClientAccessList(s []string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
func SetClientAccessList(s []string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if len(s) > 0 {
|
||||
for _, a := range s {
|
||||
c.Conf.AccessList = append(c.Conf.AccessList, a)
|
||||
c.Config().AccessList = append(c.Config().AccessList, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -405,9 +407,9 @@ func SetClientAccessList(s []string) func(*SAMClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetKeyFile sets
|
||||
func SetClientPassword(s string) func(*SAMClientForwarder) error {
|
||||
return func(c *SAMClientForwarder) error {
|
||||
c.Conf.KeyFilePath = s
|
||||
func SetClientPassword(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().KeyFilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -258,12 +258,12 @@ func (s *SAMClientForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
|
||||
//NewSAMClientForwarder makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMClientForwarder(host, port string) (*SAMClientForwarder, error) {
|
||||
func NewSAMClientForwarder(host, port string) (samtunnel.SAMTunnel, error) {
|
||||
return NewSAMClientForwarderFromOptions(SetClientHost(host), SetClientPort(port))
|
||||
}
|
||||
|
||||
//NewSAMClientForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMClientForwarderFromOptions(opts ...func(*SAMClientForwarder) error) (*SAMClientForwarder, error) {
|
||||
func NewSAMClientForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMClientForwarder, error) {
|
||||
var s SAMClientForwarder
|
||||
s.Conf = i2ptunconf.NewI2PBlankTunConf()
|
||||
s.Conf.Type = "tcpclient"
|
||||
|
@ -3,79 +3,81 @@ package samforwarder
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
)
|
||||
|
||||
//Option is a SAMForwarder Option
|
||||
type Option func(*SAMForwarder) error
|
||||
type Option func(samtunnel.SAMTunnel) error
|
||||
|
||||
//SetFilePath sets the path to save the config file at.
|
||||
func SetFilePath(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.FilePath = s
|
||||
func SetFilePath(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().FilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetType sets the type of the forwarder server
|
||||
func SetType(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "http" {
|
||||
c.Conf.Type = s
|
||||
c.Config().Type = s
|
||||
return nil
|
||||
} else {
|
||||
c.Conf.Type = "server"
|
||||
c.Config().Type = "server"
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SetSigType sets the type of the forwarder server
|
||||
func SetSigType(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetSigType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "" {
|
||||
c.Conf.SigType = ""
|
||||
c.Config().SigType = ""
|
||||
} else if s == "DSA_SHA1" {
|
||||
c.Conf.SigType = "DSA_SHA1"
|
||||
c.Config().SigType = "DSA_SHA1"
|
||||
} else if s == "ECDSA_SHA256_P256" {
|
||||
c.Conf.SigType = "ECDSA_SHA256_P256"
|
||||
c.Config().SigType = "ECDSA_SHA256_P256"
|
||||
} else if s == "ECDSA_SHA384_P384" {
|
||||
c.Conf.SigType = "ECDSA_SHA384_P384"
|
||||
c.Config().SigType = "ECDSA_SHA384_P384"
|
||||
} else if s == "ECDSA_SHA512_P521" {
|
||||
c.Conf.SigType = "ECDSA_SHA512_P521"
|
||||
c.Config().SigType = "ECDSA_SHA512_P521"
|
||||
} else if s == "EdDSA_SHA512_Ed25519" {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
} else {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSaveFile tells the router to save the tunnel's keys long-term
|
||||
func SetSaveFile(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.SaveFile = b
|
||||
func SetSaveFile(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SaveFile = b
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetHost sets the host of the service to forward
|
||||
func SetHost(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.TargetHost = s
|
||||
func SetHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TargetHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetPort sets the port of the service to forward
|
||||
func SetPort(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid TCP Server Target Port %s; non-number ", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.TargetPort = s
|
||||
c.Config().TargetPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -83,22 +85,22 @@ func SetPort(s string) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetSAMHost sets the host of the SAMForwarder's SAM bridge
|
||||
func SetSAMHost(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.SamHost = s
|
||||
func SetSAMHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SamHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSAMPort sets the port of the SAMForwarder's SAM bridge using a string
|
||||
func SetSAMPort(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetSAMPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.SamPort = s
|
||||
c.Config().SamPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -106,18 +108,18 @@ func SetSAMPort(s string) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetName sets the host of the SAMForwarder's SAM bridge
|
||||
func SetName(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.TunName = s
|
||||
func SetName(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TunName = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetInLength sets the number of hops inbound
|
||||
func SetInLength(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetInLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.InLength = u
|
||||
c.Config().InLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -125,10 +127,10 @@ func SetInLength(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutLength sets the number of hops outbound
|
||||
func SetOutLength(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetOutLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.OutLength = u
|
||||
c.Config().OutLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel length")
|
||||
@ -136,10 +138,10 @@ func SetOutLength(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetInVariance sets the variance of a number of hops inbound
|
||||
func SetInVariance(i int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetInVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.InVariance = i
|
||||
c.Config().InVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -147,10 +149,10 @@ func SetInVariance(i int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutVariance sets the variance of a number of hops outbound
|
||||
func SetOutVariance(i int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetOutVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.OutVariance = i
|
||||
c.Config().OutVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel variance")
|
||||
@ -158,10 +160,10 @@ func SetOutVariance(i int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetInQuantity sets the inbound tunnel quantity
|
||||
func SetInQuantity(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetInQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.InQuantity = u
|
||||
c.Config().InQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel quantity")
|
||||
@ -169,10 +171,10 @@ func SetInQuantity(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutQuantity sets the outbound tunnel quantity
|
||||
func SetOutQuantity(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetOutQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.OutQuantity = u
|
||||
c.Config().OutQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel quantity")
|
||||
@ -180,10 +182,10 @@ func SetOutQuantity(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetInBackups sets the inbound tunnel backups
|
||||
func SetInBackups(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetInBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.InBackupQuantity = u
|
||||
c.Config().InBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel backup quantity")
|
||||
@ -191,10 +193,10 @@ func SetInBackups(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutBackups sets the inbound tunnel backups
|
||||
func SetOutBackups(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetOutBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.OutBackupQuantity = u
|
||||
c.Config().OutBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel backup quantity")
|
||||
@ -202,115 +204,115 @@ func SetOutBackups(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetEncrypt tells the router to use an encrypted leaseset
|
||||
func SetEncrypt(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetEncrypt(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.EncryptLeaseSet = true
|
||||
c.Config().EncryptLeaseSet = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.EncryptLeaseSet = false
|
||||
c.Config().EncryptLeaseSet = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetLeaseSetKey(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.LeaseSetKey = s
|
||||
func SetLeaseSetKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetPrivateKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetLeaseSetPrivateKey(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.LeaseSetPrivateKey = s
|
||||
func SetLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetPrivateSigningKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetLeaseSetPrivateSigningKey(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.LeaseSetPrivateSigningKey = s
|
||||
func SetLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateSigningKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetMessageReliability sets the host of the SAMForwarder's SAM bridge
|
||||
func SetMessageReliability(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.MessageReliability = s
|
||||
func SetMessageReliability(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().MessageReliability = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
|
||||
func SetAllowZeroIn(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.InAllowZeroHop = true
|
||||
c.Config().InAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.InAllowZeroHop = false
|
||||
c.Config().InAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
|
||||
func SetAllowZeroOut(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.OutAllowZeroHop = true
|
||||
c.Config().OutAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.OutAllowZeroHop = false
|
||||
c.Config().OutAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetCompress tells clients to use compression
|
||||
func SetCompress(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetCompress(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.UseCompression = true
|
||||
c.Config().UseCompression = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.UseCompression = false
|
||||
c.Config().UseCompression = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetFastRecieve tells clients to use compression
|
||||
func SetFastRecieve(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetFastRecieve(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.FastRecieve = true
|
||||
c.Config().FastRecieve = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.FastRecieve = false
|
||||
c.Config().FastRecieve = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
|
||||
func SetReduceIdle(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetReduceIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.ReduceIdle = true
|
||||
c.Config().ReduceIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.ReduceIdle = false
|
||||
c.Config().ReduceIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
|
||||
func SetReduceIdleTime(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetReduceIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.ReduceIdleTime = (u * 60) * 1000
|
||||
c.Config().ReduceIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
|
||||
@ -318,11 +320,11 @@ func SetReduceIdleTime(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
|
||||
func SetReduceIdleTimeMs(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.ReduceIdleTime = u
|
||||
c.Config().ReduceIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -330,10 +332,10 @@ func SetReduceIdleTimeMs(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
|
||||
func SetReduceIdleQuantity(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetReduceIdleQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 5 {
|
||||
c.Conf.ReduceIdleQuantity = u
|
||||
c.Config().ReduceIdleQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce tunnel quantity")
|
||||
@ -341,23 +343,23 @@ func SetReduceIdleQuantity(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
|
||||
func SetCloseIdle(b bool) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetCloseIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.CloseIdle = true
|
||||
c.Config().CloseIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.CloseIdle = false
|
||||
c.Config().CloseIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
|
||||
func SetCloseIdleTime(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetCloseIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.CloseIdleTime = (u * 60) * 1000
|
||||
c.Config().CloseIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
|
||||
@ -365,11 +367,11 @@ func SetCloseIdleTime(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
|
||||
func SetCloseIdleTimeMs(u int) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.CloseIdleTime = u
|
||||
c.Config().CloseIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -377,19 +379,19 @@ func SetCloseIdleTimeMs(u int) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetAccessListType tells the system to treat the AccessList as a allowlist
|
||||
func SetAccessListType(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetAccessListType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "allowlist" {
|
||||
c.Conf.AccessListType = "allowlist"
|
||||
c.Config().AccessListType = "allowlist"
|
||||
return nil
|
||||
} else if s == "blocklist" {
|
||||
c.Conf.AccessListType = "blocklist"
|
||||
c.Config().AccessListType = "blocklist"
|
||||
return nil
|
||||
} else if s == "none" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
} else if s == "" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid Access list type(allowlist, blocklist, none)")
|
||||
@ -397,11 +399,11 @@ func SetAccessListType(s string) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetAccessList tells the system to treat the AccessList as a allowlist
|
||||
func SetAccessList(s []string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
func SetAccessList(s []string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if len(s) > 0 {
|
||||
for _, a := range s {
|
||||
c.Conf.AccessList = append(c.Conf.AccessList, a)
|
||||
c.Config().AccessList = append(c.Config().AccessList, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -410,14 +412,14 @@ func SetAccessList(s []string) func(*SAMForwarder) error {
|
||||
}
|
||||
|
||||
//SetTargetForPort sets the port of the SAMForwarder's SAM bridge using a string
|
||||
/*func SetTargetForPort443(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
/*func SetTargetForPort443(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid Target Port %s; non-number ", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.TargetForPort443 = s
|
||||
c.Config().TargetForPort443 = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -426,9 +428,9 @@ func SetAccessList(s []string) func(*SAMForwarder) error {
|
||||
*/
|
||||
|
||||
//SetKeyFile sets
|
||||
func SetKeyFile(s string) func(*SAMForwarder) error {
|
||||
return func(c *SAMForwarder) error {
|
||||
c.Conf.KeyFilePath = s
|
||||
func SetKeyFile(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().KeyFilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package samforwarder
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@ -29,7 +30,7 @@ type SAMForwarder struct {
|
||||
SamKeys i2pkeys.I2PKeys
|
||||
Hasher *hashhash.Hasher
|
||||
publishStream *sam3.StreamSession
|
||||
publishListen *sam3.StreamListener
|
||||
publishListen net.Listener //*sam3.StreamListener
|
||||
Bytes map[string]int64
|
||||
ByteLimit int64
|
||||
|
||||
@ -198,12 +199,12 @@ func (f *SAMForwarder) sam() string {
|
||||
return f.Config().SamHost + ":" + f.Config().SamPort
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) ClientBase64(conn *sam3.SAMConn) string {
|
||||
func (f *SAMForwarder) ClientBase64(conn net.Conn) string {
|
||||
dest := conn.RemoteAddr().(i2pkeys.I2PAddr)
|
||||
return dest.Base32()
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) HTTPRequestBytes(conn *sam3.SAMConn) ([]byte, *http.Request, error) {
|
||||
func (f *SAMForwarder) HTTPRequestBytes(conn net.Conn) ([]byte, *http.Request, error) {
|
||||
var request *http.Request
|
||||
var retrequest []byte
|
||||
var err error
|
||||
@ -249,7 +250,7 @@ func (f *SAMForwarder) clientUnlockAndClose(cli, conn bool, client net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) connUnlockAndClose(cli, conn bool, connection *sam3.SAMConn) {
|
||||
func (f *SAMForwarder) connUnlockAndClose(cli, conn bool, connection net.Conn) {
|
||||
if cli {
|
||||
f.connClientLock = cli
|
||||
}
|
||||
@ -263,7 +264,7 @@ func (f *SAMForwarder) connUnlockAndClose(cli, conn bool, connection *sam3.SAMCo
|
||||
}
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
|
||||
func (f *SAMForwarder) forward(conn net.Conn) { //(conn net.Conn) {
|
||||
if !f.Up() {
|
||||
return
|
||||
}
|
||||
@ -351,15 +352,20 @@ func (f *SAMForwarder) Serve() error {
|
||||
return err
|
||||
}
|
||||
log.Println("SAM stream session established.")
|
||||
if f.publishListen, err = f.publishStream.Listen(); err != nil {
|
||||
publishListen, err := f.publishStream.Listen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Starting Listener.")
|
||||
log.Println("SAM Listener created,", f.Base32())
|
||||
log.Println("Human-readable hash:\n ", f.Base32Readable())
|
||||
|
||||
if f.Conf.UseTLS {
|
||||
f.publishListen = tls.NewListener(publishListen, f.Conf.TLSConf)
|
||||
} else {
|
||||
f.publishListen = publishListen
|
||||
}
|
||||
for {
|
||||
conn, err := f.publishListen.AcceptI2P()
|
||||
conn, err := f.publishListen.Accept()
|
||||
if err != nil {
|
||||
log.Printf("ERROR: failed to accept listener: %v", err)
|
||||
return nil
|
||||
@ -414,12 +420,12 @@ func (s *SAMForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
|
||||
//NewSAMForwarder makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMForwarder(host, port string) (*SAMForwarder, error) {
|
||||
func NewSAMForwarder(host, port string) (samtunnel.SAMTunnel, error) {
|
||||
return NewSAMForwarderFromOptions(SetHost(host), SetPort(port))
|
||||
}
|
||||
|
||||
//NewSAMForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMForwarderFromOptions(opts ...func(*SAMForwarder) error) (*SAMForwarder, error) {
|
||||
func NewSAMForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMForwarder, error) {
|
||||
var s SAMForwarder
|
||||
s.Conf = i2ptunconf.NewI2PBlankTunConf()
|
||||
s.clientLock = false
|
||||
|
@ -3,44 +3,46 @@ package samforwarderudp
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
)
|
||||
|
||||
//ClientOption is a SAMDGClientForwarder Option
|
||||
type ClientOption func(*SAMDGClientForwarder) error
|
||||
type ClientOption func(samtunnel.SAMTunnel) error
|
||||
|
||||
//SetClientFilePath sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetClientFilePath(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.FilePath = s
|
||||
func SetClientFilePath(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().FilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientSaveFile tells the router to use an encrypted leaseset
|
||||
func SetClientSaveFile(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.SaveFile = b
|
||||
func SetClientSaveFile(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SaveFile = b
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientHost sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetClientHost(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.TargetHost = s
|
||||
func SetClientHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TargetHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientPort sets the port of the SAMDGForwarder's SAM bridge using a string
|
||||
func SetClientPort(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SSU Client Target Port %s; non-number ", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.TargetPort = s
|
||||
c.Config().TargetPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -48,22 +50,22 @@ func SetClientPort(s string) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientSAMHost sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetClientSAMHost(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.SamHost = s
|
||||
func SetClientSAMHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SamHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientSAMPort sets the port of the SAMDGForwarder's SAM bridge using a string
|
||||
func SetClientSAMPort(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientSAMPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.SamPort = s
|
||||
c.Config().SamPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -71,48 +73,48 @@ func SetClientSAMPort(s string) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientDestination sets the destination to forwarder SAMClientForwarder's to
|
||||
func SetClientDestination(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.ClientDest = s
|
||||
func SetClientDestination(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ClientDest = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientName sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetClientName(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.TunName = s
|
||||
func SetClientName(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TunName = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientSigType sets the type of the forwarder server
|
||||
func SetClientSigType(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientSigType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "" {
|
||||
c.Conf.SigType = ""
|
||||
c.Config().SigType = ""
|
||||
} else if s == "DSA_SHA1" {
|
||||
c.Conf.SigType = "DSA_SHA1"
|
||||
c.Config().SigType = "DSA_SHA1"
|
||||
} else if s == "ECDSA_SHA256_P256" {
|
||||
c.Conf.SigType = "ECDSA_SHA256_P256"
|
||||
c.Config().SigType = "ECDSA_SHA256_P256"
|
||||
} else if s == "ECDSA_SHA384_P384" {
|
||||
c.Conf.SigType = "ECDSA_SHA384_P384"
|
||||
c.Config().SigType = "ECDSA_SHA384_P384"
|
||||
} else if s == "ECDSA_SHA512_P521" {
|
||||
c.Conf.SigType = "ECDSA_SHA512_P521"
|
||||
c.Config().SigType = "ECDSA_SHA512_P521"
|
||||
} else if s == "EdDSA_SHA512_Ed25519" {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
} else {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientInLength sets the number of hops inbound
|
||||
func SetClientInLength(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientInLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.InLength = u
|
||||
c.Config().InLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -120,10 +122,10 @@ func SetClientInLength(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutLength sets the number of hops outbound
|
||||
func SetClientOutLength(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientOutLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.OutLength = u
|
||||
c.Config().OutLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel length")
|
||||
@ -131,10 +133,10 @@ func SetClientOutLength(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInVariance sets the variance of a number of hops inbound
|
||||
func SetClientInVariance(i int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientInVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.InVariance = i
|
||||
c.Config().InVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -142,10 +144,10 @@ func SetClientInVariance(i int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutVariance sets the variance of a number of hops outbound
|
||||
func SetClientOutVariance(i int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientOutVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.OutVariance = i
|
||||
c.Config().OutVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel variance")
|
||||
@ -153,10 +155,10 @@ func SetClientOutVariance(i int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInQuantity sets the inbound tunnel quantity
|
||||
func SetClientInQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientInQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.InQuantity = u
|
||||
c.Config().InQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel quantity")
|
||||
@ -164,10 +166,10 @@ func SetClientInQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutQuantity sets the outbound tunnel quantity
|
||||
func SetClientOutQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientOutQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.OutQuantity = u
|
||||
c.Config().OutQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel quantity")
|
||||
@ -175,10 +177,10 @@ func SetClientOutQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientInBackups sets the inbound tunnel backups
|
||||
func SetClientInBackups(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientInBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.InBackupQuantity = u
|
||||
c.Config().InBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel backup quantity")
|
||||
@ -186,10 +188,10 @@ func SetClientInBackups(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientOutBackups sets the inbound tunnel backups
|
||||
func SetClientOutBackups(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientOutBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.OutBackupQuantity = u
|
||||
c.Config().OutBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel backup quantity")
|
||||
@ -197,115 +199,115 @@ func SetClientOutBackups(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientEncrypt tells the router to use an encrypted leaseset
|
||||
func SetClientEncrypt(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientEncrypt(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.EncryptLeaseSet = true
|
||||
c.Config().EncryptLeaseSet = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.EncryptLeaseSet = false
|
||||
c.Config().EncryptLeaseSet = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetClientLeaseSetKey(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.LeaseSetKey = s
|
||||
func SetClientLeaseSetKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetPrivateKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetClientLeaseSetPrivateKey(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.LeaseSetPrivateKey = s
|
||||
func SetClientLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientLeaseSetPrivateSigningKey sets the host of the SAMForwarder's SAM bridge
|
||||
func SetClientLeaseSetPrivateSigningKey(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.LeaseSetPrivateSigningKey = s
|
||||
func SetClientLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateSigningKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientMessageReliability sets
|
||||
func SetClientMessageReliability(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.MessageReliability = s
|
||||
func SetClientMessageReliability(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().MessageReliability = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientAllowZeroIn tells the tunnel to accept zero-hop peers
|
||||
func SetClientAllowZeroIn(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.InAllowZeroHop = true
|
||||
c.Config().InAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.InAllowZeroHop = false
|
||||
c.Config().InAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientAllowZeroOut tells the tunnel to accept zero-hop peers
|
||||
func SetClientAllowZeroOut(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.OutAllowZeroHop = true
|
||||
c.Config().OutAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.OutAllowZeroHop = false
|
||||
c.Config().OutAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetFastRecieve tells clients to use i2cp.fastRecieve
|
||||
func SetClientFastRecieve(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientFastRecieve(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.FastRecieve = true
|
||||
c.Config().FastRecieve = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.FastRecieve = false
|
||||
c.Config().FastRecieve = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientCompress tells clients to use compression
|
||||
func SetClientCompress(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientCompress(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.UseCompression = true
|
||||
c.Config().UseCompression = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.UseCompression = false
|
||||
c.Config().UseCompression = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientReduceIdle tells the connection to reduce it's tunnels during extended idle time.
|
||||
func SetClientReduceIdle(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientReduceIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.ReduceIdle = true
|
||||
c.Config().ReduceIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.ReduceIdle = false
|
||||
c.Config().ReduceIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientReduceIdleTime sets the time to wait before reducing tunnels to idle levels
|
||||
func SetClientReduceIdleTime(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetClientReduceIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.ReduceIdleTime = (u * 60) * 1000
|
||||
c.Config().ReduceIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
|
||||
@ -313,11 +315,11 @@ func SetClientReduceIdleTime(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
|
||||
func SetClientReduceIdleTimeMs(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetClientReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.ReduceIdleTime = u
|
||||
c.Config().ReduceIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
|
||||
@ -325,10 +327,10 @@ func SetClientReduceIdleTimeMs(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
|
||||
func SetClientReduceIdleQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientReduceIdleQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 5 {
|
||||
c.Conf.ReduceIdleQuantity = u
|
||||
c.Config().ReduceIdleQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce tunnel quantity")
|
||||
@ -336,23 +338,23 @@ func SetClientReduceIdleQuantity(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientCloseIdle tells the connection to close it's tunnels during extended idle time.
|
||||
func SetClientCloseIdle(b bool) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientCloseIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.CloseIdle = true
|
||||
c.Config().CloseIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.CloseIdle = false
|
||||
c.Config().CloseIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetClientCloseIdleTime sets the time to wait before closing tunnels to idle levels
|
||||
func SetClientCloseIdleTime(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetClientCloseIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.CloseIdleTime = (u * 60) * 1000
|
||||
c.Config().CloseIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
|
||||
@ -360,11 +362,11 @@ func SetClientCloseIdleTime(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
|
||||
func SetClientCloseIdleTimeMs(u int) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetClientCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.CloseIdleTime = u
|
||||
c.Config().CloseIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -372,19 +374,19 @@ func SetClientCloseIdleTimeMs(u int) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientAccessListType tells the system to treat the accessList as a allowlist
|
||||
func SetClientAccessListType(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientAccessListType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "allowlist" {
|
||||
c.Conf.AccessListType = "allowlist"
|
||||
c.Config().AccessListType = "allowlist"
|
||||
return nil
|
||||
} else if s == "blocklist" {
|
||||
c.Conf.AccessListType = "blocklist"
|
||||
c.Config().AccessListType = "blocklist"
|
||||
return nil
|
||||
} else if s == "none" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
} else if s == "" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid Access list type(allowlist, blocklist, none)")
|
||||
@ -392,11 +394,11 @@ func SetClientAccessListType(s string) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetClientAccessList tells the system to treat the accessList as a allowlist
|
||||
func SetClientAccessList(s []string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
func SetClientAccessList(s []string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if len(s) > 0 {
|
||||
for _, a := range s {
|
||||
c.Conf.AccessList = append(c.Conf.AccessList, a)
|
||||
c.Config().AccessList = append(c.Config().AccessList, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -405,9 +407,9 @@ func SetClientAccessList(s []string) func(*SAMDGClientForwarder) error {
|
||||
}
|
||||
|
||||
//SetKeyFile sets
|
||||
func SetClientPassword(s string) func(*SAMDGClientForwarder) error {
|
||||
return func(c *SAMDGClientForwarder) error {
|
||||
c.Conf.KeyFilePath = s
|
||||
func SetClientPassword(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().KeyFilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func (s *SAMDGClientForwarder) Load() (samtunnel.SAMTunnel, error) {
|
||||
}
|
||||
|
||||
//NewSAMDGClientForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMDGClientForwarderFromOptions(opts ...func(*SAMDGClientForwarder) error) (*SAMDGClientForwarder, error) {
|
||||
func NewSAMDGClientForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMDGClientForwarder, error) {
|
||||
var s SAMDGClientForwarder
|
||||
s.Conf = i2ptunconf.NewI2PBlankTunConf()
|
||||
s.Conf.Type = "udpclient"
|
||||
|
@ -3,44 +3,46 @@ package samforwarderudp
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/eyedeekay/sam-forwarder/interface"
|
||||
)
|
||||
|
||||
//Option is a SAMDGForwarder Option
|
||||
type Option func(*SAMDGForwarder) error
|
||||
type Option func(samtunnel.SAMTunnel) error
|
||||
|
||||
//SetFilePath sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetFilePath(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.FilePath = s
|
||||
func SetFilePath(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().FilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSaveFile tells the router to use an encrypted leaseset
|
||||
func SetSaveFile(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.SaveFile = b
|
||||
func SetSaveFile(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SaveFile = b
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetHost sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetHost(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.TargetHost = s
|
||||
func SetHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TargetHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetPort sets the port of the SAMDGForwarder's SAM bridge using a string
|
||||
func SetPort(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SSU Server Target Port %s; non-number ", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.TargetPort = s
|
||||
c.Config().TargetPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -48,22 +50,22 @@ func SetPort(s string) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetSAMHost sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetSAMHost(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.SamHost = s
|
||||
func SetSAMHost(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().SamHost = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSAMPort sets the port of the SAMDGForwarder's SAM bridge using a string
|
||||
func SetSAMPort(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetSAMPort(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
port, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
|
||||
}
|
||||
if port < 65536 && port > -1 {
|
||||
c.Conf.SamPort = s
|
||||
c.Config().SamPort = s
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid port")
|
||||
@ -71,40 +73,40 @@ func SetSAMPort(s string) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetName sets the host of the SAMDGForwarder's SAM bridge
|
||||
func SetName(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.TunName = s
|
||||
func SetName(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().TunName = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetSigType sets the type of the forwarder server
|
||||
func SetSigType(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetSigType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "" {
|
||||
c.Conf.SigType = ""
|
||||
c.Config().SigType = ""
|
||||
} else if s == "DSA_SHA1" {
|
||||
c.Conf.SigType = "DSA_SHA1"
|
||||
c.Config().SigType = "DSA_SHA1"
|
||||
} else if s == "ECDSA_SHA256_P256" {
|
||||
c.Conf.SigType = "ECDSA_SHA256_P256"
|
||||
c.Config().SigType = "ECDSA_SHA256_P256"
|
||||
} else if s == "ECDSA_SHA384_P384" {
|
||||
c.Conf.SigType = "ECDSA_SHA384_P384"
|
||||
c.Config().SigType = "ECDSA_SHA384_P384"
|
||||
} else if s == "ECDSA_SHA512_P521" {
|
||||
c.Conf.SigType = "ECDSA_SHA512_P521"
|
||||
c.Config().SigType = "ECDSA_SHA512_P521"
|
||||
} else if s == "EdDSA_SHA512_Ed25519" {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
} else {
|
||||
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
|
||||
c.Config().SigType = "EdDSA_SHA512_Ed25519"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetInLength sets the number of hops inbound
|
||||
func SetInLength(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetInLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.InLength = u
|
||||
c.Config().InLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -112,10 +114,10 @@ func SetInLength(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutLength sets the number of hops outbound
|
||||
func SetOutLength(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetOutLength(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 7 && u >= 0 {
|
||||
c.Conf.OutLength = u
|
||||
c.Config().OutLength = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel length")
|
||||
@ -123,10 +125,10 @@ func SetOutLength(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetInVariance sets the variance of a number of hops inbound
|
||||
func SetInVariance(i int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetInVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.InVariance = i
|
||||
c.Config().InVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel length")
|
||||
@ -134,10 +136,10 @@ func SetInVariance(i int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutVariance sets the variance of a number of hops outbound
|
||||
func SetOutVariance(i int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetOutVariance(i int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if i < 7 && i > -7 {
|
||||
c.Conf.OutVariance = i
|
||||
c.Config().OutVariance = i
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel variance")
|
||||
@ -145,10 +147,10 @@ func SetOutVariance(i int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetInQuantity sets the inbound tunnel quantity
|
||||
func SetInQuantity(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetInQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.InQuantity = u
|
||||
c.Config().InQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel quantity")
|
||||
@ -156,10 +158,10 @@ func SetInQuantity(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutQuantity sets the outbound tunnel quantity
|
||||
func SetOutQuantity(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetOutQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u <= 16 && u > 0 {
|
||||
c.Conf.OutQuantity = u
|
||||
c.Config().OutQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel quantity")
|
||||
@ -167,10 +169,10 @@ func SetOutQuantity(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetInBackups sets the inbound tunnel backups
|
||||
func SetInBackups(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetInBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.InBackupQuantity = u
|
||||
c.Config().InBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid inbound tunnel backup quantity")
|
||||
@ -178,10 +180,10 @@ func SetInBackups(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetOutBackups sets the inbound tunnel backups
|
||||
func SetOutBackups(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetOutBackups(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 6 && u >= 0 {
|
||||
c.Conf.OutBackupQuantity = u
|
||||
c.Config().OutBackupQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid outbound tunnel backup quantity")
|
||||
@ -189,115 +191,115 @@ func SetOutBackups(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetEncrypt tells the router to use an encrypted leaseset
|
||||
func SetEncrypt(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetEncrypt(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.EncryptLeaseSet = true
|
||||
c.Config().EncryptLeaseSet = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.EncryptLeaseSet = false
|
||||
c.Config().EncryptLeaseSet = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetKey sets
|
||||
func SetLeaseSetKey(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.LeaseSetKey = s
|
||||
func SetLeaseSetKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetPrivateKey sets
|
||||
func SetLeaseSetPrivateKey(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.LeaseSetPrivateKey = s
|
||||
func SetLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetLeaseSetPrivateSigningKey sets
|
||||
func SetLeaseSetPrivateSigningKey(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.LeaseSetPrivateSigningKey = s
|
||||
func SetLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().LeaseSetPrivateSigningKey = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetMessageReliability sets
|
||||
func SetMessageReliability(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.MessageReliability = s
|
||||
func SetMessageReliability(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().MessageReliability = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
|
||||
func SetAllowZeroIn(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.InAllowZeroHop = true
|
||||
c.Config().InAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.InAllowZeroHop = false
|
||||
c.Config().InAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
|
||||
func SetAllowZeroOut(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.OutAllowZeroHop = true
|
||||
c.Config().OutAllowZeroHop = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.OutAllowZeroHop = false
|
||||
c.Config().OutAllowZeroHop = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetFastRecieve tells clients to use compression
|
||||
func SetFastRecieve(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetFastRecieve(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.FastRecieve = true
|
||||
c.Config().FastRecieve = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.FastRecieve = false
|
||||
c.Config().FastRecieve = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetCompress tells clients to use compression
|
||||
func SetCompress(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetCompress(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.UseCompression = true
|
||||
c.Config().UseCompression = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.UseCompression = false
|
||||
c.Config().UseCompression = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
|
||||
func SetReduceIdle(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetReduceIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.ReduceIdle = true
|
||||
c.Config().ReduceIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.ReduceIdle = false
|
||||
c.Config().ReduceIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
|
||||
func SetReduceIdleTime(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetReduceIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.ReduceIdleTime = (u * 60) * 1000
|
||||
c.Config().ReduceIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
|
||||
@ -305,11 +307,11 @@ func SetReduceIdleTime(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
|
||||
func SetReduceIdleTimeMs(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.ReduceIdleTime = 300000
|
||||
func SetReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().ReduceIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.ReduceIdleTime = u
|
||||
c.Config().ReduceIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
|
||||
@ -317,10 +319,10 @@ func SetReduceIdleTimeMs(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
|
||||
func SetReduceIdleQuantity(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetReduceIdleQuantity(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if u < 5 {
|
||||
c.Conf.ReduceIdleQuantity = u
|
||||
c.Config().ReduceIdleQuantity = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce tunnel quantity")
|
||||
@ -328,23 +330,23 @@ func SetReduceIdleQuantity(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
|
||||
func SetCloseIdle(b bool) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetCloseIdle(b bool) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if b {
|
||||
c.Conf.CloseIdle = true
|
||||
c.Config().CloseIdle = true
|
||||
return nil
|
||||
}
|
||||
c.Conf.CloseIdle = false
|
||||
c.Config().CloseIdle = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
|
||||
func SetCloseIdleTime(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetCloseIdleTime(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 6 {
|
||||
c.Conf.CloseIdleTime = (u * 60) * 1000
|
||||
c.Config().CloseIdleTime = (u * 60) * 1000
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
|
||||
@ -352,11 +354,11 @@ func SetCloseIdleTime(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
|
||||
func SetCloseIdleTimeMs(u int) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.CloseIdleTime = 300000
|
||||
func SetCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().CloseIdleTime = 300000
|
||||
if u >= 300000 {
|
||||
c.Conf.CloseIdleTime = u
|
||||
c.Config().CloseIdleTime = u
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
|
||||
@ -364,19 +366,19 @@ func SetCloseIdleTimeMs(u int) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetAccessListType tells the system to treat the accessList as a allowlist
|
||||
func SetAccessListType(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetAccessListType(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if s == "allowlist" {
|
||||
c.Conf.AccessListType = "allowlist"
|
||||
c.Config().AccessListType = "allowlist"
|
||||
return nil
|
||||
} else if s == "blocklist" {
|
||||
c.Conf.AccessListType = "blocklist"
|
||||
c.Config().AccessListType = "blocklist"
|
||||
return nil
|
||||
} else if s == "none" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
} else if s == "" {
|
||||
c.Conf.AccessListType = ""
|
||||
c.Config().AccessListType = ""
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Invalid Access list type(allowlist, blocklist, none)")
|
||||
@ -384,11 +386,11 @@ func SetAccessListType(s string) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetAccessList tells the system to treat the accessList as a allowlist
|
||||
func SetAccessList(s []string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
func SetAccessList(s []string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
if len(s) > 0 {
|
||||
for _, a := range s {
|
||||
c.Conf.AccessList = append(c.Conf.AccessList, a)
|
||||
c.Config().AccessList = append(c.Config().AccessList, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -397,9 +399,9 @@ func SetAccessList(s []string) func(*SAMDGForwarder) error {
|
||||
}
|
||||
|
||||
//SetKeyFile sets
|
||||
func SetKeyFile(s string) func(*SAMDGForwarder) error {
|
||||
return func(c *SAMDGForwarder) error {
|
||||
c.Conf.KeyFilePath = s
|
||||
func SetKeyFile(s string) func(samtunnel.SAMTunnel) error {
|
||||
return func(c samtunnel.SAMTunnel) error {
|
||||
c.Config().KeyFilePath = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -300,12 +300,12 @@ func (f *SAMDGForwarder) Up() bool {
|
||||
}
|
||||
|
||||
//NewSAMDGForwarder makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMDGForwarder(host, port string) (*SAMDGForwarder, error) {
|
||||
func NewSAMDGForwarder(host, port string) (samtunnel.SAMTunnel, error) {
|
||||
return NewSAMDGForwarderFromOptions(SetHost(host), SetPort(port))
|
||||
}
|
||||
|
||||
//NewSAMDGForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
|
||||
func NewSAMDGForwarderFromOptions(opts ...func(*SAMDGForwarder) error) (*SAMDGForwarder, error) {
|
||||
func NewSAMDGForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMDGForwarder, error) {
|
||||
var s SAMDGForwarder
|
||||
s.Conf = i2ptunconf.NewI2PBlankTunConf()
|
||||
s.Conf.Type = "udpserver"
|
||||
|
Reference in New Issue
Block a user