fixes for invites

This commit is contained in:
Raven Scott
2025-12-17 21:18:48 -05:00
parent f5fd92f9e6
commit 8a82681054
2 changed files with 5285 additions and 6 deletions
+39 -6
View File
@@ -638,13 +638,46 @@ async function main() {
const localPeerId = getPersistentPublicKey();
if (localPeerId === originPeerId) {
// This invite is for us! Process it via the invite channel handler
// This invite is for us! Process it directly (same logic as invite channel handler)
logInfo('Swarm', 'Relay invite is for us, processing...');
// Simulate receiving the invite on the invite channel
const inviteChannelInfo = state.pluginChannels?.get(CORE_DOMAIN)?.get('invite');
const handler = state.pluginChannelHandlers?.get(CORE_DOMAIN)?.get('invite');
if (handler && handler.onMessage) {
handler.onMessage(inviteHex, peerId);
// Check if we already have dnsPass
if (getDnsPass()) {
logWarn('Swarm', 'Pass already initialized, ignoring relay invite');
return;
}
try {
logDebug('Swarm', 'Processing received relay invite...');
// Follow Autopass pairing pattern: pair -> finished -> ready
const pair = Autopass.pair(store, inviteHex);
const newPass = await pair.finished();
logDebug('Swarm', 'Autopass pair finished');
await newPass.ready();
logDebug('Swarm', 'Paired Autopass ready');
// Use helper to ensure consistent state
setDnsPass(newPass);
logDebug('Swarm', `Core retrieved for joiner. Writable: ${core.writable}`);
// Sync initial data
await core.update();
logDebug('Swarm', 'Synced initial data from master');
// Setup domains watcher for joiner
setupDomainsWatcher();
await listDomains();
// Perform initial auto-votes
doAutoVotes();
// Set up update listeners
setupListeners();
// Send invite acknowledgment back to the relay peer
try {
channelManager.sendToPeer(CORE_DOMAIN, 'request', peerId, 'invite_ack');
logInfo('Swarm', `Sent invite_ack to relay peer ${peerId}`);
} catch (ackErr) {
logWarn('Swarm', `Failed to send invite_ack to relay peer: ${ackErr.message}`);
}
logInfo('Swarm', 'Successfully processed relay invite and initialized dnsPass');
} catch (err) {
logError('Swarm', `Error processing received relay invite: ${err.message}`);
}
} else {
// Forward the response toward the origin
File diff suppressed because it is too large Load Diff