From 3631c87bfac3ea12b2fd07b0c0de6658c750f5f0 Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 19 Sep 2018 12:08:20 -0400 Subject: [PATCH] enabled setting client destinations from ini file. --- README.md.asc | 16 +++---- config/dest.go | 27 ++++++++++++ config/tunconf.go | 4 ++ etc/sam-forwarder/tunnels.ini | 3 +- etc/samcatd/tunnels.ini | 66 +++++++++++++++-------------- udp/forwarder-client-options-udp.go | 8 ++++ 6 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 config/dest.go diff --git a/README.md.asc b/README.md.asc index 9c6a835..fc5853f 100644 --- a/README.md.asc +++ b/README.md.asc @@ -81,12 +81,12 @@ I'm eventually going to make the manager implement net.Conn. This won't be exposed in the default application probably though, but rather as a library. -----BEGIN PGP SIGNATURE----- -iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAluiarYACgkQ11wDs5te -FOFb/wgAi8jrj66r8vaEnkABlOSpNems7X5jJbh3FcUVjo8tQPVANzaHf0nBo3yl -zi0ccERToNyDKqwo9J4z+OxXv5vv3A90uJaKUASMn34a84WQ4SD0jQ4RCsrkQqaa -du8HIUclfXr67qoYJx4OiE6biBJ2f9r8I243ll8RN/8eI1O55kWEhLn/k2hAqPHV -fI5OarJdaaM3ltKwsMXAPzNjm4tAyFaBLQbDcPUf3557zUFOwBA+qy17oeBmwklR -ALBhPnpEWVpVdV64zcVPQTkoLx9NXY8HwwMQQ/ROmA0tHs39NktHgkFPpuJhx1fs -sy0o9xWgzFHu7tmXTRMrS/ToX3GAEw== -=cOx/ +iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAluidHEACgkQ11wDs5te +FOFRDQgAigrVlLTqIXoExr2pa9UMsW2l+9586Ma+mIkUpUkQMxhi3Tp+mZa5JJRZ +bbBO8Fum+kmLcZBR2R9xLP7v+Td72+mVOff3lJ0MvoiBfrZ9Yyrv+0j9HJ+alctd +4wZt3zc7860togquQ99OXMVfY8Q/Xse/RwgGlPNl3iq9gQK+xoFUBVT0YuJLs4n0 +K0ayVYJdKrSpfyStAxD2TegGrJWCh3r8uxfSqhcO6VjdC7Nd/1s63Oq8EK9lMGro +eoiTKdOocMmEMm6B5ZDn4l9oFuHTMAnIPrFNmMtR7qY+FmLfxiGrsPrGxFBpbrN3 +R1hayLzsaK+i5WYnGl5W0tuzsMEtdA== +=Du9h -----END PGP SIGNATURE----- diff --git a/config/dest.go b/config/dest.go new file mode 100644 index 0000000..a62dc27 --- /dev/null +++ b/config/dest.go @@ -0,0 +1,27 @@ +package i2ptunconf + +// GetClientDest 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) GetClientDest(arg, def string, label ...string) string { + if arg != def { + return arg + } + if c.config == nil { + return arg + } + if x, o := c.Get("destination", label...); o { + return x + } + return arg +} + +// SetClientDest sets the key name from the config file +func (c *Conf) SetClientDest(label ...string) { + if v, ok := c.Get("destination", label...); ok { + c.ClientDest = v + } else { + c.ClientDest = v + } +} diff --git a/config/tunconf.go b/config/tunconf.go index 0829df5..df8ca38 100644 --- a/config/tunconf.go +++ b/config/tunconf.go @@ -21,6 +21,7 @@ type Conf struct { KeyFilePath string Labels []string Client bool + ClientDest string Type string SaveDirectory string SaveFile bool @@ -212,6 +213,7 @@ func (c *Conf) I2PINILoad(iniFile string, label ...string) error { c.SetAccessListType(label...) c.SetTargetPort443(label...) c.SetMessageReliability(label...) + c.SetClientDest(label...) c.SetKeyFile(label...) if v, ok := c.Get("i2cp.accessList", label...); ok { csv := strings.Split(v, ",") @@ -337,6 +339,7 @@ func NewSAMClientForwarderFromConf(config *Conf) (*samforwarder.SAMClientForward samforwarder.SetClientAccessList(config.AccessList), samforwarder.SetClientMessageReliability(config.MessageReliability), samforwarder.SetClientPassword(config.KeyFilePath), + samforwarder.SetClientDestination(config.ClientDest), ) } return nil, nil @@ -455,6 +458,7 @@ func NewSAMSSUClientForwarderFromConf(config *Conf) (*samforwarderudp.SAMSSUClie samforwarderudp.SetClientAccessList(config.AccessList), samforwarderudp.SetClientMessageReliability(config.MessageReliability), samforwarderudp.SetClientPassword(config.KeyFilePath), + samforwarderudp.SetClientDestination(config.ClientDest), ) } return nil, nil diff --git a/etc/sam-forwarder/tunnels.ini b/etc/sam-forwarder/tunnels.ini index 7d0435d..2f63ef1 100644 --- a/etc/sam-forwarder/tunnels.ini +++ b/etc/sam-forwarder/tunnels.ini @@ -1,6 +1,5 @@ -## Defaults, these are only invoked with the -start option or if labeled tunnels -## are not present(samcatd instructions) +## DO NOT USE THESE AS DEFAULTS. THEY ARE FOR TESTING. [ephsite] type = server diff --git a/etc/samcatd/tunnels.ini b/etc/samcatd/tunnels.ini index 1cc9d20..05e3565 100644 --- a/etc/samcatd/tunnels.ini +++ b/etc/samcatd/tunnels.ini @@ -1,9 +1,11 @@ ## Defaults, these are only invoked with the -start option or if labeled tunnels -## are not present(samcatd instructions) +## are not present(samcatd instructions). **THESE** are the correct config files +## to use as defaults, and not the ones in ../sam-forwarder/tunnels.ini, which +## are used for testing settings availability only. inbound.length = 3 -outbound.length = 6 +outbound.length = 3 inbound.lengthVariance = 0 outbound.lengthVariance = 0 inbound.backupQuantity = 3 @@ -26,37 +28,39 @@ type = server host = 127.0.0.1 port = 8081 inbound.length = 3 -outbound.length = 6 +outbound.length = 3 keys = forwarder -[sam-forwarder-two] -type = client -host = 127.0.0.1 -port = 8082 -inbound.length = 6 -outbound.length = 3 -keys = forwarder-two +#[sam-forwarder-two] +#type = client +#host = 127.0.0.1 +#port = 8082 +#inbound.length = 6 +#outbound.length = 3 +#destination = i2p-projekt.i2p +#keys = forwarder-two -[sam-forwarder-three] -type = udpclient -host = 127.0.0.1 -port = 8083 -inbound.length = 3 -outbound.length = 6 -keys = forwarder-three +#[sam-forwarder-three] +#type = udpclient +#host = 127.0.0.1 +#port = 8083 +#inbound.length = 3 +#outbound.length = 3 +#keys = forwarder-three -[sam-forwarder-four] -type = udpserver -host = 127.0.0.1 -port = 8084 -inbound.length = 6 -outbound.length = 3 -keys = forwarder-four +#[sam-forwarder-four] +#type = udpserver +#host = 127.0.0.1 +#port = 8084 +#inbound.length = 6 +#outbound.length = 3 +#destination = example-udp-stream.i2p +#keys = forwarder-four -[sam-forwarder-five] -type = http -host = 127.0.0.1 -port = 8085 -inbound.length = 3 -outbound.length = 6 -keys = forwarder-five +#[sam-forwarder-five] +#type = http +#host = 127.0.0.1 +#port = 8085 +#inbound.length = 3 +#outbound.length = 3 +#keys = forwarder-five diff --git a/udp/forwarder-client-options-udp.go b/udp/forwarder-client-options-udp.go index 5fb3f93..7dd0d7b 100644 --- a/udp/forwarder-client-options-udp.go +++ b/udp/forwarder-client-options-udp.go @@ -70,6 +70,14 @@ func SetClientSAMPort(s string) func(*SAMSSUClientForwarder) error { } } +//SetClientDestination sets the destination to forwarder SAMClientForwarder's to +func SetClientDestination(s string) func(*SAMSSUClientForwarder) error { + return func(c *SAMSSUClientForwarder) error { + c.dest = 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 {