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 (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ type metakey struct {
|
|||||||
|
|
||||||
type memoryPeerMetadata struct {
|
type memoryPeerMetadata struct {
|
||||||
// store other data, like versions
|
// store other data, like versions
|
||||||
//ds ds.ThreadSafeDatastore
|
// ds ds.ThreadSafeDatastore
|
||||||
ds map[metakey]interface{}
|
ds map[metakey]interface{}
|
||||||
dslock sync.RWMutex
|
dslock sync.RWMutex
|
||||||
interned map[string]interface{}
|
interned map[string]interface{}
|
||||||
@ -36,7 +36,7 @@ func NewPeerMetadata() *memoryPeerMetadata {
|
|||||||
|
|
||||||
func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error {
|
func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
ps.dslock.Lock()
|
ps.dslock.Lock()
|
||||||
defer ps.dslock.Unlock()
|
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) {
|
func (ps *memoryPeerMetadata) Get(p peer.ID, key string) (interface{}, error) {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return nil, err
|
panic(err)
|
||||||
}
|
}
|
||||||
ps.dslock.RLock()
|
ps.dslock.RLock()
|
||||||
defer ps.dslock.RUnlock()
|
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 {
|
func (pb *memoryProtoBook) SetProtocols(p peer.ID, protos ...string) error {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
if len(protos) > pb.maxProtos {
|
if len(protos) > pb.maxProtos {
|
||||||
return errTooManyProtocols
|
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 {
|
func (pb *memoryProtoBook) AddProtocols(p peer.ID, protos ...string) error {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := pb.segments.get(p)
|
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) {
|
func (pb *memoryProtoBook) GetProtocols(p peer.ID) ([]string, error) {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return nil, err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := pb.segments.get(p)
|
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 {
|
func (pb *memoryProtoBook) RemoveProtocols(p peer.ID, protos ...string) error {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := pb.segments.get(p)
|
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) {
|
func (pb *memoryProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return nil, err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := pb.segments.get(p)
|
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) {
|
func (pb *memoryProtoBook) FirstSupportedProtocol(p peer.ID, protos ...string) (string, error) {
|
||||||
if err := p.Validate(); err != nil {
|
if err := p.Validate(); err != nil {
|
||||||
return "", err
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := pb.segments.get(p)
|
s := pb.segments.get(p)
|
||||||
|
Loading…
Reference in New Issue
Block a user