BYOK Personal Data Server (PDS) written in Go
ipfs vow atproto pds go
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(server): proper ipfs persistance

+29 -6
+13 -5
blockstore/ipfs.go
··· 13 13 "github.com/ipfs/go-cid" 14 14 "github.com/ipfs/kubo/client/rpc" 15 15 caopts "github.com/ipfs/kubo/core/coreiface/options" 16 + "github.com/multiformats/go-multicodec" 16 17 ) 17 18 18 19 // IPFSBlockstore stores blocks through Kubo. ··· 101 102 102 103 stat, err := bs.cli.Block().Put(ctx, r, 103 104 caopts.Block.Hash(pref.MhType, pref.MhLength), 105 + caopts.Block.CidCodec(multicodec.Code(pref.Codec).String()), 104 106 caopts.Block.Pin(true), 105 107 ) 106 108 if err != nil { ··· 108 110 } 109 111 110 112 // Verify the returned CID matches 111 - returnedPath := stat.Path() 112 - returnedCid, err := cid.Decode(returnedPath.String()) 113 - if err != nil { 114 - return fmt.Errorf("ipfs block/put: parsing returned CID: %w", err) 115 - } 113 + returnedCid := stat.Path().RootCid() 116 114 if !returnedCid.Equals(blk.Cid()) { 117 115 return fmt.Errorf("ipfs block/put: CID mismatch: expected %s, got %s", blk.Cid(), returnedCid) 118 116 } ··· 177 175 maps.Copy(out, bs.inserts) 178 176 return out 179 177 } 178 + 179 + // Verify checks that a block exists in IPFS, bypassing the local cache. 180 + func (bs *IPFSBlockstore) Verify(ctx context.Context, c cid.Cid) error { 181 + p := path.FromCid(c) 182 + _, err := bs.cli.Block().Stat(ctx, p) 183 + if err != nil { 184 + return fmt.Errorf("ipfs block/stat %s: %w", c, err) 185 + } 186 + return nil 187 + }
+12
server/repo.go
··· 249 249 return cid.Undef, fmt.Errorf("writing commit block: %w", err) 250 250 } 251 251 252 + // Verify the commit block and MST root were persisted to IPFS (bypassing local cache) 253 + if verifier, ok := bs.(interface { 254 + Verify(context.Context, cid.Cid) error 255 + }); ok { 256 + if err := verifier.Verify(ctx, commitCid); err != nil { 257 + return cid.Undef, fmt.Errorf("verifying commit block persisted: %w", err) 258 + } 259 + if err := verifier.Verify(ctx, commit.Data); err != nil { 260 + return cid.Undef, fmt.Errorf("verifying MST root block persisted: %w", err) 261 + } 262 + } 263 + 252 264 return commitCid, nil 253 265 } 254 266
+4 -1
server/server.go
··· 394 394 return nil, fmt.Errorf("failed to create event persister: %w", err) 395 395 } 396 396 397 - ipfsAPI, err := rpc.NewURLApiWithClient(args.IPFSConfig.NodeURL, http.DefaultClient) 397 + ipfsHTTPClient := &http.Client{ 398 + Timeout: 30 * time.Second, 399 + } 400 + ipfsAPI, err := rpc.NewURLApiWithClient(args.IPFSConfig.NodeURL, ipfsHTTPClient) 398 401 if err != nil { 399 402 return nil, fmt.Errorf("failed to create IPFS client: %w", err) 400 403 }