third_part/mdns: do not announce host addresses when port is zero

  Vanadium discovery is using only TXT records which include the
  vanadium object names and so it doesn't need to announce host
  addresses separately. So in order to save mDNS packet space,
  this CL makes mDNS to not announce host addresses when the port
  of the announced service is zero.

Change-Id: I031c54c033df58df5b21390b5a546d219e3d1e16
diff --git a/go/src/github.com/presotto/go-mdns-sd/README.google b/go/src/github.com/presotto/go-mdns-sd/README.google
index 287fe3a..004647a 100644
--- a/go/src/github.com/presotto/go-mdns-sd/README.google
+++ b/go/src/github.com/presotto/go-mdns-sd/README.google
@@ -9,4 +9,5 @@
 Local Modifications:
  - added a function for removing registered services.
  - changed to support multiple watchers for a same service.
- - fixed data races
+ - changed to not announce host addresses when service port is zero.
+ - fixed data races.
diff --git a/go/src/github.com/presotto/go-mdns-sd/mdns.go b/go/src/github.com/presotto/go-mdns-sd/mdns.go
index ab76107..70b08c4 100644
--- a/go/src/github.com/presotto/go-mdns-sd/mdns.go
+++ b/go/src/github.com/presotto/go-mdns-sd/mdns.go
@@ -138,9 +138,7 @@
 	msg.Answer = append(msg.Answer, NewPtrRR(serviceDN, dns.ClassINET, ttl, uniqueServiceDN))
 	m.appendTxtRR(msg, service, host, txt, ttl)
 	m.appendSrvRR(msg, service, host, port, ttl)
-	if ttl > 0 {
-		// Do not append host address in a goodbye packet, since host may be
-		// shared by other services and we do not want to delete it.
+	if port > 0 {
 		m.appendHostAddresses(msg, host, dns.TypeALL, ttl)
 	}
 }
@@ -592,7 +590,7 @@
 	}
 	for _, set := range s.services {
 		for _, req := range set {
-			if q.Name == hostFQDN(req.host) {
+			if q.Name == hostFQDN(req.host) && req.port > 0 {
 				m.mifc.appendHostAddresses(msg, req.host, dns.TypeA, s.ttl)
 				return
 			}
@@ -607,7 +605,7 @@
 	}
 	for _, set := range s.services {
 		for _, req := range set {
-			if q.Name == hostFQDN(req.host) {
+			if q.Name == hostFQDN(req.host) && req.port > 0 {
 				m.mifc.appendHostAddresses(msg, req.host, dns.TypeAAAA, s.ttl)
 				return
 			}
@@ -631,7 +629,9 @@
 		for _, req := range set {
 			if q.Name == instanceFQDN(req.host, service) {
 				m.mifc.appendSrvRR(msg, service, req.host, req.port, s.ttl)
-				m.mifc.appendHostAddresses(msg, req.host, dns.TypeALL, s.ttl)
+				if req.port > 0 {
+					m.mifc.appendHostAddresses(msg, req.host, dns.TypeALL, s.ttl)
+				}
 			}
 		}
 	}
@@ -803,6 +803,7 @@
 }
 
 // Announce a service.  If the host name is empty, we just use the host name from NewMDNS.  If the host name ends in .local. we strip it off.
+// If the port is zero, we do not announce the host addresses.
 func (s *MDNS) AddService(service, host string, port uint16, txt ...string) error {
 	if len(service) == 0 {
 		return errors.New("service name cannot be null")