mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2024-12-27 23:40:16 +08:00
read/write protocol lock
This commit is contained in:
parent
b496ee5433
commit
af2cb17f80
10
peerstore.go
10
peerstore.go
@ -21,7 +21,7 @@ type peerstore struct {
|
||||
PeerMetadata
|
||||
|
||||
// lock for protocol information, separate from datastore lock
|
||||
protolock sync.Mutex
|
||||
protolock sync.RWMutex
|
||||
internedProtocols map[string]string
|
||||
}
|
||||
|
||||
@ -142,8 +142,8 @@ func (ps *peerstore) getProtocolMap(p peer.ID) (map[string]struct{}, error) {
|
||||
}
|
||||
|
||||
func (ps *peerstore) GetProtocols(p peer.ID) ([]string, error) {
|
||||
ps.protolock.Lock()
|
||||
defer ps.protolock.Unlock()
|
||||
ps.protolock.RLock()
|
||||
defer ps.protolock.RUnlock()
|
||||
pmap, err := ps.getProtocolMap(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -158,8 +158,8 @@ func (ps *peerstore) GetProtocols(p peer.ID) ([]string, error) {
|
||||
}
|
||||
|
||||
func (ps *peerstore) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
|
||||
ps.protolock.Lock()
|
||||
defer ps.protolock.Unlock()
|
||||
ps.protolock.RLock()
|
||||
defer ps.protolock.RUnlock()
|
||||
pmap, err := ps.getProtocolMap(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user