support extracting inlined public keys

Technically, the caller can do this but this is more convenient.
This commit is contained in:
Steven Allen
2018-04-16 13:17:06 +09:00
parent 2c122745dc
commit 3f5b1a304a
2 changed files with 13 additions and 4 deletions

View File

@@ -127,6 +127,15 @@ func (kb *keybook) PubKey(p peer.ID) ic.PubKey {
kb.RLock()
pk := kb.pks[p]
kb.RUnlock()
if pk != nil {
return pk
}
pk, err := p.ExtractPublicKey()
if err == nil && pk != nil {
kb.Lock()
kb.pks[p] = pk
kb.Unlock()
}
return pk
}