Skip to content

Commit

Permalink
*really* remove CloudFront and DNSimple support from peerscanner
Browse files Browse the repository at this point in the history
A lot was missing.

I thought I couldn't properly test this without bringing down the production
peerscanner because we didn't have enough spare domains, but since we're
removing CloudFront and hence DNSimple support, we only need one domain.
  • Loading branch information
aranhoide committed Aug 6, 2015
1 parent a3b4fa6 commit ab8c11e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 37 deletions.
76 changes: 52 additions & 24 deletions src/github.com/getlantern/peerscanner/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

"github.com/getlantern/cloudflare"
"github.com/getlantern/enproxy"
"github.com/getlantern/go-dnsimple/dnsimple"
"github.com/getlantern/peerscanner/cfr"
// Temporarily disable CloudFront/DNSimple.
//"github.com/getlantern/go-dnsimple/dnsimple"
//"github.com/getlantern/peerscanner/cfr"
"github.com/getlantern/tlsdialer"
"github.com/getlantern/withtimeout"
)
Expand Down Expand Up @@ -57,22 +58,25 @@ type status struct {
// If the host hasn't heard from the real-world host in over 10 minutes, it
// pauses its processing and only resumes once it hears from the client again.
type host struct {
name string
ip string
port string
cflRecord *cloudflare.Record
dspRecord *dnsimple.Record
name string
ip string
port string
cflRecord *cloudflare.Record
isProxying bool
cflGroups map[string]*cflGroup
/* Temporarily disable CloudFront/DNSimple.
dspRecord *dnsimple.Record
cfrDist *cfr.Distribution
isProxying bool
cflGroups map[string]*cflGroup
dspGroups map[string]*dspGroup
*/
lastSuccess time.Time
lastTest time.Time

resetCh chan string
unregisterCh chan interface{}
statusCh chan chan *status
initCfrCh chan interface{}
// Temporarily disable CloudFront/DNSimple.
//initCfrCh chan interface{}

proxiedClient *http.Client
reportedHost string
Expand All @@ -88,17 +92,22 @@ func (h *host) String() string {
******************************************************************************/

// newHost creates a new host for the given name, ip and optional DNS records.
func newHost(name string, ip string, port string, cflRecord *cloudflare.Record, dspRecord *dnsimple.Record) *host {

// Temporarily disable CloudFront/DNSimple.
//func newHost(name string, ip string, port string, cflRecord *cloudflare.Record, dspRecord *dnsimple.Record) *host {
func newHost(name string, ip string, port string, cflRecord *cloudflare.Record) *host {
h := &host{
name: name,
ip: ip,
port: port,
cflRecord: cflRecord,
dspRecord: dspRecord,
name: name,
ip: ip,
port: port,
cflRecord: cflRecord,
// Temporarily disable CloudFront/DNSimple.
//dspRecord: dspRecord,
resetCh: make(chan string, 1000),
unregisterCh: make(chan interface{}, 1),
statusCh: make(chan chan *status, 1000),
initCfrCh: make(chan interface{}, 1),
// Temporarily disable CloudFront/DNSimple.
//initCfrCh: make(chan interface{}, 1),
}

if h.isFallback() {
Expand All @@ -108,16 +117,19 @@ func newHost(name string, ip string, port string, cflRecord *cloudflare.Record,
Fallbacks: &cflGroup{subdomain: Fallbacks},
Peers: &cflGroup{subdomain: Peers},
}
/* Temporarily disable CloudFront/DNSimple.
h.dspGroups = map[string]*dspGroup{
RoundRobin: &dspGroup{subdomain: RoundRobin},
Fallbacks: &dspGroup{subdomain: Fallbacks},
Peers: &dspGroup{subdomain: Peers},
}
*/
country := fallbackCountry(name)
if country != "" {
// Add host to country-specific rotation
h.cflGroups[country] = &cflGroup{subdomain: country}
h.dspGroups[country] = &dspGroup{subdomain: country}
// Temporarily disable CloudFront/DNSimple.
//h.dspGroups[country] = &dspGroup{subdomain: country}
}
} else {
log.Errorf("Somehow adding peer host? %v (%v)", name, ip)
Expand Down Expand Up @@ -211,6 +223,7 @@ func (h *host) unregister() {
}
}

/* Temporarily disable CloudFront/DNSimple.
func (h *host) initCloudfront() {
h.initCfrCh <- nil
}
Expand All @@ -233,6 +246,7 @@ func (h *host) doInitCfrDist() {
}
}
}
*/

/*******************************************************************************
* Implementation
Expand Down Expand Up @@ -264,9 +278,10 @@ func (h *host) run() {
log.Debugf("Unregistering %v and pausing", h)
h.pause()
checkImmediately = true
/* Temporarily disable CloudFront/DNSimple.
case <-h.initCfrCh:
// (CloudFront/DNSimple support temporarily disabled)
// h.doInitCfrDist()
h.doInitCfrDist()
*/
case <-pauseTimer.C:
log.Debugf("%v had no successful checks or resets in %v, pausing", h, pauseAfter)
h.pause()
Expand Down Expand Up @@ -347,13 +362,15 @@ func (h *host) doReset(newName string) {
log.Error(cflErr.Error())
}
}
/* Temporarily disable CloudFront/DNSimple.
if h.dspRecord != nil {
log.Debugf("Deregistering old DNSimple hostname %v", h.name)
dspErr = h.doDeregisterDspHost()
if dspErr != nil {
log.Error(dspErr.Error())
}
}
*/
if cflErr != nil || dspErr != nil {
return
}
Expand All @@ -369,7 +386,9 @@ func (h *host) doReset(newName string) {

func (h *host) register() error {
cflErr := h.registerCfl()
dspErr := h.registerDsp()
// Temporarily disable CloudFront/DNSimple.
//dspErr := h.registerDsp()
var dspErr error
if cflErr != nil && dspErr == nil {
return fmt.Errorf("Error registering Cloudflare: %v", cflErr)
} else if cflErr == nil && dspErr != nil {
Expand All @@ -392,8 +411,8 @@ func (h *host) registerCfl() error {
return nil
}

/* Temporarily disable CloudFront/DNSimple.
func (h *host) registerDsp() error {
/* (CloudFront/DNSimple support temporarily disabled)
err := h.registerDspHost()
if err != nil {
return fmt.Errorf("Unable to register DNSimple host %v: %v", h, err)
Expand All @@ -402,9 +421,9 @@ func (h *host) registerDsp() error {
if err != nil {
return err
}
*/
return nil
}
*/

func (h *host) registerCflHost() error {
if h.isProxying {
Expand All @@ -417,6 +436,7 @@ func (h *host) registerCflHost() error {
return err
}

/* Temporarily disable CloudFront/DNSimple.
func (h *host) registerDspHost() error {
if h.dspRecord != nil {
log.Debugf("DNSimple record already registered, no need to re-register: %v", h)
Expand All @@ -427,6 +447,7 @@ func (h *host) registerDspHost() error {
h.dspRecord, err = dsputil.Register(h.name, h.ip)
return err
}
*/

func (h *host) registerToCflRotations() error {
for _, group := range h.cflGroups {
Expand All @@ -438,6 +459,7 @@ func (h *host) registerToCflRotations() error {
return nil
}

/* Temporarily disable CloudFront/DNSimple.
func (h *host) registerToDspRotations() error {
if !h.cfrDistReady() {
log.Debugf("Cloudfront distribution for %v not ready yet; not registering to rotations.", h.name)
Expand All @@ -451,6 +473,7 @@ func (h *host) registerToDspRotations() error {
}
return nil
}
*/

func (h *host) deregisterFromRotations() {
for _, group := range h.cflGroups {
Expand Down Expand Up @@ -568,6 +591,8 @@ func (h *host) doDeregisterCflHost() error {
return nil
}

/* Temporarily disable CloudFront/DNSimple.
func (h *host) doDeregisterDspHost() error {
err := dsputil.DestroyRecord(h.dspRecord)
h.dspRecord = nil
Expand All @@ -580,8 +605,11 @@ func (h *host) doDeregisterDspHost() error {
func (h *host) cfrDistReady() bool {
return h.cfrDist != nil && h.cfrDist.Status == "Deployed"
}
*/

func (h *host) reportedHostOk() bool {
// Match the FQDN at Cloudflare or Cloudfront
return (h.reportedHost == h.name+"."+*cfldomain) || (h.cfrDistReady() && h.reportedHost == h.cfrDist.Domain)
// Temporarily disable CloudFront/DNSimple.
//return (h.reportedHost == h.name+"."+*cfldomain) || (h.cfrDistReady() && h.reportedHost == h.cfrDist.Domain)
return h.reportedHost == h.name+"."+*cfldomain
}
Loading

0 comments on commit ab8c11e

Please sign in to comment.