···150150151151 # check sync progress for all hosts
152152 cat hosts.txt | parallel -j1 ./sync_pds.sh {}
153153+154154+155155+## Admin API
156156+157157+The relay has a number of admin HTTP API endpoints. Given a relay setup listening on port 2470 and with a reasonably secure admin secret:
158158+159159+```
160160+RELAY_ADMIN_PASSWORD=$(openssl rand --hex 16)
161161+bigsky --api-listen :2470 --admin-key ${RELAY_ADMIN_PASSWORD} ...
162162+```
163163+164164+One can, for example, begin compaction of all repos
165165+166166+```
167167+curl -H 'Authorization: Bearer '${RELAY_ADMIN_PASSWORD} -H 'Content-Type: application/x-www-form-urlencoded' --data '' http://127.0.0.1:2470/admin/repo/compactAll
168168+```
169169+170170+### /admin/subs/getUpstreamConns
171171+172172+Return list of PDS host names in json array of strings: ["host", ...]
173173+174174+### /admin/subs/perDayLimit
175175+176176+Return `{"limit": int}` for the number of new PDS subscriptions that the relay may start in a rolling 24 hour window.
177177+178178+### /admin/subs/setPerDayLimit
179179+180180+POST with `?limit={int}` to set the number of new PDS subscriptions that the relay may start in a rolling 24 hour window.
181181+182182+### /admin/subs/setEnabled
183183+184184+POST with param `?enabled=true` or `?enabled=false` to enable or disable PDS-requested new-PDS crawling.
185185+186186+### /admin/subs/getEnabled
187187+188188+Return `{"enabled": bool}` if non-admin new PDS crawl requests are enabled
189189+190190+### /admin/subs/killUpstream
191191+192192+POST with `?host={pds host name}` to disconnect from their firehose.
193193+194194+Optionally add `&block=true` to prevent connecting to them in the future.
195195+196196+### /admin/subs/listDomainBans
197197+198198+Return `{"banned_domains": ["host name", ...]}`
199199+200200+### /admin/subs/banDomain
201201+202202+POST `{"Domain": "host name"}` to ban a domain
203203+204204+### /admin/subs/unbanDomain
205205+206206+POST `{"Domain": "host name"}` to un-ban a domain
207207+208208+### /admin/repo/takeDown
209209+210210+POST `{"did": "did:..."}` to take-down a bad repo; deletes all local data for the repo
211211+212212+### /admin/repo/reverseTakedown
213213+214214+POST `?did={did:...}` to reverse a repo take-down
215215+216216+### /admin/repo/compact
217217+218218+POST `?did={did:...}` to compact a repo. Optionally `&fast=true`. HTTP blocks until the compaction finishes.
219219+220220+### /admin/repo/compactAll
221221+222222+POST to begin compaction of all repos. Optional query params:
223223+224224+ * `fast=true`
225225+ * `limit={int}` maximum number of repos to compact (biggest first) (default 50)
226226+ * `threhsold={int}` minimum number of shard files a repo must have on disk to merit compaction (default 20)
227227+228228+### /admin/repo/reset
229229+230230+POST `?did={did:...}` deletes all local data for the repo
231231+232232+### /admin/repo/verify
233233+234234+POST `?did={did:...}` checks that all repo data is accessible. HTTP blocks until done.
235235+236236+### /admin/pds/requestCrawl
237237+238238+POST `{"hostname":"pds host"}` to start crawling a PDS
239239+240240+### /admin/pds/list
241241+242242+GET returns JSON list of records
243243+```json
244244+[{
245245+ "Host": string,
246246+ "Did": string,
247247+ "SSL": bool,
248248+ "Cursor": int,
249249+ "Registered": bool,
250250+ "Blocked": bool,
251251+ "RateLimit": float,
252252+ "CrawlRateLimit": float,
253253+ "RepoCount": int,
254254+ "RepoLimit": int,
255255+ "HourlyEventLimit": int,
256256+ "DailyEventLimit": int,
257257+258258+ "HasActiveConnection": bool,
259259+ "EventsSeenSinceStartup": int,
260260+ "PerSecondEventRate": {"Max": float, "Window": float seconds},
261261+ "PerHourEventRate": {"Max": float, "Window": float seconds},
262262+ "PerDayEventRate": {"Max": float, "Window": float seconds},
263263+ "CrawlRate": {"Max": float, "Window": float seconds},
264264+ "UserCount": int,
265265+}, ...]
266266+```
267267+268268+### /admin/pds/resync
269269+270270+POST `?host={host}` to start a resync of a PDS
271271+272272+GET `?host={host}` to get status of a PDS resync, return
273273+274274+```json
275275+{"resync": {
276276+ "pds": {
277277+ "Host": string,
278278+ "Did": string,
279279+ "SSL": bool,
280280+ "Cursor": int,
281281+ "Registered": bool,
282282+ "Blocked": bool,
283283+ "RateLimit": float,
284284+ "CrawlRateLimit": float,
285285+ "RepoCount": int,
286286+ "RepoLimit": int,
287287+ "HourlyEventLimit": int,
288288+ "DailyEventLimit": int,
289289+ },
290290+ "numRepoPages": int,
291291+ "numRepos": int,
292292+ "numReposChecked": int,
293293+ "numReposToResync": int,
294294+ "status": string,
295295+ "statusChangedAt": time,
296296+}}
297297+```
298298+299299+### /admin/pds/changeLimits
300300+301301+POST to set the limits for a PDS. body:
302302+303303+```json
304304+{
305305+ "host": string,
306306+ "per_second": int,
307307+ "per_hour": int,
308308+ "per_day": int,
309309+ "crawl_rate": int,
310310+ "repo_limit": int,
311311+}
312312+```
313313+314314+### /admin/pds/block
315315+316316+POST `?host={host}` to block a PDS
317317+318318+### /admin/pds/unblock
319319+320320+POST `?host={host}` to un-block a PDS
321321+322322+323323+### /admin/pds/addTrustedDomain
324324+325325+POST `?domain={}` to make a domain trusted
326326+327327+### /admin/consumers/list
328328+329329+GET returns list json of clients currently reading from the relay firehose
330330+331331+```json
332332+[{
333333+ "id": int,
334334+ "remote_addr": string,
335335+ "user_agent": string,
336336+ "events_consumed": int,
337337+ "connected_at": time,
338338+}, ...]
339339+```