Clean up some code-review issues

This commit is contained in:
Bryan Boreham committed 2014-10-20 14:21:29 +01:00
1 parent 8e2af9eec5
commit dcce09de52
1 file changed
+11 -12
+11 -12
View File
@@ -10,9 +10,11 @@ import (
// Portions of this code taken from github.com/armon/mdns // Portions of this code taken from github.com/armon/mdns
const ( const (
ipv4mdns = "224.0.0.251" // link-local multicast address ipv4mdns = "224.0.0.251" // link-local multicast address
mdnsPort = 5353 // mDNS assigned port mdnsPort = 5353 // mDNS assigned port
mDNSTimeout = 200 * time.Millisecond // We wait this long to hear responses from other mDNS servers on the network.
// TODO: introduce caching so we don't have to wait this long on every call.
mDNSTimeout = 250 * time.Millisecond
MaxDuration = time.Duration(math.MaxInt64) MaxDuration = time.Duration(math.MaxInt64)
) )
@@ -62,11 +64,10 @@ func NewMDNSClient() (*MDNSClient, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
retval := &MDNSClient{ return &MDNSClient{
conn: conn, conn: conn,
addr: ipv4Addr, addr: ipv4Addr,
inflight: make(map[string]*inflightQuery)} inflight: make(map[string]*inflightQuery)}, nil
return retval, nil
} }
func (c *MDNSClient) Start(ifi *net.Interface) error { func (c *MDNSClient) Start(ifi *net.Interface) error {
@@ -77,7 +78,7 @@ func (c *MDNSClient) Start(ifi *net.Interface) error {
handleMDNS := func(w dns.ResponseWriter, r *dns.Msg) { handleMDNS := func(w dns.ResponseWriter, r *dns.Msg) {
//log.Println("client received:", r) //log.Println("client received:", r)
// Only handle responses here // Don't want to handle queries here, so filter anything out that isn't a response
if len(r.Answer) > 0 { if len(r.Answer) > 0 {
c.ResponseCallback(r) c.ResponseCallback(r)
} }
@@ -193,7 +194,7 @@ func (c *MDNSClient) queryLoop(queryChan <-chan *MDNSInteraction) {
} }
} }
func (c *MDNSClient) handleSendQuery(q mDNSQueryInfo) error { func (c *MDNSClient) handleSendQuery(q mDNSQueryInfo) {
query, found := c.inflight[q.name] query, found := c.inflight[q.name]
if !found { if !found {
m := new(dns.Msg) m := new(dns.Msg)
@@ -203,7 +204,7 @@ func (c *MDNSClient) handleSendQuery(q mDNSQueryInfo) error {
if err != nil { if err != nil {
q.responseCh <- &ResponseA{Err: err} q.responseCh <- &ResponseA{Err: err}
close(q.responseCh) close(q.responseCh)
return err return
} }
query = &inflightQuery{ query = &inflightQuery{
name: q.name, name: q.name,
@@ -214,7 +215,7 @@ func (c *MDNSClient) handleSendQuery(q mDNSQueryInfo) error {
if err != nil { if err != nil {
q.responseCh <- &ResponseA{Err: err} q.responseCh <- &ResponseA{Err: err}
close(q.responseCh) close(q.responseCh)
return err return
} }
} }
info := &responseInfo{ info := &responseInfo{
@@ -222,8 +223,6 @@ func (c *MDNSClient) handleSendQuery(q mDNSQueryInfo) error {
timeout: time.Now().Add(mDNSTimeout), timeout: time.Now().Add(mDNSTimeout),
} }
query.responseInfos = append(query.responseInfos, info) query.responseInfos = append(query.responseInfos, info)
return nil
} }
func (c *MDNSClient) handleResponse(r *dns.Msg) { func (c *MDNSClient) handleResponse(r *dns.Msg) {