mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-15 02:40:07 +08:00
read/write metadata lock
This commit is contained in:
parent
0ddad15bd2
commit
3cd491431b
@ -16,7 +16,7 @@ type memoryPeerMetadata struct {
|
||||
// store other data, like versions
|
||||
//ds ds.ThreadSafeDatastore
|
||||
ds map[metakey]interface{}
|
||||
dslock sync.Mutex
|
||||
dslock sync.RWMutex
|
||||
}
|
||||
|
||||
var _ pstore.PeerMetadata = (*memoryPeerMetadata)(nil)
|
||||
@ -35,8 +35,8 @@ func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error
|
||||
}
|
||||
|
||||
func (ps *memoryPeerMetadata) Get(p peer.ID, key string) (interface{}, error) {
|
||||
ps.dslock.Lock()
|
||||
defer ps.dslock.Unlock()
|
||||
ps.dslock.RLock()
|
||||
defer ps.dslock.RUnlock()
|
||||
i, ok := ps.ds[metakey{p, key}]
|
||||
if !ok {
|
||||
return nil, pstore.ErrNotFound
|
||||
|
Loading…
Reference in New Issue
Block a user