diff --git a/config/helpers/tunconf_client.go b/config/helpers/tunconf_client.go index be84c83..742f463 100644 --- a/config/helpers/tunconf_client.go +++ b/config/helpers/tunconf_client.go @@ -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 @@ -168,40 +169,40 @@ func NewSAMClientForwarderFromConfig(iniFile, SamHost, SamPort string, label ... func NewSAMDGClientForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMDGClientForwarder, error) { if config != nil { return samforwarderudp.NewSAMDGClientForwarderFromOptions( - 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), + 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 diff --git a/config/helpers/tunconf_server.go b/config/helpers/tunconf_server.go index d2e533c..78808a1 100644 --- a/config/helpers/tunconf_server.go +++ b/config/helpers/tunconf_server.go @@ -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 @@ -73,39 +74,39 @@ func NewSAMForwarderFromConfig(iniFile, SamHost, SamPort string, label ...string func NewSAMDGForwarderFromConf(config *i2ptunconf.Conf) (*samforwarderudp.SAMDGForwarder, error) { if config != nil { return samforwarderudp.NewSAMDGForwarderFromOptions( - 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), + 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 diff --git a/udp/forwarder-options-udp.go b/options/options.go similarity index 82% rename from udp/forwarder-options-udp.go rename to options/options.go index caa835c..5f2c6b3 100644 --- a/udp/forwarder-options-udp.go +++ b/options/options.go @@ -1,4 +1,4 @@ -package samforwarderudp +package samoptions import ( "fmt" @@ -7,10 +7,10 @@ import ( "github.com/eyedeekay/sam-forwarder/interface" ) -//Option is a SAMDGForwarder Option +//Option is a SAMForwarder Option type Option func(samtunnel.SAMTunnel) error -//SetFilePath sets the host of the SAMDGForwarder's SAM bridge +//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 @@ -18,65 +18,16 @@ func SetFilePath(s string) func(samtunnel.SAMTunnel) error { } } -//SetSaveFile tells the router to use an encrypted leaseset -func SetSaveFile(b bool) func(samtunnel.SAMTunnel) error { +//SetType sets the type of the forwarder server +func SetType(s string) func(samtunnel.SAMTunnel) error { return func(c samtunnel.SAMTunnel) error { - c.Config().SaveFile = b - return nil - } -} - -//SetHost sets the host of the SAMDGForwarder's SAM bridge -func SetHost(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TargetHost = s - return nil - } -} - -//SetPort sets the port of the SAMDGForwarder's SAM bridge using a string -func SetPort(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - port, err := strconv.Atoi(s) - if err != nil { - return fmt.Errorf("Invalid SSU Server Target Port %s; non-number ", s) - } - if port < 65536 && port > -1 { - c.Config().TargetPort = s + if s == "http" { + c.Config().Type = s + return nil + } else { + c.Config().Type = "server" return nil } - return fmt.Errorf("Invalid port") - } -} - -//SetSAMHost sets the host of the SAMDGForwarder'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 SAMDGForwarder'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 SAMDGForwarder's SAM bridge -func SetName(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TunName = s - return nil } } @@ -102,6 +53,68 @@ func SetSigType(s string) func(samtunnel.SAMTunnel) error { } } +//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 { @@ -202,7 +215,7 @@ func SetEncrypt(b bool) func(samtunnel.SAMTunnel) error { } } -//SetLeaseSetKey sets +//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 @@ -210,7 +223,7 @@ func SetLeaseSetKey(s string) func(samtunnel.SAMTunnel) error { } } -//SetLeaseSetPrivateKey sets +//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 @@ -218,7 +231,7 @@ func SetLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error { } } -//SetLeaseSetPrivateSigningKey sets +//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 @@ -226,7 +239,7 @@ func SetLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error { } } -//SetMessageReliability sets +//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 @@ -258,18 +271,6 @@ func SetAllowZeroOut(b bool) func(samtunnel.SAMTunnel) error { } } -//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 - } -} - //SetCompress tells clients to use compression func SetCompress(b bool) func(samtunnel.SAMTunnel) error { return func(c samtunnel.SAMTunnel) error { @@ -282,6 +283,18 @@ func SetCompress(b bool) func(samtunnel.SAMTunnel) error { } } +//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 { @@ -302,7 +315,7 @@ func SetReduceIdleTime(u int) func(samtunnel.SAMTunnel) error { c.Config().ReduceIdleTime = (u * 60) * 1000 return nil } - return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u) + return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u) } } @@ -314,7 +327,7 @@ func SetReduceIdleTimeMs(u int) func(samtunnel.SAMTunnel) error { c.Config().ReduceIdleTime = u return nil } - return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u) + return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u) } } @@ -349,7 +362,7 @@ func SetCloseIdleTime(u int) func(samtunnel.SAMTunnel) error { c.Config().CloseIdleTime = (u * 60) * 1000 return nil } - return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)") + return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u) } } @@ -361,11 +374,11 @@ func SetCloseIdleTimeMs(u int) func(samtunnel.SAMTunnel) error { c.Config().CloseIdleTime = u return nil } - return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes)") + return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u) } } -//SetAccessListType tells the system to treat the accessList as a allowlist +//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" { @@ -385,7 +398,7 @@ func SetAccessListType(s string) func(samtunnel.SAMTunnel) error { } } -//SetAccessList tells the system to treat the accessList as a allowlist +//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 { @@ -398,6 +411,22 @@ func SetAccessList(s []string) func(samtunnel.SAMTunnel) error { } } +//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 { @@ -405,3 +434,17 @@ func SetKeyFile(s string) func(samtunnel.SAMTunnel) error { 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 + } +} diff --git a/tcp/forwarder-client-options.go b/tcp/forwarder-client-options.go deleted file mode 100644 index f3082fc..0000000 --- a/tcp/forwarder-client-options.go +++ /dev/null @@ -1,415 +0,0 @@ -package samforwarder - -import ( - "fmt" - "strconv" - - "github.com/eyedeekay/sam-forwarder/interface" -) - -//ClientOption is a SAMClientForwarder Option -type ClientOption func(samtunnel.SAMTunnel) error - -//SetClientFilePath sets the host of the SAMClientForwarder's SAM bridge -func SetClientFilePath(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().FilePath = s - return nil - } -} - -//SetClientSaveFile tells the router to save the tunnel keys long-term -func SetClientSaveFile(b bool) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().SaveFile = b - return nil - } -} - -//SetClientHost sets the host of the SAMClientForwarder's SAM bridge -func SetClientHost(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TargetHost = s - return nil - } -} - -//SetClientDestination sets the destination to forwarder SAMClientForwarder's to -func SetClientDestination(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().ClientDest = s - return nil - } -} - -//SetClientPort sets the port of the SAMClientForwarder's SAM bridge using a string -func SetClientPort(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - port, err := strconv.Atoi(s) - if err != nil { - return fmt.Errorf("Invalid TCP Client Target Port %s; non-number ", s) - } - if port < 65536 && port > -1 { - c.Config().TargetPort = s - return nil - } - return fmt.Errorf("Invalid port") - } -} - -//SetClientSAMHost sets the host of the SAMClientForwarder's SAM bridge -func SetClientSAMHost(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().SamHost = s - return nil - } -} - -//SetClientSAMPort sets the port of the SAMClientForwarder's SAM bridge using a string -func SetClientSAMPort(s string) func(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") - } -} - -//SetClientName sets the host of the SAMClientForwarder's SAM bridge -func SetClientName(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TunName = s - return nil - } -} - -//SetSigType sets the type of the forwarder server -func SetClientSigType(s string) func(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 - } -} - -//SetClientInLength sets the number of hops inbound -func SetClientInLength(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") - } -} - -//SetClientOutLength sets the number of hops outbound -func SetClientOutLength(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") - } -} - -//SetClientInVariance sets the variance of a number of hops inbound -func SetClientInVariance(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") - } -} - -//SetClientOutVariance sets the variance of a number of hops outbound -func SetClientOutVariance(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") - } -} - -//SetClientInQuantity sets the inbound tunnel quantity -func SetClientInQuantity(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") - } -} - -//SetClientOutQuantity sets the outbound tunnel quantity -func SetClientOutQuantity(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") - } -} - -//SetClientInBackups sets the inbound tunnel backups -func SetClientInBackups(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") - } -} - -//SetClientOutBackups sets the inbound tunnel backups -func SetClientOutBackups(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") - } -} - -//SetClientEncrypt tells the router to use an encrypted leaseset -func SetClientEncrypt(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 - } -} - -//SetClientLeaseSetKey sets -func SetClientLeaseSetKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetKey = s - return nil - } -} - -//SetClientLeaseSetPrivateKey sets -func SetClientLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetPrivateKey = s - return nil - } -} - -//SetClientLeaseSetPrivateSigningKey sets -func SetClientLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetPrivateSigningKey = s - return nil - } -} - -//SetClientMessageReliability sets -func SetClientMessageReliability(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().MessageReliability = s - return nil - } -} - -//SetClientAllowZeroIn tells the tunnel to accept zero-hop peers -func SetClientAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - if b { - c.Config().InAllowZeroHop = true - return nil - } - c.Config().InAllowZeroHop = false - return nil - } -} - -//SetClientAllowZeroOut tells the tunnel to accept zero-hop peers -func SetClientAllowZeroOut(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 - } -} - -//SetClientFastRecieve tells clients use the i2cp.fastRecieve option -func SetClientFastRecieve(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 - } -} - -//SetClientCompress tells clients to use compression -func SetClientCompress(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 - } -} - -//SetClientReduceIdle tells the connection to reduce it's tunnels during extended idle time. -func SetClientReduceIdle(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 - } -} - -//SetClientReduceIdleTime sets the time to wait before reducing tunnels to idle levels -func SetClientReduceIdleTime(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) - } -} - -//SetClientReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds -func SetClientReduceIdleTimeMs(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) - } -} - -//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time -func SetClientReduceIdleQuantity(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") - } -} - -//SetClientCloseIdle tells the connection to close it's tunnels during extended idle time. -func SetClientCloseIdle(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 - } -} - -//SetClientCloseIdleTime sets the time to wait before closing tunnels to idle levels -func SetClientCloseIdleTime(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) - } -} - -//SetClientCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds -func SetClientCloseIdleTimeMs(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) - } -} - -//SetClientAccessListType tells the system to treat the accessList as a allowlist -func SetClientAccessListType(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)") - } -} - -//SetClientAccessList tells the system to treat the accessList as a allowlist -func SetClientAccessList(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 - } -} - -//SetKeyFile sets -func SetClientPassword(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().KeyFilePath = s - return nil - } -} diff --git a/tcp/forwarder-client.go b/tcp/forwarder-client.go index 4b62c01..d4c5f72 100644 --- a/tcp/forwarder-client.go +++ b/tcp/forwarder-client.go @@ -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" ) @@ -259,7 +260,7 @@ 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) (samtunnel.SAMTunnel, error) { - return NewSAMClientForwarderFromOptions(SetClientHost(host), SetClientPort(port)) + return NewSAMClientForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(port)) } //NewSAMClientForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments diff --git a/tcp/forwarder-options.go b/tcp/forwarder-options.go index c2d7d79..e6e47af 100644 --- a/tcp/forwarder-options.go +++ b/tcp/forwarder-options.go @@ -1,440 +1,5 @@ package samforwarder -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 - } -} - //SetByteLimit sets the number of hops inbound func SetByteLimit(u int64) func(*SAMForwarder) error { return func(c *SAMForwarder) error { diff --git a/tcp/forwarder.go b/tcp/forwarder.go index 7486dde..ce36061 100644 --- a/tcp/forwarder.go +++ b/tcp/forwarder.go @@ -19,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" ) @@ -421,7 +422,7 @@ 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) (samtunnel.SAMTunnel, error) { - return NewSAMForwarderFromOptions(SetHost(host), SetPort(port)) + return NewSAMForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(port)) } //NewSAMForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments diff --git a/tcp/forwarder_test.go b/tcp/forwarder_test.go index 7bc8d8e..db59745 100644 --- a/tcp/forwarder_test.go +++ b/tcp/forwarder_test.go @@ -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) } diff --git a/udp/forwarder-client-options-udp.go b/udp/forwarder-client-options-udp.go deleted file mode 100644 index bc9ddf4..0000000 --- a/udp/forwarder-client-options-udp.go +++ /dev/null @@ -1,415 +0,0 @@ -package samforwarderudp - -import ( - "fmt" - "strconv" - - "github.com/eyedeekay/sam-forwarder/interface" -) - -//ClientOption is a SAMDGClientForwarder Option -type ClientOption func(samtunnel.SAMTunnel) error - -//SetClientFilePath sets the host of the SAMDGForwarder's SAM bridge -func SetClientFilePath(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().FilePath = s - return nil - } -} - -//SetClientSaveFile tells the router to use an encrypted leaseset -func SetClientSaveFile(b bool) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().SaveFile = b - return nil - } -} - -//SetClientHost sets the host of the SAMDGForwarder's SAM bridge -func SetClientHost(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TargetHost = s - return nil - } -} - -//SetClientPort sets the port of the SAMDGForwarder's SAM bridge using a string -func SetClientPort(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - port, err := strconv.Atoi(s) - if err != nil { - return fmt.Errorf("Invalid SSU Client Target Port %s; non-number ", s) - } - if port < 65536 && port > -1 { - c.Config().TargetPort = s - return nil - } - return fmt.Errorf("Invalid port") - } -} - -//SetClientSAMHost sets the host of the SAMDGForwarder's SAM bridge -func SetClientSAMHost(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().SamHost = s - return nil - } -} - -//SetClientSAMPort sets the port of the SAMDGForwarder's SAM bridge using a string -func SetClientSAMPort(s string) func(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") - } -} - -//SetClientDestination sets the destination to forwarder SAMClientForwarder's to -func SetClientDestination(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().ClientDest = s - return nil - } -} - -//SetClientName sets the host of the SAMDGForwarder's SAM bridge -func SetClientName(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().TunName = s - return nil - } -} - -//SetClientSigType sets the type of the forwarder server -func SetClientSigType(s string) func(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 - } -} - -//SetClientInLength sets the number of hops inbound -func SetClientInLength(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") - } -} - -//SetClientOutLength sets the number of hops outbound -func SetClientOutLength(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") - } -} - -//SetClientInVariance sets the variance of a number of hops inbound -func SetClientInVariance(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") - } -} - -//SetClientOutVariance sets the variance of a number of hops outbound -func SetClientOutVariance(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") - } -} - -//SetClientInQuantity sets the inbound tunnel quantity -func SetClientInQuantity(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") - } -} - -//SetClientOutQuantity sets the outbound tunnel quantity -func SetClientOutQuantity(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") - } -} - -//SetClientInBackups sets the inbound tunnel backups -func SetClientInBackups(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") - } -} - -//SetClientOutBackups sets the inbound tunnel backups -func SetClientOutBackups(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") - } -} - -//SetClientEncrypt tells the router to use an encrypted leaseset -func SetClientEncrypt(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 - } -} - -//SetClientLeaseSetKey sets the host of the SAMForwarder's SAM bridge -func SetClientLeaseSetKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetKey = s - return nil - } -} - -//SetClientLeaseSetPrivateKey sets the host of the SAMForwarder's SAM bridge -func SetClientLeaseSetPrivateKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetPrivateKey = s - return nil - } -} - -//SetClientLeaseSetPrivateSigningKey sets the host of the SAMForwarder's SAM bridge -func SetClientLeaseSetPrivateSigningKey(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().LeaseSetPrivateSigningKey = s - return nil - } -} - -//SetClientMessageReliability sets -func SetClientMessageReliability(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().MessageReliability = s - return nil - } -} - -//SetClientAllowZeroIn tells the tunnel to accept zero-hop peers -func SetClientAllowZeroIn(b bool) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - if b { - c.Config().InAllowZeroHop = true - return nil - } - c.Config().InAllowZeroHop = false - return nil - } -} - -//SetClientAllowZeroOut tells the tunnel to accept zero-hop peers -func SetClientAllowZeroOut(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 - } -} - -//SetFastRecieve tells clients to use i2cp.fastRecieve -func SetClientFastRecieve(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 - } -} - -//SetClientCompress tells clients to use compression -func SetClientCompress(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 - } -} - -//SetClientReduceIdle tells the connection to reduce it's tunnels during extended idle time. -func SetClientReduceIdle(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 - } -} - -//SetClientReduceIdleTime sets the time to wait before reducing tunnels to idle levels -func SetClientReduceIdleTime(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)") - } -} - -//SetClientReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds -func SetClientReduceIdleTimeMs(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 minutes)") - } -} - -//SetClientReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time -func SetClientReduceIdleQuantity(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") - } -} - -//SetClientCloseIdle tells the connection to close it's tunnels during extended idle time. -func SetClientCloseIdle(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 - } -} - -//SetClientCloseIdleTime sets the time to wait before closing tunnels to idle levels -func SetClientCloseIdleTime(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) - } -} - -//SetClientCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds -func SetClientCloseIdleTimeMs(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) - } -} - -//SetClientAccessListType tells the system to treat the accessList as a allowlist -func SetClientAccessListType(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)") - } -} - -//SetClientAccessList tells the system to treat the accessList as a allowlist -func SetClientAccessList(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 - } -} - -//SetKeyFile sets -func SetClientPassword(s string) func(samtunnel.SAMTunnel) error { - return func(c samtunnel.SAMTunnel) error { - c.Config().KeyFilePath = s - return nil - } -} diff --git a/udp/forwarder-client-udp.go b/udp/forwarder-client-udp.go index 7586dba..65bf729 100644 --- a/udp/forwarder-client-udp.go +++ b/udp/forwarder-client-udp.go @@ -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" i2pkeys "github.com/eyedeekay/sam3/i2pkeys" ) @@ -281,6 +282,11 @@ func (s *SAMDGClientForwarder) Load() (samtunnel.SAMTunnel, error) { return s, nil } +//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 diff --git a/udp/forwarder-udp.go b/udp/forwarder-udp.go index 35e9e37..f97b842 100644 --- a/udp/forwarder-udp.go +++ b/udp/forwarder-udp.go @@ -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" ) @@ -301,7 +302,7 @@ func (f *SAMDGForwarder) Up() bool { //NewSAMDGForwarder makes a new SAM forwarder with default options, accepts host:port arguments func NewSAMDGForwarder(host, port string) (samtunnel.SAMTunnel, error) { - return NewSAMDGForwarderFromOptions(SetHost(host), SetPort(port)) + return NewSAMDGForwarderFromOptions(samoptions.SetHost(host), samoptions.SetPort(port)) } //NewSAMDGForwarderFromOptions makes a new SAM forwarder with default options, accepts host:port arguments diff --git a/udp/forwarder_test.go b/udp/forwarder_test.go index 9bacdb1..c4f8fa5 100644 --- a/udp/forwarder_test.go +++ b/udp/forwarder_test.go @@ -3,10 +3,12 @@ package samforwarderudp import ( "log" "testing" + + "github.com/eyedeekay/sam-forwarder/options" ) func TestOptionUDPHost(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetHost("127.0.0.1")) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetHost("127.0.0.1")) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -14,7 +16,7 @@ func TestOptionUDPHost(t *testing.T) { } func TestOptionUDPPort(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetPort("7656")) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetPort("7656")) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -22,7 +24,7 @@ func TestOptionUDPPort(t *testing.T) { } func TestOptionUDPInLength(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetInLength(3)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetInLength(3)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -30,7 +32,7 @@ func TestOptionUDPInLength(t *testing.T) { } func TestOptionUDPOutLength(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetInLength(3)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetInLength(3)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -38,7 +40,7 @@ func TestOptionUDPOutLength(t *testing.T) { } func TestOptionUDPInVariance(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetInVariance(1)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetInVariance(1)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -46,7 +48,7 @@ func TestOptionUDPInVariance(t *testing.T) { } func TestOptionUDPOutVariance(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetOutVariance(1)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutVariance(1)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -54,7 +56,7 @@ func TestOptionUDPOutVariance(t *testing.T) { } func TestOptionUDPInQuantity(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetInQuantity(6)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetInQuantity(6)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -62,7 +64,7 @@ func TestOptionUDPInQuantity(t *testing.T) { } func TestOptionUDPOutQuantity(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetOutQuantity(6)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutQuantity(6)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -70,7 +72,7 @@ func TestOptionUDPOutQuantity(t *testing.T) { } func TestOptionUDPInBackups(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetInBackups(5)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetInBackups(5)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -78,7 +80,7 @@ func TestOptionUDPInBackups(t *testing.T) { } func TestOptionUDPOutBackups(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetOutBackups(5)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetOutBackups(5)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -86,7 +88,7 @@ func TestOptionUDPOutBackups(t *testing.T) { } func TestOptionUDPReduceIdleQuantity(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetReduceIdleQuantity(4)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetReduceIdleQuantity(4)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -94,7 +96,7 @@ func TestOptionUDPReduceIdleQuantity(t *testing.T) { } func TestOptionUDPEncryptLease(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetEncrypt(true)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetEncrypt(true)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -102,7 +104,7 @@ func TestOptionUDPEncryptLease(t *testing.T) { } func TestOptionUDPSaveFile(t *testing.T) { - client, err := NewSAMDGForwarderFromOptions(SetSaveFile(true)) + client, err := NewSAMDGForwarderFromOptions(samoptions.SetSaveFile(true)) if err != nil { t.Fatalf("NewSAMDGForwarder() Error: %q\n", err) } @@ -110,7 +112,7 @@ func TestOptionUDPSaveFile(t *testing.T) { } func TestClientOptionHost(t *testing.T) { - client, err := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(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 := NewSAMDGClientForwarderFromOptions(SetClientSaveFile(true)) + client, err := NewSAMDGClientForwarderFromOptions(samoptions.SetSaveFile(true)) if err != nil { t.Fatalf("NewSAMForwarder() Error: %q\n", err) }