···12logger = logging.getLogger(__name__)
131415-# TODO: this should be done via actual DID resolution, not hardcoded!
16-SERVICE_ROUTES = {
17- "did:web:api.bsky.chat#bsky_chat": "https://api.bsky.chat",
18- "did:web:discover.bsky.app#bsky_fg": "https://discover.bsky.app",
19- "did:plc:ar7c4by46qjdydhdevvrndac#atproto_labeler": "https://mod.bsky.app",
20-}
21-22-23@authenticated
24async def service_proxy(request: web.Request, service: Optional[str] = None):
25 """
···30 logger.info(f"proxying lxm {lxm}")
31 db = get_db(request)
32 if service:
33- service_did = service.partition("#")[0]
34- service_route = SERVICE_ROUTES.get(service)
35- if service_route is None:
0000000000036 return web.HTTPBadRequest(f"unable to resolve service {service!r}")
37- else:
38 service_did = db.config["bsky_appview_did"]
39 service_route = db.config["bsky_appview_pfx"]
40
···12logger = logging.getLogger(__name__)
13140000000015@authenticated
16async def service_proxy(request: web.Request, service: Optional[str] = None):
17 """
···22 logger.info(f"proxying lxm {lxm}")
23 db = get_db(request)
24 if service:
25+ service_did, _, fragment = service.partition("#")
26+ fragment = "#" + fragment
27+ did_doc = await get_did_resolver(request).resolve_with_db_cache(
28+ db, service_did
29+ )
30+ if did_doc is None:
31+ return web.HTTPInternalServerError(
32+ f"unable to resolve service {service!r}"
33+ )
34+ for service in did_doc.get("service", []):
35+ if service.get("id") == fragment:
36+ service_route = service["serviceEndpoint"]
37+ break
38+ else:
39 return web.HTTPBadRequest(f"unable to resolve service {service!r}")
40+ else: # fall thru to assuming bsky appview
41 service_did = db.config["bsky_appview_did"]
42 service_route = db.config["bsky_appview_pfx"]
43
+3-2
src/millipds/did.py
···55 # try the db first
56 now = int(time.time())
57 row = db.con.execute(
58- "SELECT doc FROM did_cache WHERE did=? AND expires_at<?", (did, now)
59 ).fetchone()
6061 # cache hit
···71 )
72 try:
73 doc = await self.resolve_uncached(did)
074 except Exception as e:
75- logger.exception(f"Error resolving DID {did}: {e}")
76 doc = None
7778 # update "now" because resolution might've taken a while
···55 # try the db first
56 now = int(time.time())
57 row = db.con.execute(
58+ "SELECT doc FROM did_cache WHERE did=? AND ?<expires_at", (did, now)
59 ).fetchone()
6061 # cache hit
···71 )
72 try:
73 doc = await self.resolve_uncached(did)
74+ logger.info(f"Successfully resolved {did}")
75 except Exception as e:
76+ logger.exception(f"Error resolving {did}: {e}")
77 doc = None
7879 # update "now" because resolution might've taken a while
···1011GROUPNAME = "millipds-sock"
1213-MILLIPDS_DB_VERSION = (
14- 1 # this gets bumped if we make breaking changes to the db schema
15-)
16ATPROTO_REPO_VERSION_3 = 3 # might get bumped if the atproto spec changes
17CAR_VERSION_1 = 1
18···2728DID_CACHE_TTL = 60 * 60 # 1 hour
29DID_CACHE_ERROR_TTL = 60 * 5 # 5 mins
00
···1011GROUPNAME = "millipds-sock"
1213+# this gets bumped if we make breaking changes to the db schema
14+MILLIPDS_DB_VERSION = 2
15+16ATPROTO_REPO_VERSION_3 = 3 # might get bumped if the atproto spec changes
17CAR_VERSION_1 = 1
18···2728DID_CACHE_TTL = 60 * 60 # 1 hour
29DID_CACHE_ERROR_TTL = 60 * 5 # 5 mins
30+31+PLC_DIRECTORY_HOST = "https://plc.directory"