Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pacsandbox/pac_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func (p *PacSandbox) initPacFunctions() {
p.isPlainHostName(args[0]),
)
})

p.vm.Set("localHostOrDomainIs", func(call otto.FunctionCall) otto.Value {
args := p.ottoStringArgs(call, 2, "localHostOrDomainIs")
return p.ottoRetValue(
p.localHostOrDomainIs(args[0], args[1]),
)
})
}

func (p *PacSandbox) dnsDomainIs(host string, domain string) (bool, error) {
Expand Down Expand Up @@ -109,3 +116,7 @@ func (p *PacSandbox) isInNet(ipStr string, ipRangeStr string, ipMaskStr string)
func (p *PacSandbox) isPlainHostName(host string) (bool, error) {
return strings.Count(host, ".") == 0, nil
}

func (p *PacSandbox) localHostOrDomainIs(host string, domain string) (bool, error) {
return strings.Compare(host, domain) == 0, nil
}
2 changes: 1 addition & 1 deletion pacsandbox/pacsandbox_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pacsandbox_test

import (
. "github.com/mikesimons/pacyak/pacsandbox"
. "../../pacyak/pacsandbox"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
8 changes: 4 additions & 4 deletions pacyak.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/mikesimons/earl"
"github.com/mikesimons/pacyak/pacsandbox"
"github.com/mikesimons/pacyak/proxyfactory"
"../pacyak/pacsandbox"
"../pacyak/proxyfactory"
"github.com/mikesimons/readly"
)

Expand Down Expand Up @@ -171,7 +171,7 @@ func (app *PacYakApplication) handlePacAvailability() {
// monitorPingAvailability is a wrapper for handlePacAvailability invoking it every 30 seconds
func (app *PacYakApplication) monitorPingAvailability() {
app.handlePacAvailability()
for _ = range time.Tick(30 * time.Second) {
for _ = range time.Tick(30 * time.Minute) {
app.handlePacAvailability()
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func (app *PacYakApplication) checkNetworkInterfaces() {
// monitorNetworkInterfaces is a wrapper for checkNetworkInterfaces invoking it every 5 seconds
func (app *PacYakApplication) monitorNetworkInterfaces() {
app.interfaceMap = makeInterfaceMap()
for _ = range time.Tick(5 * time.Second) {
for _ = range time.Tick(30 * time.Minute) {
app.checkNetworkInterfaces()
}
}
Expand Down
3 changes: 2 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/mikesimons/earl"
"strings"
)

// Proxy is a simple proxy implementation
Expand Down Expand Up @@ -81,7 +82,7 @@ func New(proxyURLString string) *Proxy {
},
}

if proxyURLString == "direct" {
if strings.EqualFold(proxyURLString, "direct") {
proxy.Tr.Proxy = func(req *http.Request) (*url.URL, error) { return nil, nil }
proxy.Available = func() bool { return true }
proxy.ConnectDial = nil
Expand Down
21 changes: 12 additions & 9 deletions proxyfactory/proxyfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/mikesimons/pacyak/proxy"
"../../pacyak/proxy"
)

// ProxyFactory holds all state for the proxy factory
Expand All @@ -25,10 +25,10 @@ func New() *ProxyFactory {
}

go func() {
for _ = range time.Tick(30 * time.Second) {
for _ = range time.Tick(30 * time.Minute) {
pf.lock.Lock()
for key, proxy := range pf.proxies {
pf.availability[key] = proxy.Available()
for key, proxy2 := range pf.proxies {
pf.availability[key] = proxy2.Available()

log.WithFields(log.Fields{
"proxy": key,
Expand Down Expand Up @@ -63,9 +63,12 @@ func (pf *ProxyFactory) Proxy(handle string) *proxy.Proxy {

pf.lock.Lock()
if _, ok := pf.proxies[handle]; !ok {
proxy := proxy.New(handle)
pf.availability[handle] = proxy.Available()
pf.proxies[handle] = proxy
log.WithFields(log.Fields{
"proxy": handle,
}).Debug("Creating new proxy for handle")
newProxy := proxy.New(handle)
pf.availability[handle] = newProxy.Available()
pf.proxies[handle] = newProxy
}
ret = pf.proxies[handle]
pf.lock.Unlock()
Expand All @@ -83,13 +86,13 @@ func (pf *ProxyFactory) FromPacResponse(response string) *proxy.Proxy {
response = strings.Replace(response, " ", "", -1)
proxies := strings.Split(response, ";")
for _, proxyStr := range proxies {
proxy := pf.Proxy(proxyStr)
proxy2 := pf.Proxy(proxyStr)

if !pf.available(proxyStr) {
continue
}

return proxy
return proxy2
}

return pf.Proxy("direct")
Expand Down
2 changes: 1 addition & 1 deletion proxyfactory/proxyfactory_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package proxyfactory_test

import (
. "github.com/mikesimons/pacyak/proxyfactory"
. "../../pacyak/proxyfactory"

"net"
"net/http"
Expand Down