feat: optimize edge routing for global latency reduction
This PR introduces the new adaptive edge routing algorithm. It significantly reduces latency by ~40ms for users in AP-AC and EU-West regions by caching DNS lookups more aggressively and utilizing the new UDP-based handshake protocol.
Changes included:
- Refactored `EdgeRouter` class to support async resolution.
- Added fallback logic for IPv6 connectivity issues.
- Updated unit tests to cover edge cases in `resolver.test.ts`.
src/core/EdgeRouter.ts
+42
-18
lines
| 18 | // Legacy DNS resolution |
| 19 | async resolve(host: string) { return await fetchDNS(host);} |
| 20 | |
| 21 | // New adaptive resolution with caching |
| 22 | async resolve(host: string) { if (this.cache.has(host)) return this.cache.get(host); const target = await this.upstream.resolve(host); this.cache.set(host, target, { ttl: 60000 }); return target;} |
tests/EdgeRouter.test.ts
+128
-0
lines
| 45 | |
| 46 | it('should cache successful DNS lookups', async () => { // ... test implementation }); |
Conversation
1
MK
Marcus.Kim
reviewed 2 hours ago
Looks solid. The caching TTL logic is exactly what we discussed in the architecture review. Just one question about the fallback handler on line 45 in `utils.ts`.