Skip to content
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

finding hte correct cid from flatfs datastore #221

Open
ehsan6sha opened this issue Mar 19, 2024 · 1 comment
Open

finding hte correct cid from flatfs datastore #221

ehsan6sha opened this issue Mar 19, 2024 · 1 comment

Comments

@ehsan6sha
Copy link
Member

ehsan6sha commented Mar 19, 2024

flatfs stores files in blocks folder wit ha specific format that is explained in ipfs (next-to-last explained in https://github.com/ipfs/go-ds-flatfs/blob/5b0a8b85445049bdf226091c2a4d14b259b7e8c2/readme.go#L11). I created the method below but it seems it has issues:
https://github.com/functionland/go-fula/blob/main/blox/blox.go#L374

// GetCidv1FromBlockFilename extracts CIDv1 from block filename
func (p *Blox) GetCidv1FromBlockFilename(filename string) (cid.Cid, error) {
	// Implement the logic to extract CIDv1 from filename
	// For example, you can use regular expressions or string manipulation
	// This is just a placeholder implementation
	// Adjust it according to your actual filename format
	// Here's a sample implementation:
	base := filepath.Base(filename)
	b58 := "B" + strings.ToUpper(strings.TrimSuffix(base, filepath.Ext(base)))
	cidV0, err := cid.Decode(b58)
	if err != nil {
		fmt.Println("Error encoding to cidV0:", err)
		return cid.Cid{}, err
	}
	cidV1 := cid.NewCidV1(uint64(multicodec.DagPb), cidV0.Hash())
	return cidV1, nil
}

For exmaple for the below filenames it cannot create the cid:

Mar 18 21:17:52 pool-4 go-fula[160692]: 2024-03-18T21:17:52.183Z        ERROR        fula/blox        blox/blox.go:505        Error extracting CIDv1 from filename /uniondrive/ipfs_datastore/blocks/PU/DYQBWGIP2Y4K5N4JKPHH2TWLF4F7LKNTZF3SEOF2MBILVDRMRMWMPUY.data: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: Error encoding to cidV0: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: 2024-03-18T21:17:52.183Z        ERROR        fula/blox        blox/blox.go:505        Error extracting CIDv1 from filename /uniondrive/ipfs_datastore/blocks/MQ/DYQPPDK3Q5KGOI5LAYKHWI3LZ3OLMRGEFRK75ZKLRGJDBGAQQI2JMQA.data: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: Error encoding to cidV0: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: 2024-03-18T21:17:52.183Z        ERROR        fula/blox        blox/blox.go:505        Error extracting CIDv1 from filename /uniondrive/ipfs_datastore/blocks/U2/DYQL6GCHLZOWBBQEL5B4LYBPWIINNVFIVN6GCVTL6ZYP54VGIEUTU2I.data: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: Error encoding to cidV0: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: 2024-03-18T21:17:52.183Z        ERROR        fula/blox        blox/blox.go:505        Error extracting CIDv1 from filename /uniondrive/ipfs_datastore/blocks/LS/DYQBWQRQRIAZZNGU7YRIUEKO5MM2VWWOOSU32YS5N35MAW6NQQ7MLSQ.data: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: Error encoding to cidV0: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: 2024-03-18T21:17:52.183Z        ERROR        fula/blox        blox/blox.go:505        Error extracting CIDv1 from filename /uniondrive/ipfs_datastore/blocks/TW/DYQIKVANSVYVG53UKLK7JAYG2OEUGNQDIS37TNL3OKAGTNDGUFSUTWY.data: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
Mar 18 21:17:52 pool-4 go-fula[160692]: Error encoding to cidV0: invalid cid: invalid cid: expected 1 as the cid version number, got: 30
@ehsan6sha
Copy link
Member Author

ehsan6sha commented Mar 19, 2024

The goal is to find the list of pinned cids on the machine from the last check time as efficiently as possible if there are any other methods.
the APIs in ipfs nad ipfs-cluster to get pinned cids do not have a timestamp filter so we need to fetch all and filter locally which might not be the best approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant