···4455## Example Usage
6677-In this example we'll *tap into* everything in the "sh.tangled.*" NSID starting from the @tangled.org AT repo.
77+In this example we'll crawl all DIDs from the "sh.tangled.*" NSID, starting from the @tangled.org AT repo.
8899### 1. Setup a PostgreSQL cluster and create a database
1010···2727 Run `trap`, seeding from the DID of @tangled.org:
28282929 ```bash
3030- RUST_LOG=debug,sqlx=warn TRAP_DATABASE_URL=postgresql:///trap_tangled trap --seed did:plc:wshs7t2adsemcrrd4snkeqli
3030+ RUST_LOG=debug,sqlx=warn TRAP_DATABASE_URL=postgresql:///trap_tangled trap --crawl --seed did:plc:wshs7t2adsemcrrd4snkeqli
3131 ```
32323333 Trap will submit the seed DID to the Tap service. Each record returned by Tap is scanned, and any DIDs found will also be added to the Tap service.
+4
src/cli.rs
···2424 /// DIDs to seed from.
2525 #[arg(long, value_delimiter = ',', env = "TAP_DUMP_SEED")]
2626 pub seed: Vec<String>,
2727+2828+ /// Crawl records for DIDs and add to the Tap service.
2929+ #[arg(long)]
3030+ pub crawl: bool,
2731}
28322933pub fn parse() -> Arguments {
+24-11
src/main.rs
···5555 pool.clone(),
5656 did_tx.clone(),
5757 shutdown.child_token(),
5858+ arguments.crawl,
5859 ));
59606060- tasks.spawn(did_task(tap, pool, did_rx, shutdown.child_token()));
6161+ tasks.spawn(did_task(
6262+ tap,
6363+ pool,
6464+ did_rx,
6565+ shutdown.child_token(),
6666+ arguments.crawl,
6767+ ));
6168 tasks.spawn(shutdown_task(shutdown.clone()));
62696370 // Submit seed DIDs to the Tap service.
···99106 pool: PgPool,
100107 tx: mpsc::UnboundedSender<(String, DidSource)>,
101108 shutdown: CancellationToken,
109109+ crawl: bool,
102110) -> anyhow::Result<()> {
103111 while let Some(Some((span, event, ack))) = shutdown.run_until_cancelled(channel.recv()).await {
104112 async {
···107115 TapEvent::Record(record) => {
108116 let (record, parsed_record) = handle_record(record, &mut transaction).await?;
109117110110- // Expand the network of tracked DIDs.
111111- let nsid = record.collection.into_boxed_str();
112112- for did in extract_dids(&parsed_record) {
113113- tx.send((did, DidSource::Record(nsid.clone())))?;
118118+ if crawl {
119119+ // Expand the network of tracked DIDs.
120120+ let nsid = record.collection.into_boxed_str();
121121+ for did in extract_dids(&parsed_record) {
122122+ tx.send((did, DidSource::Record(nsid.clone())))?;
123123+ }
114124 }
115125 }
116126 TapEvent::Identity(identity) => {
···202212 pool: PgPool,
203213 mut did_rx: mpsc::UnboundedReceiver<(String, DidSource)>,
204214 shutdown: CancellationToken,
215215+ crawl: bool,
205216) -> anyhow::Result<()> {
206217 const BATCH: usize = 64;
207218208219 let mut seen: HashSet<String> = HashSet::with_capacity(10_000);
209220 let mut dids = Vec::new();
210221211211- // Query known DIDs from the database.
212212- let mut query = sqlx::query!("SELECT did FROM identity").fetch(&pool);
213213- while let Some(Ok(row)) = query.next().await {
214214- seen.insert(row.did);
222222+ if crawl {
223223+ // Query known DIDs from the database.
224224+ let mut query = sqlx::query!("SELECT did FROM identity").fetch(&pool);
225225+ while let Some(Ok(row)) = query.next().await {
226226+ seen.insert(row.did);
227227+ }
228228+229229+ tracing::debug!(count = seen.len(), "loaded tracked DIDs from database");
215230 }
216216-217217- tracing::debug!(count = seen.len(), "loaded tracked DIDs from database");
218231219232 loop {
220233 tokio::time::sleep(Duration::from_millis(200)).await;