Skip to content

Commit

Permalink
Some minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Oct 24, 2024
1 parent 0e53a9b commit 7a9a1c3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
this.logger.info('Pausing!')
await this.closeSocket()
this.logger.info('Pausing libp2pService!')
await this.libp2pService?.pause()
this.peerInfo = await this.libp2pService?.pause()
this.logger.info('Found the following peer info on pause: ', this.peerInfo)
}

public async resume() {
Expand Down
19 changes: 14 additions & 5 deletions packages/backend/src/nest/libp2p/libp2p.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PeerId, type Libp2p } from '@libp2p/interface'
import { kadDHT } from '@libp2p/kad-dht'
import { keychain } from '@libp2p/keychain'
import { peerIdFromString } from '@libp2p/peer-id'
import { ping } from '@libp2p/ping'
import { preSharedKey } from '@libp2p/pnet'
import * as filters from '@libp2p/websockets/filters'
import { createLibp2p } from 'libp2p'
Expand All @@ -31,10 +32,8 @@ import { getUsersAddresses } from '../common/utils'
import { LIBP2P_DB_PATH, SERVER_IO_PROVIDER, SOCKS_PROXY_AGENT } from '../const'
import { ServerIoProviderTypes } from '../types'
import { webSockets } from '../websocketOverTor'
import { Libp2pConnectedPeer, Libp2pEvents, Libp2pNodeParams } from './libp2p.types'
import { Libp2pConnectedPeer, Libp2pEvents, Libp2pNodeParams, Libp2pPeerInfo } from './libp2p.types'
import { createLogger } from '../common/logger'
// import { ping } from './ping.service'
import { ping } from '@libp2p/ping'

const KEY_LENGTH = 32
export const LIBP2P_PSK_METADATA = '/key/swarm/psk/1.0.0/\n/base16/\n'
Expand Down Expand Up @@ -109,14 +108,24 @@ export class Libp2pService extends EventEmitter {
await this.dialPeers(addrs)
}

public pause = async () => {
public getCurrentPeerInfo = (): Libp2pPeerInfo => {
return {
dialed: Array.from(this.dialedPeers),
connected: Array.from(this.connectedPeers.values()).map(peer => peer.address),
}
}

public pause = async (): Promise<Libp2pPeerInfo> => {
const peerInfo = this.getCurrentPeerInfo()
await this.hangUpPeers(Array.from(this.dialedPeers))
this.dialedPeers.clear()
this.connectedPeers.clear()
this.logger.info('Found the following peer info on pause: ', this.connectedPeers, this.dialedPeers)
await this.datastore?.close()
return peerInfo
}

public resume = async (peersToDial: string[]): Promise<void> => {
await this.datastore?.open()
if (peersToDial.length === 0) {
this.logger.warn('No peers to redial!')
return
Expand Down
158 changes: 0 additions & 158 deletions packages/backend/src/nest/libp2p/ping.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/mobile/ios/NodeJsMobile/NodeRunner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ - (void) startEngineWithArguments:(NSArray*)arguments:(NSString*)builtinModulesP
nodePath = [nodePath stringByAppendingString:builtinModulesPath];
}
setenv([@"NODE_PATH" UTF8String], (const char*)[nodePath UTF8String], 1);
setenv([@"DEBUG" UTF8String], "backend:*,state-manager:*,libp2p:pnet", 1);
setenv([@"DEBUG" UTF8String], "backend*,quiet*,state-manager*,desktop*,utils*,identity*,common*,libp2p*,helia*,blockstore*,datastore*", 1);

int c_arguments_size=0;

Expand Down

0 comments on commit 7a9a1c3

Please sign in to comment.