Skip to content

Commit

Permalink
revert to explicit peerstore for persistence (#327)
Browse files Browse the repository at this point in the history
* revert to explicit peerstore for persistence

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* add closing logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign authored Apr 29, 2020
1 parent 61506ac commit 87df70f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
host "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-kad-dht/dual"
peerstore "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-peerstore/pstoreds"
ma "github.com/multiformats/go-multiaddr"
"github.com/textileio/go-threads/core/app"
"github.com/textileio/go-threads/logstore/lstoreds"
Expand Down Expand Up @@ -60,6 +62,12 @@ func DefaultNetwork(repoPath string, opts ...NetOption) (NetBoostrapper, error)
}

ctx, cancel := context.WithCancel(context.Background())
pstore, err := pstoreds.NewPeerstore(ctx, litestore, pstoreds.DefaultOpts())
if err != nil {
litestore.Close()
cancel()
return nil, err
}
priv := util.LoadKey(filepath.Join(ipfsLitePath, "key"))
h, d, err := ipfslite.SetupLibp2p(
ctx,
Expand All @@ -68,6 +76,7 @@ func DefaultNetwork(repoPath string, opts ...NetOption) (NetBoostrapper, error)
[]ma.Multiaddr{config.HostAddr},
litestore,
libp2p.ConnectionManager(connmgr.NewConnManager(100, 400, time.Minute)),
libp2p.Peerstore(pstore),
)
if err != nil {
cancel()
Expand Down Expand Up @@ -120,6 +129,7 @@ func DefaultNetwork(repoPath string, opts ...NetOption) (NetBoostrapper, error)
cancel: cancel,
Net: api,
litepeer: lite,
pstore: pstore,
logstore: logstore,
litestore: litestore,
host: h,
Expand Down Expand Up @@ -160,6 +170,7 @@ type netBoostrapper struct {
cancel context.CancelFunc
app.Net
litepeer *ipfslite.Peer
pstore peerstore.Peerstore
logstore datastore.Datastore
litestore datastore.Datastore
host host.Host
Expand Down Expand Up @@ -187,6 +198,9 @@ func (tsb *netBoostrapper) Close() error {
if err := tsb.host.Close(); err != nil {
return err
}
if err := tsb.pstore.Close(); err != nil {
return err
}
if err := tsb.litestore.Close(); err != nil {
return err
}
Expand Down

0 comments on commit 87df70f

Please sign in to comment.