Skip to content

Commit

Permalink
Merge pull request #8 from wadahiro/add-explicit-only
Browse files Browse the repository at this point in the history
Add explicit only
  • Loading branch information
wadahiro authored Feb 6, 2018
2 parents 95908fb + 1fc404b commit 2bc35b3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Options:
DNS Listen on UDP (default true)
-explicit-proxy-listen [host]:port
Explicit Proxy listen address for HTTP/HTTPS, as [host]:port Note: This proxy doesn't use authentication info of the `http_proxy` and `https_proxy` environment variables (default ":3132")
-explicit-proxy-only
Boot Explicit Proxies only
-explicit-proxy-with-auth-listen [host]:port
Explicit Proxy with auth listen address for HTTP/HTTPS, as [host]:port Note: This proxy uses authentication info of the `http_proxy` and `https_proxy` environment variables (default ":3133")
-http-proxy-listen [host]:port
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION=0.4
VERSION=0.5

DIR=$(cd $(dirname $0); pwd)
cd $DIR
Expand Down
68 changes: 48 additions & 20 deletions cmd/transproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var (
"explicit-proxy-with-auth-listen", ":3133", "Explicit Proxy with auth listen address for HTTP/HTTPS, as `[host]:port` Note: This proxy uses authentication info of the `http_proxy` and `https_proxy` environment variables",
)

explicitProxyOnly = fs.Bool(
"explicit-proxy-only", false, "Boot Explicit Proxies only",
)

dnsOverTCPDisabled = fs.Bool(
"dns-over-tcp-disabled", false, "Disable DNS-over-TCP for querying to public DNS")

Expand Down Expand Up @@ -94,6 +98,26 @@ func main() {
// seed the global random number generator, used in secureoperator
rand.Seed(time.Now().UTC().UnixNano())

if *explicitProxyOnly {
startExplicitProxyOnly()
} else {
startAllProxy()
}
}

func startExplicitProxyOnly() {
startExplicitProxy()

// serve until exit
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig

log.Printf("info: Proxy servers stopping.")
log.Printf("info: go-transproxy exited.")
}

func startAllProxy() {
// setup logger
colog.SetDefaultLevel(colog.LDebug)
colog.SetMinLevel(colog.LInfo)
Expand All @@ -114,8 +138,8 @@ func main() {
if noProxy == "" {
noProxy = os.Getenv("NO_PROXY")
}
np := parseNoProxy(noProxy)

np := parseNoProxy(noProxy)
// start servers
tcpProxy := transproxy.NewTCPProxy(
transproxy.TCPProxyConfig{
Expand Down Expand Up @@ -163,25 +187,7 @@ func main() {
log.Fatalf("alert: %s", err.Error())
}

explicitProxyWithAuth := transproxy.NewExplicitProxy(
transproxy.ExplicitProxyConfig{
ListenAddress: *explicitProxyWithAuthListenAddress,
UseProxyAuthorization: true,
},
)
if err := explicitProxyWithAuth.Start(); err != nil {
log.Fatalf("alert: %s", err.Error())
}

explicitProxy := transproxy.NewExplicitProxy(
transproxy.ExplicitProxyConfig{
ListenAddress: *explicitProxyListenAddress,
UseProxyAuthorization: false,
},
)
if err := explicitProxy.Start(); err != nil {
log.Fatalf("alert: %s", err.Error())
}
startExplicitProxy()

log.Printf("info: All proxy servers started.")

Expand Down Expand Up @@ -233,6 +239,28 @@ func main() {
log.Printf("info: go-transproxy exited.")
}

func startExplicitProxy() {
explicitProxyWithAuth := transproxy.NewExplicitProxy(
transproxy.ExplicitProxyConfig{
ListenAddress: *explicitProxyWithAuthListenAddress,
UseProxyAuthorization: true,
},
)
if err := explicitProxyWithAuth.Start(); err != nil {
log.Fatalf("alert: %s", err.Error())
}

explicitProxy := transproxy.NewExplicitProxy(
transproxy.ExplicitProxyConfig{
ListenAddress: *explicitProxyListenAddress,
UseProxyAuthorization: false,
},
)
if err := explicitProxy.Start(); err != nil {
log.Fatalf("alert: %s", err.Error())
}
}

func useDNSProxy() bool {
if *privateDNS == "" && *publicDNS == "" && *dnsOverHTTPSEnabled == false {
return false
Expand Down

0 comments on commit 2bc35b3

Please sign in to comment.