Skip to content

dirmgr: add Store trait & MemoryStore impl

tharvik requested to merge tharvik/arti:add-memorystore into main

As discussed in #267 (closed), here goes the Store trait to abstract the caching done in tor-dirmgr. To actually try it out, I've also added a MemoryStore (behind a feature flag) that shows how to select between two Store implementation (and that can be used in wasm!).

  • Store trait is mostly all pub fn from SqliteStore, minus the constructors
    • also, removed the use of iterator as dynamic object can't be parametrized per function
  • MemoryStore is selected for tests when the feature is activated
  • configuration is a bit more complex now, as one can select between two Store impl. I'm sure that you've a nicer way to do it 😅
    • also, it kinda duplicates configuration as arti_client::StorageCacheConfig::Sqlite uses CfgPath but tor_dirmgr::StorageConfig::Sqlite uses PathBuf
    • and sadly derive_builder doesn't supports nested builder, so that less nice than wanted (config.cache(StorageCacheConfig::Sqlite{ directory: CfgPath::new("/tmp".to_owned()) }) vs conf.storage().sqlite("/tmp") 👀 )
[storage]
cache = { sqlite = { directory = "${ARTI_CACHE}" } }
# cache = "memory"

NB: this PR is actually not really useful for fixing #267 (closed), as having hooks or a custom DirProvider does the trick, but I coded it, hopefully it'll help you 😄

Edited by tharvik

Merge request reports

Loading