15 Commits

38 changed files with 1353 additions and 2638 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ bin/*
*.i2pkeys
*/*.i2pkeys
README.md.asc
samcatd
*/*.pem
*.pem

View File

@ -25,6 +25,7 @@ echo:
@echo "$(GOPATH)"
find . -path ./.go -prune -o -name "*.go" -exec gofmt -w {} \;
find . -path ./.go -prune -o -name "*.i2pkeys" -exec rm {} \;
find . -path ./.go -prune -o -name "*.pem" -exec rm {} \;
find . -path ./.go -prune -o -name "*.go" -exec cat {} \; | nl
tag:

View File

@ -58,12 +58,12 @@ key:
[*] - i2cp.tcp.port 1-65535 7654 Router I2CP port. If the client is running in the same JVM as a router, this option is ignored, and the client connects to that router internally.
Default Description
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blacklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a whitelist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a whitelist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blacklist for incoming connections. As of release 0.7.13.
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blocklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a allowlist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a allowlist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blocklist for incoming connections. As of release 0.7.13.
[U] - i2p.streaming.answerPings true Whether to respond to incoming pings
[U] - i2p.streaming.blacklist null Comma- or space-separated list of Base64 peer Hashes to be blacklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.blocklist null Comma- or space-separated list of Base64 peer Hashes to be blocklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.bufferSize 64K How much transmit data (in bytes) will be accepted that hasn't been written out yet.
[U] - i2p.streaming.congestionAvoidanceGrowthRateFactor 1 When we're in congestion avoidance, we grow the window size at the rate of 1/(windowSize*factor). In standard TCP, window sizes are in bytes, while in I2P, window sizes are in messages. A higher number means slower growth.
[U] - i2p.streaming.connectDelay -1 How long to wait after instantiating a new con before actually attempting to connect. If this is <= 0, connect immediately with no initial data. If greater than 0, wait until the output stream is flushed, the buffer fills, or that many milliseconds pass, and include any initial data with the SYN.

View File

@ -55,12 +55,12 @@ key:
[U] - i2cp.tcp.port 1-65535 7654 Router I2CP port. If the client is running in the same JVM as a router, this option is ignored, and the client connects to that router internally.
Default Description
[U] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blacklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a whitelist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[U] - i2cp.enableAccessList false Use the access list as a whitelist for incoming connections. As of release 0.7.13.
[U] - i2cp.enableBlackList false Use the access list as a blacklist for incoming connections. As of release 0.7.13.
[U] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blocklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a allowlist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[U] - i2cp.enableAccessList false Use the access list as a allowlist for incoming connections. As of release 0.7.13.
[U] - i2cp.enableBlackList false Use the access list as a blocklist for incoming connections. As of release 0.7.13.
[U] - i2p.streaming.answerPings true Whether to respond to incoming pings
[U] - i2p.streaming.blacklist null Comma- or space-separated list of Base64 peer Hashes to be blacklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.blocklist null Comma- or space-separated list of Base64 peer Hashes to be blocklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.bufferSize 64K How much transmit data (in bytes) will be accepted that hasn't been written out yet.
[U] - i2p.streaming.congestionAvoidanceGrowthRateFactor 1 When we're in congestion avoidance, we grow the window size at the rate of 1/(windowSize*factor). In standard TCP, window sizes are in bytes, while in I2P, window sizes are in messages. A higher number means slower growth.
[U] - i2p.streaming.connectDelay -1 How long to wait after instantiating a new con before actually attempting to connect. If this is <= 0, connect immediately with no initial data. If greater than 0, wait until the output stream is flushed, the buffer fills, or that many milliseconds pass, and include any initial data with the SYN.

View File

@ -22,20 +22,20 @@ func (c *Conf) GetAccessListType(arg, def string, label ...string) string {
func (c *Conf) SetAccessListType(label ...string) {
if v, ok := c.GetBool("i2cp.enableBlackList", label...); ok {
if v {
c.AccessListType = "blacklist"
c.AccessListType = "blocklist"
}
}
if v, ok := c.GetBool("i2cp.enableAccessList", label...); ok {
if v {
c.AccessListType = "whitelist"
c.AccessListType = "allowlist"
}
}
if c.AccessListType != "whitelist" && c.AccessListType != "blacklist" {
if c.AccessListType != "allowlist" && c.AccessListType != "blocklist" {
c.AccessListType = "none"
}
}
// AddAccessListMember adds a member to either the blacklist or the whitelist
// AddAccessListMember adds a member to either the blocklist or the allowlist
func (c *Conf) AddAccessListMember(key string) {
for _, item := range c.AccessList {
if item == key {
@ -46,9 +46,9 @@ func (c *Conf) AddAccessListMember(key string) {
}
func (c *Conf) accesslisttype() string {
if c.AccessListType == "whitelist" {
if c.AccessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if c.AccessListType == "blacklist" {
} else if c.AccessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if c.AccessListType == "none" {
return ""

View File

@ -47,17 +47,18 @@ 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(),
f.accesslist(),
@ -107,9 +108,9 @@ func (f *Conf) Search(search string) string {
/*
func (f *Conf) accesslisttype() string {
if f.accessListType == "whitelist" {
if f.accessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if f.accessListType == "blacklist" {
} else if f.accessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if f.accessListType == "none" {
return ""

View File

@ -22,6 +22,6 @@ func (c *Conf) SetClientDest(label ...string) {
if v, ok := c.Get("destination", label...); ok {
c.ClientDest = v
} else {
c.ClientDest = v
c.ClientDest = ""
}
}

View File

@ -4,6 +4,7 @@ import (
"github.com/eyedeekay/httptunnel"
"github.com/eyedeekay/httptunnel/multiproxy"
"github.com/eyedeekay/sam-forwarder/config"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam-forwarder/tcp"
"github.com/eyedeekay/sam-forwarder/udp"
)
@ -107,40 +108,40 @@ func NewSAMBrowserClientFromConfig(iniFile, SamHost, SamPort string, label ...st
func NewSAMClientForwarderFromConf(config *i2ptunconf.Conf) (*samforwarder.SAMClientForwarder, error) {
if config != nil {
return samforwarder.NewSAMClientForwarderFromOptions(
samforwarder.SetClientSaveFile(config.SaveFile),
samforwarder.SetClientFilePath(config.SaveDirectory),
samforwarder.SetClientHost(config.TargetHost),
samforwarder.SetClientPort(config.TargetPort),
samforwarder.SetClientSAMHost(config.SamHost),
samforwarder.SetClientSAMPort(config.SamPort),
samforwarder.SetClientSigType(config.SigType),
samforwarder.SetClientName(config.TunName),
samforwarder.SetClientInLength(config.InLength),
samforwarder.SetClientOutLength(config.OutLength),
samforwarder.SetClientInVariance(config.InVariance),
samforwarder.SetClientOutVariance(config.OutVariance),
samforwarder.SetClientInQuantity(config.InQuantity),
samforwarder.SetClientOutQuantity(config.OutQuantity),
samforwarder.SetClientInBackups(config.InBackupQuantity),
samforwarder.SetClientOutBackups(config.OutBackupQuantity),
samforwarder.SetClientEncrypt(config.EncryptLeaseSet),
samforwarder.SetClientLeaseSetKey(config.LeaseSetKey),
samforwarder.SetClientLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samforwarder.SetClientLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samforwarder.SetClientAllowZeroIn(config.InAllowZeroHop),
samforwarder.SetClientAllowZeroOut(config.OutAllowZeroHop),
samforwarder.SetClientFastRecieve(config.FastRecieve),
samforwarder.SetClientCompress(config.UseCompression),
samforwarder.SetClientReduceIdle(config.ReduceIdle),
samforwarder.SetClientReduceIdleTimeMs(config.ReduceIdleTime),
samforwarder.SetClientReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarder.SetClientCloseIdle(config.CloseIdle),
samforwarder.SetClientCloseIdleTimeMs(config.CloseIdleTime),
samforwarder.SetClientAccessListType(config.AccessListType),
samforwarder.SetClientAccessList(config.AccessList),
samforwarder.SetClientMessageReliability(config.MessageReliability),
samforwarder.SetClientPassword(config.KeyFilePath),
samforwarder.SetClientDestination(config.ClientDest),
samoptions.SetSaveFile(config.SaveFile),
samoptions.SetFilePath(config.SaveDirectory),
samoptions.SetHost(config.TargetHost),
samoptions.SetPort(config.TargetPort),
samoptions.SetSAMHost(config.SamHost),
samoptions.SetSAMPort(config.SamPort),
samoptions.SetSigType(config.SigType),
samoptions.SetName(config.TunName),
samoptions.SetInLength(config.InLength),
samoptions.SetOutLength(config.OutLength),
samoptions.SetInVariance(config.InVariance),
samoptions.SetOutVariance(config.OutVariance),
samoptions.SetInQuantity(config.InQuantity),
samoptions.SetOutQuantity(config.OutQuantity),
samoptions.SetInBackups(config.InBackupQuantity),
samoptions.SetOutBackups(config.OutBackupQuantity),
samoptions.SetEncrypt(config.EncryptLeaseSet),
samoptions.SetLeaseSetKey(config.LeaseSetKey),
samoptions.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samoptions.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samoptions.SetAllowZeroIn(config.InAllowZeroHop),
samoptions.SetAllowZeroOut(config.OutAllowZeroHop),
samoptions.SetFastRecieve(config.FastRecieve),
samoptions.SetCompress(config.UseCompression),
samoptions.SetReduceIdle(config.ReduceIdle),
samoptions.SetReduceIdleTimeMs(config.ReduceIdleTime),
samoptions.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samoptions.SetCloseIdle(config.CloseIdle),
samoptions.SetCloseIdleTimeMs(config.CloseIdleTime),
samoptions.SetAccessListType(config.AccessListType),
samoptions.SetAccessList(config.AccessList),
samoptions.SetMessageReliability(config.MessageReliability),
samoptions.SetPassword(config.KeyFilePath),
samoptions.SetDestination(config.ClientDest),
)
}
return nil, nil
@ -164,50 +165,50 @@ func NewSAMClientForwarderFromConfig(iniFile, SamHost, SamPort string, label ...
return nil, nil
}
// NewSAMSSUClientForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
func NewSAMSSUClientForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMSSUClientForwarder, error) {
// NewSAMDGClientForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
func NewSAMDGClientForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMDGClientForwarder, error) {
if config != nil {
return samforwarderudp.NewSAMSSUClientForwarderFromOptions(
samforwarderudp.SetClientSaveFile(config.SaveFile),
samforwarderudp.SetClientFilePath(config.SaveDirectory),
samforwarderudp.SetClientHost(config.TargetHost),
samforwarderudp.SetClientPort(config.TargetPort),
samforwarderudp.SetClientSAMHost(config.SamHost),
samforwarderudp.SetClientSAMPort(config.SamPort),
samforwarderudp.SetClientSigType(config.SigType),
samforwarderudp.SetClientName(config.TunName),
samforwarderudp.SetClientInLength(config.InLength),
samforwarderudp.SetClientOutLength(config.OutLength),
samforwarderudp.SetClientInVariance(config.InVariance),
samforwarderudp.SetClientOutVariance(config.OutVariance),
samforwarderudp.SetClientInQuantity(config.InQuantity),
samforwarderudp.SetClientOutQuantity(config.OutQuantity),
samforwarderudp.SetClientInBackups(config.InBackupQuantity),
samforwarderudp.SetClientOutBackups(config.OutBackupQuantity),
samforwarderudp.SetClientEncrypt(config.EncryptLeaseSet),
samforwarderudp.SetClientLeaseSetKey(config.LeaseSetKey),
samforwarderudp.SetClientLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samforwarderudp.SetClientLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samforwarderudp.SetClientAllowZeroIn(config.InAllowZeroHop),
samforwarderudp.SetClientAllowZeroOut(config.OutAllowZeroHop),
samforwarderudp.SetClientFastRecieve(config.FastRecieve),
samforwarderudp.SetClientCompress(config.UseCompression),
samforwarderudp.SetClientReduceIdle(config.ReduceIdle),
samforwarderudp.SetClientReduceIdleTimeMs(config.ReduceIdleTime),
samforwarderudp.SetClientReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarderudp.SetClientCloseIdle(config.CloseIdle),
samforwarderudp.SetClientCloseIdleTimeMs(config.CloseIdleTime),
samforwarderudp.SetClientAccessListType(config.AccessListType),
samforwarderudp.SetClientAccessList(config.AccessList),
samforwarderudp.SetClientMessageReliability(config.MessageReliability),
samforwarderudp.SetClientPassword(config.KeyFilePath),
samforwarderudp.SetClientDestination(config.ClientDest),
return samforwarderudp.NewSAMDGClientForwarderFromOptions(
samoptions.SetSaveFile(config.SaveFile),
samoptions.SetFilePath(config.SaveDirectory),
samoptions.SetHost(config.TargetHost),
samoptions.SetPort(config.TargetPort),
samoptions.SetSAMHost(config.SamHost),
samoptions.SetSAMPort(config.SamPort),
samoptions.SetSigType(config.SigType),
samoptions.SetName(config.TunName),
samoptions.SetInLength(config.InLength),
samoptions.SetOutLength(config.OutLength),
samoptions.SetInVariance(config.InVariance),
samoptions.SetOutVariance(config.OutVariance),
samoptions.SetInQuantity(config.InQuantity),
samoptions.SetOutQuantity(config.OutQuantity),
samoptions.SetInBackups(config.InBackupQuantity),
samoptions.SetOutBackups(config.OutBackupQuantity),
samoptions.SetEncrypt(config.EncryptLeaseSet),
samoptions.SetLeaseSetKey(config.LeaseSetKey),
samoptions.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samoptions.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samoptions.SetAllowZeroIn(config.InAllowZeroHop),
samoptions.SetAllowZeroOut(config.OutAllowZeroHop),
samoptions.SetFastRecieve(config.FastRecieve),
samoptions.SetCompress(config.UseCompression),
samoptions.SetReduceIdle(config.ReduceIdle),
samoptions.SetReduceIdleTimeMs(config.ReduceIdleTime),
samoptions.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samoptions.SetCloseIdle(config.CloseIdle),
samoptions.SetCloseIdleTimeMs(config.CloseIdleTime),
samoptions.SetAccessListType(config.AccessListType),
samoptions.SetAccessList(config.AccessList),
samoptions.SetMessageReliability(config.MessageReliability),
samoptions.SetPassword(config.KeyFilePath),
samoptions.SetDestination(config.ClientDest),
)
}
return nil, nil
}
func NewSAMSSUClientForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string) (*samforwarderudp.SAMSSUClientForwarder, error) {
func NewSAMDGClientForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string) (*samforwarderudp.SAMDGClientForwarder, error) {
if iniFile != "none" {
config, err := i2ptunconf.NewI2PTunConf(iniFile, label...)
if err != nil {
@ -219,7 +220,7 @@ func NewSAMSSUClientForwarderFromConfig(iniFile, SamHost, SamPort string, label
if SamPort != "" && SamPort != "7656" {
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
}
return NewSAMSSUClientForwarderFromConf(config)
return NewSAMDGClientForwarderFromConf(config)
}
return nil, nil
}

View File

@ -3,6 +3,7 @@ package i2ptunhelper
import (
"github.com/eyedeekay/eephttpd"
"github.com/eyedeekay/sam-forwarder/config"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam-forwarder/tcp"
"github.com/eyedeekay/sam-forwarder/udp"
)
@ -11,41 +12,41 @@ import (
func NewSAMForwarderFromConf(config *i2ptunconf.Conf) (*samforwarder.SAMForwarder, error) {
if config != nil {
return samforwarder.NewSAMForwarderFromOptions(
samforwarder.SetType(config.Type),
samforwarder.SetSaveFile(config.SaveFile),
samforwarder.SetFilePath(config.SaveDirectory),
samforwarder.SetHost(config.TargetHost),
samforwarder.SetPort(config.TargetPort),
samforwarder.SetSAMHost(config.SamHost),
samforwarder.SetSAMPort(config.SamPort),
samforwarder.SetSigType(config.SigType),
samforwarder.SetName(config.TunName),
samforwarder.SetInLength(config.InLength),
samforwarder.SetOutLength(config.OutLength),
samforwarder.SetInVariance(config.InVariance),
samforwarder.SetOutVariance(config.OutVariance),
samforwarder.SetInQuantity(config.InQuantity),
samforwarder.SetOutQuantity(config.OutQuantity),
samforwarder.SetInBackups(config.InBackupQuantity),
samforwarder.SetOutBackups(config.OutBackupQuantity),
samforwarder.SetEncrypt(config.EncryptLeaseSet),
samforwarder.SetLeaseSetKey(config.LeaseSetKey),
samforwarder.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samforwarder.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samforwarder.SetAllowZeroIn(config.InAllowZeroHop),
samforwarder.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarder.SetFastRecieve(config.FastRecieve),
samforwarder.SetCompress(config.UseCompression),
samforwarder.SetReduceIdle(config.ReduceIdle),
samforwarder.SetReduceIdleTimeMs(config.ReduceIdleTime),
samforwarder.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarder.SetCloseIdle(config.CloseIdle),
samforwarder.SetCloseIdleTimeMs(config.CloseIdleTime),
samforwarder.SetAccessListType(config.AccessListType),
samforwarder.SetAccessList(config.AccessList),
samforwarder.SetMessageReliability(config.MessageReliability),
samforwarder.SetKeyFile(config.KeyFilePath),
//samforwarder.SetTargetForPort443(config.TargetForPort443),
samoptions.SetType(config.Type),
samoptions.SetSaveFile(config.SaveFile),
samoptions.SetFilePath(config.SaveDirectory),
samoptions.SetHost(config.TargetHost),
samoptions.SetPort(config.TargetPort),
samoptions.SetSAMHost(config.SamHost),
samoptions.SetSAMPort(config.SamPort),
samoptions.SetSigType(config.SigType),
samoptions.SetName(config.TunName),
samoptions.SetInLength(config.InLength),
samoptions.SetOutLength(config.OutLength),
samoptions.SetInVariance(config.InVariance),
samoptions.SetOutVariance(config.OutVariance),
samoptions.SetInQuantity(config.InQuantity),
samoptions.SetOutQuantity(config.OutQuantity),
samoptions.SetInBackups(config.InBackupQuantity),
samoptions.SetOutBackups(config.OutBackupQuantity),
samoptions.SetEncrypt(config.EncryptLeaseSet),
samoptions.SetLeaseSetKey(config.LeaseSetKey),
samoptions.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samoptions.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samoptions.SetAllowZeroIn(config.InAllowZeroHop),
samoptions.SetAllowZeroOut(config.OutAllowZeroHop),
samoptions.SetFastRecieve(config.FastRecieve),
samoptions.SetCompress(config.UseCompression),
samoptions.SetReduceIdle(config.ReduceIdle),
samoptions.SetReduceIdleTimeMs(config.ReduceIdleTime),
samoptions.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samoptions.SetCloseIdle(config.CloseIdle),
samoptions.SetCloseIdleTimeMs(config.CloseIdleTime),
samoptions.SetAccessListType(config.AccessListType),
samoptions.SetAccessList(config.AccessList),
samoptions.SetMessageReliability(config.MessageReliability),
samoptions.SetKeyFile(config.KeyFilePath),
//samoptions.SetTargetForPort443(config.TargetForPort443),
)
}
return nil, nil
@ -69,50 +70,50 @@ func NewSAMForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string
return nil, nil
}
// NewSAMSSUForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
func NewSAMSSUForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMSSUForwarder, error) {
// NewSAMDGForwarderFromConf generates a SAMSSUforwarder from *i2ptunconf.Conf
func NewSAMDGForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMDGForwarder, error) {
if config != nil {
return samforwarderudp.NewSAMSSUForwarderFromOptions(
samforwarderudp.SetSaveFile(config.SaveFile),
samforwarderudp.SetFilePath(config.SaveDirectory),
samforwarderudp.SetHost(config.TargetHost),
samforwarderudp.SetPort(config.TargetPort),
samforwarderudp.SetSAMHost(config.SamHost),
samforwarderudp.SetSAMPort(config.SamPort),
samforwarderudp.SetSigType(config.SigType),
samforwarderudp.SetName(config.TunName),
samforwarderudp.SetInLength(config.InLength),
samforwarderudp.SetOutLength(config.OutLength),
samforwarderudp.SetInVariance(config.InVariance),
samforwarderudp.SetOutVariance(config.OutVariance),
samforwarderudp.SetInQuantity(config.InQuantity),
samforwarderudp.SetOutQuantity(config.OutQuantity),
samforwarderudp.SetInBackups(config.InBackupQuantity),
samforwarderudp.SetOutBackups(config.OutBackupQuantity),
samforwarderudp.SetEncrypt(config.EncryptLeaseSet),
samforwarderudp.SetLeaseSetKey(config.LeaseSetKey),
samforwarderudp.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samforwarderudp.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samforwarderudp.SetAllowZeroIn(config.InAllowZeroHop),
samforwarderudp.SetAllowZeroOut(config.OutAllowZeroHop),
samforwarderudp.SetFastRecieve(config.FastRecieve),
samforwarderudp.SetCompress(config.UseCompression),
samforwarderudp.SetReduceIdle(config.ReduceIdle),
samforwarderudp.SetReduceIdleTimeMs(config.ReduceIdleTime),
samforwarderudp.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samforwarderudp.SetCloseIdle(config.CloseIdle),
samforwarderudp.SetCloseIdleTimeMs(config.CloseIdleTime),
samforwarderudp.SetAccessListType(config.AccessListType),
samforwarderudp.SetAccessList(config.AccessList),
samforwarderudp.SetMessageReliability(config.MessageReliability),
samforwarderudp.SetKeyFile(config.KeyFilePath),
return samforwarderudp.NewSAMDGForwarderFromOptions(
samoptions.SetSaveFile(config.SaveFile),
samoptions.SetFilePath(config.SaveDirectory),
samoptions.SetHost(config.TargetHost),
samoptions.SetPort(config.TargetPort),
samoptions.SetSAMHost(config.SamHost),
samoptions.SetSAMPort(config.SamPort),
samoptions.SetSigType(config.SigType),
samoptions.SetName(config.TunName),
samoptions.SetInLength(config.InLength),
samoptions.SetOutLength(config.OutLength),
samoptions.SetInVariance(config.InVariance),
samoptions.SetOutVariance(config.OutVariance),
samoptions.SetInQuantity(config.InQuantity),
samoptions.SetOutQuantity(config.OutQuantity),
samoptions.SetInBackups(config.InBackupQuantity),
samoptions.SetOutBackups(config.OutBackupQuantity),
samoptions.SetEncrypt(config.EncryptLeaseSet),
samoptions.SetLeaseSetKey(config.LeaseSetKey),
samoptions.SetLeaseSetPrivateKey(config.LeaseSetPrivateKey),
samoptions.SetLeaseSetPrivateSigningKey(config.LeaseSetPrivateSigningKey),
samoptions.SetAllowZeroIn(config.InAllowZeroHop),
samoptions.SetAllowZeroOut(config.OutAllowZeroHop),
samoptions.SetFastRecieve(config.FastRecieve),
samoptions.SetCompress(config.UseCompression),
samoptions.SetReduceIdle(config.ReduceIdle),
samoptions.SetReduceIdleTimeMs(config.ReduceIdleTime),
samoptions.SetReduceIdleQuantity(config.ReduceIdleQuantity),
samoptions.SetCloseIdle(config.CloseIdle),
samoptions.SetCloseIdleTimeMs(config.CloseIdleTime),
samoptions.SetAccessListType(config.AccessListType),
samoptions.SetAccessList(config.AccessList),
samoptions.SetMessageReliability(config.MessageReliability),
samoptions.SetKeyFile(config.KeyFilePath),
)
}
return nil, nil
}
// NewSAMSSUForwarderFromConfig generates a new SAMSSUForwarder from a config file
func NewSAMSSUForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string) (*samforwarderudp.SAMSSUForwarder, error) {
// NewSAMDGForwarderFromConfig generates a new SAMDGForwarder from a config file
func NewSAMDGForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string) (*samforwarderudp.SAMDGForwarder, error) {
if iniFile != "none" {
config, err := i2ptunconf.NewI2PTunConf(iniFile, label...)
if err != nil {
@ -124,7 +125,7 @@ func NewSAMSSUForwarderFromConfig(iniFile, SamHost, SamPort string, label ...str
if SamPort != "" && SamPort != "7656" {
config.SamPort = config.GetSAMPort(SamPort, config.SamPort)
}
return NewSAMSSUForwarderFromConf(config)
return NewSAMDGForwarderFromConf(config)
}
return nil, nil
}

View File

@ -103,3 +103,29 @@ func (c *Conf) SetLeasesetPrivateSigningKey(label ...string) {
c.LeaseSetPrivateSigningKey = ""
}
}
// GetLeaseSetEncType takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
// default is returned.
func (c *Conf) GetLeaseSetEncType(arg, def string, label ...string) string {
if arg != def {
return arg
}
if c.Config == nil {
return arg
}
if x, o := c.Get("i2cp.leaseSetEncType", label...); o {
return x
}
return arg
}
// SetLeaseSetEncType tells the conf to use encrypted leasesets the from the config file
func (c *Conf) SetLeaseSetEncType(label ...string) {
if v, ok := c.Get("i2cp.leaseSetEncType", label...); ok {
c.LeaseSetEncType = v
} else {
c.LeaseSetEncType = ""
}
}

View File

@ -1,5 +1,12 @@
package i2ptunconf
import (
"crypto/tls"
"strings"
"github.com/eyedeekay/sam-forwarder/tls"
)
// GetPort443 takes an argument and a default. If the argument differs from the
// default, the argument is always returned. If the argument and default are
// the same and the key exists, the key is returned. If the key is absent, the
@ -25,3 +32,80 @@ func (c *Conf) SetTargetPort443(label ...string) {
c.TargetForPort443 = ""
}
}
// Get
func (c *Conf) GetUseTLS(arg, def bool, label ...string) bool {
if arg != def {
return arg
}
if c.Config == nil {
return arg
}
if x, o := c.GetBool("usetls", label...); o {
return x
}
return arg
}
// SetAllowZeroHopOut sets the config to allow zero-hop tunnels
func (c *Conf) SetUseTLS(label ...string) {
if v, ok := c.GetBool("usetls", label...); ok {
c.UseTLS = v
} else {
c.UseTLS = false
}
}
// GetTLSConfig
func (c *Conf) GetTLSConfigCertPem(arg, def string, label ...string) string {
if arg != def {
return arg
}
if c.Config == nil {
return arg
}
if x, o := c.Get("cert.pem", label...); o {
return x
}
return arg
}
// SetClientDest sets the key name from the config file
func (c *Conf) SetTLSConfigCertPem(label ...string) {
if v, ok := c.Get("cert.pem", label...); ok {
c.Cert = v
} else {
c.Cert = ""
}
}
// GetTLSConfig
func (c *Conf) GetTLSConfigKeyPem(arg, def string, label ...string) string {
if arg != def {
return arg
}
if c.Config == nil {
return arg
}
if x, o := c.Get("key.pem", label...); o {
return x
}
return arg
}
// SetClientDest sets the key name from the config file
func (c *Conf) SetTLSConfigKeyPem(label ...string) {
if v, ok := c.Get("key.pem", label...); ok {
c.Pem = v
} else {
c.Pem = ""
}
}
func (c *Conf) TLSConfig() (*tls.Config, error) {
names := []string{c.Base32()}
if c.HostName != "" && strings.HasSuffix(c.HostName, ".i2p") {
names = append(names, c.HostName)
}
return i2ptls.TLSConfig(c.Cert, c.Pem, names)
}

View File

@ -1,6 +1,7 @@
package i2ptunconf
import (
// "crypto/tls"
"io/ioutil"
"log"
"os"
@ -10,6 +11,7 @@ import (
)
import (
// "github.com/eyedeekay/sam3"
"github.com/eyedeekay/sam3/i2pkeys"
"github.com/zieckey/goini"
)
@ -17,54 +19,60 @@ import (
// Conf is a tructure containing an ini config, with some functions to help
// when you use it for in conjunction with command-line flags
type Conf struct {
Config *goini.INI
FilePath string
KeyFilePath string
Labels []string
Client bool
ClientDest string
SigType string
Type string
SaveDirectory string
ServeDirectory string
SaveFile bool
TargetHost string
TargetPort string
SamHost string
SamPort string
TunnelHost string
ControlHost string
ControlPort string
TargetForPort443 string
TunName string
EncryptLeaseSet bool
LeaseSetKey string
LeaseSetPrivateKey string
LeaseSetPrivateSigningKey string
InAllowZeroHop bool
OutAllowZeroHop bool
InLength int
OutLength int
InQuantity int
OutQuantity int
InVariance int
OutVariance int
InBackupQuantity int
OutBackupQuantity int
UseCompression bool
FastRecieve bool
ReduceIdle bool
ReduceIdleTime int
ReduceIdleQuantity int
CloseIdle bool
CloseIdleTime int
AccessListType string
AccessList []string
MessageReliability string
exists bool
UserName string
Password string
LoadedKeys i2pkeys.I2PKeys
Config *goini.INI `default:&goini.INI{}`
FilePath string `default:"./"`
KeyFilePath string `default:"./"`
Labels []string `default:{""}`
Client bool `default:true`
ClientDest string `default:"idk.i2p"`
SigType string `default:"SIGNATURE_TYPE=EdDSA_SHA512_Ed25519"`
Type string `default:"client"`
SaveDirectory string `default:"./"`
ServeDirectory string `default:"./www"`
SaveFile bool `default:false`
TargetHost string `default:"127.0.0.1"`
TargetPort string `default:"7778"`
SamHost string `default:"127.0.0.1"`
SamPort string `default:"7656"`
TunnelHost string `default:"127.0.0.1"`
ControlHost string `default:"127.0.0.1"`
ControlPort string `default:"7951"`
TargetForPort443 string `default:""`
TunName string `default:"goi2ptunnel"`
EncryptLeaseSet bool `default:false`
LeaseSetKey string `default:""`
LeaseSetEncType string `default:"4,0"`
LeaseSetPrivateKey string `default:""`
LeaseSetPrivateSigningKey string `default:""`
InAllowZeroHop bool `default:false`
OutAllowZeroHop bool `default:false`
InLength int `default:3`
OutLength int `default:3`
InQuantity int `default:1`
OutQuantity int `default:1`
InVariance int `default:0`
OutVariance int `default:0`
InBackupQuantity int `default:1`
OutBackupQuantity int `default:1`
UseCompression bool `default:true`
FastRecieve bool `default:true`
ReduceIdle bool `default:false`
ReduceIdleTime int `default:36000000`
ReduceIdleQuantity int `default:1`
CloseIdle bool `default:false`
CloseIdleTime int `default:36000000`
AccessListType string `default:"none"`
AccessList []string `default:{""}`
MessageReliability string `default:""`
exists bool `default:false`
UserName string `default:""`
Password string `default:""`
UseTLS bool `default:false`
Cert string `default:""`
Pem string `default:""`
HostName string `default:""`
//TLSConf *tls.Config
LoadedKeys i2pkeys.I2PKeys
}
// PrintSlice returns and prints a formatted list of configured tunnel settings.
@ -245,6 +253,7 @@ func (c *Conf) I2PINILoad(iniFile string, label ...string) error {
c.SetTunName(label...)
c.SetSigType(label...)
c.SetEncryptLease(label...)
c.SetLeaseSetEncType(label...)
c.SetLeasesetKey(label...)
c.SetLeasesetPrivateKey(label...)
c.SetLeasesetPrivateSigningKey(label...)
@ -275,6 +284,9 @@ func (c *Conf) I2PINILoad(iniFile string, label ...string) error {
c.SetControlHost(label...)
c.SetControlPort(label...)
c.SetWWWDir(label...)
c.SetUseTLS(label...)
c.SetTLSConfigCertPem(label...)
c.SetTLSConfigKeyPem(label...)
if v, ok := c.Get("i2cp.accessList", label...); ok {
csv := strings.Split(v, ",")
for _, z := range csv {
@ -287,11 +299,19 @@ func (c *Conf) I2PINILoad(iniFile string, label ...string) error {
// NewI2PBlankTunConf returns an empty but intialized tunconf
func NewI2PBlankTunConf() *Conf {
var c Conf
// var c Conf
c := new(Conf)
c.SamHost = "127.0.0.1"
c.SamPort = "7656"
c.TunName = "unksam"
c.TargetHost = "127.0.0.1"
c.TargetPort = "0"
c.ClientDest = "idk.i2p"
c.LeaseSetEncType = "4,0"
c.Config = &goini.INI{}
c.Config = goini.New()
c.Config.Parse([]byte(""), "\n", "=")
return &c
c.Config.Parse([]byte("[client]\nsamhost=\"127.0.0.1\"\nsamport=\"7656\"\n"), "\n", "=")
return c
}
// NewI2PTunConf returns a Conf structure from an ini file, for modification

View File

@ -13,7 +13,7 @@ usage:
flag needs an argument: -h
Usage of ./bin/samcatd:
-a string
Type of access list to use, can be "whitelist" "blacklist" or "none". (default "none")
Type of access list to use, can be "allowlist" "blocklist" or "none". (default "none")
-c Client proxy mode(true or false)
-conv string
Display the base32 and base64 values of a specified .i2pkeys file

View File

@ -53,12 +53,12 @@
[*] - i2cp.tcp.port 1-65535 7654 Router I2CP port. If the client is running in the same JVM as a router, this option is ignored, and the client connects to that router internally.
Default Description
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blacklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a whitelist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a whitelist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blacklist for incoming connections. As of release 0.7.13.
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blocklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a allowlist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a allowlist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blocklist for incoming connections. As of release 0.7.13.
[U] - i2p.streaming.answerPings true Whether to respond to incoming pings
[U] - i2p.streaming.blacklist null Comma- or space-separated list of Base64 peer Hashes to be blacklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.blocklist null Comma- or space-separated list of Base64 peer Hashes to be blocklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.bufferSize 64K How much transmit data (in bytes) will be accepted that hasn&#39;t been written out yet.
[U] - i2p.streaming.congestionAvoidanceGrowthRateFactor 1 When we&#39;re in congestion avoidance, we grow the window size at the rate of 1/(windowSize*factor). In standard TCP, window sizes are in bytes, while in I2P, window sizes are in messages. A higher number means slower growth.
[U] - i2p.streaming.connectDelay -1 How long to wait after instantiating a new con before actually attempting to connect. If this is &lt;= 0, connect immediately with no initial data. If greater than 0, wait until the output stream is flushed, the buffer fills, or that many milliseconds pass, and include any initial data with the SYN.

View File

@ -58,12 +58,12 @@ key:
[*] - i2cp.tcp.port 1-65535 7654 Router I2CP port. If the client is running in the same JVM as a router, this option is ignored, and the client connects to that router internally.
Default Description
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blacklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a whitelist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a whitelist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blacklist for incoming connections. As of release 0.7.13.
[C] - i2cp.accessList null Comma- or space-separated list of Base64 peer Hashes used for either access list or blocklist. As of release 0.7.13.
[U] - i2cp.destination.sigType DSA_SHA1 Use the access list as a allowlist for incoming connections. The name or number of the signature type for a transient destination. As of release 0.9.12.
[C] - i2cp.enableAccessList false Use the access list as a allowlist for incoming connections. As of release 0.7.13.
[C] - i2cp.enableBlackList false Use the access list as a blocklist for incoming connections. As of release 0.7.13.
[U] - i2p.streaming.answerPings true Whether to respond to incoming pings
[U] - i2p.streaming.blacklist null Comma- or space-separated list of Base64 peer Hashes to be blacklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.blocklist null Comma- or space-separated list of Base64 peer Hashes to be blocklisted for incoming connections to ALL destinations in the context. This option must be set in the context properties, NOT in the createManager() options argument. Note that setting this in the router context will not affect clients outside the router in a separate JVM and context. As of release 0.9.3.
[U] - i2p.streaming.bufferSize 64K How much transmit data (in bytes) will be accepted that hasn't been written out yet.
[U] - i2p.streaming.congestionAvoidanceGrowthRateFactor 1 When we're in congestion avoidance, we grow the window size at the rate of 1/(windowSize*factor). In standard TCP, window sizes are in bytes, while in I2P, window sizes are in messages. A higher number means slower growth.
[U] - i2p.streaming.connectDelay -1 How long to wait after instantiating a new con before actually attempting to connect. If this is <= 0, connect immediately with no initial data. If greater than 0, wait until the output stream is flushed, the buffer fills, or that many milliseconds pass, and include any initial data with the SYN.

View File

@ -4,7 +4,7 @@
<pre><code>flag needs an argument: -h
Usage of ./bin/samcatd:
-a string
Type of access list to use, can be &quot;whitelist&quot; &quot;blacklist&quot; or &quot;none&quot;. (default &quot;none&quot;)
Type of access list to use, can be &quot;allowlist&quot; &quot;blocklist&quot; or &quot;none&quot;. (default &quot;none&quot;)
-c Client proxy mode(true or false)
-conv string
Display the base32 and base64 values of a specified .i2pkeys file

View File

@ -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
@ -40,22 +40,22 @@ outbound.length = 3
destination = i2p-projekt.i2p
keys = tcpclient
#[sam-forwarder-udp-server]
#type = udpserver
#host = 127.0.0.1
#port = 8084
#inbound.length = 6
#outbound.length = 3
#keys = udpserver
[sam-forwarder-udp-server]
type = udpserver
host = 127.0.0.1
port = 8084
inbound.length = 3
outbound.length = 3
keys = udpserver
#[sam-forwarder-udp-client]
#type = udpclient
#host = 127.0.0.1
#port = 8083
#inbound.length = 3
#outbound.length = 3
#destination = pointmeatatrealudpserveritwillbreakwithoutone.b32.i2p
#keys = udpclient
[sam-forwarder-udp-client]
type = udpclient
host = 127.0.0.1
port = 8083
inbound.length = 3
outbound.length = 3
destination = icdj5g5u4jwwyjoinucty223s2yrq6pzxcqfwmyrmkp7ssn2fjlq.b32.i2p
keys = udpclient
[sam-forwarder-tcp-http-server]
type = http

85
go.sum Normal file
View File

@ -0,0 +1,85 @@
crawshaw.io/littleboss v0.0.0-20190317185602-8957d0aedcce h1:4VyRNGOpNgP9ioTYZ7ah3x8C28I7wsMt4Ao9nTXv2ec=
crawshaw.io/littleboss v0.0.0-20190317185602-8957d0aedcce/go.mod h1:TIbCAHgttUfOKudw59Il7Z0XIlitzo228/mtwMe4vPM=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/boreq/friendlyhash v0.0.0-20190522010448-1ca64b3ca69e h1:2q8XPjAYhXX8H71AoAPdgBrCUA3HPhC4ax8XHrTsY6I=
github.com/boreq/friendlyhash v0.0.0-20190522010448-1ca64b3ca69e/go.mod h1:y80zLCg0QS5u3fJKeF2rwpezcyZuCpZpbFcWv6Pn98w=
github.com/cryptix/go v1.3.1/go.mod h1:mFQotm9rTzptzvNjJM+1vSIDa/rVOVqMu0889GIXg70=
github.com/cryptix/goSam v0.1.0/go.mod h1:7ewkjhXT8V5RG07pvWUOHHtMahvGbeKlEv8ukUyRiTA=
github.com/d5/tengo v1.24.3 h1:wp44VW7fdfzMzIDT19tT5uNeGnm2UMd6s3TLAahrwSU=
github.com/d5/tengo v1.24.3/go.mod h1:VhLq8Q2QFhCIJO3NhvM934qOThykMqJi9y9Siqd1ocQ=
github.com/eyedeekay/eephttpd v0.0.0-20190903000420-52f5a8485a4e h1:YizBXWVO0QN/1vkcdXXGenBS0bJAHgJcG+2WO22im0Y=
github.com/eyedeekay/eephttpd v0.0.0-20190903000420-52f5a8485a4e/go.mod h1:wFPQsNBnY95LkuujFEZARo7slafRwoF0D97FFHBoZro=
github.com/eyedeekay/goSam v0.1.1-0.20190814204230-d4c9b8c57dd6 h1:+5eM/MhjGMWCGQCCqn9pb1bmvoRewweWhOaE6fA7kZ0=
github.com/eyedeekay/goSam v0.1.1-0.20190814204230-d4c9b8c57dd6/go.mod h1:kGTfZrncJ4CwMX3d1qA6bcMJTOcuTbOqgWg7WrFNAQ0=
github.com/eyedeekay/httptunnel v0.0.0-20190831065052-9eab288b8a82/go.mod h1:VeXBZz04xj4eUGAcD8ygn2WFxY/dAvRbSNYMWoDzMxc=
github.com/eyedeekay/httptunnel v0.0.0-20190831071439-0ff3d5f798fb h1:jxY4AjQDgkeG2WBop17iJrKcwulVF+fOakOWSiIVcwY=
github.com/eyedeekay/httptunnel v0.0.0-20190831071439-0ff3d5f798fb/go.mod h1:SnCAM9CskhwSFkzDfh+H5yNTbvhcTeKekkuX0ejCcSk=
github.com/eyedeekay/i2pdig v0.0.0-20180718204453-a67cb46e2e5f/go.mod h1:Zp2JSsndmRykjDGbNS5QHnCYCLnOeYFvwuZFwsATz8k=
github.com/eyedeekay/outproxy v0.0.0-20190908174238-22bd71d43733 h1:bm9QcH6cMUUKQ9cOiTgTVLaU9FwhvwecxCSZepKTMcU=
github.com/eyedeekay/outproxy v0.0.0-20190908174238-22bd71d43733/go.mod h1:jUBr6XRbiuUBe/sSbVdO5upU4mp8842bdpXDsQY54Rc=
github.com/eyedeekay/portcheck v0.0.0-20190218044454-bb8718669680 h1:wZxtUXCp5cOF5gB6PGeUny7ljGFcK6YKFfU7Sf8JBLc=
github.com/eyedeekay/portcheck v0.0.0-20190218044454-bb8718669680/go.mod h1:8VVIH19/CU2VFJB8P6e58Mo9nvDqqKgllS0oQY3F83U=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab h1:EfTRHxGSbiaEyxNzvKRBWVIDw3mD8xXGxj4gvwFzY7Q=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc=
github.com/eyedeekay/sam-forwarder v0.0.0-20190814201550-7c0d7cb0d56c/go.mod h1:Ptrm1d4a3KC5/cN264Gn6OntYOmcuJ8Pkyd7+hA01gw=
github.com/eyedeekay/sam-forwarder v0.0.0-20190831071254-d67c0c0e311f/go.mod h1:u4K8aGwSIuMSQ/OzsH7zkshnEvCQgUupfexLXZIjsDI=
github.com/eyedeekay/sam-forwarder v0.0.0-20190905212604-029317222e15/go.mod h1:kFP6jkqHUTGGW/nMUZLnRonkPWE9fyEc8/eSU1CqTFg=
github.com/eyedeekay/sam3 v0.0.0-20190613034117-99ad6522ebe3/go.mod h1:Vrxh+71E3HVYqyRlT5Jg+E26sSuu8UNTLB4p8qyT408=
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM=
github.com/eyedeekay/sam3 v0.32.1 h1:xaquh9Sxyuxh0SKyv3Gh6wXcZ5QAfWC4Iz4IsjVSESk=
github.com/eyedeekay/sam3 v0.32.1/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM=
github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-stack/stack v1.7.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69 h1:7xsUJsB2NrdcttQPa7JLEaGzvdbk7KvfrjgHZXOQRo0=
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69/go.mod h1:YLEMZOtU+AZ7dhN9T/IpGhXVGly2bvkJQ+zxj3WeVQo=
github.com/justinas/nosurf v0.0.0-20190416172904-05988550ea18 h1:ci3v0mUqcCewO25ntt7hprt2ZMNA0AWI6s6qV0rSpc0=
github.com/justinas/nosurf v0.0.0-20190416172904-05988550ea18/go.mod h1:Aucr5I5chr4OCuuVB4LTuHVrKHBuyRSo7vM2hqrcb7E=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/miolini/datacounter v0.0.0-20171104152933-fd4e42a1d5e0/go.mod h1:P6fDJzlxN+cWYR09KbE9/ta+Y6JofX9tAUhJpWkWPaM=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 h1:E0lEWrifmR0ACbGf5PLji1XbW6rtIXLHCXO/YOqi0AE=
github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26/go.mod h1:TQpdgg7I9+PFIkatlx/dnZyZb4iZyCUx1HJj4rXi3+E=
github.com/zserge/lorca v0.1.8 h1:gZwyvesmaoGCwxF5NssI6pdydXkCVHOoHw2nks/PBRs=
github.com/zserge/lorca v0.1.8/go.mod h1:gTrVdXKyWxNhc8aUb1Uu3s0mY343arR1T6jUtxmBxR8=
github.com/zserge/webview v0.0.0-20190123072648-16c93bcaeaeb h1:zVjnyZIM7UtkG3dNckiudIm+TUHkZqi5xlVQPd3J6/c=
github.com/zserge/webview v0.0.0-20190123072648-16c93bcaeaeb/go.mod h1:a1CV8KR4Dd1eP2g+mEijGOp+HKczwdKHWyx0aPHKvo4=
gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a h1:Ax7kdHNICZiIeFpmevmaEWb0Ae3BUj3zCTKhZHZ+zd0=
gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a/go.mod h1:JT4uoTz0tfPoyVH88GZoWDNm5NHJI2VbUW+eyPClueI=
gitlab.com/golang-commonmark/linkify v0.0.0-20180917065525-c22b7bdb1179 h1:rbON2KwBnWuFMlSHM8LELLlwroDRZw6xv0e6il6e5dk=
gitlab.com/golang-commonmark/linkify v0.0.0-20180917065525-c22b7bdb1179/go.mod h1:Gn+LZmCrhPECMD3SOKlE+BOHwhOYD9j7WT9NUtkCrC8=
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f h1:jwXy/CsM4xS2aoiF2fHAlukmInWhd2TlWB+HDCyvzKc=
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f/go.mod h1:SIHlEr9462fpIfTrVWf3GqQDxnA65Vm3BMMsUtuA6W0=
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2 h1:wD/sPUgx2QJFPTyXZpJnLaROolfeKuruh06U4pRV0WY=
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2/go.mod h1:wQk4rLkWrdOPjUAtqJRJ10hIlseLSVYWP95PLrjDF9s=
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe h1:5kUPFAF52umOUPH12MuNUmyVTseJRNBftDl/KfsvX3I=
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe/go.mod h1:P9LSM1KVzrIstFgUaveuwiAm8PK5VTB3yJEU8kqlbrU=
gitlab.com/opennota/wd v0.0.0-20191124020556-236695b0ea63/go.mod h1:n0SNS6rmmsb705EuaYk2RDZyy+pcmwEAuwQkTOOjsu8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190830223141-573d9926052a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -60,29 +60,6 @@ func (m *TunnelHandlerMux) HandlerWrapper(h http.Handler) http.Handler {
})
}
func (m *TunnelHandlerMux) ColorHeader(h http.Handler, r *http.Request, w http.ResponseWriter) {
if !strings.HasSuffix(r.URL.Path, "color") {
h.ServeHTTP(w, r)
} else {
fmt.Fprintf(w, "<!DOCTYPE html>\n")
fmt.Fprintf(w, "<html>\n")
fmt.Fprintf(w, "<head>\n")
fmt.Fprintf(w, " <link rel=\"stylesheet\" href=\"/styles.css\">")
fmt.Fprintf(w, "</head>\n")
fmt.Fprintf(w, "<body>\n")
fmt.Fprintf(w, "<h1>\n")
w.Write([]byte(fmt.Sprintf("<a href=\"/index.html\">Welcome %s! you are serving %d tunnels. </a>\n", m.user, len(m.tunnels))))
fmt.Fprintf(w, "</h1>\n")
fmt.Fprintf(w, " <div id=\"toggleall\" class=\"global control\">\n")
fmt.Fprintf(w, " <a href=\"#\" onclick=\"toggle_visibility_class('%s');\">Show/Hide %s</a>\n", "prop", "all")
fmt.Fprintf(w, " </div>\n")
h.ServeHTTP(w, r)
fmt.Fprintf(w, " <script src=\"/scripts.js\"></script>\n")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
}
func (t *TunnelHandlerMux) Tunnels() []*TunnelHandler {
return t.tunnels
}

View File

@ -1,5 +1,11 @@
package samtunnelhandler
import (
"fmt"
"net/http"
"strings"
)
func DefaultCSS() string {
return `.server {
width: 63%;
@ -185,3 +191,70 @@ function toggle_visibility_class(id) {
toggle_visibility_class("prop")
`
}
func (t *TunnelHandler) ColorSpan(shortid string) string {
r := fmt.Sprintf(" <span id=\"toggle%s\" class=\"control\">\n", t.SAMTunnel.ID())
r += fmt.Sprintf(" <a href=\"#\" onclick=\"toggle_visibility_class('%s');\"> Show/Hide %s</a><br>\n", t.SAMTunnel.ID(), t.SAMTunnel.ID())
r += fmt.Sprintf(" <a href=\"/%s/color\">Tunnel page</a>\n", t.SAMTunnel.ID())
r += fmt.Sprintf(" </span>\n")
return r
}
func (t *TunnelHandler) ColorForm(shortid, tuntype string) string {
r := fmt.Sprintf(" </div>\n\n")
r += fmt.Sprintf(" <div id=\"%s\" class=\"%s control panel\" >", shortid+".control", tuntype)
r += fmt.Sprintf(" <form class=\"linkstyle\" name=\"start\" action=\"/%s\" method=\"post\">", shortid)
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"hidden\" value=\"start\" name=\"action\" />")
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"submit\" value=\".[START]\">")
r += fmt.Sprintf(" </form>")
r += fmt.Sprintf(" <form class=\"linkstyle\" name=\"stop\" action=\"/%s\" method=\"post\">", shortid)
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"hidden\" value=\"stop\" name=\"action\" />")
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"submit\" value=\".[STOP].\">")
r += fmt.Sprintf(" </form>")
r += fmt.Sprintf(" <form class=\"linkstyle\" name=\"restart\" action=\"/%s\" method=\"post\">", shortid)
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"hidden\" value=\"restart\" name=\"action\" />")
r += fmt.Sprintf(" <input class=\"linkstyle\" type=\"submit\" value=\"[RESTART].\">")
r += fmt.Sprintf(" </form>")
r += fmt.Sprintf(" <div id=\"%s.status\" class=\"%s status\">.[STATUS].</div>", shortid, shortid)
r += fmt.Sprintf(" </div>\n\n")
return r
}
func (t *TunnelHandler) ColorWrap(longid, shortid, key, tuntype, prop, value string) string {
r := fmt.Sprintf(" <div id=\"%s\" class=\"%s %s %s %s\" >\n", longid, shortid, key, tuntype, prop)
r += fmt.Sprintf(" <span id=\"%s\" class=\"key\">%s</span>=", longid, key)
r += fmt.Sprintf(" <textarea id=\"%s\" rows=\"1\" class=\"value\">%s</textarea>\n", longid, value)
r += fmt.Sprintf(" </div>\n\n")
return r
}
func (t *TunnelHandler) ColorDiv(shortid, tuntype string) string {
return fmt.Sprintf(" <div id=\"%s\" class=\"%s\" >", t.SAMTunnel.ID(), t.SAMTunnel.GetType())
}
func (m *TunnelHandlerMux) ColorHeader(h http.Handler, r *http.Request, w http.ResponseWriter) {
if !strings.HasSuffix(r.URL.Path, "color") {
h.ServeHTTP(w, r)
} else {
fmt.Fprintf(w, "<!DOCTYPE html>\n")
fmt.Fprintf(w, "<html>\n")
fmt.Fprintf(w, "<head>\n")
fmt.Fprintf(w, " <link rel=\"stylesheet\" href=\"/styles.css\">")
fmt.Fprintf(w, "</head>\n")
fmt.Fprintf(w, "<body>\n")
fmt.Fprintf(w, "<h1>\n")
w.Write([]byte(fmt.Sprintf("<a href=\"/index.html\">Welcome %s! you are serving %d tunnels. </a>\n", m.user, len(m.tunnels))))
fmt.Fprintf(w, "</h1>\n")
fmt.Fprintf(w, " <div id=\"toggleall\" class=\"global control\">\n")
fmt.Fprintf(w, " <a href=\"#\" onclick=\"toggle_visibility_class('%s');\">Show/Hide %s</a>\n", "prop", "all")
fmt.Fprintf(w, " </div>\n")
h.ServeHTTP(w, r)
fmt.Fprintf(w, " <script src=\"/scripts.js\"></script>\n")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
}

View File

@ -27,14 +27,18 @@ func (t *TunnelHandler) Printdivf(id, key, value string, rw http.ResponseWriter,
if key != "TunName" {
prop = "prop"
}
if strings.HasSuffix(req.URL.Path, "color") {
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s %s %s %s\" >\n", ID, t.SAMTunnel.ID(), key, t.SAMTunnel.GetType(), prop)
fmt.Fprintf(rw, " <span id=\"%s\" class=\"key\">%s</span>=", ID, key)
fmt.Fprintf(rw, " <textarea id=\"%s\" rows=\"1\" class=\"value\">%s</textarea>\n", ID, value)
fmt.Fprintf(rw, " </div>\n\n")
} else {
fmt.Fprintf(rw, "%s=%s\n", ID, t.SAMTunnel.ID())
fmt.Fprintf(rw, t.ColorWrap(ID, t.SAMTunnel.ID(), key, t.SAMTunnel.GetType(), prop, value))
}
func (t *TunnelHandler) Printf(id, key, value string, rw http.ResponseWriter, req *http.Request) {
if key == "" || value == "" {
return
}
ID := t.SAMTunnel.ID()
if id != "" {
ID = t.SAMTunnel.ID() + "." + id
}
fmt.Fprintf(rw, "%s=%s\n", ID, t.SAMTunnel.ID())
}
func PropSort(props map[string]string) []string {
@ -91,47 +95,27 @@ func (t *TunnelHandler) ControlForm(rw http.ResponseWriter, req *http.Request) {
func (t *TunnelHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
t.ControlForm(rw, req)
if strings.HasSuffix(req.URL.Path, "color") {
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s\" >", t.SAMTunnel.ID(), t.SAMTunnel.GetType())
}
t.Printdivf(t.SAMTunnel.ID(), "TunName", t.SAMTunnel.ID(), rw, req)
if strings.HasSuffix(req.URL.Path, "color") {
fmt.Fprintf(rw, " <span id=\"toggle%s\" class=\"control\">\n", t.SAMTunnel.ID())
fmt.Fprintf(rw, " <a href=\"#\" onclick=\"toggle_visibility_class('%s');\"> Show/Hide %s</a><br>\n", t.SAMTunnel.ID(), t.SAMTunnel.ID())
fmt.Fprintf(rw, " <a href=\"/%s/color\">Tunnel page</a>\n", t.SAMTunnel.ID())
fmt.Fprintf(rw, " </span>\n")
}
for _, value := range PropSort(t.SAMTunnel.Props()) {
key := strings.SplitN(value, "=", 2)[0]
val := strings.SplitN(value, "=", 2)[1]
if key != "TunName" {
t.Printdivf(key, key, val, rw, req)
fmt.Fprintf(rw, t.ColorDiv(t.SAMTunnel.ID(), t.SAMTunnel.GetType()))
t.Printdivf(t.SAMTunnel.ID(), "TunName", t.SAMTunnel.ID(), rw, req)
fmt.Fprintf(rw, t.ColorSpan(t.SAMTunnel.ID()))
for _, value := range PropSort(t.SAMTunnel.Props()) {
key := strings.SplitN(value, "=", 2)[0]
val := strings.SplitN(value, "=", 2)[1]
if key != "TunName" {
t.Printdivf(key, key, val, rw, req)
}
}
fmt.Fprintf(rw, t.ColorForm(t.SAMTunnel.ID(), t.SAMTunnel.GetType()))
} else {
t.Printf(t.SAMTunnel.ID(), "TunName", t.SAMTunnel.ID(), rw, req)
for _, value := range PropSort(t.SAMTunnel.Props()) {
key := strings.SplitN(value, "=", 2)[0]
val := strings.SplitN(value, "=", 2)[1]
if key != "TunName" {
t.Printf(key, key, val, rw, req)
}
}
}
if strings.HasSuffix(req.URL.Path, "color") {
fmt.Fprintf(rw, " </div>\n\n")
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s control panel\" >", t.SAMTunnel.ID()+".control", t.SAMTunnel.GetType())
fmt.Fprintf(rw, " <form class=\"linkstyle\" name=\"start\" action=\"/%s\" method=\"post\">", t.SAMTunnel.ID())
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"hidden\" value=\"start\" name=\"action\" />")
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"submit\" value=\".[START]\">")
fmt.Fprintf(rw, " </form>")
fmt.Fprintf(rw, " <form class=\"linkstyle\" name=\"stop\" action=\"/%s\" method=\"post\">", t.SAMTunnel.ID())
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"hidden\" value=\"stop\" name=\"action\" />")
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"submit\" value=\".[STOP].\">")
fmt.Fprintf(rw, " </form>")
fmt.Fprintf(rw, " <form class=\"linkstyle\" name=\"restart\" action=\"/%s\" method=\"post\">", t.SAMTunnel.ID())
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"hidden\" value=\"restart\" name=\"action\" />")
fmt.Fprintf(rw, " <input class=\"linkstyle\" type=\"submit\" value=\"[RESTART].\">")
fmt.Fprintf(rw, " </form>")
fmt.Fprintf(rw, " <div id=\"%s.status\" class=\"%s status\">.[STATUS].</div>", t.SAMTunnel.ID(), t.SAMTunnel.ID())
fmt.Fprintf(rw, " </div>\n\n")
}
}

View File

@ -1,462 +0,0 @@
package samtunnel
import (
"fmt"
"strconv"
)
//SetAccessListType tells the system to treat the accessList as a whitelist
func SetAccessListType(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if s == "whitelist" {
c.Config().AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.Config().AccessListType = "blacklist"
return nil
} else if s == "none" {
c.Config().AccessListType = ""
return nil
} else if s == "" {
c.Config().AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetAccessList tells the system to treat the accessList as a whitelist
func SetAccessList(s []string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if len(s) > 0 {
for _, a := range s {
c.Config().AccessList = append(c.Config().AccessList, a)
}
return nil
}
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().UseCompression = b // "false"
return nil
}
}
//SetFilePath sets the path to save the config file at.
func SetFilePath(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().FilePath = s
return nil
}
}
//SetControlHost sets the host of the service to present an API on
func SetControlHost(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().ControlHost = s
return nil
}
}
//SetControlPort sets the port of the service to present an API on
func SetControlPort(s string) func(SAMTunnel) error {
return func(c 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.Config().ControlPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetKeyFile sets the path to a file containing a private key for decrypting
//locally-encrypted i2p keys.
func SetKeyFile(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().KeyFilePath = s
return nil
}
}
//SetDestination tells the
func SetDestination(b string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().ClientDest = b
return nil
}
}
//SetTunnelHost is used for VPN endpoints only.
func SetTunnelHost(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().TunnelHost = s
return nil
}
}
//SetFastRecieve tells clients to recieve all messages as quicky as possible
func SetFastRecieve(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().FastRecieve = b
return nil
}
}
//SetHost sets the host of the service to forward
func SetHost(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().TargetHost = s
return nil
}
}
//SetPort sets the port of the service to forward
func SetPort(s string) func(SAMTunnel) error {
return func(c 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.Config().TargetPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetEncrypt tells the outproxy.SetHttp to use an encrypted leaseset
func SetEncrypt(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().EncryptLeaseSet = b //"false"
return nil
}
}
//SetLeaseSetKey sets key to use with the encrypted leaseset
func SetLeaseSetKey(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().LeaseSetKey = s
return nil
}
}
//SetLeaseSetPrivateKey sets the private key to use with the encrypted leaseset
func SetLeaseSetPrivateKey(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().LeaseSetPrivateKey = s
return nil
}
}
//SetLeaseSetPrivateSigningKey sets the private signing key to use with the encrypted leaseset
func SetLeaseSetPrivateSigningKey(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().LeaseSetPrivateSigningKey = s
return nil
}
}
//SetInLength sets the number of hops inbound
func SetInLength(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u < 7 && u >= 0 {
c.Config().InLength = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u < 7 && u >= 0 {
c.Config().OutLength = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetName sets the host of the Conf's SAM bridge
func SetName(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().TunName = s
return nil
}
}
//SetSaveFile tells the application to save the tunnel's keys long-term
func SetSaveFile(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().SaveFile = b
return nil
}
}
//SetPassword sets the host of the Conf's SAM bridge
func SetPassword(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().Password = s
return nil
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u <= 16 && u > 0 {
c.Config().InQuantity = u //strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u <= 16 && u > 0 {
c.Config().OutQuantity = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().ReduceIdle = b // "false"
return nil
}
}
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().ReduceIdleTime = 300000
if u >= 6 {
c.Config().ReduceIdleTime = (u * 60) * 1000 // strconv.Itoa((u * 60) * 1000)
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().ReduceIdleTime = 300000
if u >= 300000 {
c.Config().ReduceIdleTime = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u < 5 {
c.Config().ReduceIdleQuantity = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().CloseIdle = b // "false"
return nil
}
}
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().CloseIdleTime = 300000
if u >= 6 {
c.Config().CloseIdleTime = (u * 60) * 1000 // strconv.Itoa((u * 60) * 1000)
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().CloseIdleTime = 300000
if u >= 300000 {
c.Config().CloseIdleTime = u //strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetMessageReliability sets the host of the Conf's SAM bridge
func SetMessageReliability(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().MessageReliability = s
return nil
}
}
//SetSAMHost sets the host of the Conf's SAM bridge
func SetSAMHost(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().SamHost = s
return nil
}
}
//SetSAMPort sets the port of the Conf's SAM bridge using a string
func SetSAMPort(s string) func(SAMTunnel) error {
return func(c 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.Config().SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
switch s {
case "DSA_SHA1":
c.Config().SigType = "DSA_SHA1"
case "ECDSA_SHA256_P256":
c.Config().SigType = "ECDSA_SHA256_P256"
case "ECDSA_SHA384_P384":
c.Config().SigType = "ECDSA_SHA384_P384"
case "ECDSA_SHA512_P521":
c.Config().SigType = "ECDSA_SHA512_P521"
case "EdDSA_SHA512_Ed25519":
c.Config().SigType = "EdDSA_SHA512_Ed25519"
default:
c.Config().SigType = "EdDSA_SHA512_Ed25519"
}
return nil
}
}
//SetType sets the type of the forwarder server
func SetType(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
switch c.Config().Type {
case "server":
c.Config().Type = s
case "http":
c.Config().Type = s
case "client":
c.Config().Type = s
case "httpclient":
c.Config().Type = s
case "browserclient":
c.Config().Type = s
case "udpserver":
c.Config().Type = s
case "udpclient":
c.Config().Type = s
case "vpnserver":
c.Config().Type = s
case "vpnclient":
c.Config().Type = s
case "kcpclient":
c.Config().Type = s
case "kcpserver":
c.Config().Type = s
default:
c.Config().Type = "browserclient"
}
return nil
}
}
//SetUserName sets username for authentication purposes
func SetUserName(s string) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().UserName = s
return nil
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if i < 7 && i > -7 {
c.Config().InVariance = i //strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if i < 7 && i > -7 {
c.Config().OutVariance = i //strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().InAllowZeroHop = b // "false"
return nil
}
}
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(SAMTunnel) error {
return func(c SAMTunnel) error {
c.Config().OutAllowZeroHop = b // "false"
return nil
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u < 6 && u >= 0 {
c.Config().InBackupQuantity = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(SAMTunnel) error {
return func(c SAMTunnel) error {
if u < 6 && u >= 0 {
c.Config().OutBackupQuantity = u // strconv.Itoa(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}

View File

@ -164,14 +164,14 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
return nil, e
}
case "udpserver":
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMSSUForwarderFromConfig(s.config.FilePath, s.SamHost, s.SamPort, label)); e == nil {
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMDGForwarderFromConfig(s.config.FilePath, s.SamHost, s.SamPort, label)); e == nil {
log.Println("found udpserver under", label)
s.handlerMux = s.handlerMux.Append(f)
} else {
return nil, e
}
case "udpclient":
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMSSUClientForwarderFromConfig(s.config.FilePath, s.SamHost, s.SamPort, label)); e == nil {
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMDGClientForwarderFromConfig(s.config.FilePath, s.SamHost, s.SamPort, label)); e == nil {
log.Println("found udpclient under", label)
s.handlerMux = s.handlerMux.Append(f)
} else {
@ -265,14 +265,14 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
return nil, e
}
case "udpserver":
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMSSUForwarderFromConf(s.config)); e == nil {
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMDGForwarderFromConf(s.config)); e == nil {
log.Println("found default udpserver")
s.handlerMux = s.handlerMux.Append(f)
} else {
return nil, e
}
case "udpclient":
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMSSUClientForwarderFromConf(s.config)); e == nil {
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunhelper.NewSAMDGClientForwarderFromConf(s.config)); e == nil {
log.Println("found default udpclient")
s.handlerMux = s.handlerMux.Append(f)
} else {

450
options/options.go Normal file
View File

@ -0,0 +1,450 @@
package samoptions
import (
"fmt"
"strconv"
"github.com/eyedeekay/sam-forwarder/interface"
)
//Option is a SAMForwarder Option
type Option func(samtunnel.SAMTunnel) error
//SetFilePath sets the path to save the config file at.
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(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if s == "http" {
c.Config().Type = s
return nil
} else {
c.Config().Type = "server"
return nil
}
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if s == "" {
c.Config().SigType = ""
} else if s == "DSA_SHA1" {
c.Config().SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.Config().SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.Config().SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.Config().SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.Config().SigType = "EdDSA_SHA512_Ed25519"
} else {
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(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(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(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.Config().TargetPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetSAMHost sets the host of the SAMForwarder's SAM bridge
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(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.Config().SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetName sets the host of the SAMForwarder's SAM bridge
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(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u < 7 && u >= 0 {
c.Config().InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u < 7 && u >= 0 {
c.Config().OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if i < 7 && i > -7 {
c.Config().InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if i < 7 && i > -7 {
c.Config().OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u <= 16 && u > 0 {
c.Config().InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u <= 16 && u > 0 {
c.Config().OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u < 6 && u >= 0 {
c.Config().InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u < 6 && u >= 0 {
c.Config().OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().EncryptLeaseSet = true
return nil
}
c.Config().EncryptLeaseSet = false
return nil
}
}
//SetLeaseSetKey sets the host of the SAMForwarder's SAM bridge
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(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(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(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(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().InAllowZeroHop = true
return nil
}
c.Config().InAllowZeroHop = false
return nil
}
}
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().OutAllowZeroHop = true
return nil
}
c.Config().OutAllowZeroHop = false
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().UseCompression = true
return nil
}
c.Config().UseCompression = false
return nil
}
}
//SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().FastRecieve = true
return nil
}
c.Config().FastRecieve = false
return nil
}
}
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().ReduceIdle = true
return nil
}
c.Config().ReduceIdle = false
return nil
}
}
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().ReduceIdleTime = 300000
if u >= 6 {
c.Config().ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().ReduceIdleTime = 300000
if u >= 300000 {
c.Config().ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if u < 5 {
c.Config().ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if b {
c.Config().CloseIdle = true
return nil
}
c.Config().CloseIdle = false
return nil
}
}
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().CloseIdleTime = 300000
if u >= 6 {
c.Config().CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().CloseIdleTime = 300000
if u >= 300000 {
c.Config().CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetAccessListType tells the system to treat the AccessList as a allowlist
func SetAccessListType(s string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if s == "allowlist" {
c.Config().AccessListType = "allowlist"
return nil
} else if s == "blocklist" {
c.Config().AccessListType = "blocklist"
return nil
} else if s == "none" {
c.Config().AccessListType = ""
return nil
} else if s == "" {
c.Config().AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(allowlist, blocklist, none)")
}
}
//SetAccessList tells the system to treat the AccessList as a allowlist
func SetAccessList(s []string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
if len(s) > 0 {
for _, a := range s {
c.Config().AccessList = append(c.Config().AccessList, a)
}
return nil
}
return nil
}
}
//SetTargetForPort sets the port of the SAMForwarder's SAM bridge using a string
/*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.Config().TargetForPort443 = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
*/
//SetKeyFile sets
func SetKeyFile(s string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().KeyFilePath = s
return nil
}
}
func SetPassword(s string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().KeyFilePath = s
return nil
}
}
func SetDestination(s string) func(samtunnel.SAMTunnel) error {
return func(c samtunnel.SAMTunnel) error {
c.Config().ClientDest = s
return nil
}
}

View File

@ -110,7 +110,7 @@ var (
tunName = flag.String("n", "forwarder",
"Tunnel name, this must be unique but can be anything.")
accessListType = flag.String("a", "none",
"Type of access list to use, can be \"whitelist\" \"blacklist\" or \"none\".")
"Type of access list to use, can be \"allowlist\" \"blocklist\" or \"none\".")
inLength = flag.Int("il", 3,
"Set inbound tunnel length(0 to 7)")
outLength = flag.Int("ol", 3,

View File

@ -111,7 +111,7 @@ func echoclient() {
}
func serveudp() {
ssuforwarder, err = samforwarderudp.NewSAMSSUForwarderFromOptions(
ssuforwarder, err = samforwarderudp.NewSAMDGForwarderFromOptions(
samforwarderudp.SetHost("127.0.0.1"),
samforwarderudp.SetPort(UDPServerPort),
samforwarderudp.SetSAMHost("127.0.0.1"),
@ -130,7 +130,7 @@ func serveudp() {
}
func clientudp() {
ssuforwarderclient, err = samforwarderudp.NewSAMSSUClientForwarderFromOptions(
ssuforwarderclient, err = samforwarderudp.NewSAMDGClientForwarderFromOptions(
samforwarderudp.SetClientHost("127.0.0.1"),
samforwarderudp.SetClientPort(UDPClientPort),
samforwarderudp.SetClientSAMHost("127.0.0.1"),

View File

@ -1,413 +0,0 @@
package samforwarder
import (
"fmt"
"strconv"
)
//ClientOption is a SAMClientForwarder Option
type ClientOption func(*SAMClientForwarder) 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
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
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
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
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 {
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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//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
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 {
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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//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
return nil
}
}
//SetSigType sets the type of the forwarder server
func SetClientSigType(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if s == "" {
c.Conf.SigType = ""
} else if s == "DSA_SHA1" {
c.Conf.SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.Conf.SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.Conf.SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.Conf.SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
} else {
c.Conf.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 {
if u < 7 && u >= 0 {
c.Conf.InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetClientOutLength sets the number of hops outbound
func SetClientOutLength(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u < 7 && u >= 0 {
c.Conf.OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetClientInVariance sets the variance of a number of hops inbound
func SetClientInVariance(i int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if i < 7 && i > -7 {
c.Conf.InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetClientOutVariance sets the variance of a number of hops outbound
func SetClientOutVariance(i int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if i < 7 && i > -7 {
c.Conf.OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetClientInQuantity sets the inbound tunnel quantity
func SetClientInQuantity(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u <= 16 && u > 0 {
c.Conf.InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetClientOutQuantity sets the outbound tunnel quantity
func SetClientOutQuantity(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u <= 16 && u > 0 {
c.Conf.OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetClientInBackups sets the inbound tunnel backups
func SetClientInBackups(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u < 6 && u >= 0 {
c.Conf.InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetClientOutBackups sets the inbound tunnel backups
func SetClientOutBackups(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u < 6 && u >= 0 {
c.Conf.OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetClientEncrypt tells the router to use an encrypted leaseset
func SetClientEncrypt(b bool) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if b {
c.Conf.EncryptLeaseSet = true
return nil
}
c.Conf.EncryptLeaseSet = false
return nil
}
}
//SetClientLeaseSetKey sets
func SetClientLeaseSetKey(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
c.Conf.LeaseSetKey = s
return nil
}
}
//SetClientLeaseSetPrivateKey sets
func SetClientLeaseSetPrivateKey(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
c.Conf.LeaseSetPrivateKey = s
return nil
}
}
//SetClientLeaseSetPrivateSigningKey sets
func SetClientLeaseSetPrivateSigningKey(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
c.Conf.LeaseSetPrivateSigningKey = s
return nil
}
}
//SetClientMessageReliability sets
func SetClientMessageReliability(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
c.Conf.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 {
if b {
c.Conf.InAllowZeroHop = true
return nil
}
c.Conf.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 {
if b {
c.Conf.OutAllowZeroHop = true
return nil
}
c.Conf.OutAllowZeroHop = false
return nil
}
}
//SetClientFastRecieve tells clients use the i2cp.fastRecieve option
func SetClientFastRecieve(b bool) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if b {
c.Conf.FastRecieve = true
return nil
}
c.Conf.FastRecieve = false
return nil
}
}
//SetClientCompress tells clients to use compression
func SetClientCompress(b bool) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if b {
c.Conf.UseCompression = true
return nil
}
c.Conf.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 {
if b {
c.Conf.ReduceIdle = true
return nil
}
c.Conf.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
if u >= 6 {
c.Conf.ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//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
if u >= 300000 {
c.Conf.ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetClientReduceIdleQuantity(u int) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if u < 5 {
c.Conf.ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//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 {
if b {
c.Conf.CloseIdle = true
return nil
}
c.Conf.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
if u >= 6 {
c.Conf.CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//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
if u >= 300000 {
c.Conf.CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetClientAccessListType tells the system to treat the accessList as a whitelist
func SetClientAccessListType(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if s == "whitelist" {
c.Conf.AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.Conf.AccessListType = "blacklist"
return nil
} else if s == "none" {
c.Conf.AccessListType = ""
return nil
} else if s == "" {
c.Conf.AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetClientAccessList tells the system to treat the accessList as a whitelist
func SetClientAccessList(s []string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
if len(s) > 0 {
for _, a := range s {
c.Conf.AccessList = append(c.Conf.AccessList, a)
}
return nil
}
return nil
}
}
//SetKeyFile sets
func SetClientPassword(s string) func(*SAMClientForwarder) error {
return func(c *SAMClientForwarder) error {
c.Conf.KeyFilePath = s
return nil
}
}

View File

@ -15,6 +15,7 @@ import (
"github.com/eyedeekay/sam-forwarder/hashhash"
"github.com/eyedeekay/sam-forwarder/i2pkeys"
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam3"
"github.com/eyedeekay/sam3/i2pkeys"
)
@ -108,9 +109,9 @@ func (f *SAMClientForwarder) Search(search string) string {
}
func (f *SAMClientForwarder) accesslisttype() string {
if f.Config().AccessListType == "whitelist" {
if f.Config().AccessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if f.Config().AccessListType == "blacklist" {
} else if f.Config().AccessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if f.Config().AccessListType == "none" {
return ""
@ -258,12 +259,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) {
return NewSAMClientForwarderFromOptions(SetClientHost(host), SetClientPort(port))
func NewSAMClientForwarder(host, port string) (samtunnel.SAMTunnel, error) {
return NewSAMClientForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(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"

View File

@ -1,438 +1,5 @@
package samforwarder
import (
"fmt"
"strconv"
)
//Option is a SAMForwarder Option
type Option func(*SAMForwarder) 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
return nil
}
}
//SetType sets the type of the forwarder server
func SetType(s string) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if s == "http" {
c.Conf.Type = s
return nil
} else {
c.Conf.Type = "server"
return nil
}
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if s == "" {
c.Conf.SigType = ""
} else if s == "DSA_SHA1" {
c.Conf.SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.Conf.SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.Conf.SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.Conf.SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
} else {
c.Conf.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
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
return nil
}
}
//SetPort sets the port of the service to forward
func SetPort(s string) func(*SAMForwarder) error {
return func(c *SAMForwarder) 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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//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
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 {
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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//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
return nil
}
}
//SetInLength sets the number of hops inbound
func SetInLength(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u < 7 && u >= 0 {
c.Conf.InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u < 7 && u >= 0 {
c.Conf.OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if i < 7 && i > -7 {
c.Conf.InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if i < 7 && i > -7 {
c.Conf.OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u <= 16 && u > 0 {
c.Conf.InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u <= 16 && u > 0 {
c.Conf.OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u < 6 && u >= 0 {
c.Conf.InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u < 6 && u >= 0 {
c.Conf.OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if b {
c.Conf.EncryptLeaseSet = true
return nil
}
c.Conf.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
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
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
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
return nil
}
}
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if b {
c.Conf.InAllowZeroHop = true
return nil
}
c.Conf.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 {
if b {
c.Conf.OutAllowZeroHop = true
return nil
}
c.Conf.OutAllowZeroHop = false
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if b {
c.Conf.UseCompression = true
return nil
}
c.Conf.UseCompression = false
return nil
}
}
//SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if b {
c.Conf.FastRecieve = true
return nil
}
c.Conf.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 {
if b {
c.Conf.ReduceIdle = true
return nil
}
c.Conf.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
if u >= 6 {
c.Conf.ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//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
if u >= 300000 {
c.Conf.ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if u < 5 {
c.Conf.ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//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 {
if b {
c.Conf.CloseIdle = true
return nil
}
c.Conf.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
if u >= 6 {
c.Conf.CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//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
if u >= 300000 {
c.Conf.CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetAccessListType tells the system to treat the AccessList as a whitelist
func SetAccessListType(s string) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if s == "whitelist" {
c.Conf.AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.Conf.AccessListType = "blacklist"
return nil
} else if s == "none" {
c.Conf.AccessListType = ""
return nil
} else if s == "" {
c.Conf.AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetAccessList tells the system to treat the AccessList as a whitelist
func SetAccessList(s []string) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
if len(s) > 0 {
for _, a := range s {
c.Conf.AccessList = append(c.Conf.AccessList, a)
}
return nil
}
return nil
}
}
//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 {
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
return nil
}
return fmt.Errorf("Invalid port")
}
}
*/
//SetKeyFile sets
func SetKeyFile(s string) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {
c.Conf.KeyFilePath = s
return nil
}
}
//SetByteLimit sets the number of hops inbound
func SetByteLimit(u int64) func(*SAMForwarder) error {
return func(c *SAMForwarder) error {

View File

@ -2,6 +2,7 @@ package samforwarder
import (
"bufio"
"crypto/tls"
"io"
"log"
"net"
@ -18,6 +19,7 @@ import (
"github.com/eyedeekay/sam-forwarder/hashhash"
"github.com/eyedeekay/sam-forwarder/i2pkeys"
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam3"
i2pkeys "github.com/eyedeekay/sam3/i2pkeys"
)
@ -29,7 +31,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
@ -129,7 +131,7 @@ func (f *SAMForwarder) Print() string {
r += "type=" + f.Conf.Type + "\n"
r += "base32=" + f.Base32() + "\n"
r += "base64=" + f.Base64() + "\n"
if f.Conf.Type == "http" {
if f.Conf.Type == "http" || f.Conf.Type == "https" {
r += "httpserver\n"
} else {
r += "ntcpserver\n"
@ -154,9 +156,9 @@ func (f *SAMForwarder) Search(search string) string {
}
func (f *SAMForwarder) accesslisttype() string {
if f.Config().AccessListType == "whitelist" {
if f.Config().AccessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if f.Config().AccessListType == "blacklist" {
} else if f.Config().AccessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if f.Config().AccessListType == "none" {
return ""
@ -198,12 +200,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 +251,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 +265,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
}
@ -276,7 +278,7 @@ func (f *SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
log.Fatalf("Dial failed: %v", err)
}
go func() {
if f.Conf.Type == "http" {
if f.Conf.Type == "http" || f.Conf.Type == "https" {
defer f.clientUnlockAndClose(true, false, client)
defer f.connUnlockAndClose(false, true, conn)
if requestbytes, request, err = f.HTTPRequestBytes(conn); err == nil {
@ -303,7 +305,7 @@ func (f *SAMForwarder) forward(conn *sam3.SAMConn) { //(conn net.Conn) {
}
}()
go func() {
if f.Conf.Type == "http" {
if f.Conf.Type == "http" || f.Conf.Type == "https" {
defer f.clientUnlockAndClose(false, true, client)
defer f.connUnlockAndClose(true, false, conn)
if responsebytes, err = f.HTTPResponseBytes(client, request); err == nil {
@ -351,15 +353,24 @@ 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 {
tlsconf, err := f.Conf.TLSConfig()
if err != nil {
return err
}
f.publishListen = tls.NewListener(publishListen, 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 +425,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) {
return NewSAMForwarderFromOptions(SetHost(host), SetPort(port))
func NewSAMForwarder(host, port string) (samtunnel.SAMTunnel, error) {
return NewSAMForwarderFromOptions(samoptions.SetHost(host), samoptions.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

View File

@ -3,10 +3,12 @@ package samforwarder
import (
"log"
"testing"
"github.com/eyedeekay/sam-forwarder/options"
)
func TestOptionHost(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetHost("127.0.0.1"))
client, err := NewSAMForwarderFromOptions(samoptions.SetHost("127.0.0.1"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -14,7 +16,7 @@ func TestOptionHost(t *testing.T) {
}
func TestOptionPort(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetPort("8080"))
client, err := NewSAMForwarderFromOptions(samoptions.SetPort("8080"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -22,7 +24,7 @@ func TestOptionPort(t *testing.T) {
}
func TestOptionInLength(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetInLength(3))
client, err := NewSAMForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -30,7 +32,7 @@ func TestOptionInLength(t *testing.T) {
}
func TestOptionOutLength(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetInLength(3))
client, err := NewSAMForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -38,7 +40,7 @@ func TestOptionOutLength(t *testing.T) {
}
func TestOptionInVariance(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetInVariance(1))
client, err := NewSAMForwarderFromOptions(samoptions.SetInVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -46,7 +48,7 @@ func TestOptionInVariance(t *testing.T) {
}
func TestOptionOutVariance(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetOutVariance(1))
client, err := NewSAMForwarderFromOptions(samoptions.SetOutVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -54,7 +56,7 @@ func TestOptionOutVariance(t *testing.T) {
}
func TestOptionInQuantity(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetInQuantity(6))
client, err := NewSAMForwarderFromOptions(samoptions.SetInQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -62,7 +64,7 @@ func TestOptionInQuantity(t *testing.T) {
}
func TestOptionOutQuantity(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetOutQuantity(6))
client, err := NewSAMForwarderFromOptions(samoptions.SetOutQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -70,7 +72,7 @@ func TestOptionOutQuantity(t *testing.T) {
}
func TestOptionInBackups(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetInBackups(5))
client, err := NewSAMForwarderFromOptions(samoptions.SetInBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -78,7 +80,7 @@ func TestOptionInBackups(t *testing.T) {
}
func TestOptionOutBackups(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetOutBackups(5))
client, err := NewSAMForwarderFromOptions(samoptions.SetOutBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -86,7 +88,7 @@ func TestOptionOutBackups(t *testing.T) {
}
func TestOptionReduceIdleQuantity(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetReduceIdleQuantity(4))
client, err := NewSAMForwarderFromOptions(samoptions.SetReduceIdleQuantity(4))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -94,7 +96,7 @@ func TestOptionReduceIdleQuantity(t *testing.T) {
}
func TestOptionReduceIdleTimeMs(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetReduceIdleTimeMs(300000))
client, err := NewSAMForwarderFromOptions(samoptions.SetReduceIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -102,7 +104,7 @@ func TestOptionReduceIdleTimeMs(t *testing.T) {
}
func TestOptionReduceIdleTime(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetReduceIdleTime(6))
client, err := NewSAMForwarderFromOptions(samoptions.SetReduceIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -110,7 +112,7 @@ func TestOptionReduceIdleTime(t *testing.T) {
}
func TestOptionCloseIdleTimeMs(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetCloseIdleTimeMs(300000))
client, err := NewSAMForwarderFromOptions(samoptions.SetCloseIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -118,7 +120,7 @@ func TestOptionCloseIdleTimeMs(t *testing.T) {
}
func TestOptionCloseIdleTime(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetCloseIdleTime(6))
client, err := NewSAMForwarderFromOptions(samoptions.SetCloseIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -126,7 +128,7 @@ func TestOptionCloseIdleTime(t *testing.T) {
}
func TestOptionEncryptLease(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetEncrypt(true))
client, err := NewSAMForwarderFromOptions(samoptions.SetEncrypt(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -134,7 +136,7 @@ func TestOptionEncryptLease(t *testing.T) {
}
func TestOptionSaveFile(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetSaveFile(true))
client, err := NewSAMForwarderFromOptions(samoptions.SetSaveFile(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -142,7 +144,7 @@ func TestOptionSaveFile(t *testing.T) {
}
func TestClientOptionHost(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientHost("127.0.0.1"))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetHost("127.0.0.1"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -150,7 +152,7 @@ func TestClientOptionHost(t *testing.T) {
}
func TestClientOptionPort(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientSAMPort("7656"))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetSAMPort("7656"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -158,7 +160,7 @@ func TestClientOptionPort(t *testing.T) {
}
func TestClientOptionInLength(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientInLength(3))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -166,7 +168,7 @@ func TestClientOptionInLength(t *testing.T) {
}
func TestClientOptionOutLength(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientInLength(3))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -174,7 +176,7 @@ func TestClientOptionOutLength(t *testing.T) {
}
func TestClientOptionInVariance(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientInVariance(1))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetInVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -182,7 +184,7 @@ func TestClientOptionInVariance(t *testing.T) {
}
func TestClientOptionOutVariance(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientOutVariance(1))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetOutVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -190,7 +192,7 @@ func TestClientOptionOutVariance(t *testing.T) {
}
func TestClientOptionInQuantity(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientInQuantity(6))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetInQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -198,7 +200,7 @@ func TestClientOptionInQuantity(t *testing.T) {
}
func TestClientOptionOutQuantity(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientOutQuantity(6))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetOutQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -206,7 +208,7 @@ func TestClientOptionOutQuantity(t *testing.T) {
}
func TestClientOptionInBackups(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientInBackups(5))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetInBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -214,7 +216,7 @@ func TestClientOptionInBackups(t *testing.T) {
}
func TestClientOptionOutBackups(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientOutBackups(5))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetOutBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -222,7 +224,7 @@ func TestClientOptionOutBackups(t *testing.T) {
}
func TestClientOptionReduceIdleQuantity(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientReduceIdleQuantity(4))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetReduceIdleQuantity(4))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -230,7 +232,7 @@ func TestClientOptionReduceIdleQuantity(t *testing.T) {
}
func TestClientOptionReduceIdleTimeMs(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientReduceIdleTimeMs(300000))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetReduceIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -238,7 +240,7 @@ func TestClientOptionReduceIdleTimeMs(t *testing.T) {
}
func TestClientOptionReduceIdleTime(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientReduceIdleTime(6))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetReduceIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -246,7 +248,7 @@ func TestClientOptionReduceIdleTime(t *testing.T) {
}
func TestClientOptionCloseIdleTimeMs(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientCloseIdleTimeMs(300000))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetCloseIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -254,7 +256,7 @@ func TestClientOptionCloseIdleTimeMs(t *testing.T) {
}
func TestClientOptionCloseIdleTime(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientCloseIdleTime(6))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetCloseIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -262,7 +264,7 @@ func TestClientOptionCloseIdleTime(t *testing.T) {
}
func TestClientOptionEncryptLease(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientEncrypt(true))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetEncrypt(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -270,7 +272,7 @@ func TestClientOptionEncryptLease(t *testing.T) {
}
func TestClientOptionSaveFile(t *testing.T) {
client, err := NewSAMClientForwarderFromOptions(SetClientSaveFile(true))
client, err := NewSAMClientForwarderFromOptions(samoptions.SetSaveFile(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -278,7 +280,7 @@ func TestClientOptionSaveFile(t *testing.T) {
}
/*func TestOptionTargetForPort443(t *testing.T) {
client, err := NewSAMForwarderFromOptions(SetTargetForPort443("443"))
client, err := NewSAMForwarderFromOptions(samoptions.SetTargetForPort443("443"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}

100
tls/tls.go Normal file
View File

@ -0,0 +1,100 @@
package i2ptls
import (
"crypto/ed25519"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"log"
"math/big"
"os"
)
func CheckFile(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func CertPemificate(CertPem, KeyPem string, names []string, priv ed25519.PrivateKey) (tls.Certificate, error) {
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Fatalf("Failed to generate serial number: %v", err)
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Acme Co"},
},
// NotBefore: notBefore,
// NotAfter: notAfter,
// KeyUsage: keyUsage,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
if len(names) > 0 {
template.DNSNames = append(template.DNSNames, names...)
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, priv.Public().(ed25519.PublicKey), priv)
if err != nil {
log.Fatalf("Failed to create certificate: %v", err)
}
certOut, err := os.Create(CertPem)
if err != nil {
log.Fatalf("Failed to open "+CertPem+" for writing: %v", err)
}
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
log.Fatalf("Failed to write data to "+CertPem+": %v", err)
}
if err := certOut.Close(); err != nil {
log.Fatalf("Error closing "+CertPem+": %v", err)
}
log.Print("wrote " + CertPem + "\n")
keyOut, err := os.OpenFile(KeyPem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
log.Fatalf("Failed to open "+KeyPem+" for writing: %v", err)
}
privBytes, err := x509.MarshalPKCS8PrivateKey(priv)
if err != nil {
log.Fatalf("Unable to marshal private key: %v", err)
}
if err := pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes}); err != nil {
log.Fatalf("Failed to write data to key.pem: %v", err)
}
if err := keyOut.Close(); err != nil {
log.Fatalf("Error closing key.pem: %v", err)
}
return tls.LoadX509KeyPair(CertPem, KeyPem)
}
func TLSConfig(CertPem, KeyPem string, names []string) (*tls.Config, error) {
var ServerName string
if len(names) > 0 {
ServerName = names[0]
}
if CheckFile(CertPem) && CheckFile(KeyPem) {
cert, err := tls.LoadX509KeyPair(CertPem, KeyPem)
if err != nil {
return nil, err
}
return &tls.Config{Certificates: []tls.Certificate{cert}, ServerName: ServerName}, nil
} else {
_, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
cert, err := CertPemificate(CertPem, KeyPem, names, priv)
if err != nil {
return nil, err
}
return &tls.Config{Certificates: []tls.Certificate{cert}, ServerName: ServerName}, nil
}
}

11
tls/tls_test.go Normal file
View File

@ -0,0 +1,11 @@
package i2ptls
import "testing"
func TestTLSGenerate(t *testing.T) {
config, err := TLSConfig("cert.pem", "key.pem", []string{"idk.i2p"})
if err != nil {
t.Fatal(err.Error())
}
t.Log(config.ServerName)
}

View File

@ -1,413 +0,0 @@
package samforwarderudp
import (
"fmt"
"strconv"
)
//ClientOption is a SAMSSUClientForwarder Option
type ClientOption func(*SAMSSUClientForwarder) error
//SetClientFilePath sets the host of the SAMSSUForwarder's SAM bridge
func SetClientFilePath(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.FilePath = s
return nil
}
}
//SetClientSaveFile tells the router to use an encrypted leaseset
func SetClientSaveFile(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.SaveFile = b
return nil
}
}
//SetClientHost sets the host of the SAMSSUForwarder's SAM bridge
func SetClientHost(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.TargetHost = s
return nil
}
}
//SetClientPort sets the port of the SAMSSUForwarder's SAM bridge using a string
func SetClientPort(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) 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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetClientSAMHost sets the host of the SAMSSUForwarder's SAM bridge
func SetClientSAMHost(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.SamHost = s
return nil
}
}
//SetClientSAMPort sets the port of the SAMSSUForwarder's SAM bridge using a string
func SetClientSAMPort(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) 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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetClientDestination sets the destination to forwarder SAMClientForwarder's to
func SetClientDestination(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.ClientDest = s
return nil
}
}
//SetClientName sets the host of the SAMSSUForwarder's SAM bridge
func SetClientName(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.TunName = s
return nil
}
}
//SetClientSigType sets the type of the forwarder server
func SetClientSigType(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if s == "" {
c.Conf.SigType = ""
} else if s == "DSA_SHA1" {
c.Conf.SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.Conf.SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.Conf.SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.Conf.SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
} else {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
}
return nil
}
}
//SetClientInLength sets the number of hops inbound
func SetClientInLength(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u < 7 && u >= 0 {
c.Conf.InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetClientOutLength sets the number of hops outbound
func SetClientOutLength(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u < 7 && u >= 0 {
c.Conf.OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetClientInVariance sets the variance of a number of hops inbound
func SetClientInVariance(i int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if i < 7 && i > -7 {
c.Conf.InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetClientOutVariance sets the variance of a number of hops outbound
func SetClientOutVariance(i int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if i < 7 && i > -7 {
c.Conf.OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetClientInQuantity sets the inbound tunnel quantity
func SetClientInQuantity(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u <= 16 && u > 0 {
c.Conf.InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetClientOutQuantity sets the outbound tunnel quantity
func SetClientOutQuantity(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u <= 16 && u > 0 {
c.Conf.OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetClientInBackups sets the inbound tunnel backups
func SetClientInBackups(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u < 6 && u >= 0 {
c.Conf.InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetClientOutBackups sets the inbound tunnel backups
func SetClientOutBackups(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u < 6 && u >= 0 {
c.Conf.OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetClientEncrypt tells the router to use an encrypted leaseset
func SetClientEncrypt(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.EncryptLeaseSet = true
return nil
}
c.Conf.EncryptLeaseSet = false
return nil
}
}
//SetClientLeaseSetKey sets the host of the SAMForwarder's SAM bridge
func SetClientLeaseSetKey(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.LeaseSetKey = s
return nil
}
}
//SetClientLeaseSetPrivateKey sets the host of the SAMForwarder's SAM bridge
func SetClientLeaseSetPrivateKey(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.LeaseSetPrivateKey = s
return nil
}
}
//SetClientLeaseSetPrivateSigningKey sets the host of the SAMForwarder's SAM bridge
func SetClientLeaseSetPrivateSigningKey(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.LeaseSetPrivateSigningKey = s
return nil
}
}
//SetClientMessageReliability sets
func SetClientMessageReliability(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.MessageReliability = s
return nil
}
}
//SetClientAllowZeroIn tells the tunnel to accept zero-hop peers
func SetClientAllowZeroIn(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.InAllowZeroHop = true
return nil
}
c.Conf.InAllowZeroHop = false
return nil
}
}
//SetClientAllowZeroOut tells the tunnel to accept zero-hop peers
func SetClientAllowZeroOut(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.OutAllowZeroHop = true
return nil
}
c.Conf.OutAllowZeroHop = false
return nil
}
}
//SetFastRecieve tells clients to use i2cp.fastRecieve
func SetClientFastRecieve(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.FastRecieve = true
return nil
}
c.Conf.FastRecieve = false
return nil
}
}
//SetClientCompress tells clients to use compression
func SetClientCompress(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.UseCompression = true
return nil
}
c.Conf.UseCompression = false
return nil
}
}
//SetClientReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetClientReduceIdle(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.ReduceIdle = true
return nil
}
c.Conf.ReduceIdle = false
return nil
}
}
//SetClientReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetClientReduceIdleTime(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.ReduceIdleTime = 300000
if u >= 6 {
c.Conf.ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
}
}
//SetClientReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetClientReduceIdleTimeMs(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.ReduceIdleTime = 300000
if u >= 300000 {
c.Conf.ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
}
}
//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetClientReduceIdleQuantity(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if u < 5 {
c.Conf.ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetClientCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetClientCloseIdle(b bool) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if b {
c.Conf.CloseIdle = true
return nil
}
c.Conf.CloseIdle = false
return nil
}
}
//SetClientCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetClientCloseIdleTime(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.CloseIdleTime = 300000
if u >= 6 {
c.Conf.CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetClientCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetClientCloseIdleTimeMs(u int) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.CloseIdleTime = 300000
if u >= 300000 {
c.Conf.CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetClientAccessListType tells the system to treat the accessList as a whitelist
func SetClientAccessListType(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if s == "whitelist" {
c.Conf.AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.Conf.AccessListType = "blacklist"
return nil
} else if s == "none" {
c.Conf.AccessListType = ""
return nil
} else if s == "" {
c.Conf.AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetClientAccessList tells the system to treat the accessList as a whitelist
func SetClientAccessList(s []string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
if len(s) > 0 {
for _, a := range s {
c.Conf.AccessList = append(c.Conf.AccessList, a)
}
return nil
}
return nil
}
}
//SetKeyFile sets
func SetClientPassword(s string) func(*SAMSSUClientForwarder) error {
return func(c *SAMSSUClientForwarder) error {
c.Conf.KeyFilePath = s
return nil
}
}

View File

@ -1,6 +1,7 @@
package samforwarderudp
import (
"fmt"
"io"
"log"
"net"
@ -14,13 +15,14 @@ import (
"github.com/eyedeekay/sam-forwarder/hashhash"
"github.com/eyedeekay/sam-forwarder/i2pkeys"
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam3"
i2pkeys "github.com/eyedeekay/sam3/i2pkeys"
)
//SAMSSUClientForwarder is a structure which automatically configured the forwarding of
//SAMDGClientForwarder is a structure which automatically configured the forwarding of
//a local port to i2p over the SAM API.
type SAMSSUClientForwarder struct {
type SAMDGClientForwarder struct {
samConn *sam3.SAM
SamKeys i2pkeys.I2PKeys
Hasher *hashhash.Hasher
@ -35,42 +37,42 @@ type SAMSSUClientForwarder struct {
Conf *i2ptunconf.Conf
}
func (f *SAMSSUClientForwarder) Config() *i2ptunconf.Conf {
func (f *SAMDGClientForwarder) Config() *i2ptunconf.Conf {
if f.Conf == nil {
f.Conf = i2ptunconf.NewI2PBlankTunConf()
}
return f.Conf
}
func (f *SAMSSUClientForwarder) GetType() string {
func (f *SAMDGClientForwarder) GetType() string {
return f.Config().Type
}
func (f *SAMSSUClientForwarder) ID() string {
func (f *SAMDGClientForwarder) ID() string {
return f.Config().TunName
}
func (f *SAMSSUClientForwarder) Keys() i2pkeys.I2PKeys {
func (f *SAMDGClientForwarder) Keys() i2pkeys.I2PKeys {
return f.SamKeys
}
func (f *SAMSSUClientForwarder) Cleanup() {
func (f *SAMDGClientForwarder) Cleanup() {
f.publishConnection.Close()
f.connectStream.Close()
f.samConn.Close()
}
func (f *SAMSSUClientForwarder) Close() error {
func (f *SAMDGClientForwarder) Close() error {
f.Cleanup()
f.up = false
return nil
}
func (f *SAMSSUClientForwarder) print() []string {
func (f *SAMDGClientForwarder) print() []string {
return f.Config().PrintSlice()
}
func (f *SAMSSUClientForwarder) Props() map[string]string {
func (f *SAMDGClientForwarder) Props() map[string]string {
r := make(map[string]string)
print := f.print()
print = append(print, "base32="+f.Base32())
@ -83,7 +85,7 @@ func (f *SAMSSUClientForwarder) Props() map[string]string {
return r
}
func (f *SAMSSUClientForwarder) Print() string {
func (f *SAMDGClientForwarder) Print() string {
var r string
r += "name=" + f.Config().TunName + "\n"
r += "type=" + f.Config().Type + "\n"
@ -97,7 +99,7 @@ func (f *SAMSSUClientForwarder) Print() string {
return strings.Replace(r, "\n\n", "\n", -1)
}
func (f *SAMSSUClientForwarder) Search(search string) string {
func (f *SAMDGClientForwarder) Search(search string) string {
terms := strings.Split(search, ",")
if search == "" {
return f.Print()
@ -110,10 +112,10 @@ func (f *SAMSSUClientForwarder) Search(search string) string {
return f.Print()
}
func (f *SAMSSUClientForwarder) accesslisttype() string {
if f.Config().AccessListType == "whitelist" {
func (f *SAMDGClientForwarder) accesslisttype() string {
if f.Config().AccessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if f.Config().AccessListType == "blacklist" {
} else if f.Config().AccessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if f.Config().AccessListType == "none" {
return ""
@ -121,7 +123,7 @@ func (f *SAMSSUClientForwarder) accesslisttype() string {
return ""
}
func (f *SAMSSUClientForwarder) accesslist() string {
func (f *SAMDGClientForwarder) accesslist() string {
if f.Config().AccessListType != "" && len(f.Config().AccessList) > 0 {
r := ""
for _, s := range f.Config().AccessList {
@ -132,7 +134,7 @@ func (f *SAMSSUClientForwarder) accesslist() string {
return ""
}
func (f *SAMSSUClientForwarder) leasesetsettings() (string, string, string) {
func (f *SAMDGClientForwarder) leasesetsettings() (string, string, string) {
var r, s, t string
if f.Config().LeaseSetKey != "" {
r = "i2cp.leaseSetKey=" + f.Config().LeaseSetKey
@ -147,37 +149,37 @@ func (f *SAMSSUClientForwarder) leasesetsettings() (string, string, string) {
}
// Destination returns the destination of the i2p service you want to forward locally
func (f *SAMSSUClientForwarder) Destination() string {
func (f *SAMDGClientForwarder) Destination() string {
return f.addr.Base32()
}
// Target returns the host:port of the local service you want to forward to i2p
func (f *SAMSSUClientForwarder) Target() string {
func (f *SAMDGClientForwarder) Target() string {
return f.Config().TargetHost + ":" + f.Config().TargetPort
}
func (f *SAMSSUClientForwarder) sam() string {
func (f *SAMDGClientForwarder) sam() string {
return f.Config().SamHost + ":" + f.Config().SamPort
}
//Base32 returns the base32 address of the local destination
func (f *SAMSSUClientForwarder) Base32() string {
func (f *SAMDGClientForwarder) Base32() string {
return f.SamKeys.Addr().Base32()
}
//Base32Readable returns the base32 address where the local service is being forwarded
func (f *SAMSSUClientForwarder) Base32Readable() string {
func (f *SAMDGClientForwarder) Base32Readable() string {
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
rhash, _ := f.Hasher.Friendly(b32)
return rhash + " " + strconv.Itoa(len(b32))
}
//Base64 returns the base64 address of the local destination
func (f *SAMSSUClientForwarder) Base64() string {
func (f *SAMDGClientForwarder) Base64() string {
return f.SamKeys.Addr().Base64()
}
func (f *SAMSSUClientForwarder) forward(conn net.PacketConn) {
func (f *SAMDGClientForwarder) forward(conn net.PacketConn) {
// go func() {
// defer f.connectStream.Close()
// defer f.publishConnection.Close()
@ -202,11 +204,11 @@ func (f *SAMSSUClientForwarder) forward(conn net.PacketConn) {
// }()
}
func (f *SAMSSUClientForwarder) Up() bool {
func (f *SAMDGClientForwarder) Up() bool {
return f.up
}
func (f *SAMSSUClientForwarder) errSleep(err error) bool {
func (f *SAMDGClientForwarder) errSleep(err error) bool {
if err != nil {
log.Printf("Dial failed: %v, waiting 5 minutes to try again\n", err)
time.Sleep(5 * time.Minute)
@ -217,11 +219,11 @@ func (f *SAMSSUClientForwarder) errSleep(err error) bool {
}
//Serve starts the SAM connection and and forwards the local host:port to i2p
func (f *SAMSSUClientForwarder) Serve() error {
func (f *SAMDGClientForwarder) Serve() error {
var err error
log.Println("Establishing a SAM datagram session.")
if f.publishConnection, err = net.ListenPacket("udp", f.Config().Target()); err != nil {
return err
return fmt.Errorf("Listener creation Error%s", err)
}
//p, _ := strconv.Atoi(f.Config().TargetPort)
sp, _ := strconv.Atoi(f.Config().SamPort)
@ -251,48 +253,53 @@ func (f *SAMSSUClientForwarder) Serve() error {
return nil
}
func (s *SAMSSUClientForwarder) Load() (samtunnel.SAMTunnel, error) {
func (s *SAMDGClientForwarder) Load() (samtunnel.SAMTunnel, error) {
if s.samConn, err = sam3.NewSAM(s.sam()); err != nil {
return nil, err
return nil, fmt.Errorf("SAM connection error %s", err)
}
if s.addr, err = s.samConn.Lookup(s.Config().ClientDest); err != nil {
return nil, err
return nil, fmt.Errorf("%s", err)
}
log.Println("SAM Bridge connection established.")
if s.Config().SaveFile {
log.Println("Saving i2p keys")
}
if s.SamKeys, err = sfi2pkeys.Load(s.Config().FilePath, s.Config().TunName, s.Config().KeyFilePath, s.samConn, s.Config().SaveFile); err != nil {
return nil, err
return nil, fmt.Errorf("I2P key load/generate error%s", err)
}
log.Println("Destination keys generated, tunnel name:", s.Config().TunName)
if s.Config().SaveFile {
if err := sfi2pkeys.Save(s.Config().FilePath, s.Config().TunName, s.Config().KeyFilePath, s.SamKeys); err != nil {
return nil, err
return nil, fmt.Errorf("I2P key storage error %s", err)
}
log.Println("Saved tunnel keys for", s.Conf.TunName, "in", s.Conf.FilePath)
}
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
if err != nil {
return nil, err
return nil, fmt.Errorf("Human-readable hasher error %s", err)
}
s.up = true
return s, nil
}
//NewSAMSSUClientForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMSSUClientForwarderFromOptions(opts ...func(*SAMSSUClientForwarder) error) (*SAMSSUClientForwarder, error) {
var s SAMSSUClientForwarder
//NewSAMDGForwarder makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMDGClientForwarder(host, port string) (samtunnel.SAMTunnel, error) {
return NewSAMDGClientForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(port))
}
//NewSAMDGClientForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMDGClientForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMDGClientForwarder, error) {
var s SAMDGClientForwarder
s.Conf = i2ptunconf.NewI2PBlankTunConf()
s.Conf.Type = "udpclient"
for _, o := range opts {
if err := o(&s); err != nil {
return nil, err
return nil, fmt.Errorf("Option setting error %s", err)
}
}
l, e := s.Load()
if e != nil {
return nil, e
return nil, fmt.Errorf("Tunnel loading error %s", e)
}
return l.(*SAMSSUClientForwarder), nil
return l.(*SAMDGClientForwarder), nil
}

View File

@ -1,405 +0,0 @@
package samforwarderudp
import (
"fmt"
"strconv"
)
//Option is a SAMSSUForwarder Option
type Option func(*SAMSSUForwarder) error
//SetFilePath sets the host of the SAMSSUForwarder's SAM bridge
func SetFilePath(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.FilePath = s
return nil
}
}
//SetSaveFile tells the router to use an encrypted leaseset
func SetSaveFile(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.SaveFile = b
return nil
}
}
//SetHost sets the host of the SAMSSUForwarder's SAM bridge
func SetHost(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.TargetHost = s
return nil
}
}
//SetPort sets the port of the SAMSSUForwarder's SAM bridge using a string
func SetPort(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) 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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetSAMHost sets the host of the SAMSSUForwarder's SAM bridge
func SetSAMHost(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.SamHost = s
return nil
}
}
//SetSAMPort sets the port of the SAMSSUForwarder's SAM bridge using a string
func SetSAMPort(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) 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
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetName sets the host of the SAMSSUForwarder's SAM bridge
func SetName(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.TunName = s
return nil
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if s == "" {
c.Conf.SigType = ""
} else if s == "DSA_SHA1" {
c.Conf.SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.Conf.SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.Conf.SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.Conf.SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
} else {
c.Conf.SigType = "EdDSA_SHA512_Ed25519"
}
return nil
}
}
//SetInLength sets the number of hops inbound
func SetInLength(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u < 7 && u >= 0 {
c.Conf.InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u < 7 && u >= 0 {
c.Conf.OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if i < 7 && i > -7 {
c.Conf.InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if i < 7 && i > -7 {
c.Conf.OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u <= 16 && u > 0 {
c.Conf.InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u <= 16 && u > 0 {
c.Conf.OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u < 6 && u >= 0 {
c.Conf.InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u < 6 && u >= 0 {
c.Conf.OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.EncryptLeaseSet = true
return nil
}
c.Conf.EncryptLeaseSet = false
return nil
}
}
//SetLeaseSetKey sets
func SetLeaseSetKey(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.LeaseSetKey = s
return nil
}
}
//SetLeaseSetPrivateKey sets
func SetLeaseSetPrivateKey(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.LeaseSetPrivateKey = s
return nil
}
}
//SetLeaseSetPrivateSigningKey sets
func SetLeaseSetPrivateSigningKey(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.LeaseSetPrivateSigningKey = s
return nil
}
}
//SetMessageReliability sets
func SetMessageReliability(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.MessageReliability = s
return nil
}
}
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.InAllowZeroHop = true
return nil
}
c.Conf.InAllowZeroHop = false
return nil
}
}
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.OutAllowZeroHop = true
return nil
}
c.Conf.OutAllowZeroHop = false
return nil
}
}
//SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.FastRecieve = true
return nil
}
c.Conf.FastRecieve = false
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.UseCompression = true
return nil
}
c.Conf.UseCompression = false
return nil
}
}
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.ReduceIdle = true
return nil
}
c.Conf.ReduceIdle = false
return nil
}
}
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.ReduceIdleTime = 300000
if u >= 6 {
c.Conf.ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.ReduceIdleTime = 300000
if u >= 300000 {
c.Conf.ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if u < 5 {
c.Conf.ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if b {
c.Conf.CloseIdle = true
return nil
}
c.Conf.CloseIdle = false
return nil
}
}
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.CloseIdleTime = 300000
if u >= 6 {
c.Conf.CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
}
}
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.CloseIdleTime = 300000
if u >= 300000 {
c.Conf.CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)")
}
}
//SetAccessListType tells the system to treat the accessList as a whitelist
func SetAccessListType(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if s == "whitelist" {
c.Conf.AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.Conf.AccessListType = "blacklist"
return nil
} else if s == "none" {
c.Conf.AccessListType = ""
return nil
} else if s == "" {
c.Conf.AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetAccessList tells the system to treat the accessList as a whitelist
func SetAccessList(s []string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
if len(s) > 0 {
for _, a := range s {
c.Conf.AccessList = append(c.Conf.AccessList, a)
}
return nil
}
return nil
}
}
//SetKeyFile sets
func SetKeyFile(s string) func(*SAMSSUForwarder) error {
return func(c *SAMSSUForwarder) error {
c.Conf.KeyFilePath = s
return nil
}
}

View File

@ -1,6 +1,7 @@
package samforwarderudp
import (
"fmt"
"io"
"log"
"net"
@ -14,13 +15,14 @@ import (
"github.com/eyedeekay/sam-forwarder/hashhash"
"github.com/eyedeekay/sam-forwarder/i2pkeys"
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/options"
"github.com/eyedeekay/sam3"
"github.com/eyedeekay/sam3/i2pkeys"
)
//SAMSSUForwarder is a structure which automatically configured the forwarding of
//SAMDGForwarder is a structure which automatically configured the forwarding of
//a local service to i2p over the SAM API.
type SAMSSUForwarder struct {
type SAMDGForwarder struct {
samConn *sam3.SAM
SamKeys i2pkeys.I2PKeys
Hasher *hashhash.Hasher
@ -36,36 +38,36 @@ type SAMSSUForwarder struct {
var err error
func (f *SAMSSUForwarder) Config() *i2ptunconf.Conf {
func (f *SAMDGForwarder) Config() *i2ptunconf.Conf {
if f.Conf == nil {
f.Conf = i2ptunconf.NewI2PBlankTunConf()
}
return f.Conf
}
func (f *SAMSSUForwarder) GetType() string {
func (f *SAMDGForwarder) GetType() string {
return f.Config().Type
}
func (f *SAMSSUForwarder) ID() string {
func (f *SAMDGForwarder) ID() string {
return f.Config().TunName
}
func (f *SAMSSUForwarder) Keys() i2pkeys.I2PKeys {
func (f *SAMDGForwarder) Keys() i2pkeys.I2PKeys {
return f.SamKeys
}
func (f *SAMSSUForwarder) Cleanup() {
func (f *SAMDGForwarder) Cleanup() {
f.publishConnection.Close()
f.clientConnection.Close()
f.samConn.Close()
}
func (f *SAMSSUForwarder) Close() error {
func (f *SAMDGForwarder) Close() error {
return nil
}
func (f *SAMSSUForwarder) print() []string {
func (f *SAMDGForwarder) print() []string {
/*lsk, lspk, lspsk := f.leasesetsettings()
return []string{
//f.targetForPort443(),
@ -95,7 +97,7 @@ func (f *SAMSSUForwarder) print() []string {
return f.Config().PrintSlice()
}
func (f *SAMSSUForwarder) Props() map[string]string {
func (f *SAMDGForwarder) Props() map[string]string {
r := make(map[string]string)
print := f.print()
print = append(print, "base32="+f.Base32())
@ -108,7 +110,7 @@ func (f *SAMSSUForwarder) Props() map[string]string {
return r
}
func (f *SAMSSUForwarder) Print() string {
func (f *SAMDGForwarder) Print() string {
var r string
r += "name=" + f.Config().TunName + "\n"
r += "type=" + f.Config().Type + "\n"
@ -121,7 +123,7 @@ func (f *SAMSSUForwarder) Print() string {
return strings.Replace(r, "\n\n", "\n", -1)
}
func (f *SAMSSUForwarder) Search(search string) string {
func (f *SAMDGForwarder) Search(search string) string {
terms := strings.Split(search, ",")
if search == "" {
return f.Print()
@ -134,10 +136,10 @@ func (f *SAMSSUForwarder) Search(search string) string {
return f.Print()
}
func (f *SAMSSUForwarder) accesslisttype() string {
if f.Config().AccessListType == "whitelist" {
func (f *SAMDGForwarder) accesslisttype() string {
if f.Config().AccessListType == "allowlist" {
return "i2cp.enableAccessList=true"
} else if f.Config().AccessListType == "blacklist" {
} else if f.Config().AccessListType == "blocklist" {
return "i2cp.enableBlackList=true"
} else if f.Config().AccessListType == "none" {
return ""
@ -145,7 +147,7 @@ func (f *SAMSSUForwarder) accesslisttype() string {
return ""
}
func (f *SAMSSUForwarder) accesslist() string {
func (f *SAMDGForwarder) accesslist() string {
if f.Config().AccessListType != "" && len(f.Config().AccessList) > 0 {
r := ""
for _, s := range f.Config().AccessList {
@ -156,7 +158,7 @@ func (f *SAMSSUForwarder) accesslist() string {
return ""
}
func (f *SAMSSUForwarder) leasesetsettings() (string, string, string) {
func (f *SAMDGForwarder) leasesetsettings() (string, string, string) {
var r, s, t string
if f.Config().LeaseSetKey != "" {
r = "i2cp.leaseSetKey=" + f.Config().LeaseSetKey
@ -171,16 +173,16 @@ func (f *SAMSSUForwarder) leasesetsettings() (string, string, string) {
}
// Target returns the host:port of the local service you want to forward to i2p
func (f *SAMSSUForwarder) Target() string {
func (f *SAMDGForwarder) Target() string {
return f.Config().TargetHost + ":" + f.Config().TargetPort
}
func (f *SAMSSUForwarder) sam() string {
func (f *SAMDGForwarder) sam() string {
return f.Config().SamHost + ":" + f.Config().SamPort
}
//func (f *SAMSSUForwarder) forward(conn net.Conn) {
func (f *SAMSSUForwarder) forward() {
//func (f *SAMDGForwarder) forward(conn net.Conn) {
func (f *SAMDGForwarder) forward() {
Loop := false
if f.clientConnection == nil {
for !Loop {
@ -217,23 +219,23 @@ func (f *SAMSSUForwarder) forward() {
}
//Base32 returns the base32 address where the local service is being forwarded
func (f *SAMSSUForwarder) Base32() string {
func (f *SAMDGForwarder) Base32() string {
return f.SamKeys.Addr().Base32()
}
//Base32Readable returns the base32 address where the local service is being forwarded
func (f *SAMSSUForwarder) Base32Readable() string {
func (f *SAMDGForwarder) Base32Readable() string {
b32 := strings.Replace(f.Base32(), ".b32.i2p", "", 1)
rhash, _ := f.Hasher.Friendly(b32)
return rhash + " " + strconv.Itoa(len(b32))
}
//Base64 returns the base64 address where the local service is being forwarded
func (f *SAMSSUForwarder) Base64() string {
func (f *SAMDGForwarder) Base64() string {
return f.SamKeys.Addr().Base64()
}
func (f *SAMSSUForwarder) errSleep(err error) bool {
func (f *SAMDGForwarder) errSleep(err error) bool {
if err != nil {
log.Printf("Dial failed: %v, waiting 5 minutes to try again\n", err)
time.Sleep(5 * time.Minute)
@ -244,10 +246,10 @@ func (f *SAMSSUForwarder) errSleep(err error) bool {
}
//Serve starts the SAM connection and and forwards the local host:port to i2p
func (f *SAMSSUForwarder) Serve() error {
func (f *SAMDGForwarder) Serve() error {
var err error
sp, _ := strconv.Atoi(f.Config().SamPort)
sp, err := strconv.Atoi(f.Config().SamPort)
f.publishConnection, err = f.samConn.NewDatagramSession(
f.Config().TunName,
f.SamKeys,
@ -255,8 +257,7 @@ func (f *SAMSSUForwarder) Serve() error {
sp-1,
)
if err != nil {
log.Println("Session Creation error:", err.Error())
return err
return fmt.Errorf("Session creation Error%s", err)
}
log.Println("SAM datagram session established.")
@ -268,55 +269,55 @@ func (f *SAMSSUForwarder) Serve() error {
}
}
func (s *SAMSSUForwarder) Load() (samtunnel.SAMTunnel, error) {
func (s *SAMDGForwarder) Load() (samtunnel.SAMTunnel, error) {
s.samConn, err = sam3.NewSAM(s.sam())
if err != nil {
return nil, err
return nil, fmt.Errorf("SAM connection error%s", err)
}
log.Println("SAM Bridge connection established.")
if s.Config().SaveFile {
log.Println("Saving i2p keys")
}
if s.SamKeys, err = sfi2pkeys.Load(s.Config().FilePath, s.Config().TunName, s.Config().KeyFilePath, s.samConn, s.Config().SaveFile); err != nil {
return nil, err
return nil, fmt.Errorf("SAM key load/generate error%s", err)
}
log.Println("Destination keys generated, tunnel name:", s.Config().TunName)
if s.Config().SaveFile {
if err := sfi2pkeys.Save(s.Config().FilePath, s.Config().TunName, s.Config().KeyFilePath, s.SamKeys); err != nil {
return nil, err
return nil, fmt.Errorf("SAM key save error%s", err)
}
log.Println("Saved tunnel keys for", s.Conf.TunName, "in", s.Conf.FilePath)
}
s.Hasher, err = hashhash.NewHasher(len(strings.Replace(s.Base32(), ".b32.i2p", "", 1)))
if err != nil {
return nil, err
return nil, fmt.Errorf("Word-hash generation error%s", err)
}
s.up = true
return s, nil
}
func (f *SAMSSUForwarder) Up() bool {
func (f *SAMDGForwarder) Up() bool {
return f.up
}
//NewSAMSSUForwarder makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMSSUForwarder(host, port string) (*SAMSSUForwarder, error) {
return NewSAMSSUForwarderFromOptions(SetHost(host), SetPort(port))
//NewSAMDGForwarder makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMDGForwarder(host, port string) (samtunnel.SAMTunnel, error) {
return NewSAMDGForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(port))
}
//NewSAMSSUForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMSSUForwarderFromOptions(opts ...func(*SAMSSUForwarder) error) (*SAMSSUForwarder, error) {
var s SAMSSUForwarder
//NewSAMDGForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewSAMDGForwarderFromOptions(opts ...func(samtunnel.SAMTunnel) error) (*SAMDGForwarder, error) {
var s SAMDGForwarder
s.Conf = i2ptunconf.NewI2PBlankTunConf()
s.Conf.Type = "udpserver"
for _, o := range opts {
if err := o(&s); err != nil {
return nil, err
return nil, fmt.Errorf("Option Setting Error: %s", err)
}
}
l, e := s.Load()
if e != nil {
return nil, e
return nil, fmt.Errorf("%s", e)
}
return l.(*SAMSSUForwarder), nil
return l.(*SAMDGForwarder), nil
}

View File

@ -3,114 +3,116 @@ package samforwarderudp
import (
"log"
"testing"
"github.com/eyedeekay/sam-forwarder/options"
)
func TestOptionUDPHost(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetHost("127.0.0.1"))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetHost("127.0.0.1"))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPPort(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetPort("7656"))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetPort("7656"))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPInLength(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetInLength(3))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPOutLength(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetInLength(3))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPInVariance(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetInVariance(1))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetInVariance(1))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPOutVariance(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetOutVariance(1))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutVariance(1))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPInQuantity(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetInQuantity(6))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetInQuantity(6))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPOutQuantity(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetOutQuantity(6))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutQuantity(6))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPInBackups(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetInBackups(5))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetInBackups(5))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPOutBackups(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetOutBackups(5))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutBackups(5))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPReduceIdleQuantity(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetReduceIdleQuantity(4))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetReduceIdleQuantity(4))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPEncryptLease(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetEncrypt(true))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetEncrypt(true))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestOptionUDPSaveFile(t *testing.T) {
client, err := NewSAMSSUForwarderFromOptions(SetSaveFile(true))
client, err := NewSAMDGForwarderFromOptions(samoptions.SetSaveFile(true))
if err != nil {
t.Fatalf("NewSAMSSUForwarder() Error: %q\n", err)
t.Fatalf("NewSAMDGForwarder() Error: %q\n", err)
}
log.Println(client.Base32())
}
func TestClientOptionHost(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientHost("127.0.0.1"))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetHost("127.0.0.1"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -118,7 +120,7 @@ func TestClientOptionHost(t *testing.T) {
}
func TestClientOptionPort(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientSAMPort("7656"))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetSAMPort("7656"))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -126,7 +128,7 @@ func TestClientOptionPort(t *testing.T) {
}
func TestClientOptionInLength(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientInLength(3))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -134,7 +136,7 @@ func TestClientOptionInLength(t *testing.T) {
}
func TestClientOptionOutLength(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientInLength(3))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetInLength(3))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -142,7 +144,7 @@ func TestClientOptionOutLength(t *testing.T) {
}
func TestClientOptionInVariance(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientInVariance(1))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetInVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -150,7 +152,7 @@ func TestClientOptionInVariance(t *testing.T) {
}
func TestClientOptionOutVariance(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientOutVariance(1))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetOutVariance(1))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -158,7 +160,7 @@ func TestClientOptionOutVariance(t *testing.T) {
}
func TestClientOptionInQuantity(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientInQuantity(6))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetInQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -166,7 +168,7 @@ func TestClientOptionInQuantity(t *testing.T) {
}
func TestClientOptionOutQuantity(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientOutQuantity(6))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetOutQuantity(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -174,7 +176,7 @@ func TestClientOptionOutQuantity(t *testing.T) {
}
func TestClientOptionInBackups(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientInBackups(5))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetInBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -182,7 +184,7 @@ func TestClientOptionInBackups(t *testing.T) {
}
func TestClientOptionOutBackups(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientOutBackups(5))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetOutBackups(5))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -190,7 +192,7 @@ func TestClientOptionOutBackups(t *testing.T) {
}
func TestClientOptionReduceIdleQuantity(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientReduceIdleQuantity(4))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetReduceIdleQuantity(4))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -198,7 +200,7 @@ func TestClientOptionReduceIdleQuantity(t *testing.T) {
}
func TestClientOptionReduceIdleTimeMs(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientReduceIdleTimeMs(300000))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetReduceIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -206,7 +208,7 @@ func TestClientOptionReduceIdleTimeMs(t *testing.T) {
}
func TestClientOptionReduceIdleTime(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientReduceIdleTime(6))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetReduceIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -214,7 +216,7 @@ func TestClientOptionReduceIdleTime(t *testing.T) {
}
func TestClientOptionCloseIdleTimeMs(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientCloseIdleTimeMs(300000))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetCloseIdleTimeMs(300000))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -222,7 +224,7 @@ func TestClientOptionCloseIdleTimeMs(t *testing.T) {
}
func TestClientOptionCloseIdleTime(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientCloseIdleTime(6))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetCloseIdleTime(6))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -230,7 +232,7 @@ func TestClientOptionCloseIdleTime(t *testing.T) {
}
func TestClientOptionEncryptLease(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientEncrypt(true))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetEncrypt(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}
@ -238,7 +240,7 @@ func TestClientOptionEncryptLease(t *testing.T) {
}
func TestClientOptionSaveFile(t *testing.T) {
client, err := NewSAMSSUClientForwarderFromOptions(SetClientSaveFile(true))
client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetSaveFile(true))
if err != nil {
t.Fatalf("NewSAMForwarder() Error: %q\n", err)
}