An atproto PDS written in Go

use the configuration when getting blockstore

+1 -9
cmd/cocoon/main.go
···
Usage: "Start the cocoon PDS",
Flags: []cli.Flag{},
Action: func(cmd *cli.Context) error {
-
var bsv server.BlockstoreVariant
-
maybeBsv := cmd.String("blockstore-variant")
-
switch maybeBsv {
-
case "sqlite":
-
bsv = server.BlockstoreVariantSqlite
-
default:
-
panic("invalid blockstore variant!")
-
}
s, err := server.New(&server.Args{
Addr: cmd.String("addr"),
···
},
SessionSecret: cmd.String("session-secret"),
DefaultAtprotoProxy: cmd.String("default-atproto-proxy"),
-
BlockstoreVariant: bsv,
})
if err != nil {
fmt.Printf("error creating cocoon: %v", err)
···
Usage: "Start the cocoon PDS",
Flags: []cli.Flag{},
Action: func(cmd *cli.Context) error {
s, err := server.New(&server.Args{
Addr: cmd.String("addr"),
···
},
SessionSecret: cmd.String("session-secret"),
DefaultAtprotoProxy: cmd.String("default-atproto-proxy"),
+
BlockstoreVariant: server.MustReturnBlockstoreVariant(cmd.String("blockstore-variant")),
})
if err != nil {
fmt.Printf("error creating cocoon: %v", err)
+23
server/blockstore_variant.go
···
package server
type BlockstoreVariant int
const (
BlockstoreVariantSqlite = iota
)
···
package server
+
import (
+
"github.com/haileyok/cocoon/sqlite_blockstore"
+
blockstore "github.com/ipfs/go-ipfs-blockstore"
+
)
+
type BlockstoreVariant int
const (
BlockstoreVariantSqlite = iota
)
+
+
func MustReturnBlockstoreVariant(maybeBsv string) BlockstoreVariant {
+
switch maybeBsv {
+
case "sqlite":
+
return BlockstoreVariantSqlite
+
default:
+
panic("invalid blockstore variant provided")
+
}
+
}
+
+
func (s *Server) getBlockstore(did string) blockstore.Blockstore {
+
switch s.config.BlockstoreVariant {
+
case BlockstoreVariantSqlite:
+
return sqlite_blockstore.New(did, s.db)
+
default:
+
return sqlite_blockstore.New(did, s.db)
+
}
+
}
+1 -1
server/handle_import_repo.go
···
return helpers.ServerError(e, nil)
}
-
bs := s.createBlockstore(urepo.Repo.Did)
cs, err := car.NewCarReader(bytes.NewReader(b))
if err != nil {
···
return helpers.ServerError(e, nil)
}
+
bs := s.getBlockstore(urepo.Repo.Did)
cs, err := car.NewCarReader(bytes.NewReader(b))
if err != nil {
+1 -1
server/handle_server_create_account.go
···
}
if customDidHeader == "" {
-
bs := s.createBlockstore(signupDid)
r := repo.NewRepo(context.TODO(), signupDid, bs)
root, rev, err := r.Commit(context.TODO(), urepo.SignFor)
···
}
if customDidHeader == "" {
+
bs := s.getBlockstore(signupDid)
r := repo.NewRepo(context.TODO(), signupDid, bs)
root, rev, err := r.Commit(context.TODO(), urepo.SignFor)
+1 -1
server/handle_sync_get_blocks.go
···
return helpers.ServerError(e, nil)
}
-
bs := s.createBlockstore(urepo.Repo.Did)
for _, c := range cids {
b, err := bs.Get(context.TODO(), c)
···
return helpers.ServerError(e, nil)
}
+
bs := s.getBlockstore(urepo.Repo.Did)
for _, c := range cids {
b, err := bs.Get(context.TODO(), c)
+2 -2
server/repo.go
···
return nil, err
}
-
dbs := rm.s.createBlockstore(urepo.Did)
bs := recording_blockstore.New(dbs)
r, err := repo.OpenRepo(context.TODO(), dbs, rootcid)
···
return cid.Undef, nil, err
}
-
dbs := rm.s.createBlockstore(urepo.Did)
bs := recording_blockstore.New(dbs)
r, err := repo.OpenRepo(context.TODO(), bs, c)
···
return nil, err
}
+
dbs := rm.s.getBlockstore(urepo.Did)
bs := recording_blockstore.New(dbs)
r, err := repo.OpenRepo(context.TODO(), dbs, rootcid)
···
return cid.Undef, nil, err
}
+
dbs := rm.s.getBlockstore(urepo.Did)
bs := recording_blockstore.New(dbs)
r, err := repo.OpenRepo(context.TODO(), bs, c)
+2 -7
server/server.go
···
"github.com/haileyok/cocoon/oauth/dpop"
"github.com/haileyok/cocoon/oauth/provider"
"github.com/haileyok/cocoon/plc"
-
"github.com/haileyok/cocoon/sqlite_blockstore"
"github.com/ipfs/go-cid"
-
blockstore "github.com/ipfs/go-ipfs-blockstore"
echo_session "github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
···
SmtpEmail string
SmtpName string
DefaultAtprotoProxy string
}
type CustomValidator struct {
···
SmtpName: args.SmtpName,
SmtpEmail: args.SmtpEmail,
DefaultAtprotoProxy: args.DefaultAtprotoProxy,
},
evtman: events.NewEventManager(events.NewMemPersister()),
passport: identity.NewPassport(h, identity.NewMemCache(10_000)),
···
for range ticker.C {
go s.doBackup()
}
-
}
-
-
func (s *Server) createBlockstore(did string) blockstore.Blockstore {
-
// TODO: eventually configurable blockstore types here
-
return sqlite_blockstore.New(did, s.db)
}
func (s *Server) UpdateRepo(ctx context.Context, did string, root cid.Cid, rev string) error {
···
"github.com/haileyok/cocoon/oauth/dpop"
"github.com/haileyok/cocoon/oauth/provider"
"github.com/haileyok/cocoon/plc"
"github.com/ipfs/go-cid"
echo_session "github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
···
SmtpEmail string
SmtpName string
DefaultAtprotoProxy string
+
BlockstoreVariant BlockstoreVariant
}
type CustomValidator struct {
···
SmtpName: args.SmtpName,
SmtpEmail: args.SmtpEmail,
DefaultAtprotoProxy: args.DefaultAtprotoProxy,
+
BlockstoreVariant: args.BlockstoreVariant,
},
evtman: events.NewEventManager(events.NewMemPersister()),
passport: identity.NewPassport(h, identity.NewMemCache(10_000)),
···
for range ticker.C {
go s.doBackup()
}
}
func (s *Server) UpdateRepo(ctx context.Context, did string, root cid.Cid, rev string) error {