Skip to content

Commit

Permalink
Rename Resolver to staticResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Jun 4, 2015
1 parent bba5222 commit 948c447
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
c := xfer.NewCollector(*batch)
defer c.Stop()

r := NewResolver(probes, c.AddAddress)
r := newStaticResolver(probes, c.AddAddress)
defer r.Stop()

lifo := NewReportLIFO(c, *window)
Expand Down
20 changes: 11 additions & 9 deletions app/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ var (
lookupIP = net.LookupIP
)

// Resolver periodically tries to resolve the IP addresses for a given
// set of hostnames.
type Resolver struct {
type resolver interface {
Stop()
}

type staticResolver struct {
quit chan struct{}
add func(string)
peers []peer
Expand All @@ -33,8 +35,8 @@ type peer struct {
// resolved IPs. It explictiy supports hostnames which
// resolve to multiple IPs; it will repeatedly call
// add with the same IP, expecting the target to dedupe.
func NewResolver(peers []string, add func(string)) Resolver {
r := Resolver{
func newStaticResolver(peers []string, add func(string)) resolver {
r := staticResolver{
quit: make(chan struct{}),
add: add,
peers: prepareNames(peers),
Expand Down Expand Up @@ -67,20 +69,21 @@ func prepareNames(strs []string) []peer {
return results
}

func (r Resolver) loop() {
func (r staticResolver) loop() {
r.resolveHosts()
t := tick(time.Minute)
for {
select {
case <-t:
r.resolveHosts()

case <-r.quit:
return
}
}
}

func (r Resolver) resolveHosts() {
func (r staticResolver) resolveHosts() {
for _, peer := range r.peers {
var addrs []net.IP
if addr := net.ParseIP(peer.hostname); addr != nil {
Expand All @@ -103,7 +106,6 @@ func (r Resolver) resolveHosts() {
}
}

// Stop this Resolver.
func (r Resolver) Stop() {
func (r staticResolver) Stop() {
close(r.quit)
}

0 comments on commit 948c447

Please sign in to comment.