diff --git a/conn.go b/conn.go index 8100e27..6fe40c8 100644 --- a/conn.go +++ b/conn.go @@ -26,7 +26,7 @@ type Conn struct { queryInterval time.Duration localNames []string - queries []query + queries []*query ifaces []net.Interface closed chan interface{} @@ -111,7 +111,7 @@ func Server(conn *ipv4.PacketConn, config *Config) (*Conn, error) { c := &Conn{ queryInterval: defaultQueryInterval, - queries: []query{}, + queries: []*query{}, socket: conn, dstAddr: dstAddr, localNames: localNames, @@ -163,8 +163,9 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade nameWithSuffix := name + "." queryChan := make(chan queryResult, 1) + query := &query{nameWithSuffix, queryChan} c.mu.Lock() - c.queries = append(c.queries, query{nameWithSuffix, queryChan}) + c.queries = append(c.queries, query) ticker := time.NewTicker(c.queryInterval) c.mu.Unlock() @@ -173,7 +174,7 @@ func (c *Conn) Query(ctx context.Context, name string) (dnsmessage.ResourceHeade c.mu.Lock() defer c.mu.Unlock() for i := len(c.queries) - 1; i >= 0; i-- { - if c.queries[i].nameWithSuffix == nameWithSuffix { + if c.queries[i] == query { c.queries = append(c.queries[:i], c.queries[i+1:]...) } }