Commit d1d80624 authored by Steven Allen's avatar Steven Allen

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.
parent 59abcf54
...@@ -11,20 +11,20 @@ import ( ...@@ -11,20 +11,20 @@ import (
type pstoremem struct { type pstoremem struct {
peerstore.Metrics peerstore.Metrics
memoryKeyBook *memoryKeyBook
memoryAddrBook *memoryAddrBook
memoryProtoBook *memoryProtoBook
memoryPeerMetadata *memoryPeerMetadata
} }
// NewPeerstore creates an in-memory threadsafe collection of peers. // NewPeerstore creates an in-memory threadsafe collection of peers.
func NewPeerstore() *pstoremem { func NewPeerstore() *pstoremem {
return &pstoremem{ return &pstoremem{
Metrics: pstore.NewMetrics(), Metrics: pstore.NewMetrics(),
memoryKeyBook: *NewKeyBook(), memoryKeyBook: NewKeyBook(),
memoryAddrBook: *NewAddrBook(), memoryAddrBook: NewAddrBook(),
memoryProtoBook: *NewProtoBook(), memoryProtoBook: NewProtoBook(),
memoryPeerMetadata: *NewPeerMetadata(), memoryPeerMetadata: NewPeerMetadata(),
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment