Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Hollensbe <[email protected]>
  • Loading branch information
Erik Hollensbe committed Oct 4, 2021
1 parent af8e889 commit 1e455f0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
ipv4bits = net.IPv4len * 8
)

// parameter list for multiple template operations
type templateScaffold struct {
Interface string
NetworkName string
Expand All @@ -39,6 +40,8 @@ type templateScaffold struct {
MagicComment string
}

// wrapped openapi client. should probably be replaced with a code generator in
// a separate repository as it's always out of date.
type serviceAPIClient struct {
apiKey string
client *http.Client
Expand All @@ -58,13 +61,14 @@ func errExit(msg interface{}) {
os.Exit(1)
}

// Do initiates a client transaction.
// Do initiates a client transaction. 99% of what the wrapped client does is inject the right header.
func (c *serviceAPIClient) Do(req *http.Request) (*http.Response, error) {
req.Header.Add("X-ZT1-Auth", c.apiKey)
return c.client.Do(req)
}

func main() {
// two flags for the CLI auto-restart and reconcile are defaulted to true, so you rarely need them.
autoRestartFlag := flag.Bool("auto-restart", true, "Automatically restart systemd-resolved when things change")
reconcileFlag := flag.Bool("reconcile", true, "Automatically remove left networks from systemd-networkd configuration")
flag.Parse()
Expand All @@ -82,6 +86,13 @@ func main() {
errExit("your template is busted; get a different version or stop modifying the source code :)")
}

/*
this bit is fundamentally a set difference of the networks zerotier knows
about, and systemd-resolved knows about. If reconcile is true, this is
corrected. If any corrections are made, or any networks added, and
auto-restart is true, then systemd-resolved is reloaded near the end.
*/

sAPI, err := newServiceAPI()
if err != nil {
errExit(err)
Expand Down Expand Up @@ -137,7 +148,6 @@ func main() {
}

// This calculates in-addr.arpa and ip6.arpa search domains by calculating them from the IP assignments.
// This probably only works for ipv4 right now.
if network.AssignedAddresses != nil && len(*network.AssignedAddresses) > 0 {
for _, addr := range *network.AssignedAddresses {
ip, ipnet, err := net.ParseCIDR(addr)
Expand Down

0 comments on commit 1e455f0

Please sign in to comment.