Alternative ATProto PDS implementation

cargo fix

Changed files
+39 -39
src
actor_store
storage
+35 -35
src/actor_store/block_map.rs
··· 12 12 13 13 /// Ref: https://github.com/blacksky-algorithms/rsky/blob/main/rsky-repo/src/types.rs#L341C1-L350C2 14 14 #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 15 - pub struct CommitData { 15 + pub(super) struct CommitData { 16 16 pub cid: Cid, 17 17 pub rev: String, 18 18 pub since: Option<String>, ··· 24 24 25 25 /// Ref: https://github.com/blacksky-algorithms/rsky/blob/main/rsky-repo/src/cid_set.rs 26 26 #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 27 - pub struct CidSet { 27 + pub(super) struct CidSet { 28 28 pub set: HashSet<String>, 29 29 } 30 30 impl CidSet { 31 - pub fn new(arr: Option<Vec<Cid>>) -> Self { 31 + pub(super) fn new(arr: Option<Vec<Cid>>) -> Self { 32 32 let str_arr: Vec<String> = arr 33 33 .unwrap_or(Vec::new()) 34 34 .into_iter() ··· 39 39 } 40 40 } 41 41 42 - pub fn add(&mut self, cid: Cid) -> () { 42 + pub(super) fn add(&mut self, cid: Cid) -> () { 43 43 let _ = &self.set.insert(cid.to_string()); 44 44 () 45 45 } 46 46 47 - pub fn add_set(&mut self, to_merge: CidSet) -> () { 47 + pub(super) fn add_set(&mut self, to_merge: CidSet) -> () { 48 48 for cid in to_merge.to_list() { 49 49 let _ = &self.add(cid); 50 50 } 51 51 () 52 52 } 53 53 54 - pub fn subtract_set(&mut self, to_subtract: CidSet) -> () { 54 + pub(super) fn subtract_set(&mut self, to_subtract: CidSet) -> () { 55 55 for cid in to_subtract.to_list() { 56 56 self.delete(cid); 57 57 } 58 58 () 59 59 } 60 60 61 - pub fn delete(&mut self, cid: Cid) -> () { 61 + pub(super) fn delete(&mut self, cid: Cid) -> () { 62 62 self.set.remove(&cid.to_string()); 63 63 () 64 64 } 65 65 66 - pub fn has(&self, cid: Cid) -> bool { 66 + pub(super) fn has(&self, cid: Cid) -> bool { 67 67 self.set.contains(&cid.to_string()) 68 68 } 69 69 70 - pub fn size(&self) -> usize { 70 + pub(super) fn size(&self) -> usize { 71 71 self.set.len() 72 72 } 73 73 74 - pub fn clear(mut self) -> () { 74 + pub(super) fn clear(mut self) -> () { 75 75 self.set.clear(); 76 76 () 77 77 } 78 78 79 - pub fn to_list(&self) -> Vec<Cid> { 79 + pub(super) fn to_list(&self) -> Vec<Cid> { 80 80 self.set 81 81 .clone() 82 82 .into_iter() ··· 89 89 } 90 90 91 91 /// Ref: https://github.com/blacksky-algorithms/rsky/blob/main/rsky-common/src/lib.rs#L57 92 - pub fn struct_to_cbor<T: Serialize>(obj: &T) -> Result<Vec<u8>> { 92 + pub(super) fn struct_to_cbor<T: Serialize>(obj: &T) -> Result<Vec<u8>> { 93 93 Ok(serde_ipld_dagcbor::to_vec(obj)?) 94 94 } 95 95 96 96 /// Ref: https://github.com/blacksky-algorithms/rsky/blob/37954845d06aaafea2b914d9096a1657abfc8d75/rsky-common/src/ipld.rs 97 97 /// Create a CID for CBOR-encoded data 98 - pub fn cid_for_cbor<T: Serialize>(data: &T) -> Result<Cid> { 98 + pub(super) fn cid_for_cbor<T: Serialize>(data: &T) -> Result<Cid> { 99 99 let bytes = struct_to_cbor(data)?; 100 100 let multihash = atrium_repo::Multihash::wrap( 101 101 atrium_repo::blockstore::SHA2_256, ··· 108 108 } 109 109 110 110 /// Create a CID from a SHA-256 hash with the specified codec 111 - pub fn sha256_to_cid(hash: Vec<u8>, codec: u64) -> Cid { 111 + pub(super) fn sha256_to_cid(hash: Vec<u8>, codec: u64) -> Cid { 112 112 let multihash = atrium_repo::Multihash::wrap(atrium_repo::blockstore::SHA2_256, &hash) 113 113 .expect("valid multihash"); 114 114 ··· 116 116 } 117 117 118 118 /// Create a CID from a raw SHA-256 hash (using raw codec 0x55) 119 - pub fn sha256_raw_to_cid(hash: Vec<u8>) -> Cid { 119 + pub(super) fn sha256_raw_to_cid(hash: Vec<u8>) -> Cid { 120 120 sha256_to_cid(hash, 0x55) // 0x55 is the codec for raw 121 121 } 122 122 123 123 /// Ref: https://github.com/blacksky-algorithms/rsky/blob/main/rsky-repo/src/types.rs#L436 124 - pub type CarBlock = CidAndBytes; 125 - pub struct CidAndBytes { 124 + pub(super) type CarBlock = CidAndBytes; 125 + pub(super) struct CidAndBytes { 126 126 pub cid: Cid, 127 127 pub bytes: Vec<u8>, 128 128 } ··· 132 132 // this newtype is treated the same as the underlying Vec<u8>. 133 133 #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 134 134 #[serde(transparent)] 135 - pub struct Bytes(#[serde(with = "serde_bytes")] pub Vec<u8>); 135 + pub(super) struct Bytes(#[serde(with = "serde_bytes")] pub Vec<u8>); 136 136 137 137 #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 138 - pub struct BlockMap { 138 + pub(super) struct BlockMap { 139 139 pub map: BTreeMap<String, Bytes>, 140 140 } 141 141 142 142 impl BlockMap { 143 - pub fn new() -> Self { 143 + pub(super) fn new() -> Self { 144 144 BlockMap { 145 145 map: BTreeMap::new(), 146 146 } 147 147 } 148 148 149 - pub fn add<T: Serialize>(&mut self, value: T) -> Result<Cid> { 149 + pub(super) fn add<T: Serialize>(&mut self, value: T) -> Result<Cid> { 150 150 let cid = cid_for_cbor(&value)?; 151 151 self.set( 152 152 cid, ··· 155 155 Ok(cid) 156 156 } 157 157 158 - pub fn set(&mut self, cid: Cid, bytes: Vec<u8>) -> () { 158 + pub(super) fn set(&mut self, cid: Cid, bytes: Vec<u8>) -> () { 159 159 self.map.insert(cid.to_string(), Bytes(bytes)); 160 160 () 161 161 } 162 162 163 - pub fn get(&self, cid: Cid) -> Option<&Vec<u8>> { 163 + pub(super) fn get(&self, cid: Cid) -> Option<&Vec<u8>> { 164 164 self.map.get(&cid.to_string()).map(|bytes| &bytes.0) 165 165 } 166 - pub fn delete(&mut self, cid: Cid) -> Result<()> { 166 + pub(super) fn delete(&mut self, cid: Cid) -> Result<()> { 167 167 self.map.remove(&cid.to_string()); 168 168 Ok(()) 169 169 } 170 170 171 - pub fn get_many(&mut self, cids: Vec<Cid>) -> Result<BlocksAndMissing> { 171 + pub(super) fn get_many(&mut self, cids: Vec<Cid>) -> Result<BlocksAndMissing> { 172 172 let mut missing: Vec<Cid> = Vec::new(); 173 173 let mut blocks = BlockMap::new(); 174 174 for cid in cids { ··· 182 182 Ok(BlocksAndMissing { blocks, missing }) 183 183 } 184 184 185 - pub fn has(&self, cid: Cid) -> bool { 185 + pub(super) fn has(&self, cid: Cid) -> bool { 186 186 self.map.contains_key(&cid.to_string()) 187 187 } 188 188 189 - pub fn clear(&mut self) -> () { 189 + pub(super) fn clear(&mut self) -> () { 190 190 self.map.clear() 191 191 } 192 192 193 193 // Not really using. Issues with closures 194 - pub fn for_each(&self, cb: impl Fn(&Vec<u8>, Cid) -> ()) -> Result<()> { 194 + pub(super) fn for_each(&self, cb: impl Fn(&Vec<u8>, Cid) -> ()) -> Result<()> { 195 195 for (key, val) in self.map.iter() { 196 196 cb(&val.0, Cid::from_str(&key)?); 197 197 } 198 198 Ok(()) 199 199 } 200 200 201 - pub fn entries(&self) -> Result<Vec<CidAndBytes>> { 201 + pub(super) fn entries(&self) -> Result<Vec<CidAndBytes>> { 202 202 let mut entries: Vec<CidAndBytes> = Vec::new(); 203 203 for (cid, bytes) in self.map.iter() { 204 204 entries.push(CidAndBytes { ··· 209 209 Ok(entries) 210 210 } 211 211 212 - pub fn cids(&self) -> Result<Vec<Cid>> { 212 + pub(super) fn cids(&self) -> Result<Vec<Cid>> { 213 213 Ok(self.entries()?.into_iter().map(|e| e.cid).collect()) 214 214 } 215 215 216 - pub fn add_map(&mut self, to_add: BlockMap) -> Result<()> { 216 + pub(super) fn add_map(&mut self, to_add: BlockMap) -> Result<()> { 217 217 let results = for (cid, bytes) in to_add.map.iter() { 218 218 self.set(Cid::from_str(cid)?, bytes.0.clone()); 219 219 }; 220 220 Ok(results) 221 221 } 222 222 223 - pub fn size(&self) -> usize { 223 + pub(super) fn size(&self) -> usize { 224 224 self.map.len() 225 225 } 226 226 227 - pub fn byte_size(&self) -> Result<usize> { 227 + pub(super) fn byte_size(&self) -> Result<usize> { 228 228 let mut size = 0; 229 229 for (_, bytes) in self.map.iter() { 230 230 size += bytes.0.len(); ··· 232 232 Ok(size) 233 233 } 234 234 235 - pub fn equals(&self, other: BlockMap) -> Result<bool> { 235 + pub(super) fn equals(&self, other: BlockMap) -> Result<bool> { 236 236 if self.size() != other.size() { 237 237 return Ok(false); 238 238 } ··· 274 274 } 275 275 276 276 #[derive(Debug)] 277 - pub struct BlocksAndMissing { 277 + pub(super) struct BlocksAndMissing { 278 278 pub blocks: BlockMap, 279 279 pub missing: Vec<Cid>, 280 280 }
+3 -3
src/actor_store/preference/transactor.rs
··· 5 5 use super::reader::{AccountPreference, PreferenceReader, pref_in_scope, pref_match_namespace}; 6 6 7 7 /// Transactor for preference operations. 8 - pub struct PreferenceTransactor { 8 + pub(super) struct PreferenceTransactor { 9 9 /// Preference reader. 10 10 pub reader: PreferenceReader, 11 11 } 12 12 13 13 impl PreferenceTransactor { 14 14 /// Create a new preference transactor. 15 - pub fn new(db: SqlitePool, did: String) -> Self { 15 + pub(super) fn new(db: SqlitePool, did: String) -> Self { 16 16 Self { 17 17 reader: PreferenceReader::new(db, did), 18 18 } 19 19 } 20 20 21 21 /// Put preferences for a namespace. 22 - pub async fn put_preferences( 22 + pub(super) async fn put_preferences( 23 23 &self, 24 24 values: Vec<AccountPreference>, 25 25 namespace: &str,
+1 -1
src/storage/mod.rs
··· 6 6 use anyhow::{Context as _, Result}; 7 7 use atrium_repo::{ 8 8 Cid, Repository, 9 - blockstore::{AsyncBlockStoreRead, AsyncBlockStoreWrite, CarStore, Error as BlockstoreError}, 9 + blockstore::{AsyncBlockStoreRead, AsyncBlockStoreWrite}, 10 10 }; 11 11 use std::str::FromStr as _; 12 12