Browse Source

Close peerstore and document Host Close (#1037)

* close peerstore and docs change

* update docs
pull/1075/head
Aarsh Shah 4 years ago
committed by GitHub
parent
commit
890f2e86b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      libp2p.go
  2. 4
      p2p/host/basic/basic_host.go

2
libp2p.go

@ -52,7 +52,7 @@ func ChainOptions(opts ...Option) Option {
// - If no peerstore is provided, the host is initialized with an empty // - If no peerstore is provided, the host is initialized with an empty
// peerstore. // peerstore.
// //
// Canceling the passed context will stop the returned libp2p node. // To stop/shutdown the returned libp2p node, the user needs to cancel the passed context and call `Close` on the returned Host.
func New(ctx context.Context, opts ...Option) (host.Host, error) { func New(ctx context.Context, opts ...Option) (host.Host, error) {
return NewWithoutDefaults(ctx, append(opts, FallbackDefaults)...) return NewWithoutDefaults(ctx, append(opts, FallbackDefaults)...)
} }

4
p2p/host/basic/basic_host.go

@ -1007,6 +1007,10 @@ func (h *BasicHost) Close() error {
_ = h.emitters.evtLocalAddrsUpdated.Close() _ = h.emitters.evtLocalAddrsUpdated.Close()
h.Network().Close() h.Network().Close()
if h.Peerstore() != nil {
h.Peerstore().Close()
}
h.refCount.Wait() h.refCount.Wait()
}) })

Loading…
Cancel
Save