An atproto PDS written in Go

use the configuration when getting blockstore

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