Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinek007 committed Nov 18, 2022
2 parents 0ea6b58 + a5be67f commit 0386591
Show file tree
Hide file tree
Showing 173 changed files with 44,482 additions and 46,804 deletions.
49 changes: 0 additions & 49 deletions .github/workflows/waggle-tests-connect.yml

This file was deleted.

87 changes: 5 additions & 82 deletions packages/backend/src/common/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'fs'
import getPort from 'get-port'
import Libp2p from 'libp2p'
import { HttpsProxyAgent } from 'https-proxy-agent'
import { Response } from 'node-fetch'
import path from 'path'
import PeerId from 'peer-id'
import tmp from 'tmp'
import { ConnectionsManagerOptions } from '../common/types'
import { Config } from '../constants'
import { ConnectionsManager } from '../libp2p/connectionsManager'
import { createCertificatesTestHelper } from '../libp2p/tests/client-server'
Expand All @@ -16,7 +14,6 @@ import { Tor } from '../torManager'
import {
createLibp2pAddress,
createLibp2pListenAddress,
DummyIOServer,
getPorts,
Ports,
torBinForPlatform,
Expand All @@ -36,7 +33,7 @@ export const rootPermsData: PermsData = {
tmp.setGracefulCleanup()

export const testBootstrapMultiaddrs = [
createLibp2pAddress('abcd.onion', 1111, 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4', 'wss')
createLibp2pAddress('abcd.onion', 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4')
]

export const spawnTorProcess = async (quietDirPath: string, ports?: Ports): Promise<Tor> => {
Expand All @@ -46,8 +43,6 @@ export const spawnTorProcess = async (quietDirPath: string, ports?: Ports): Prom
const tor = new Tor({
appDataPath: quietDirPath,
torPath: torPath,
controlPort: _ports.controlPort,
socksPort: _ports.socksPort,
httpTunnelPort: _ports.httpTunnelPort,
options: {
env: {
Expand All @@ -60,33 +55,17 @@ export const spawnTorProcess = async (quietDirPath: string, ports?: Ports): Prom
return tor
}

export const createMinConnectionManager = (
options: ConnectionsManagerOptions
): ConnectionsManager => {
if (!options.env?.appDataPath) throw new Error('Test connection manager is lacking appDataPath!')
return new ConnectionsManager({
agentHost: 'localhost',
agentPort: 2222,
httpTunnelPort: 3333,
io: new DummyIOServer(),
options: {
bootstrapMultiaddrs: testBootstrapMultiaddrs,
...options
}
})
}

export const createLibp2p = async (peerId: PeerId): Promise<Libp2p> => {
const port = await getPort()
const virtPort = 443
const pems = await createCertificatesTestHelper('address1.onion', 'address2.onion')

const port = await getPort()

return ConnectionsManager.createBootstrapNode({
peerId,
listenAddresses: [createLibp2pListenAddress('localhost', virtPort, 'wss')],
listenAddresses: [createLibp2pListenAddress('localhost')],
bootstrapMultiaddrsList: testBootstrapMultiaddrs,
agent: new HttpsProxyAgent({ port: 1234, host: 'localhost' }),
localAddress: createLibp2pAddress('localhost', virtPort, peerId.toB58String(), 'wss'),
localAddress: createLibp2pAddress('localhost', peerId.toB58String()),
transportClass: WebsocketsOverTor,
cert: pems.userCert,
key: pems.userKey,
Expand Down Expand Up @@ -123,59 +102,3 @@ export function createFile(filePath: string, size: number) {
stream.end()
})
}

export class TorMock {
// TODO: extend Tor to be sure that mocked api is correct
public async spawnHiddenService({
virtPort,
targetPort,
privKey
}: {
virtPort: number
targetPort: number
privKey: string
}): Promise<any> {
log('TorMock.spawnHiddenService', virtPort, targetPort, privKey)
return 'mockedOnionAddress.onion'
}

public async createNewHiddenService(
virtPort: number,
targetPort: number
): Promise<{ onionAddress: string; privateKey: string }> {
log('TorMock.createNewHiddenService', virtPort, targetPort)
return {
onionAddress: 'mockedOnionAddress',
privateKey: 'mockedPrivateKey'
}
}

protected readonly spawnTor = resolve => {
log('TorMock.spawnTor')
resolve()
}

public kill = async (): Promise<void> => {
log('TorMock.kill')
}
}

export class ResponseMock extends Response {
_json: {}
_status: number

public init(respStatus: number, respJson?: {}) {
this._json = respJson
this._status = respStatus
return this
}

// @ts-expect-error
get status() {
return this._status
}

public async json() {
return this._json
}
}
22 changes: 0 additions & 22 deletions packages/backend/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class StorageOptions {
orbitDbDir?: string
ipfsDir?: string
createPaths: boolean = true
isEntryNode?: boolean = false
}

export interface IPublicKey {
Expand All @@ -36,27 +35,6 @@ export class ConnectionsManagerOptions {

bootstrapMultiaddrs?: string[] = []
createPaths?: boolean = true
isEntryNode?: boolean = false
createSnapshot?: boolean = false
useSnapshot?: boolean = false
libp2pTransportClass?: any = null
spawnTor?: boolean = true
torControlPort: number
torPassword?: string
torAuthCookie?: string
useLocalTorFiles?: boolean = false // Use tor binaries and their libs from backend
wsType?: 'wss' | 'ws' = 'wss'
}

export interface IConstructor {
host: string
port: number
agentPort?: number
httpTunnelPort?: number
agentHost?: string
options?: Partial<ConnectionsManagerOptions>
io: any
storageClass?: any // TODO: what type?
}

export interface ILibp2pStatus {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ it('Gets users addresses based on user data', async () => {
]
const addresses = await getUsersAddresses(userData)
expect(addresses).toStrictEqual([
createLibp2pAddress(userData[0].onionAddress, 443, userData[0].peerId, 'wss'),
createLibp2pAddress(userData[1].onionAddress, 443, userData[1].peerId, 'wss')
createLibp2pAddress(userData[0].onionAddress, userData[0].peerId),
createLibp2pAddress(userData[1].onionAddress, userData[1].peerId)
])
})
32 changes: 11 additions & 21 deletions packages/backend/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import getPort from 'get-port'
import path from 'path'
import SocketIO from 'socket.io'
import logger from '../logger'
import { Tor } from '../torManager'
const log = logger('utils')

export interface Ports {
Expand Down Expand Up @@ -91,11 +90,11 @@ export function fetchAbsolute(fetch: Function): Function {
}

export const getPorts = async (): Promise<Ports> => {
const controlPort = await getPort({ port: 9151 })
const socksPort = await getPort({ port: 9052 })
const libp2pHiddenService = await getPort({ port: 7788 })
const dataServer = await getPort({ port: 4677 })
const httpTunnelPort = await getPort({ port: 9000 })
const controlPort = await getPort()
const socksPort = await getPort()
const libp2pHiddenService = await getPort()
const dataServer = await getPort()
const httpTunnelPort = await getPort()
return {
socksPort,
libp2pHiddenService,
Expand Down Expand Up @@ -135,26 +134,17 @@ export const torDirForPlatform = (basePath?: string): string => {
return torPath
}

export const createLibp2pAddress = (address: string, port: number, peerId: string, wsType: 'ws' | 'wss') => {
return `/dns4/${address}/tcp/${port}/${wsType}/p2p/${peerId}`
export const createLibp2pAddress = (address: string, peerId: string) => {
return `/dns4/${address}/tcp/443/wss/p2p/${peerId}`
}

export const createLibp2pListenAddress = (address: string, port: number, wsType: 'ws' | 'wss') => {
return `/dns4/${address}/tcp/${port}/${wsType}`
export const createLibp2pListenAddress = (address: string) => {
return `/dns4/${address}/tcp/443/wss`
}

export const getUsersAddresses = async (users: User[], tor: boolean = true): Promise<string[]> => {
export const getUsersAddresses = async (users: User[]): Promise<string[]> => {
const peers = users.map(async (userData: User) => {
let port: number
let ws: 'ws' | 'wss'
if (tor) {
port = 443
ws = 'wss'
} else {
port = 7788 // make sure this port is free
ws = 'ws'
}
return createLibp2pAddress(userData.onionAddress, port, userData.peerId, ws)
return createLibp2pAddress(userData.onionAddress, userData.peerId)
})

return await Promise.all(peers)
Expand Down
78 changes: 0 additions & 78 deletions packages/backend/src/communities/community.test.ts

This file was deleted.

Loading

0 comments on commit 0386591

Please sign in to comment.