mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2026-08-18 14:53:28 +08:00
add io.Closer interface and implementation to Peerstore.
This commit is contained in:
14
peerstore.go
14
peerstore.go
@@ -2,6 +2,7 @@ package peerstore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
@@ -31,6 +32,19 @@ func NewPeerstore(kb KeyBook, ab AddrBook, md PeerMetadata) Peerstore {
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *peerstore) Close() (err error) {
|
||||
if cl, ok := ps.KeyBook.(io.Closer); ok {
|
||||
cl.Close()
|
||||
}
|
||||
if cl, ok := ps.AddrBook.(io.Closer); ok {
|
||||
cl.Close()
|
||||
}
|
||||
if cl, ok := ps.PeerMetadata.(io.Closer); ok {
|
||||
cl.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *peerstore) Peers() peer.IDSlice {
|
||||
set := map[peer.ID]struct{}{}
|
||||
for _, p := range ps.PeersWithKeys() {
|
||||
|
||||
Reference in New Issue
Block a user