Allow agent to handle requests concurrently

- Prevent dup keys from being added
This commit is contained in:
Aaron Bieber 2024-01-15 12:04:11 -07:00
parent 34292747c2
commit b16c37d78a
No known key found for this signature in database
2 changed files with 15 additions and 2 deletions

View File

@ -221,9 +221,22 @@ func (t *Traygent) Add(key agent.AddedKey) error {
return err
}
t.mu.Lock()
p := NewPrivKey(signer, key)
t.mu.RLock()
for _, k := range t.keys {
if bytes.Equal(
k.signer.PublicKey().Marshal(),
signer.PublicKey().Marshal(),
) {
t.log("Key already added", "key %q already exists in agent with expiration %d", k.fingerPrint, k.lifetime)
t.mu.RUnlock()
return nil
}
}
t.mu.RUnlock()
t.mu.Lock()
t.keys = append(t.keys, p)
t.log("Key added", "added %q to agent with expiration %d", p.fingerPrint, p.lifetime)

View File

@ -86,7 +86,7 @@ func main() {
continue
}
agent.ServeAgent(&tagent, c)
go agent.ServeAgent(&tagent, c)
}
}()