Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions damus-c/damus-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#include "wasm.h"
#include "nostrscript.h"
#include "nostrdb.h"
#include "ndb_negentropy.h"
#include "lmdb.h"

49 changes: 38 additions & 11 deletions damus.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,42 @@ class NostrNetworkManager {
self.delegate.ndb.reopen()
// Pinging the network will automatically reconnect any dead websocket connections
await self.ping()

#if !EXTENSION_TARGET
// Try to use NIP-77 negentropy for efficient sync of missing events
await syncTimelineWithNegentropy()
#endif
}

#if !EXTENSION_TARGET
/// Use NIP-77 negentropy to sync timeline events efficiently
/// This fetches only the events we're missing instead of re-fetching everything
private func syncTimelineWithNegentropy() async {
guard await pool.isNegentropyAvailable else {
Log.info("Negentropy sync not available, skipping", for: .networking)
return
}

// Create a timeline filter for negentropy sync
// Note: limit is required for relay.damus.io NEG-OPEN - use large value for fingerprinting accuracy
var timelineFilter = NostrFilter(kinds: [.text, .longform, .boost, .highlight, .like])
timelineFilter.limit = 50000

do {
let startTime = CFAbsoluteTimeGetCurrent()
let results = try await pool.syncWithNegentropy(filter: timelineFilter)

let totalNeedIds = results.values.reduce(0) { $0 + $1.needIds.count }
let elapsed = CFAbsoluteTimeGetCurrent() - startTime
let relayNames = results.keys.map { $0.absoluteString }.joined(separator: ", ")

Log.info("Negentropy sync completed in %.2fs: requested %d missing events from %d relays: %s",
for: .networking, elapsed, totalNeedIds, results.count, relayNames)
} catch {
Log.error("Negentropy sync failed: %s", for: .networking, error.localizedDescription)
}
}
#endif

func close() async {
await withTaskGroup { group in
Expand Down
Loading