···1212logger = logging.getLogger(__name__)
131314141515-# TODO: this should be done via actual DID resolution, not hardcoded!
1616-SERVICE_ROUTES = {
1717- "did:web:api.bsky.chat#bsky_chat": "https://api.bsky.chat",
1818- "did:web:discover.bsky.app#bsky_fg": "https://discover.bsky.app",
1919- "did:plc:ar7c4by46qjdydhdevvrndac#atproto_labeler": "https://mod.bsky.app",
2020-}
2121-2222-2315@authenticated
2416async def service_proxy(request: web.Request, service: Optional[str] = None):
2517 """
···3022 logger.info(f"proxying lxm {lxm}")
3123 db = get_db(request)
3224 if service:
3333- service_did = service.partition("#")[0]
3434- service_route = SERVICE_ROUTES.get(service)
3535- if service_route is None:
2525+ service_did, _, fragment = service.partition("#")
2626+ fragment = "#" + fragment
2727+ did_doc = await get_did_resolver(request).resolve_with_db_cache(
2828+ db, service_did
2929+ )
3030+ if did_doc is None:
3131+ return web.HTTPInternalServerError(
3232+ f"unable to resolve service {service!r}"
3333+ )
3434+ for service in did_doc.get("service", []):
3535+ if service.get("id") == fragment:
3636+ service_route = service["serviceEndpoint"]
3737+ break
3838+ else:
3639 return web.HTTPBadRequest(f"unable to resolve service {service!r}")
3737- else:
4040+ else: # fall thru to assuming bsky appview
3841 service_did = db.config["bsky_appview_did"]
3942 service_route = db.config["bsky_appview_pfx"]
4043
+3-2
src/millipds/did.py
···5555 # try the db first
5656 now = int(time.time())
5757 row = db.con.execute(
5858- "SELECT doc FROM did_cache WHERE did=? AND expires_at<?", (did, now)
5858+ "SELECT doc FROM did_cache WHERE did=? AND ?<expires_at", (did, now)
5959 ).fetchone()
60606161 # cache hit
···7171 )
7272 try:
7373 doc = await self.resolve_uncached(did)
7474+ logger.info(f"Successfully resolved {did}")
7475 except Exception as e:
7575- logger.exception(f"Error resolving DID {did}: {e}")
7676+ logger.exception(f"Error resolving {did}: {e}")
7677 doc = None
77787879 # update "now" because resolution might've taken a while
···10101111GROUPNAME = "millipds-sock"
12121313-MILLIPDS_DB_VERSION = (
1414- 1 # this gets bumped if we make breaking changes to the db schema
1515-)
1313+# this gets bumped if we make breaking changes to the db schema
1414+MILLIPDS_DB_VERSION = 2
1515+1616ATPROTO_REPO_VERSION_3 = 3 # might get bumped if the atproto spec changes
1717CAR_VERSION_1 = 1
1818···27272828DID_CACHE_TTL = 60 * 60 # 1 hour
2929DID_CACHE_ERROR_TTL = 60 * 5 # 5 mins
3030+3131+PLC_DIRECTORY_HOST = "https://plc.directory"