From fac930b55eb929c5b2dc48387061f9041f9df311 Mon Sep 17 00:00:00 2001 From: George Date: Sun, 8 Mar 2020 23:40:08 -0400 Subject: [PATCH] Use pointers --- src/meshname/server.go | 12 ++++++------ src/meshname/server_test.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/meshname/server.go b/src/meshname/server.go index 382d76f..a3988f9 100644 --- a/src/meshname/server.go +++ b/src/meshname/server.go @@ -16,12 +16,12 @@ import ( var DomainZones = []string{"meshname.", "ygg.", "cjd."} -func DomainFromIP(target net.IP) string { - return strings.ToLower(base32.StdEncoding.EncodeToString(target)[0:26]) +func DomainFromIP(target *net.IP) string { + return strings.ToLower(base32.StdEncoding.EncodeToString(*target)[0:26]) } -func IPFromDomain(domain string) (net.IP, error) { - name := strings.ToUpper(domain) + "======" +func IPFromDomain(domain *string) (net.IP, error) { + name := strings.ToUpper(*domain) + "======" data, err := base32.StdEncoding.DecodeString(name) if err != nil { return net.IP{}, err @@ -41,7 +41,7 @@ func GenConf(target, zone string) (string, error) { if ip == nil { return "", errors.New("Invalid IP address") } - subDomain := DomainFromIP(ip) + subDomain := DomainFromIP(&ip) selfRecord := fmt.Sprintf("\t\t\"%s.%s AAAA %s\"\n", subDomain, zone, target) confString := fmt.Sprintf("{\n\t\"Domain\":\"%s\",\n\t\"Records\":[\n%s\t]\n}", subDomain, selfRecord) @@ -148,7 +148,7 @@ func (s *MeshnameServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { } } else if s.isRemoteLookupAllowed(w.RemoteAddr()) { // do remote lookups only for local clients - resolvedAddr, err := IPFromDomain(subDomain) + resolvedAddr, err := IPFromDomain(&subDomain) if err != nil { s.log.Debugln(err) continue diff --git a/src/meshname/server_test.go b/src/meshname/server_test.go index 1120861..57b453d 100644 --- a/src/meshname/server_test.go +++ b/src/meshname/server_test.go @@ -12,7 +12,7 @@ func TestIPFromDomain(t *testing.T) { test_subdomain := "aib7cwwdeob2vtnqf2cfnm7ilq" test_ip := net.ParseIP("203:f15a:c323:83aa:cdb0:2e84:56b3:e85c") - ip, err := meshname.IPFromDomain(test_subdomain) + ip, err := meshname.IPFromDomain(&test_subdomain) if err != nil { t.Errorf("Decoding IP from domain failed %s", err) } else if bytes.Compare(ip, test_ip) != 0 { @@ -24,7 +24,7 @@ func TestDomainFromIP(t *testing.T) { test_subdomain := "aib7cwwdeob2vtnqf2cfnm7ilq" test_ip := net.ParseIP("203:f15a:c323:83aa:cdb0:2e84:56b3:e85c") - subdomain := meshname.DomainFromIP(test_ip) + subdomain := meshname.DomainFromIP(&test_ip) if subdomain != test_subdomain { t.Errorf("Encoding domain error: %s != %s", subdomain, test_subdomain) }