mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-27 04:40:07 +08:00
fix: make close work again
Reference pstoremem components by pointer to: 1. Avoid copying locks around on construction. 2. Avoid copying these around when calling `weakClose`. 3. Ensures that they all implement the `io.Closer` interface (it's implemented on the pointer, not the value). Technically, we could have just taken a reference when calling `weakClose`, but this is cleaner.
This commit is contained in:
parent
59abcf549d
commit
d1d80624c4
@ -11,20 +11,20 @@ import (
|
||||
type pstoremem struct {
|
||||
peerstore.Metrics
|
||||
|
||||
memoryKeyBook
|
||||
memoryAddrBook
|
||||
memoryProtoBook
|
||||
memoryPeerMetadata
|
||||
*memoryKeyBook
|
||||
*memoryAddrBook
|
||||
*memoryProtoBook
|
||||
*memoryPeerMetadata
|
||||
}
|
||||
|
||||
// NewPeerstore creates an in-memory threadsafe collection of peers.
|
||||
func NewPeerstore() *pstoremem {
|
||||
return &pstoremem{
|
||||
Metrics: pstore.NewMetrics(),
|
||||
memoryKeyBook: *NewKeyBook(),
|
||||
memoryAddrBook: *NewAddrBook(),
|
||||
memoryProtoBook: *NewProtoBook(),
|
||||
memoryPeerMetadata: *NewPeerMetadata(),
|
||||
memoryKeyBook: NewKeyBook(),
|
||||
memoryAddrBook: NewAddrBook(),
|
||||
memoryProtoBook: NewProtoBook(),
|
||||
memoryPeerMetadata: NewPeerMetadata(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user