A fork of the Cocoon PDS but being made more distributed.
11

Configure Feed

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

use the configuration when getting blockstore

Hailey (Jul 19, 2025, 10:11 AM -0700) b5b60312 39dfab1e

+31 -21
+1 -9
cmd/cocoon/main.go
··· 163 163 Usage: "Start the cocoon PDS", 164 164 Flags: []cli.Flag{}, 165 165 Action: func(cmd *cli.Context) error { 166 - var bsv server.BlockstoreVariant 167 - maybeBsv := cmd.String("blockstore-variant") 168 - switch maybeBsv { 169 - case "sqlite": 170 - bsv = server.BlockstoreVariantSqlite 171 - default: 172 - panic("invalid blockstore variant!") 173 - } 174 166 175 167 s, err := server.New(&server.Args{ 176 168 Addr: cmd.String("addr"), ··· 199 191 }, 200 192 SessionSecret: cmd.String("session-secret"), 201 193 DefaultAtprotoProxy: cmd.String("default-atproto-proxy"), 202 - BlockstoreVariant: bsv, 194 + BlockstoreVariant: server.MustReturnBlockstoreVariant(cmd.String("blockstore-variant")), 203 195 }) 204 196 if err != nil { 205 197 fmt.Printf("error creating cocoon: %v", err)
+23
server/blockstore_variant.go
··· 1 1 package server 2 2 3 + import ( 4 + "github.com/haileyok/cocoon/sqlite_blockstore" 5 + blockstore "github.com/ipfs/go-ipfs-blockstore" 6 + ) 7 + 3 8 type BlockstoreVariant int 4 9 5 10 const ( 6 11 BlockstoreVariantSqlite = iota 7 12 ) 13 + 14 + func MustReturnBlockstoreVariant(maybeBsv string) BlockstoreVariant { 15 + switch maybeBsv { 16 + case "sqlite": 17 + return BlockstoreVariantSqlite 18 + default: 19 + panic("invalid blockstore variant provided") 20 + } 21 + } 22 + 23 + func (s *Server) getBlockstore(did string) blockstore.Blockstore { 24 + switch s.config.BlockstoreVariant { 25 + case BlockstoreVariantSqlite: 26 + return sqlite_blockstore.New(did, s.db) 27 + default: 28 + return sqlite_blockstore.New(did, s.db) 29 + } 30 + }
+1 -1
server/handle_import_repo.go
··· 26 26 return helpers.ServerError(e, nil) 27 27 } 28 28 29 - bs := s.createBlockstore(urepo.Repo.Did) 29 + bs := s.getBlockstore(urepo.Repo.Did) 30 30 31 31 cs, err := car.NewCarReader(bytes.NewReader(b)) 32 32 if err != nil {
+1 -1
server/handle_server_create_account.go
··· 176 176 } 177 177 178 178 if customDidHeader == "" { 179 - bs := s.createBlockstore(signupDid) 179 + bs := s.getBlockstore(signupDid) 180 180 r := repo.NewRepo(context.TODO(), signupDid, bs) 181 181 182 182 root, rev, err := r.Commit(context.TODO(), urepo.SignFor)
+1 -1
server/handle_sync_get_blocks.go
··· 53 53 return helpers.ServerError(e, nil) 54 54 } 55 55 56 - bs := s.createBlockstore(urepo.Repo.Did) 56 + bs := s.getBlockstore(urepo.Repo.Did) 57 57 58 58 for _, c := range cids { 59 59 b, err := bs.Get(context.TODO(), c)
+2 -2
server/repo.go
··· 102 102 return nil, err 103 103 } 104 104 105 - dbs := rm.s.createBlockstore(urepo.Did) 105 + dbs := rm.s.getBlockstore(urepo.Did) 106 106 bs := recording_blockstore.New(dbs) 107 107 r, err := repo.OpenRepo(context.TODO(), dbs, rootcid) 108 108 ··· 345 345 return cid.Undef, nil, err 346 346 } 347 347 348 - dbs := rm.s.createBlockstore(urepo.Did) 348 + dbs := rm.s.getBlockstore(urepo.Did) 349 349 bs := recording_blockstore.New(dbs) 350 350 351 351 r, err := repo.OpenRepo(context.TODO(), bs, c)
+2 -7
server/server.go
··· 38 38 "github.com/haileyok/cocoon/oauth/dpop" 39 39 "github.com/haileyok/cocoon/oauth/provider" 40 40 "github.com/haileyok/cocoon/plc" 41 - "github.com/haileyok/cocoon/sqlite_blockstore" 42 41 "github.com/ipfs/go-cid" 43 - blockstore "github.com/ipfs/go-ipfs-blockstore" 44 42 echo_session "github.com/labstack/echo-contrib/session" 45 43 "github.com/labstack/echo/v4" 46 44 "github.com/labstack/echo/v4/middleware" ··· 122 120 SmtpEmail string 123 121 SmtpName string 124 122 DefaultAtprotoProxy string 123 + BlockstoreVariant BlockstoreVariant 125 124 } 126 125 127 126 type CustomValidator struct { ··· 354 353 SmtpName: args.SmtpName, 355 354 SmtpEmail: args.SmtpEmail, 356 355 DefaultAtprotoProxy: args.DefaultAtprotoProxy, 356 + BlockstoreVariant: args.BlockstoreVariant, 357 357 }, 358 358 evtman: events.NewEventManager(events.NewMemPersister()), 359 359 passport: identity.NewPassport(h, identity.NewMemCache(10_000)), ··· 645 645 for range ticker.C { 646 646 go s.doBackup() 647 647 } 648 - } 649 - 650 - func (s *Server) createBlockstore(did string) blockstore.Blockstore { 651 - // TODO: eventually configurable blockstore types here 652 - return sqlite_blockstore.New(did, s.db) 653 648 } 654 649 655 650 func (s *Server) UpdateRepo(ctx context.Context, did string, root cid.Cid, rev string) error {