From 71c3e8d7248c6ca7a90551c0317c5302c09e3f43 Mon Sep 17 00:00:00 2001 From: Isla Koenigsknecht Date: Mon, 6 May 2024 17:22:17 -0400 Subject: [PATCH] Comment fix and better redial on resume --- .../connections-manager.service.ts | 18 +++++++++++++++--- .../backend/src/nest/libp2p/libp2p.service.ts | 8 +++----- packages/backend/src/nest/tor/tor.service.ts | 8 +------- packages/mobile/ios/Quiet/Info.plist | 16 ++++++++-------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index 2da3b48339..586bc941a4 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -265,8 +265,20 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI this.logger('Resuming!') this.logger('Reopening socket!') await this.openSocket() - this.logger('Dialing peers with info: ', this.peerInfo) - await this.libp2pService?.redialPeers(this.peerInfo) + this.logger('Attempting to redial peers!') + if (this.peerInfo && (this.peerInfo?.connected.length !== 0 || this.peerInfo?.dialed.length !== 0)) { + this.logger('Dialing peers with info from pause: ', this.peerInfo) + await this.libp2pService?.redialPeers([...this.peerInfo.connected, ...this.peerInfo.dialed]) + } else { + this.logger('Dialing peers from stored community (if exists)') + const community = await this.localDbService.getCurrentCommunity() + if (!community) { + this.logger(`No community launched, can't redial`) + return + } + const sortedPeers = await this.localDbService.getSortedPeers(community.peerList ?? []) + await this.libp2pService?.redialPeers(sortedPeers) + } } // This method is only used on iOS through rn-bridge for reacting on lifecycle changes @@ -638,7 +650,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI this.tor.on(SocketActionTypes.REDIAL_PEERS, async data => { this.logger(`Socket - ${SocketActionTypes.REDIAL_PEERS}`) const peerInfo = this.libp2pService?.getCurrentPeerInfo() - await this.libp2pService?.redialPeers(peerInfo) + await this.libp2pService?.redialPeers([...peerInfo.connected, ...peerInfo.dialed]) }) this.socketService.on(SocketActionTypes.CONNECTION_PROCESS_INFO, data => { this.serverIoProvider.io.emit(SocketActionTypes.CONNECTION_PROCESS_INFO, data) diff --git a/packages/backend/src/nest/libp2p/libp2p.service.ts b/packages/backend/src/nest/libp2p/libp2p.service.ts index 019e2e5c07..dcec245cd4 100644 --- a/packages/backend/src/nest/libp2p/libp2p.service.ts +++ b/packages/backend/src/nest/libp2p/libp2p.service.ts @@ -124,11 +124,9 @@ export class Libp2pService extends EventEmitter { * iOS where Tor receives a new port when the app resumes from background and * we want to close/re-open connections. */ - public async redialPeers(peerInfo?: Libp2pPeerInfo) { - const dialed = peerInfo ? peerInfo.dialed : Array.from(this.dialedPeers) - const toDial = peerInfo - ? [...peerInfo.connected, ...peerInfo.dialed] - : [...this.connectedPeers.keys(), ...this.dialedPeers] + public async redialPeers(peersToDial?: string[]) { + const dialed = peersToDial ?? Array.from(this.dialedPeers) + const toDial = peersToDial ?? [...this.connectedPeers.keys(), ...this.dialedPeers] if (dialed.length === 0) { this.logger('No peers to redial!') diff --git a/packages/backend/src/nest/tor/tor.service.ts b/packages/backend/src/nest/tor/tor.service.ts index 6b366b7b20..3910361abf 100644 --- a/packages/backend/src/nest/tor/tor.service.ts +++ b/packages/backend/src/nest/tor/tor.service.ts @@ -279,18 +279,12 @@ export class Tor extends EventEmitter implements OnModuleInit { this.logger(data.toString()) const bootstrappedRegexp = /Bootstrapped 0/ + // TODO: Figure out if there's a way to get this working in tests // const bootstrappedRegexp = /Loaded enough directory info to build circuits/ if (bootstrappedRegexp.test(data.toString())) { this.spawnHiddenServices() resolve() } - - // const noMoreHsdirRegexp = /No more HSDir available to query/ - // if (noMoreHsdirRegexp.test(data.toString())) { - // this.logger('We might have a bad circuit, switching to a clean one') - // this.switchToCleanCircuts() - // resolve() - // } }) this.process.stderr.on('data', (data: any) => { diff --git a/packages/mobile/ios/Quiet/Info.plist b/packages/mobile/ios/Quiet/Info.plist index b628587bef..da427de23a 100644 --- a/packages/mobile/ios/Quiet/Info.plist +++ b/packages/mobile/ios/Quiet/Info.plist @@ -36,26 +36,26 @@ CFBundleVersion 372 ITSAppUsesNonExemptEncryption - + LSRequiresIPhoneOS - + NSAppTransportSecurity NSAllowsArbitraryLoads - + NSAllowsLocalNetworking - + NSExceptionDomains localhost NSExceptionAllowsInsecureHTTPLoads - + NSLocationWhenInUseUsageDescription - + UIAppFonts Rubik-Black.ttf @@ -74,7 +74,7 @@ Rubik-SemiBoldItalic.ttf UIBackgroundModes - + UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities @@ -88,6 +88,6 @@ UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance - +