Skip to content

Commit

Permalink
Cleanup queries by reference instead of name
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVerkada committed Feb 7, 2024
1 parent 225c67e commit 5662268
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Conn struct {

queryInterval time.Duration
localNames []string
queries []query
queries []*query
ifaces []net.Interface

closed chan interface{}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand All @@ -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:]...)
}
}
Expand Down

0 comments on commit 5662268

Please sign in to comment.