mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2026-08-21 15:23:28 +08:00
support extracting inlined public keys
Technically, the caller can do this but this is more convenient.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user