An atproto PDS written in Go

fix

Changed files
+12 -27
recording_blockstore
server
sqlite_blockstore
+1
recording_blockstore/recording_blockstore.go
··· 20 20 return &RecordingBlockstore{ 21 21 base: base, 22 22 inserts: make(map[cid.Cid]blockformat.Block), 23 + reads: make(map[cid.Cid]blockformat.Block), 23 24 } 24 25 } 25 26
+10 -8
server/handle_sync_get_blocks.go
··· 11 11 "github.com/labstack/echo/v4" 12 12 ) 13 13 14 + type ComAtprotoSyncGetBlocksRequest struct { 15 + Did string `query:"did"` 16 + Cids []string `query:"cids"` 17 + } 18 + 14 19 func (s *Server) handleGetBlocks(e echo.Context) error { 15 20 ctx := e.Request().Context() 16 - did := e.QueryParam("did") 17 - if did == "" { 18 - return helpers.InputError(e, nil) 19 - } 20 21 21 - cidstrs, ok := e.QueryParams()["cids"] 22 - if !ok { 22 + var req ComAtprotoSyncGetBlocksRequest 23 + if err := e.Bind(&req); err != nil { 23 24 return helpers.InputError(e, nil) 24 25 } 26 + 25 27 var cids []cid.Cid 26 28 27 - for _, cs := range cidstrs { 29 + for _, cs := range req.Cids { 28 30 c, err := cid.Cast([]byte(cs)) 29 31 if err != nil { 30 32 return err ··· 33 35 cids = append(cids, c) 34 36 } 35 37 36 - urepo, err := s.getRepoActorByDid(did) 38 + urepo, err := s.getRepoActorByDid(req.Did) 37 39 if err != nil { 38 40 return helpers.ServerError(e, nil) 39 41 }
+1 -1
server/repo.go
··· 104 104 105 105 dbs := rm.s.getBlockstore(urepo.Did) 106 106 bs := recording_blockstore.New(dbs) 107 - r, err := repo.OpenRepo(context.TODO(), dbs, rootcid) 107 + r, err := repo.OpenRepo(context.TODO(), bs, rootcid) 108 108 109 109 entries := []models.Record{} 110 110 var results []ApplyWriteResult
-18
sqlite_blockstore/sqlite_blockstore.go
··· 135 135 func (bs *SqliteBlockstore) HashOnRead(enabled bool) { 136 136 panic("not implemented") 137 137 } 138 - 139 - func (bs *SqliteBlockstore) Execute(ctx context.Context) error { 140 - if !bs.readonly { 141 - return fmt.Errorf("blockstore was not readonly") 142 - } 143 - 144 - bs.readonly = false 145 - for _, b := range bs.inserts { 146 - bs.Put(ctx, b) 147 - } 148 - bs.readonly = true 149 - 150 - return nil 151 - } 152 - 153 - func (bs *SqliteBlockstore) GetLog() map[cid.Cid]blocks.Block { 154 - return bs.inserts 155 - }