diff --git a/bitchat/Nostr/GeoRelayDirectory.swift b/bitchat/Nostr/GeoRelayDirectory.swift index 8151f952..15e73dd2 100644 --- a/bitchat/Nostr/GeoRelayDirectory.swift +++ b/bitchat/Nostr/GeoRelayDirectory.swift @@ -14,7 +14,7 @@ final class GeoRelayDirectory { private let cacheFileName = "georelays_cache.csv" private let lastFetchKey = "georelay.lastFetchAt" private let remoteURL = URL(string: "https://raw.githubusercontent.com/permissionlesstech/georelays/refs/heads/main/nostr_relays.csv")! - private let fetchInterval: TimeInterval = 60 * 60 * 24 // 24h + private let fetchInterval: TimeInterval = TransportConfig.geoRelayFetchIntervalSeconds // 24h private init() { // Load cached or bundled data synchronously diff --git a/bitchat/Nostr/NostrRelayManager.swift b/bitchat/Nostr/NostrRelayManager.swift index d4734eee..69d2f2e1 100644 --- a/bitchat/Nostr/NostrRelayManager.swift +++ b/bitchat/Nostr/NostrRelayManager.swift @@ -48,10 +48,10 @@ class NostrRelayManager: ObservableObject { private let messageQueueLock = NSLock() // Exponential backoff configuration - private let initialBackoffInterval: TimeInterval = 1.0 // Start with 1 second - private let maxBackoffInterval: TimeInterval = 300.0 // Max 5 minutes - private let backoffMultiplier: Double = 2.0 // Double each time - private let maxReconnectAttempts = 10 // Stop after 10 attempts + private let initialBackoffInterval: TimeInterval = TransportConfig.nostrRelayInitialBackoffSeconds + private let maxBackoffInterval: TimeInterval = TransportConfig.nostrRelayMaxBackoffSeconds + private let backoffMultiplier: Double = TransportConfig.nostrRelayBackoffMultiplier + private let maxReconnectAttempts = TransportConfig.nostrRelayMaxReconnectAttempts // Reconnection timer private var reconnectionTimer: Timer? @@ -568,7 +568,7 @@ struct NostrFilter: Encodable { filter.kinds = [1059] // Gift wrap kind filter.since = since?.timeIntervalSince1970.toInt() filter.tagFilters = ["p": [pubkey]] - filter.limit = 100 // Add a reasonable limit + filter.limit = TransportConfig.nostrRelayDefaultFetchLimit // reasonable limit return filter } diff --git a/bitchat/Services/TransportConfig.swift b/bitchat/Services/TransportConfig.swift index fa22f5c9..f5e69f17 100644 --- a/bitchat/Services/TransportConfig.swift +++ b/bitchat/Services/TransportConfig.swift @@ -57,4 +57,24 @@ enum TransportConfig { static let nostrGeohashInitialLookbackSeconds: TimeInterval = 3600 static let nostrGeohashInitialLimit: Int = 200 static let nostrGeoRelayCount: Int = 5 + + // Compression + static let compressionThresholdBytes: Int = 100 + + // Message deduplication + static let messageDedupMaxAgeSeconds: TimeInterval = 300 + static let messageDedupMaxCount: Int = 1000 + + // Verification QR + static let verificationQRMaxAgeSeconds: TimeInterval = 5 * 60 + + // Nostr relay backoff + static let nostrRelayInitialBackoffSeconds: TimeInterval = 1.0 + static let nostrRelayMaxBackoffSeconds: TimeInterval = 300.0 + static let nostrRelayBackoffMultiplier: Double = 2.0 + static let nostrRelayMaxReconnectAttempts: Int = 10 + static let nostrRelayDefaultFetchLimit: Int = 100 + + // Geo relay directory + static let geoRelayFetchIntervalSeconds: TimeInterval = 60 * 60 * 24 } diff --git a/bitchat/Services/VerificationService.swift b/bitchat/Services/VerificationService.swift index 56b4caeb..2a69fbb7 100644 --- a/bitchat/Services/VerificationService.swift +++ b/bitchat/Services/VerificationService.swift @@ -102,7 +102,7 @@ final class VerificationService { } /// Verify a scanned QR and return the parsed payload if valid (signature + freshness checks) - func verifyScannedQR(_ urlString: String, maxAge: TimeInterval = 5 * 60) -> VerificationQR? { + func verifyScannedQR(_ urlString: String, maxAge: TimeInterval = TransportConfig.verificationQRMaxAgeSeconds) -> VerificationQR? { guard let url = URL(string: urlString), let qr = VerificationQR.fromURL(url) else { return nil } // Freshness let now = Date().timeIntervalSince1970 diff --git a/bitchat/Utils/CompressionUtil.swift b/bitchat/Utils/CompressionUtil.swift index ccbbb0d9..883fdaa8 100644 --- a/bitchat/Utils/CompressionUtil.swift +++ b/bitchat/Utils/CompressionUtil.swift @@ -11,7 +11,7 @@ import Compression struct CompressionUtil { // Compression threshold - don't compress if data is smaller than this - static let compressionThreshold = 100 // bytes + static let compressionThreshold = TransportConfig.compressionThresholdBytes // bytes // Compress data using zlib algorithm (most compatible) static func compress(_ data: Data) -> Data? { diff --git a/bitchat/Utils/MessageDeduplicator.swift b/bitchat/Utils/MessageDeduplicator.swift index c5fc701a..6c067466 100644 --- a/bitchat/Utils/MessageDeduplicator.swift +++ b/bitchat/Utils/MessageDeduplicator.swift @@ -11,8 +11,8 @@ final class MessageDeduplicator { private var entries: [Entry] = [] private var lookup = Set() private let lock = NSLock() - private let maxAge: TimeInterval = 300 // 5 minutes - private let maxCount = 1000 + private let maxAge: TimeInterval = TransportConfig.messageDedupMaxAgeSeconds // 5 minutes + private let maxCount = TransportConfig.messageDedupMaxCount /// Check if message is duplicate and add if not func isDuplicate(_ messageID: String) -> Bool { @@ -84,4 +84,3 @@ final class MessageDeduplicator { } } } -