mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2024-12-28 23:50:12 +08:00
make lock methods private
This commit is contained in:
parent
28b1a9f31d
commit
07ee3fb062
@ -20,25 +20,25 @@ func NewProtoBook(meta pstore.PeerMetadata) pstore.ProtoBook {
|
|||||||
return &dsProtoBook{meta: meta}
|
return &dsProtoBook{meta: meta}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) Lock(p peer.ID) {
|
func (pb *dsProtoBook) lock(p peer.ID) {
|
||||||
pb.lks[byte(p[len(p)-1])].Lock()
|
pb.lks[byte(p[len(p)-1])].Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) Unlock(p peer.ID) {
|
func (pb *dsProtoBook) unlock(p peer.ID) {
|
||||||
pb.lks[byte(p[len(p)-1])].Unlock()
|
pb.lks[byte(p[len(p)-1])].Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) RLock(p peer.ID) {
|
func (pb *dsProtoBook) rlock(p peer.ID) {
|
||||||
pb.lks[byte(p[len(p)-1])].RLock()
|
pb.lks[byte(p[len(p)-1])].RLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) RUnlock(p peer.ID) {
|
func (pb *dsProtoBook) runlock(p peer.ID) {
|
||||||
pb.lks[byte(p[len(p)-1])].RUnlock()
|
pb.lks[byte(p[len(p)-1])].RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
||||||
pb.Lock(p)
|
pb.lock(p)
|
||||||
defer pb.Unlock(p)
|
defer pb.unlock(p)
|
||||||
|
|
||||||
protomap := make(map[string]struct{}, len(protos))
|
protomap := make(map[string]struct{}, len(protos))
|
||||||
for _, proto := range protos {
|
for _, proto := range protos {
|
||||||
@ -49,8 +49,8 @@ func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
||||||
pb.Lock(p)
|
pb.lock(p)
|
||||||
defer pb.Unlock(p)
|
defer pb.unlock(p)
|
||||||
|
|
||||||
pmap, err := pb.getProtocolMap(p)
|
pmap, err := pb.getProtocolMap(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -65,8 +65,8 @@ func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
||||||
pb.RLock(p)
|
pb.rlock(p)
|
||||||
defer pb.RUnlock(p)
|
defer pb.runlock(p)
|
||||||
|
|
||||||
pmap, err := pb.getProtocolMap(p)
|
pmap, err := pb.getProtocolMap(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -82,8 +82,8 @@ func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
|
func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
|
||||||
pb.RLock(p)
|
pb.rlock(p)
|
||||||
defer pb.RUnlock(p)
|
defer pb.runlock(p)
|
||||||
|
|
||||||
pmap, err := pb.getProtocolMap(p)
|
pmap, err := pb.getProtocolMap(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user