mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-02-10 06:50:15 +08:00
panic when peer ID validation fails
This commit is contained in:
parent
8afd0b8898
commit
e5ba90639c
@ -3,7 +3,7 @@ package pstoremem
|
||||
import (
|
||||
"sync"
|
||||
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
||||
)
|
||||
|
||||
@ -36,7 +36,7 @@ func NewPeerMetadata() *memoryPeerMetadata {
|
||||
|
||||
func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error {
|
||||
if err := p.Validate(); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
ps.dslock.Lock()
|
||||
defer ps.dslock.Unlock()
|
||||
@ -53,7 +53,7 @@ func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error
|
||||
|
||||
func (ps *memoryPeerMetadata) Get(p peer.ID, key string) (interface{}, error) {
|
||||
if err := p.Validate(); err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
ps.dslock.RLock()
|
||||
defer ps.dslock.RUnlock()
|
||||
|
@ -83,7 +83,7 @@ func (pb *memoryProtoBook) internProtocol(proto string) string {
|
||||
|
||||
func (pb *memoryProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
||||
if err := p.Validate(); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
if len(protos) > pb.maxProtos {
|
||||
return errTooManyProtocols
|
||||
@ -104,7 +104,7 @@ func (pb *memoryProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
||||
|
||||
func (pb *memoryProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
||||
if err := p.Validate(); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := pb.segments.get(p)
|
||||
@ -128,7 +128,7 @@ func (pb *memoryProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
||||
|
||||
func (pb *memoryProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
||||
if err := p.Validate(); err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := pb.segments.get(p)
|
||||
@ -145,7 +145,7 @@ func (pb *memoryProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
||||
|
||||
func (pb *memoryProtoBook) RemoveProtocols(p peer.ID, protos ...string) error {
|
||||
if err := p.Validate(); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := pb.segments.get(p)
|
||||
@ -166,7 +166,7 @@ func (pb *memoryProtoBook) RemoveProtocols(p peer.ID, protos ...string) error {
|
||||
|
||||
func (pb *memoryProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
|
||||
if err := p.Validate(); err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := pb.segments.get(p)
|
||||
@ -185,7 +185,7 @@ func (pb *memoryProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]str
|
||||
|
||||
func (pb *memoryProtoBook) FirstSupportedProtocol(p peer.ID, protos ...string) (string, error) {
|
||||
if err := p.Validate(); err != nil {
|
||||
return "", err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s := pb.segments.get(p)
|
||||
|
Loading…
Reference in New Issue
Block a user