Skip to content
Merged
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
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.Add)
r := newStaticResolver(probes, c.Add)
defer r.Stop()

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

// Resolver periodically tries to resolve the IP addresses for a given
// set of hostnames.
type Resolver struct {
type staticResolver struct {
quit chan struct{}
add func(string)
peers []peer
Expand All @@ -33,8 +31,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)) staticResolver {
r := staticResolver{
quit: make(chan struct{}),
add: add,
peers: prepareNames(peers),
Expand Down Expand Up @@ -67,20 +65,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 +102,6 @@ func (r Resolver) resolveHosts() {
}
}

// Stop this Resolver.
func (r Resolver) Stop() {
func (r staticResolver) Stop() {
close(r.quit)
}
7 changes: 4 additions & 3 deletions app/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ func TestResolver(t *testing.T) {
ip2 := "192.168.0.10"
adds := make(chan string)
add := func(s string) { adds <- s }
r := NewResolver([]string{"symbolic.name" + port, "namewithnoport", ip1 + port, ip2}, add)

r := newStaticResolver([]string{"symbolic.name" + port, "namewithnoport", ip1 + port, ip2}, add)

assertAdd := func(want string) {
_, _, line, _ := runtime.Caller(1)
select {
case have := <-adds:
if want != have {
_, _, line, _ := runtime.Caller(1)
t.Errorf("line %d: want %q, have %q", line, want, have)
}
case <-time.After(time.Millisecond):
t.Fatal("didn't get add in time")
t.Fatalf("line %d: didn't get add in time", line)
}
}

Expand Down