-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ffs: enable auto-repair & update to new interopnet & ipfs pinset cache #272
Changes from all commits
c3942f2
ec4a894
5b9d349
9c4f776
6f17d9b
d05c54b
4f34cc9
0a6101a
7833149
30480e1
08b153b
b25907a
22d3979
94ea9e0
813653c
415e4d4
6229ab5
b102de0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import ( | |
|
||
var ( | ||
addrs = []string{ | ||
"/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf", | ||
"/ip4/52.36.61.156/tcp/1347/p2p/12D3KooWFETiESTf1v4PGUvtnxMAcEFMzLZbJGg4tjWfGEimYior", | ||
"/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWNjqGTNZ592wG5DmX7Rbmb76V3NHMdZMqjqPJ1xiax7w6", | ||
"/ip4/54.186.82.90/tcp/1347/p2p/12D3KooWGf4ggd3cdZJKZPHkgSe8Lxf4MDsKhVC7npRGXgsPP4fz", | ||
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New bootstrap peers of |
||
} | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"context" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make a pinset cache. Basically is loaded on first use instead of in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an in-memory only thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, just a guarded |
||
"fmt" | ||
"io" | ||
"sync" | ||
|
||
blocks "github.com/ipfs/go-block-format" | ||
"github.com/ipfs/go-cid" | ||
|
@@ -25,6 +26,9 @@ var ( | |
type CoreIpfs struct { | ||
ipfs iface.CoreAPI | ||
l ffs.CidLogger | ||
|
||
lock sync.Mutex | ||
pinset map[cid.Cid]struct{} | ||
} | ||
|
||
var _ ffs.HotStorage = (*CoreIpfs)(nil) | ||
|
@@ -58,16 +62,13 @@ func (ci *CoreIpfs) Remove(ctx context.Context, c cid.Cid) error { | |
|
||
// IsStored return if a particular Cid is stored. | ||
func (ci *CoreIpfs) IsStored(ctx context.Context, c cid.Cid) (bool, error) { | ||
pins, err := ci.ipfs.Pin().Ls(ctx) | ||
if err != nil { | ||
return false, fmt.Errorf("getting pins from IPFS: %s", err) | ||
} | ||
for _, p := range pins { | ||
if p.Path().Cid() == c { | ||
return true, nil | ||
if ci.pinset == nil { | ||
if err := ci.ensurePinsetCache(ctx); err != nil { | ||
return false, err | ||
} | ||
} | ||
return false, nil | ||
_, ok := ci.pinset[c] | ||
return ok, nil | ||
} | ||
|
||
// Add adds an io.Reader data as file in the IPFS node. | ||
|
@@ -106,6 +107,12 @@ func (ci *CoreIpfs) Store(ctx context.Context, c cid.Cid) (int, error) { | |
if err != nil { | ||
return 0, fmt.Errorf("getting stats of cid %s: %s", c, err) | ||
} | ||
if err := ci.ensurePinsetCache(ctx); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this just be done on startup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that's an option. But I tried to avoid adding load to bootstrapping and just load it on first use. But this can perfectly be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, makes sense. I guess the only downside of having it here is that there will one (the first after start) lucky user that gets a slow response time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's a good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, sounds good 💯 |
||
return 0, err | ||
} | ||
ci.lock.Lock() | ||
ci.pinset[c] = struct{}{} | ||
ci.lock.Unlock() | ||
return s.Size(), nil | ||
} | ||
|
||
|
@@ -123,3 +130,21 @@ func (ci *CoreIpfs) Replace(ctx context.Context, c1 cid.Cid, c2 cid.Cid) (int, e | |
} | ||
return stat.Size(), nil | ||
} | ||
|
||
func (ci *CoreIpfs) ensurePinsetCache(ctx context.Context) error { | ||
ci.lock.Lock() | ||
defer ci.lock.Unlock() | ||
if ci.pinset != nil { | ||
return nil | ||
} | ||
pins, err := ci.ipfs.Pin().Ls(ctx) | ||
if err != nil { | ||
ci.lock.Unlock() | ||
return fmt.Errorf("getting pins from IPFS: %s", err) | ||
} | ||
ci.pinset = make(map[cid.Cid]struct{}, len(pins)) | ||
for _, p := range pins { | ||
ci.pinset[p.Path().Cid()] = struct{}{} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New
interopnet
API change.