Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Add checks to quit if DefaultInterface address can't be resolved #133

Merged
merged 14 commits into from
Mar 20, 2017

Conversation

Mierdin
Copy link
Member

@Mierdin Mierdin commented Mar 11, 2017

The DefaultInterface configuration is necessary for both the server and the agent. If this process isn't able to successfully determine a usable IP address on either the server or agent, the respective process should quit, instead of moving forward with a value.

This PR enforces this behavior on both the server and agent.

Summary of changes:

  • Refactor the DefaultInterface logic so that it returns an error if there was a problem
  • Moved the call to this logic from comms to the agent main.go where it should be
  • Changed the call from the agent and server to the DefaultInterface logic to detect an error and quit right away if there was a problem
  • Centralized as much logic as possible to reduce duplicate code

Closes #132

@Mierdin Mierdin changed the title Added checks to quit if DefaultInterface address can't be resolved [WIP] Added checks to quit if DefaultInterface address can't be resolved Mar 14, 2017
@Mierdin Mierdin changed the title [WIP] Added checks to quit if DefaultInterface address can't be resolved Add checks to quit if DefaultInterface address can't be resolved Mar 19, 2017
@Mierdin Mierdin requested a review from vcabbage March 20, 2017 03:29
@Mierdin Mierdin added the RFR label Mar 20, 2017
Copy link
Member

@vcabbage vcabbage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple comments about simplifying. LGTM 👍

// (map of assets:hashes, lock for asset map)
ListenForAgent(assetProvider) error
// (map of assets:hashes, base asset URL)
ListenForAgent(assetProvider, string) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this ListenForAgent(_ assetProvider, assetURLPrefix string) error instead of putting the description in the comments. Although it will be a bit inconsistent with the rest of the interface definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, and I think we already discussed this in a previous review (so that's on me). I opened #137 to do this in a future PR

return "", err
} else {
return defaultaddr, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this to return getIPOfint(ifname).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - fixed in 7dec374

}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok {
if ipnet.IP.To4() != nil {
return ipnet.IP
return ipnet.IP.To4().String(), nil
}

}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like net.InterfaceByName() would make this easier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn - and it looks like this has existed for some time. Can't believe I missed that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - implemented this and got rid of some of my wheel reinvention in c21de2d

@Mierdin Mierdin merged commit 6f640dd into master Mar 20, 2017
@Mierdin Mierdin deleted the fix/nil-defaultinterface branch March 20, 2017 06:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants