Skip to content

v0.2.0 - RemoteDatabase & CDN Support

Choose a tag to compare

@dweekly dweekly released this 24 Nov 21:19
4d7d462

What's New

RemoteDatabase

New actor for automatic database updates from CDN:

  • Persistent disk caching - Downloads once, uses forever
  • ETag/Last-Modified refresh - HEAD request first (~200 bytes), only downloads if changed (~3.4 MB)
  • Bundled database support - Ship with a database for offline-first apps
  • Thread-safe - Swift actor with isolated state

CDN Hosting

Database now hosted at pkgs.networkweather.com/db/ip2asn.ultra:

  • Daily updates from iptoasn.com BGP routing data
  • Cloudflare R2 for global distribution

Documentation

  • Comprehensive DocC documentation for all public APIs
  • Updated README with usage examples
  • Code examples in documentation comments

Usage

import SwiftIP2ASN

// Automatic updates from CDN
let remote = RemoteDatabase()
let db = try await remote.load()  // Downloads once, caches forever

if let result = db.lookup("8.8.8.8") {
    print("AS\(result.asn): \(result.name ?? "Unknown")")
}

// Check for updates (HEAD request first)
switch try await remote.refresh() {
case .alreadyCurrent:
    print("Up to date")
case .updated(let newDb):
    print("Updated to \(newDb.entryCount) entries")
}

Offline-First Apps

let remote = RemoteDatabase(
    bundledDatabasePath: Bundle.main.path(forResource: "ip2asn", ofType: "ultra")
)
let db = try await remote.load()  // Works immediately, even offline

Performance

Operation Time
Lookup ~1 microsecond
Load from disk ~150 ms
Download from CDN ~2-3 seconds
Refresh check (HEAD) ~100 ms

Full Changelog: v0.1.0...v0.2.0