move configuration into the struct

This commit is contained in:
idk
2019-09-03 21:38:47 -04:00
parent 0ff3d5f798
commit 6b993d6d62
7 changed files with 222 additions and 304 deletions

View File

@ -3,8 +3,15 @@ GO111MODULE=on
GO_COMPILER_OPTS = -a -tags netgo -ldflags '-w -extldflags "-static"'
USER_GH=eyedeekay
packagename=httptunnel
VERSION=0.32.04
httpall: fmt win lin linarm mac
tag:
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION) -d "I2P Tunnel Management tool for Go applications"
include multiproxy/Makefile
opall: fmt opwin oplin oplinarm opmac
@ -12,6 +19,9 @@ opall: fmt opwin oplin oplinarm opmac
ball:
cd multiproxy && make all
blin64:
cd multiproxy && make blin64
all: httpall opall ball
fmt:

3
go.mod
View File

@ -4,8 +4,7 @@ go 1.12
require (
github.com/eyedeekay/goSam v0.1.1-0.20190814204230-d4c9b8c57dd6
github.com/eyedeekay/sam-forwarder v0.0.0-20190831071254-d67c0c0e311f
github.com/eyedeekay/sam-forwarder v0.0.0-20190831205522-ccc29b5e6647
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25
github.com/zserge/webview v0.0.0-20190123072648-16c93bcaeaeb // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
)

View File

@ -85,21 +85,21 @@ func unixRestart() error {
func (s *SAMHTTPController) windowsStart() error {
var err error
s.ProxyServer.Handler, err = NewHttpProxy(
SetHost(s.ProxyServer.Handler.(*SAMHTTPProxy).SamHost),
SetPort(s.ProxyServer.Handler.(*SAMHTTPProxy).SamPort),
SetHost(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.SamHost),
SetPort(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.SamPort),
SetDebug(s.ProxyServer.Handler.(*SAMHTTPProxy).debug),
SetInLength(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).inLength)),
SetOutLength(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).outLength)),
SetInQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).inQuantity)),
SetOutQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).outQuantity)),
SetInBackups(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).inBackups)),
SetOutBackups(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).outBackups)),
SetInVariance(s.ProxyServer.Handler.(*SAMHTTPProxy).inVariance),
SetOutVariance(s.ProxyServer.Handler.(*SAMHTTPProxy).outVariance),
SetUnpublished(s.ProxyServer.Handler.(*SAMHTTPProxy).dontPublishLease),
SetReduceIdle(s.ProxyServer.Handler.(*SAMHTTPProxy).reduceIdle),
SetReduceIdleTime(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).reduceIdleTime)),
SetReduceIdleQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).reduceIdleQuantity)),
SetInLength(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.InLength)),
SetOutLength(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.OutLength)),
SetInQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.InQuantity)),
SetOutQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.OutQuantity)),
SetInBackups(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.InBackupQuantity)),
SetOutBackups(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.OutBackupQuantity)),
SetInVariance(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.InVariance),
SetOutVariance(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.OutVariance),
SetUnpublished(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.Client),
SetReduceIdle(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.ReduceIdle),
SetReduceIdleTime(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.ReduceIdleTime)),
SetReduceIdleQuantity(uint(s.ProxyServer.Handler.(*SAMHTTPProxy).Conf.ReduceIdleQuantity)),
)
if err != nil {
log.Fatal(err)

View File

@ -13,7 +13,7 @@ type Option func(*SAMHTTPProxy) error
//SetName sets a clients's address in the form host:port or host, port
func SetName(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.tunName = s
c.Conf.TunName = s
return nil
}
}
@ -26,8 +26,8 @@ func SetAddr(s ...string) func(*SAMHTTPProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.SamHost = split[0]
c.SamPort = split[1]
c.Conf.SamHost = split[0]
c.Conf.SamPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -38,8 +38,8 @@ func SetAddr(s ...string) func(*SAMHTTPProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.SamHost = s[0]
c.SamPort = s[1]
c.Conf.SamHost = s[0]
c.Conf.SamPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -59,8 +59,8 @@ func SetControlAddr(s ...string) func(*SAMHTTPProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.controlHost = split[0]
c.controlPort = split[1]
c.Conf.ControlHost = split[0]
c.Conf.ControlPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -71,8 +71,8 @@ func SetControlAddr(s ...string) func(*SAMHTTPProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.controlHost = s[0]
c.controlPort = s[1]
c.Conf.ControlHost = s[0]
c.Conf.ControlPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -92,8 +92,8 @@ func SetProxyAddr(s ...string) func(*SAMHTTPProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.proxyHost = split[0]
c.proxyPort = split[1]
c.Conf.TargetHost = split[0]
c.Conf.TargetPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -104,8 +104,8 @@ func SetProxyAddr(s ...string) func(*SAMHTTPProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.proxyHost = s[0]
c.proxyPort = s[1]
c.Conf.TargetHost = s[0]
c.Conf.TargetPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -121,8 +121,8 @@ func SetProxyAddr(s ...string) func(*SAMHTTPProxy) error {
func SetAddrMixed(s string, i int) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if i < 65536 && i > 0 {
c.SamHost = s
c.SamPort = strconv.Itoa(i)
c.Conf.SamHost = s
c.Conf.SamPort = strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid port")
@ -132,7 +132,7 @@ func SetAddrMixed(s string, i int) func(*SAMHTTPProxy) error {
//SetContrlHost sets the host of the client's Proxy controller
func SetControlHost(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.controlHost = s
c.Conf.ControlHost = s
return nil
}
}
@ -145,7 +145,7 @@ func SetControlPort(s string) func(*SAMHTTPProxy) error {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.controlPort = s
c.Conf.ControlPort = s
return nil
}
return fmt.Errorf("Invalid port")
@ -155,7 +155,7 @@ func SetControlPort(s string) func(*SAMHTTPProxy) error {
//SetProxyHost sets the host of the client's Proxy controller
func SetProxyHost(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.proxyHost = s
c.Conf.TargetHost = s
return nil
}
}
@ -168,7 +168,7 @@ func SetProxyPort(s string) func(*SAMHTTPProxy) error {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.proxyPort = s
c.Conf.TargetPort = s
return nil
}
return fmt.Errorf("Invalid port")
@ -178,7 +178,7 @@ func SetProxyPort(s string) func(*SAMHTTPProxy) error {
//SetKeysPath sets the path to the key save files
func SetKeysPath(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.keyspath = s
c.Conf.KeyFilePath = s
return nil
}
}
@ -186,7 +186,7 @@ func SetKeysPath(s string) func(*SAMHTTPProxy) error {
//SetHost sets the host of the client's SAM bridge
func SetHost(s string) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.SamHost = s
c.Conf.SamHost = s
return nil
}
}
@ -199,7 +199,7 @@ func SetPort(s string) func(*SAMHTTPProxy) error {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.SamPort = s
c.Conf.SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
@ -210,7 +210,7 @@ func SetPort(s string) func(*SAMHTTPProxy) error {
func SetPortInt(i int) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if i < 65536 && i > -1 {
c.SamPort = strconv.Itoa(i)
c.Conf.SamPort = strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid port")
@ -229,7 +229,7 @@ func SetDebug(b bool) func(*SAMHTTPProxy) error {
func SetInLength(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u < 7 {
c.inLength = u
c.Conf.InLength = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
@ -240,7 +240,7 @@ func SetInLength(u uint) func(*SAMHTTPProxy) error {
func SetOutLength(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u < 7 {
c.outLength = u
c.Conf.OutLength = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
@ -251,7 +251,7 @@ func SetOutLength(u uint) func(*SAMHTTPProxy) error {
func SetInVariance(i int) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if i < 7 && i > -7 {
c.inVariance = i
c.Conf.InVariance = int(i)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
@ -262,7 +262,7 @@ func SetInVariance(i int) func(*SAMHTTPProxy) error {
func SetOutVariance(i int) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if i < 7 && i > -7 {
c.outVariance = i
c.Conf.OutVariance = int(i)
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
@ -273,7 +273,7 @@ func SetOutVariance(i int) func(*SAMHTTPProxy) error {
func SetInQuantity(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u <= 16 {
c.inQuantity = u
c.Conf.InQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
@ -284,7 +284,7 @@ func SetInQuantity(u uint) func(*SAMHTTPProxy) error {
func SetOutQuantity(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u <= 16 {
c.outQuantity = u
c.Conf.OutQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
@ -295,7 +295,7 @@ func SetOutQuantity(u uint) func(*SAMHTTPProxy) error {
func SetInBackups(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u < 6 {
c.inBackups = u
c.Conf.InBackupQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
@ -306,7 +306,7 @@ func SetInBackups(u uint) func(*SAMHTTPProxy) error {
func SetOutBackups(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u < 6 {
c.outBackups = u
c.Conf.OutBackupQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
@ -316,7 +316,7 @@ func SetOutBackups(u uint) func(*SAMHTTPProxy) error {
//SetUnpublished tells the router to not publish the client leaseset
func SetUnpublished(b bool) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.dontPublishLease = b
c.Conf.Client = b
return nil
}
}
@ -324,7 +324,7 @@ func SetUnpublished(b bool) func(*SAMHTTPProxy) error {
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.encryptLease = b
c.Conf.EncryptLeaseSet = b
return nil
}
}
@ -332,7 +332,7 @@ func SetEncrypt(b bool) func(*SAMHTTPProxy) error {
//SetReduceIdle sets the created tunnels to be reduced during extended idle time to avoid excessive resource usage
func SetReduceIdle(b bool) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.reduceIdle = b
c.Conf.ReduceIdle = b
return nil
}
}
@ -341,7 +341,7 @@ func SetReduceIdle(b bool) func(*SAMHTTPProxy) error {
func SetReduceIdleTime(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u > 299999 {
c.reduceIdleTime = u
c.Conf.ReduceIdleTime = int(u)
return nil
}
return fmt.Errorf("Invalid reduce idle time %v", u)
@ -352,7 +352,7 @@ func SetReduceIdleTime(u uint) func(*SAMHTTPProxy) error {
func SetReduceIdleQuantity(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
if u < 5 {
c.reduceIdleQuantity = u
c.Conf.ReduceIdleQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid reduced tunnel quantity %v", u)
@ -362,7 +362,7 @@ func SetReduceIdleQuantity(u uint) func(*SAMHTTPProxy) error {
//SetCompression sets the tunnels to close after a specific amount of time
func SetCompression(b bool) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.compression = b
c.Conf.UseCompression = b
return nil
}
}
@ -370,7 +370,7 @@ func SetCompression(b bool) func(*SAMHTTPProxy) error {
//SetCloseIdle enables debugging messages
func SetCloseIdle(b bool) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
c.closeIdle = b
c.Conf.CloseIdle = b
return nil
}
}
@ -380,7 +380,7 @@ func SetCloseIdleTime(u uint) func(*SAMHTTPProxy) error {
return func(c *SAMHTTPProxy) error {
log.Println("TEST CLOSE", u, (u > 299999))
if u > 299999 {
c.closeIdleTime = u
c.Conf.CloseIdleTime = int(u)
return nil
}
return fmt.Errorf("Invalid close idle time %v", u)
@ -389,87 +389,87 @@ func SetCloseIdleTime(u uint) func(*SAMHTTPProxy) error {
//return the inbound length as a string.
func (c *SAMHTTPProxy) inlength() string {
return fmt.Sprintf("inbound.length=%d", c.inLength)
return fmt.Sprintf("inbound.length=%d", c.Conf.InLength)
}
//return the outbound length as a string.
func (c *SAMHTTPProxy) outlength() string {
return fmt.Sprintf("outbound.length=%d", c.outLength)
return fmt.Sprintf("outbound.length=%d", c.Conf.OutLength)
}
//return the inbound length variance as a string.
func (c *SAMHTTPProxy) invariance() string {
return fmt.Sprintf("inbound.lengthVariance=%d", c.inVariance)
return fmt.Sprintf("inbound.lengthVariance=%d", c.Conf.InVariance)
}
//return the outbound length variance as a string.
func (c *SAMHTTPProxy) outvariance() string {
return fmt.Sprintf("outbound.lengthVariance=%d", c.outVariance)
return fmt.Sprintf("outbound.lengthVariance=%d", c.Conf.OutVariance)
}
//return the inbound tunnel quantity as a string.
func (c *SAMHTTPProxy) inquantity() string {
return fmt.Sprintf("inbound.quantity=%d", c.inQuantity)
return fmt.Sprintf("inbound.quantity=%d", c.Conf.InQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *SAMHTTPProxy) outquantity() string {
return fmt.Sprintf("outbound.quantity=%d", c.outQuantity)
return fmt.Sprintf("outbound.quantity=%d", c.Conf.OutQuantity)
}
//return the inbound tunnel quantity as a string.
func (c *SAMHTTPProxy) inbackups() string {
return fmt.Sprintf("inbound.backupQuantity=%d", c.inQuantity)
return fmt.Sprintf("inbound.backupQuantity=%d", c.Conf.InQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *SAMHTTPProxy) outbackups() string {
return fmt.Sprintf("outbound.backupQuantity=%d", c.outQuantity)
return fmt.Sprintf("outbound.backupQuantity=%d", c.Conf.OutQuantity)
}
func (c *SAMHTTPProxy) encryptlease() string {
if c.encryptLease {
if c.Conf.EncryptLeaseSet {
return "i2cp.encryptLeaseSet=true"
}
return "i2cp.encryptLeaseSet=false"
}
func (c *SAMHTTPProxy) dontpublishlease() string {
if c.dontPublishLease {
if c.Conf.Client {
return "i2cp.dontPublishLeaseSet=true"
}
return "i2cp.dontPublishLeaseSet=false"
}
func (c *SAMHTTPProxy) reduceonidle() string {
if c.reduceIdle {
if c.Conf.ReduceIdle {
return "i2cp.reduceOnIdle=true"
}
return "i2cp.reduceOnIdle=false"
}
func (c *SAMHTTPProxy) reduceidletime() string {
return fmt.Sprintf("i2cp.reduceIdleTime=%d", c.reduceIdleTime)
return fmt.Sprintf("i2cp.reduceIdleTime=%d", c.Conf.ReduceIdleTime)
}
func (c *SAMHTTPProxy) reduceidlecount() string {
return fmt.Sprintf("i2cp.reduceIdleQuantity=%d", c.reduceIdleQuantity)
return fmt.Sprintf("i2cp.reduceIdleQuantity=%d", c.Conf.ReduceIdleQuantity)
}
func (c *SAMHTTPProxy) usecompresion() string {
if c.compression {
if c.Conf.UseCompression {
return "i2cp.gzip=true"
}
return "i2cp.gzip=false"
}
func (c *SAMHTTPProxy) closeonidle() string {
if c.reduceIdle {
if c.Conf.ReduceIdle {
return "i2cp.closeOnIdle=true"
}
return "i2cp.closeOnIdle=false"
}
func (c *SAMHTTPProxy) closeidletime() string {
return fmt.Sprintf("i2cp.closeIdleTime=%d", c.reduceIdleTime)
return fmt.Sprintf("i2cp.closeIdleTime=%d", c.Conf.ReduceIdleTime)
}

View File

@ -27,37 +27,11 @@ import (
)
type SAMHTTPProxy struct {
goSam *goSam.Client
Hasher *hashhash.Hasher
client *http.Client
transport *http.Transport
rateLimiter *rate.Limiter
tunName string
sigType string
proxyHost string
proxyPort string
SamHost string
SamPort string
controlHost string
controlPort string
destination string
keyspath string
inLength uint
outLength uint
inVariance int
outVariance int
inQuantity uint
outQuantity uint
inBackups uint
outBackups uint
dontPublishLease bool
encryptLease bool
reduceIdle bool
reduceIdleTime uint
reduceIdleQuantity uint
closeIdle bool
closeIdleTime uint
compression bool
goSam *goSam.Client
Hasher *hashhash.Hasher
client *http.Client
transport *http.Transport
rateLimiter *rate.Limiter
useOutProxy bool
@ -89,7 +63,7 @@ func (f *SAMHTTPProxy) GetType() string {
}
func (f *SAMHTTPProxy) ID() string {
return f.tunName
return f.Conf.TunName
}
func (f *SAMHTTPProxy) Keys() i2pkeys.I2PKeys {
@ -132,7 +106,7 @@ func (p *SAMHTTPProxy) Search(search string) string {
}
func (p *SAMHTTPProxy) Target() string {
return p.proxyHost + ":" + p.proxyPort
return p.Conf.TargetHost + ":" + p.Conf.TargetPort
}
func (p *SAMHTTPProxy) Base32() string {
@ -153,7 +127,7 @@ func (p *SAMHTTPProxy) Base64() string {
}
func (p *SAMHTTPProxy) Serve() error {
ln, err := net.Listen("tcp", p.proxyHost+":"+p.proxyPort)
ln, err := net.Listen("tcp", p.Conf.TargetHost+":"+p.Conf.TargetPort)
if err != nil {
return err
}
@ -210,7 +184,7 @@ func (p *SAMHTTPProxy) freshSAMClient() (*goSam.Client, error) {
//return the combined host:port of the SAM bridge
func (p *SAMHTTPProxy) samaddr() string {
return fmt.Sprintf("%s:%s", p.SamHost, p.SamPort)
return fmt.Sprintf("%s:%s", p.Conf.SamHost, p.Conf.SamPort)
}
func (p *SAMHTTPProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
@ -226,7 +200,7 @@ func (p *SAMHTTPProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
}
if !strings.HasSuffix(req.URL.Host, ".i2p") {
if req.URL.Host == p.controlHost+":"+p.controlPort {
if req.URL.Host == p.Conf.ControlHost+":"+p.Conf.ControlPort {
p.reset(wr, req)
return
}
@ -277,10 +251,10 @@ func UnProxyLocal(additionalAddresses []string) {
}
func (p *SAMHTTPProxy) reset(wr http.ResponseWriter, req *http.Request) {
plog("Validating control access from", req.RemoteAddr, p.controlHost+":"+p.controlPort)
if strings.SplitN(req.RemoteAddr, ":", 2)[0] == p.controlHost {
plog("Validated control access from", req.RemoteAddr, p.controlHost+":"+p.controlPort)
resp, err := http.Get("http://" + p.controlHost + ":" + p.controlPort)
plog("Validating control access from", req.RemoteAddr, p.Conf.ControlHost+":"+p.Conf.ControlPort)
if strings.SplitN(req.RemoteAddr, ":", 2)[0] == p.Conf.ControlHost {
plog("Validated control access from", req.RemoteAddr, p.Conf.ControlHost+":"+p.Conf.ControlPort)
resp, err := http.Get("http://" + p.Conf.ControlHost + ":" + p.Conf.ControlPort)
if err == nil {
wr.Header().Set("Content-Type", "text/html; charset=utf-8")
wr.Header().Set("Access-Control-Allow-Origin", "*")
@ -340,18 +314,18 @@ func (f *SAMHTTPProxy) Up() bool {
}
func (p *SAMHTTPProxy) Save() string {
if p.keyspath != "invalid.tunkey" {
if _, err := os.Stat(p.keyspath); os.IsNotExist(err) {
if p.Conf.KeyFilePath != "invalid.tunkey" {
if _, err := os.Stat(p.Conf.KeyFilePath); os.IsNotExist(err) {
if p.goSam != nil {
if p.goSam.Destination() != "" {
ioutil.WriteFile(p.keyspath, []byte(p.goSam.Destination()), 0644)
p.destination = p.goSam.Destination()
ioutil.WriteFile(p.Conf.KeyFilePath, []byte(p.goSam.Destination()), 0644)
p.Conf.ClientDest = p.goSam.Destination()
return p.goSam.Destination()
}
}
} else {
if keys, err := ioutil.ReadFile(p.keyspath); err == nil {
p.destination = string(keys)
if keys, err := ioutil.ReadFile(p.Conf.KeyFilePath); err == nil {
p.Conf.ClientDest = string(keys)
return string(keys)
}
}
@ -361,25 +335,25 @@ func (p *SAMHTTPProxy) Save() string {
func (handler *SAMHTTPProxy) Load() (samtunnel.SAMTunnel, error) {
var err error
handler.destination = handler.Save()
handler.Conf.ClientDest = handler.Save()
handler.goSam, err = goSam.NewClientFromOptions(
goSam.SetHost(handler.SamHost),
goSam.SetPort(handler.SamPort),
goSam.SetUnpublished(handler.dontPublishLease),
goSam.SetInLength(handler.inLength),
goSam.SetOutLength(handler.outLength),
goSam.SetInQuantity(handler.inQuantity),
goSam.SetOutQuantity(handler.outQuantity),
goSam.SetInBackups(handler.inBackups),
goSam.SetOutBackups(handler.outBackups),
goSam.SetReduceIdle(handler.reduceIdle),
goSam.SetReduceIdleTime(handler.reduceIdleTime),
goSam.SetReduceIdleQuantity(handler.reduceIdleQuantity),
goSam.SetCloseIdle(handler.closeIdle),
goSam.SetCloseIdleTime(handler.closeIdleTime),
goSam.SetCompression(handler.compression),
goSam.SetHost(handler.Conf.SamHost),
goSam.SetPort(handler.Conf.SamPort),
goSam.SetUnpublished(handler.Conf.Client),
goSam.SetInLength(uint(handler.Conf.InLength)),
goSam.SetOutLength(uint(handler.Conf.OutLength)),
goSam.SetInQuantity(uint(handler.Conf.InQuantity)),
goSam.SetOutQuantity(uint(handler.Conf.OutQuantity)),
goSam.SetInBackups(uint(handler.Conf.InBackupQuantity)),
goSam.SetOutBackups(uint(handler.Conf.OutBackupQuantity)),
goSam.SetReduceIdle(handler.Conf.ReduceIdle),
goSam.SetReduceIdleTime(uint(handler.Conf.ReduceIdleTime)),
goSam.SetReduceIdleQuantity(uint(handler.Conf.ReduceIdleQuantity)),
goSam.SetCloseIdle(handler.Conf.CloseIdle),
goSam.SetCloseIdleTime(uint(handler.Conf.CloseIdleTime)),
goSam.SetCompression(handler.Conf.UseCompression),
goSam.SetDebug(handler.debug),
goSam.SetLocalDestination(handler.destination),
goSam.SetLocalDestination(handler.Conf.ClientDest),
)
if err != nil {
return nil, err
@ -396,31 +370,11 @@ func (handler *SAMHTTPProxy) Load() (samtunnel.SAMTunnel, error) {
func NewHttpProxy(opts ...func(*SAMHTTPProxy) error) (*SAMHTTPProxy, error) {
var handler SAMHTTPProxy
handler.SamHost = "127.0.0.1"
handler.SamPort = "7656"
handler.controlHost = "127.0.0.1"
handler.controlPort = "7951"
handler.proxyHost = "127.0.0.1"
handler.proxyPort = "7950"
handler.inLength = 2
handler.outLength = 2
handler.inVariance = 0
handler.outVariance = 0
handler.inQuantity = 1
handler.outQuantity = 1
handler.inBackups = 1
handler.outBackups = 1
handler.dontPublishLease = true
handler.encryptLease = false
handler.reduceIdle = false
handler.reduceIdleTime = 2000000
handler.closeIdleTime = 3000000
handler.reduceIdleQuantity = 1
handler.useOutProxy = false
handler.compression = true
handler.tunName = "0"
handler.keyspath = "invalid.tunkey"
handler.destination = ""
handler.Conf = &i2ptunconf.Conf{}
handler.Conf.SamHost = "127.0.0.1"
handler.Conf.SamPort = "7656"
handler.Conf.ControlHost = "127.0.0.1"
handler.Conf.ControlPort = "7951"
for _, o := range opts {
if err := o(&handler); err != nil {
return nil, err

View File

@ -13,7 +13,7 @@ type Option func(*SAMMultiProxy) error
//SetName sets a clients's address in the form host:port or host, port
func SetName(s string) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.tunName = s
c.Conf.TunName = s
return nil
}
}
@ -26,8 +26,8 @@ func SetAddr(s ...string) func(*SAMMultiProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.SamHost = split[0]
c.SamPort = split[1]
c.Conf.SamHost = split[0]
c.Conf.SamPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -38,8 +38,8 @@ func SetAddr(s ...string) func(*SAMMultiProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.SamHost = s[0]
c.SamPort = s[1]
c.Conf.SamHost = s[0]
c.Conf.SamPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -59,8 +59,8 @@ func SetControlAddr(s ...string) func(*SAMMultiProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.controlHost = split[0]
c.controlPort = split[1]
c.Conf.ControlHost = split[0]
c.Conf.ControlPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -71,8 +71,8 @@ func SetControlAddr(s ...string) func(*SAMMultiProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.controlHost = s[0]
c.controlPort = s[1]
c.Conf.ControlHost = s[0]
c.Conf.ControlPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -92,8 +92,8 @@ func SetProxyAddr(s ...string) func(*SAMMultiProxy) error {
if len(split) == 2 {
if i, err := strconv.Atoi(split[1]); err == nil {
if i < 65536 {
c.proxyHost = split[0]
c.proxyPort = split[1]
c.Conf.TargetHost = split[0]
c.Conf.TargetPort = split[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -104,8 +104,8 @@ func SetProxyAddr(s ...string) func(*SAMMultiProxy) error {
} else if len(s) == 2 {
if i, err := strconv.Atoi(s[1]); err == nil {
if i < 65536 {
c.proxyHost = s[0]
c.proxyPort = s[1]
c.Conf.TargetHost = s[0]
c.Conf.TargetPort = s[1]
return nil
}
return fmt.Errorf("Invalid port")
@ -121,18 +121,18 @@ func SetProxyAddr(s ...string) func(*SAMMultiProxy) error {
func SetAddrMixed(s string, i int) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if i < 65536 && i > 0 {
c.SamHost = s
c.SamPort = strconv.Itoa(i)
c.Conf.SamHost = s
c.Conf.SamPort = strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetContrlHost sets the host of the client's Proxy controller
//SetContrlHost sets the host of the client's Proxy Controller
func SetControlHost(s string) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.controlHost = s
c.Conf.ControlHost = s
return nil
}
}
@ -140,12 +140,12 @@ func SetControlHost(s string) func(*SAMMultiProxy) error {
//SetKeysPath sets the path to the key save files
func SetKeysPath(s string) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.keyspath = s
c.Conf.KeyFilePath = s
return nil
}
}
//SetContrlPort sets the host of the client's Proxy controller
//SetContrlPort sets the host of the client's Proxy Controller
func SetControlPort(s string) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
port, err := strconv.Atoi(s)
@ -153,7 +153,7 @@ func SetControlPort(s string) func(*SAMMultiProxy) error {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.controlPort = s
c.Conf.ControlPort = s
return nil
}
return fmt.Errorf("Invalid port")
@ -163,7 +163,7 @@ func SetControlPort(s string) func(*SAMMultiProxy) error {
//SetHost sets the host of the client's SAM bridge
func SetHost(s string) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.SamHost = s
c.Conf.SamHost = s
return nil
}
}
@ -176,7 +176,7 @@ func SetPort(s string) func(*SAMMultiProxy) error {
return fmt.Errorf("Invalid port; non-number")
}
if port < 65536 && port > -1 {
c.SamPort = s
c.Conf.SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
@ -187,7 +187,7 @@ func SetPort(s string) func(*SAMMultiProxy) error {
func SetPortInt(i int) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if i < 65536 && i > -1 {
c.SamPort = strconv.Itoa(i)
c.Conf.SamPort = strconv.Itoa(i)
return nil
}
return fmt.Errorf("Invalid port")
@ -206,7 +206,7 @@ func SetDebug(b bool) func(*SAMMultiProxy) error {
func SetInLength(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u < 7 {
c.inLength = u
c.Conf.InLength = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
@ -217,7 +217,7 @@ func SetInLength(u uint) func(*SAMMultiProxy) error {
func SetOutLength(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u < 7 {
c.outLength = u
c.Conf.OutLength = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
@ -228,7 +228,7 @@ func SetOutLength(u uint) func(*SAMMultiProxy) error {
func SetInVariance(i int) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if i < 7 && i > -7 {
c.inVariance = i
c.Conf.InVariance = int(i)
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
@ -239,7 +239,7 @@ func SetInVariance(i int) func(*SAMMultiProxy) error {
func SetOutVariance(i int) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if i < 7 && i > -7 {
c.outVariance = i
c.Conf.OutVariance = int(i)
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
@ -250,7 +250,7 @@ func SetOutVariance(i int) func(*SAMMultiProxy) error {
func SetInQuantity(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u <= 16 {
c.inQuantity = u
c.Conf.InQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
@ -261,7 +261,7 @@ func SetInQuantity(u uint) func(*SAMMultiProxy) error {
func SetOutQuantity(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u <= 16 {
c.outQuantity = u
c.Conf.OutQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
@ -272,7 +272,7 @@ func SetOutQuantity(u uint) func(*SAMMultiProxy) error {
func SetInBackups(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u < 6 {
c.inBackups = u
c.Conf.InBackupQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
@ -283,7 +283,7 @@ func SetInBackups(u uint) func(*SAMMultiProxy) error {
func SetOutBackups(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u < 6 {
c.outBackups = u
c.Conf.OutBackupQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
@ -293,7 +293,7 @@ func SetOutBackups(u uint) func(*SAMMultiProxy) error {
//SetUnpublished tells the router to not publish the client leaseset
func SetUnpublished(b bool) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.dontPublishLease = b
c.Conf.Client = b
return nil
}
}
@ -301,7 +301,7 @@ func SetUnpublished(b bool) func(*SAMMultiProxy) error {
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.encryptLease = b
c.Conf.EncryptLeaseSet = b
return nil
}
}
@ -309,7 +309,7 @@ func SetEncrypt(b bool) func(*SAMMultiProxy) error {
//SetReduceIdle sets the created tunnels to be reduced during extended idle time to avoid excessive resource usage
func SetReduceIdle(b bool) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.reduceIdle = b
c.Conf.ReduceIdle = b
return nil
}
}
@ -318,7 +318,7 @@ func SetReduceIdle(b bool) func(*SAMMultiProxy) error {
func SetReduceIdleTime(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u > 299999 {
c.reduceIdleTime = u
c.Conf.ReduceIdleTime = int(u)
return nil
}
return fmt.Errorf("Invalid reduce idle time %v", u)
@ -329,7 +329,7 @@ func SetReduceIdleTime(u uint) func(*SAMMultiProxy) error {
func SetReduceIdleQuantity(u uint) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
if u < 5 {
c.reduceIdleQuantity = u
c.Conf.ReduceIdleQuantity = int(u)
return nil
}
return fmt.Errorf("Invalid reduced tunnel quantity %v", u)
@ -339,7 +339,7 @@ func SetReduceIdleQuantity(u uint) func(*SAMMultiProxy) error {
//SetCompression sets the tunnels to close after a specific amount of time
func SetCompression(b bool) func(*SAMMultiProxy) error {
return func(c *SAMMultiProxy) error {
c.compression = b
c.Conf.UseCompression = b
return nil
}
}
@ -354,75 +354,75 @@ func SetProxyMode(b bool) func(*SAMMultiProxy) error {
//return the inbound length as a string.
func (c *SAMMultiProxy) inlength() string {
return fmt.Sprintf("inbound.length=%d", c.inLength)
return fmt.Sprintf("inbound.length=%d", c.Conf.InLength)
}
//return the outbound length as a string.
func (c *SAMMultiProxy) outlength() string {
return fmt.Sprintf("outbound.length=%d", c.outLength)
return fmt.Sprintf("outbound.length=%d", c.Conf.OutLength)
}
//return the inbound length variance as a string.
func (c *SAMMultiProxy) invariance() string {
return fmt.Sprintf("inbound.lengthVariance=%d", c.inVariance)
return fmt.Sprintf("inbound.lengthVariance=%d", c.Conf.InVariance)
}
//return the outbound length variance as a string.
func (c *SAMMultiProxy) outvariance() string {
return fmt.Sprintf("outbound.lengthVariance=%d", c.outVariance)
return fmt.Sprintf("outbound.lengthVariance=%d", c.Conf.OutVariance)
}
//return the inbound tunnel quantity as a string.
func (c *SAMMultiProxy) inquantity() string {
return fmt.Sprintf("inbound.quantity=%d", c.inQuantity)
return fmt.Sprintf("inbound.quantity=%d", c.Conf.InQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *SAMMultiProxy) outquantity() string {
return fmt.Sprintf("outbound.quantity=%d", c.outQuantity)
return fmt.Sprintf("outbound.quantity=%d", c.Conf.OutQuantity)
}
//return the inbound tunnel quantity as a string.
func (c *SAMMultiProxy) inbackups() string {
return fmt.Sprintf("inbound.backupQuantity=%d", c.inQuantity)
return fmt.Sprintf("inbound.backupQuantity=%d", c.Conf.InQuantity)
}
//return the outbound tunnel quantity as a string.
func (c *SAMMultiProxy) outbackups() string {
return fmt.Sprintf("outbound.backupQuantity=%d", c.outQuantity)
return fmt.Sprintf("outbound.backupQuantity=%d", c.Conf.OutQuantity)
}
func (c *SAMMultiProxy) encryptlease() string {
if c.encryptLease {
if c.Conf.EncryptLeaseSet {
return "i2cp.encryptLeaseSet=true"
}
return "i2cp.encryptLeaseSet=false"
}
func (c *SAMMultiProxy) dontpublishlease() string {
if c.dontPublishLease {
if c.Conf.Client {
return "i2cp.dontPublishLeaseSet=true"
}
return "i2cp.dontPublishLeaseSet=false"
}
func (c *SAMMultiProxy) reduceonidle() string {
if c.reduceIdle {
if c.Conf.ReduceIdle {
return "i2cp.reduceOnIdle=true"
}
return "i2cp.reduceOnIdle=false"
}
func (c *SAMMultiProxy) reduceidletime() string {
return fmt.Sprintf("i2cp.reduceIdleTime=%d", c.reduceIdleTime)
return fmt.Sprintf("i2cp.reduceIdleTime=%d", c.Conf.ReduceIdleTime)
}
func (c *SAMMultiProxy) reduceidlecount() string {
return fmt.Sprintf("i2cp.reduceIdleQuantity=%d", c.reduceIdleQuantity)
return fmt.Sprintf("i2cp.reduceIdleQuantity=%d", c.Conf.ReduceIdleQuantity)
}
func (c *SAMMultiProxy) usecompresion() string {
if c.compression {
if c.Conf.UseCompression {
return "i2cp.gzip=true"
}
return "i2cp.gzip=false"

View File

@ -34,32 +34,8 @@ type samClient struct {
}
type SAMMultiProxy struct {
clients map[string]*samClient
Hasher *hashhash.Hasher
tunName string
sigType string
proxyHost string
proxyPort string
SamHost string
SamPort string
controlHost string
controlPort string
destination string
keyspath string
inLength uint
outLength uint
inVariance int
outVariance int
inQuantity uint
outQuantity uint
inBackups uint
outBackups uint
dontPublishLease bool
encryptLease bool
reduceIdle bool
reduceIdleTime uint
reduceIdleQuantity uint
compression bool
clients map[string]*samClient
Hasher *hashhash.Hasher
Conf *i2ptunconf.Conf
@ -110,7 +86,7 @@ func (f *SAMMultiProxy) GetType() string {
}
func (f *SAMMultiProxy) ID() string {
return f.tunName
return f.Conf.TunName
}
func (p *SAMMultiProxy) Keys() i2pkeys.I2PKeys {
@ -153,7 +129,7 @@ func (p *SAMMultiProxy) Search(search string) string {
}
func (p *SAMMultiProxy) Target() string {
return p.proxyHost + ":" + p.proxyPort
return p.Conf.TargetHost + ":" + p.Conf.TargetPort
}
func (p *SAMMultiProxy) Base32() string {
@ -174,7 +150,7 @@ func (p *SAMMultiProxy) Base64() string {
}
func (p *SAMMultiProxy) Serve() error {
ln, err := net.Listen("tcp", p.proxyHost+":"+p.proxyPort)
ln, err := net.Listen("tcp", p.Conf.TargetHost+":"+p.Conf.TargetPort)
if err != nil {
return err
}
@ -250,27 +226,27 @@ func (p *SAMMultiProxy) freshSAMClient(key string) (*samClient, error) {
func (p *SAMMultiProxy) freshGoSAMClient() (*goSam.Client, error) {
return goSam.NewClientFromOptions(
goSam.SetHost(p.SamHost),
goSam.SetPort(p.SamPort),
goSam.SetUnpublished(p.dontPublishLease),
goSam.SetInLength(p.inLength),
goSam.SetOutLength(p.outLength),
goSam.SetInQuantity(p.inQuantity),
goSam.SetOutQuantity(p.outQuantity),
goSam.SetInBackups(p.inBackups),
goSam.SetOutBackups(p.outBackups),
goSam.SetReduceIdle(p.reduceIdle),
goSam.SetReduceIdleTime(p.reduceIdleTime),
goSam.SetReduceIdleQuantity(p.reduceIdleQuantity),
goSam.SetCompression(p.compression),
goSam.SetHost(p.Conf.SamHost),
goSam.SetPort(p.Conf.SamPort),
goSam.SetUnpublished(p.Conf.Client),
goSam.SetInLength(uint(p.Conf.InLength)),
goSam.SetOutLength(uint(p.Conf.OutLength)),
goSam.SetInQuantity(uint(p.Conf.InQuantity)),
goSam.SetOutQuantity(uint(p.Conf.OutQuantity)),
goSam.SetInBackups(uint(p.Conf.InBackupQuantity)),
goSam.SetOutBackups(uint(p.Conf.OutBackupQuantity)),
goSam.SetReduceIdle(p.Conf.ReduceIdle),
goSam.SetReduceIdleTime(uint(p.Conf.ReduceIdleTime)),
goSam.SetReduceIdleQuantity(uint(p.Conf.ReduceIdleQuantity)),
goSam.SetCompression(p.Conf.UseCompression),
goSam.SetDebug(p.debug),
goSam.SetLocalDestination(p.destination),
goSam.SetLocalDestination(p.Conf.ClientDest),
)
}
//return the combined host:port of the SAM bridge
func (p *SAMMultiProxy) samaddr() string {
return fmt.Sprintf("%s:%s", p.SamHost, p.SamPort)
return fmt.Sprintf("%s:%s", p.Conf.SamHost, p.Conf.SamPort)
}
func (p *SAMMultiProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
@ -286,7 +262,7 @@ func (p *SAMMultiProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
}
if !strings.HasSuffix(req.URL.Host, ".i2p") {
if req.URL.Host == p.controlHost+":"+p.controlPort {
if req.URL.Host == p.Conf.ControlHost+":"+p.Conf.ControlPort {
p.reset(wr, req)
return
}
@ -309,10 +285,10 @@ func (p *SAMMultiProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
}
func (p *SAMMultiProxy) reset(wr http.ResponseWriter, req *http.Request) {
plog("Validating control access from", req.RemoteAddr, p.controlHost+":"+p.controlPort)
if strings.SplitN(req.RemoteAddr, ":", 2)[0] == p.controlHost {
plog("Validated control access from", req.RemoteAddr, p.controlHost+":"+p.controlPort)
resp, err := http.Get("http://" + p.controlHost + ":" + p.controlPort)
plog("Validating control access from", req.RemoteAddr, p.Conf.ControlHost+":"+p.Conf.ControlPort)
if strings.SplitN(req.RemoteAddr, ":", 2)[0] == p.Conf.ControlHost {
plog("Validated control access from", req.RemoteAddr, p.Conf.ControlHost+":"+p.Conf.ControlPort)
resp, err := http.Get("http://" + p.Conf.ControlHost + ":" + p.Conf.ControlPort)
if err == nil {
wr.Header().Set("Content-Type", "text/html; charset=utf-8")
wr.Header().Set("Access-Control-Allow-Origin", "*")
@ -377,18 +353,18 @@ func (f *SAMMultiProxy) Up() bool {
}
func (p *SAMMultiProxy) Save() string {
if p.keyspath != "invalid.tunkey" {
if _, err := os.Stat(p.keyspath); os.IsNotExist(err) {
if p.Conf.KeyFilePath != "invalid.tunkey" {
if _, err := os.Stat(p.Conf.KeyFilePath); os.IsNotExist(err) {
if p.findClient(p.recent).goSam != nil {
if p.findClient(p.recent).goSam.Destination() != "" {
ioutil.WriteFile(p.keyspath, []byte(p.findClient(p.recent).goSam.Destination()), 0644)
p.destination = p.findClient(p.recent).goSam.Destination()
ioutil.WriteFile(p.Conf.KeyFilePath, []byte(p.findClient(p.recent).goSam.Destination()), 0644)
p.Conf.ClientDest = p.findClient(p.recent).goSam.Destination()
return p.findClient(p.recent).goSam.Destination()
}
}
} else {
if keys, err := ioutil.ReadFile(p.keyspath); err == nil {
p.destination = string(keys)
if keys, err := ioutil.ReadFile(p.Conf.KeyFilePath); err == nil {
p.Conf.ClientDest = string(keys)
return string(keys)
}
}
@ -398,24 +374,24 @@ func (p *SAMMultiProxy) Save() string {
func (handler *SAMMultiProxy) Load() (samtunnel.SAMTunnel, error) {
var err error
handler.destination = handler.Save()
handler.Conf.ClientDest = handler.Save()
handler.clients["general"] = &samClient{}
handler.clients["general"].goSam, err = goSam.NewClientFromOptions(
goSam.SetHost(handler.SamHost),
goSam.SetPort(handler.SamPort),
goSam.SetUnpublished(handler.dontPublishLease),
goSam.SetInLength(handler.inLength),
goSam.SetOutLength(handler.outLength),
goSam.SetInQuantity(handler.inQuantity),
goSam.SetOutQuantity(handler.outQuantity),
goSam.SetInBackups(handler.inBackups),
goSam.SetOutBackups(handler.outBackups),
goSam.SetReduceIdle(handler.reduceIdle),
goSam.SetReduceIdleTime(handler.reduceIdleTime),
goSam.SetReduceIdleQuantity(handler.reduceIdleQuantity),
goSam.SetCompression(handler.compression),
goSam.SetHost(handler.Conf.SamHost),
goSam.SetPort(handler.Conf.SamPort),
goSam.SetUnpublished(handler.Conf.Client),
goSam.SetInLength(uint(handler.Conf.InLength)),
goSam.SetOutLength(uint(handler.Conf.OutLength)),
goSam.SetInQuantity(uint(handler.Conf.InQuantity)),
goSam.SetOutQuantity(uint(handler.Conf.OutQuantity)),
goSam.SetInBackups(uint(handler.Conf.InBackupQuantity)),
goSam.SetOutBackups(uint(handler.Conf.OutBackupQuantity)),
goSam.SetReduceIdle(handler.Conf.ReduceIdle),
goSam.SetReduceIdleTime(uint(handler.Conf.ReduceIdleTime)),
goSam.SetReduceIdleQuantity(uint(handler.Conf.ReduceIdleQuantity)),
goSam.SetCompression(handler.Conf.UseCompression),
goSam.SetDebug(handler.debug),
goSam.SetLocalDestination(handler.destination),
goSam.SetLocalDestination(handler.Conf.ClientDest),
)
if err != nil {
return nil, err
@ -432,30 +408,9 @@ func (handler *SAMMultiProxy) Load() (samtunnel.SAMTunnel, error) {
func NewHttpProxy(opts ...func(*SAMMultiProxy) error) (*SAMMultiProxy, error) {
var handler SAMMultiProxy
handler.SamHost = "127.0.0.1"
handler.SamPort = "7656"
handler.controlHost = "127.0.0.1"
handler.controlPort = "7951"
handler.proxyHost = "127.0.0.1"
handler.proxyPort = "7950"
handler.inLength = 2
handler.outLength = 2
handler.inVariance = 0
handler.outVariance = 0
handler.inQuantity = 1
handler.outQuantity = 1
handler.inBackups = 1
handler.outBackups = 1
handler.dontPublishLease = true
handler.encryptLease = false
handler.reduceIdle = false
handler.reduceIdleTime = 2000000
handler.reduceIdleQuantity = 1
handler.useOutProxy = false
handler.compression = true
handler.tunName = "0"
handler.keyspath = "invalid.tunkey"
handler.destination = ""
handler.Conf = &i2ptunconf.Conf{}
handler.Conf.SamHost = "127.0.0.1"
handler.Conf.SamPort = "7656"
handler.clients = make(map[string]*samClient)
handler.recent = "general"
handler.aggressive = false