mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-11 00:37:41 +00:00
The web-of-trust crawl (~400 lines: outbox routing, sharded backbone sweep, Phase-B worker pool, relay-list discovery, report-deletion fetch, warm pool) was making the CLI's GrapeRankCommand unmaintainably large. Move it into a reusable, KMP-portable GrapeRankDataCrawler in quartz commonMain. The crawler takes a NostrClient + IEventStore + AdaptiveRelayLimiter, injected relay policy (discovery + content-fallback sets, since those defaults live in app code, not the protocol library), and a log callback; it streams contact lists into a TrustGraphBuilder and returns crawl Stats. GrapeRankCommand shrinks to arg-parsing + offline load + scoring + publish + sub-verbs, delegating the online path to the crawler. To reach commonMain (portable to every target, incl. iOS): - Add ConcurrentMap / ConcurrentSet expect classes under utils/concurrent, with jvmAndroid actuals (java.util.concurrent) and native actuals (copy-on-write over kotlin.concurrent.atomics.AtomicReference, mirroring ConcurrentHashCache). commonMain has no ConcurrentHashMap, and the crawl's producer/consumer/drain- worker state needs atomic getOrPut/merge plus a concurrent set. - Move AdaptiveRelayLimiter and DrainFailure/classifyDrainFailure from cli to quartz commonMain (java atomics -> kotlin.concurrent.atomics, ConcurrentHashMap -> ConcurrentMap, System.currentTimeMillis -> TimeUtils.nowMillis, stderr -> Log). - The gated drain (REQ-size splitting, per-relay permits, verify+store) moves into the crawler; Context.drain loses its now-unused gatePerRelay path. Net: cli -1077 lines; the crawler + relay machinery are now reusable by the Android app. Adds ConcurrentCollectionsTest; verified via JVM + commonMain metadata compile, the wot/graperank suites, and a bounded live crawl.