Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2295 #2439

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
28dc343
refactor: adjust customProtocolSaga code to be similar to deepLinkSag…
EmiM Mar 5, 2024
b8aa768
fix: customProtocolSaga tests
EmiM Mar 5, 2024
928a412
Merge branch 'develop' into feature/2310
EmiM Mar 5, 2024
1460d57
fix: tests; add missing file
EmiM Mar 5, 2024
b4e8f45
fix: main.ts test
EmiM Mar 6, 2024
7d0b19a
feat: handle old (psk, orbitdbIdentity, addresses) and new (cid, toke…
EmiM Mar 7, 2024
d386067
chore: adjust types
EmiM Mar 11, 2024
d5f7b66
chore: add joinNetwork saga that gathers data for createNetwork; mock…
EmiM Mar 11, 2024
67268d2
Merge branch 'develop' into feature/2310
EmiM Mar 11, 2024
a4d674b
refactor: invitation link parsers
EmiM Mar 14, 2024
8cc6fd3
fix: deepLink saga tests
EmiM Mar 14, 2024
b8203f9
refactor: simplify deepLink and customProtocol sagas
EmiM Mar 15, 2024
7d75c3a
fix: invitation code utils tests
EmiM Mar 15, 2024
d333cfe
chore: add missing github workflow for running common package tests
EmiM Mar 15, 2024
de8533c
refactor: invitation code tests
EmiM Mar 18, 2024
4895b29
fix: unit tests
EmiM Mar 18, 2024
3b5cf43
Merge branch 'develop' into feature/2310
EmiM Mar 18, 2024
54b925c
Merge branch 'develop' into feature/2310
EmiM Mar 19, 2024
6e82f71
feat: add one script for preparing AppImage for e2e tests
EmiM Mar 19, 2024
5f80ac1
fix: 'copy app image for e2e' script
EmiM Mar 19, 2024
7471a24
fix: getting env file name in e2e tests
EmiM Mar 19, 2024
967665d
chore: remove unused code responsible for locking invitation link for…
EmiM Mar 20, 2024
9f84ffe
chore: update changelog
EmiM Mar 20, 2024
bc2430d
Merge branch 'develop' into feature/2310
EmiM Mar 21, 2024
066a201
Merge branch 'develop' into feature/2310
EmiM Mar 25, 2024
3c6796d
feat: add storage server proxy for downloading and uploading data fro…
EmiM Mar 27, 2024
c6c9df4
feat: joining with v2 invitation link
EmiM Mar 28, 2024
6e35699
feat: handle relay server connection errors
EmiM Mar 28, 2024
7e6b4bc
test: add basic storage service proxy tests
EmiM Apr 2, 2024
0963a59
feat: add basic server stored metadata validator
EmiM Apr 2, 2024
fa0d7b9
Merge branch 'develop' into feature/2295
EmiM Apr 4, 2024
beaec60
Merge branch 'develop' into feature/2310
EmiM Apr 4, 2024
376a74c
Merge branch 'feature/2310' into feature/2295
EmiM Apr 4, 2024
2ff58f7
fix: pass dispatch to useEffect
EmiM Apr 4, 2024
7f28330
fix: move handling server error to container
EmiM Apr 5, 2024
cd863db
Merge branch 'develop' into feature/2310
EmiM Apr 9, 2024
a529c7f
fix: mobile tests
EmiM Apr 9, 2024
fcd8b2b
fix: long failing backend test
EmiM Apr 10, 2024
7b5b688
Merge branch 'develop' into feature/2310
EmiM Apr 10, 2024
3b6ec98
Merge branch 'feature/2310' into feature/2295
EmiM Apr 10, 2024
611ffe5
fix: add missing import
EmiM Apr 10, 2024
521c130
test: add Dockerfile for running QSS with e2e test; add e2e test for …
EmiM Apr 11, 2024
bd07e99
refactor: deduplicate UserTestData interface
EmiM Apr 11, 2024
ed6a907
chore: remove DuplicatedCertBug logs
EmiM Apr 11, 2024
ffaea57
test: add temporary workaround to e2e test to fully join community wi…
EmiM Apr 11, 2024
f5c7925
fix: add missing file and fix test
EmiM Apr 12, 2024
eb735f5
Merge branch 'develop' into feature/2295
EmiM Apr 15, 2024
f39f6b2
Merge branch 'develop' into feature/2295
EmiM Apr 16, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# New features:

* Add support for new format of invitation link: `c=<cid>&t=<token>&s=<serverAddress>&i=<inviterAddress>` ([#2310](https://github.com/TryQuiet/quiet/issues/2310))
* Use server for downloading initial community metadata if v2 invitation link is detected ([#2295](https://github.com/TryQuiet/quiet/issues/2295))

# Refactorings:

Expand Down
11 changes: 11 additions & 0 deletions packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"dotenv": "8.2.0",
"events": "^3.2.0",
"express": "^4.17.1",
"fetch-retry": "^6.0.0",
"fastq": "^1.17.1",
"get-port": "^5.1.1",
"go-ipfs": "npm:[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { SocketModule } from '../socket/socket.module'
import { StorageModule } from '../storage/storage.module'
import { TorModule } from '../tor/tor.module'
import { ConnectionsManagerService } from './connections-manager.service'
import { ServerProxyServiceModule } from '../storageServerProxy/storageServerProxy.module'

@Module({
imports: [RegistrationModule, StorageModule, TorModule, SocketModule, LocalDbModule],
imports: [RegistrationModule, StorageModule, TorModule, SocketModule, LocalDbModule, ServerProxyServiceModule],
providers: [ConnectionsManagerService],
exports: [ConnectionsManagerService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ describe('Connections manager', () => {
const spyOnDestroyHiddenService = jest.spyOn(tor, 'destroyHiddenService')
await connectionsManagerService.init()
const network = await connectionsManagerService.getNetwork()
console.log('network', network)
expect(network.hiddenService.onionAddress.split('.')[0]).toHaveLength(56)
expect(network.hiddenService.privateKey).toHaveLength(99)
const peerId = await PeerId.createFromJSON(network.peerId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
import { peerIdFromKeys } from '@libp2p/peer-id'
import { Inject, Injectable, OnModuleInit } from '@nestjs/common'
import { Crypto } from '@peculiar/webcrypto'
import { Agent } from 'https'
import fs from 'fs'
import path from 'path'
import { peerIdFromKeys } from '@libp2p/peer-id'
import { setEngine, CryptoEngine } from 'pkijs'
import { EventEmitter } from 'events'
import fs from 'fs'
import getPort from 'get-port'
import { Agent } from 'https'
import path from 'path'
import PeerId from 'peer-id'
import { CryptoEngine, setEngine } from 'pkijs'
import { getLibp2pAddressesFromCsrs, removeFilesFromDir } from '../common/utils'

import { LazyModuleLoader } from '@nestjs/core'
import { createLibp2pAddress, isPSKcodeValid, p2pAddressesToPairs } from '@quiet/common'
import { CertFieldsTypes, getCertFieldValue, loadCertificate } from '@quiet/identity'
import {
GetMessagesPayload,
ChannelMessageIdsResponse,
type DeleteChannelResponse,
ChannelSubscribedPayload,
ChannelsReplicatedPayload,
Community,
CommunityId,
CommunityMetadata,
CommunityOwnership,
ConnectionProcessInfo,
CreateChannelPayload,
CreateChannelResponse,
CreateNetworkPayload,
DeleteFilesFromChannelSocketPayload,
DownloadStatus,
ErrorMessages,
FileMetadata,
MessagesLoadedPayload,
GetMessagesPayload,
InitCommunityPayload,
MessagesLoadedPayload,
NetworkDataPayload,
NetworkInfo,
NetworkStats,
type SavedOwnerCertificatePayload,
PushNotificationPayload,
RegisterOwnerCertificatePayload,
RemoveDownloadStatus,
SaveCSRPayload,
SendCertificatesResponse,
SendMessagePayload,
ChannelSubscribedPayload,
SocketActionTypes,
StorePeerListPayload,
UploadFilePayload,
PeerId as PeerIdType,
SaveCSRPayload,
CommunityMetadata,
type PermsData,
type DeleteChannelResponse,
type SavedOwnerCertificatePayload,
type UserProfile,
type UserProfilesStoredEvent,
} from '@quiet/types'
import Logger from '../common/logger'
import { CONFIG_OPTIONS, QUIET_DIR, SERVER_IO_PROVIDER, SOCKS_PROXY_AGENT } from '../const'
import { ConfigOptions, GetPorts, ServerIoProviderTypes } from '../types'
import { SocketService } from '../socket/socket.service'
import { RegistrationService } from '../registration/registration.service'
import { LocalDbService } from '../local-db/local-db.service'
import { StorageService } from '../storage/storage.service'
import { ServiceState, TorInitState } from './connections-manager.types'
import { Libp2pService } from '../libp2p/libp2p.service'
import { Tor } from '../tor/tor.service'
import { LocalDBKeys } from '../local-db/local-db.types'
import { Libp2pEvents, Libp2pNodeParams } from '../libp2p/libp2p.types'
import { LocalDbService } from '../local-db/local-db.service'
import { LocalDBKeys } from '../local-db/local-db.types'
import { RegistrationService } from '../registration/registration.service'
import { RegistrationEvents } from '../registration/registration.types'
import { StorageEvents } from '../storage/storage.types'
import { LazyModuleLoader } from '@nestjs/core'
import Logger from '../common/logger'
import { emitError } from '../socket/socket.errors'
import { createLibp2pAddress, isPSKcodeValid } from '@quiet/common'
import { CertFieldsTypes, createRootCA, getCertFieldValue, loadCertificate } from '@quiet/identity'
import { SocketService } from '../socket/socket.service'
import { StorageService } from '../storage/storage.service'
import { StorageEvents } from '../storage/storage.types'
import { ServerProxyService } from '../storageServerProxy/storageServerProxy.service'
import { ServerStoredCommunityMetadata } from '../storageServerProxy/storageServerProxy.types'
import { Tor } from '../tor/tor.service'
import { ConfigOptions, GetPorts, ServerIoProviderTypes } from '../types'
import { ServiceState, TorInitState } from './connections-manager.types'

@Injectable()
export class ConnectionsManagerService extends EventEmitter implements OnModuleInit {
Expand All @@ -81,6 +80,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
@Inject(SOCKS_PROXY_AGENT) public readonly socksProxyAgent: Agent,
private readonly socketService: SocketService,
private readonly registrationService: RegistrationService,
private readonly storageServerProxyService: ServerProxyService,
private readonly localDbService: LocalDbService,
private readonly storageService: StorageService,
private readonly tor: Tor,
Expand Down Expand Up @@ -628,6 +628,33 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
await this.storageService?.saveCSR(payload)
})

this.socketService.on(
SocketActionTypes.DOWNLOAD_INVITE_DATA,
async (payload: { cid: string; serverAddress: string }, callback: (response: CreateNetworkPayload) => void) => {
this.logger(`socketService - ${SocketActionTypes.DOWNLOAD_INVITE_DATA}`)
this.storageServerProxyService.setServerAddress(payload.serverAddress)
let downloadedData: ServerStoredCommunityMetadata
try {
downloadedData = await this.storageServerProxyService.downloadData(payload.cid)
} catch (e) {
this.logger.error(`Downloading community data failed`, e)
emitError(this.serverIoProvider.io, {
type: SocketActionTypes.DOWNLOAD_INVITE_DATA,
message: ErrorMessages.STORAGE_SERVER_CONNECTION_FAILED,
})
return
}

const createNetworkPayload: CreateNetworkPayload = {
ownership: CommunityOwnership.User,
peers: p2pAddressesToPairs(downloadedData.peerList),
psk: downloadedData.psk,
ownerOrbitDbIdentity: downloadedData.ownerOrbitDbIdentity,
}
callback(createNetworkPayload)
}
)

// Public Channels
this.socketService.on(
SocketActionTypes.CREATE_CHANNEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const extractPendingCsrs = async (payload: { csrs: string[]; certificates
pendingCsrs.push(csr)
}
}
logger('DuplicatedCertBug', { parsedUniqueCsrs, pendingNames, certNames })
return pendingCsrs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class RegistrationService extends EventEmitter implements OnModuleInit {
certificates: (await this.storageService?.loadAllCertificates()) as string[],
})

this.logger('Finished issuing certificates')
// Event processing finished
this.registrationEventInProgress = false

Expand Down Expand Up @@ -90,14 +89,13 @@ export class RegistrationService extends EventEmitter implements OnModuleInit {
return
}

this.logger('DuplicatedCertBug', { payload })
const pendingCsrs = await extractPendingCsrs(payload)
this.logger('DuplicatedCertBug', { pendingCsrs })
await Promise.all(
pendingCsrs.map(async csr => {
await this.registerUserCertificate(csr)
})
)
this.logger('Finished issuing certificates')
}

// TODO: This doesn't save the owner's certificate in OrbitDB, so perhaps we
Expand All @@ -121,7 +119,6 @@ export class RegistrationService extends EventEmitter implements OnModuleInit {

public async registerUserCertificate(csr: string): Promise<void> {
const result = await issueCertificate(csr, this.permsData)
this.logger('DuplicatedCertBug', { result })
if (result?.cert) {
// Save certificate (awaited) so that we are sure that the certs
// are saved before processing the next round of CSRs.
Expand Down
11 changes: 2 additions & 9 deletions packages/backend/src/nest/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,8 @@ export class SocketService extends EventEmitter implements OnModuleInit {
socket.on(
SocketActionTypes.DOWNLOAD_INVITE_DATA,
async (payload: { serverAddress: string; cid: string }, callback: (response: CreateNetworkPayload) => void) => {
// this.emit(SocketActionTypes.DOWNLOAD_INVITE_DATA, payload, callback)
console.log('download invite data', payload)
// Mock it for now
callback({
ownership: CommunityOwnership.User,
peers: [],
psk: '',
ownerOrbitDbIdentity: '',
})
console.log('SOCKET Downloading invite data', payload)
this.emit(SocketActionTypes.DOWNLOAD_INVITE_DATA, payload, callback)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ export class CertificatesRequestsStore extends EventEmitter {
return e.payload.value
})

this.logger('DuplicatedCertBug', { allEntries })
const allCsrsUnique = [...new Set(allEntries)]
this.logger('DuplicatedCertBug', { allCsrsUnique })
await Promise.all(
allCsrsUnique
.filter(async csr => {
const validation = await CertificatesRequestsStore.validateUserCsr(csr)
this.logger('DuplicatedCertBug', { validation, csr })
if (validation) return true
return false
})
Expand All @@ -121,7 +118,6 @@ export class CertificatesRequestsStore extends EventEmitter {
filteredCsrsMap.set(pubKey, csr)
})
)
this.logger('DuplicatedCertBug', '[...filteredCsrsMap.values()]', [...filteredCsrsMap.values()])
return [...filteredCsrsMap.values()]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export class CertificatesStore extends EventEmitter {
}

const validation = await this.validateCertificate(certificate)
this.logger('DuplicatedCertBug', { validation, certificate })
if (validation) {
const parsedCertificate = parseCertificate(certificate)
const pubkey = keyFromCertificate(parsedCertificate)
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/nest/storage/storage.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { CertificatesRequestsStore } from './certifacteRequests/certificatesRequ
import { CertificatesStore } from './certificates/certificates.store'
import { CommunityMetadataStore } from './communityMetadata/communityMetadata.store'
import { OrbitDb } from './orbitDb/orbitDb.service'
import { UserProfileStore } from './userProfile/userProfile.store'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
Expand Down Expand Up @@ -72,6 +73,7 @@ describe('StorageService', () => {
let certificatesRequestsStore: CertificatesRequestsStore
let certificatesStore: CertificatesStore
let communityMetadataStore: CommunityMetadataStore
let userProfileStore: UserProfileStore
let orbitDbService: OrbitDb
let peerId: PeerId

Expand Down Expand Up @@ -135,7 +137,7 @@ describe('StorageService', () => {
certificatesRequestsStore = await module.resolve(CertificatesRequestsStore)
certificatesStore = await module.resolve(CertificatesStore)
communityMetadataStore = await module.resolve(CommunityMetadataStore)
console.log({ communityMetadataStore })
userProfileStore = await module.resolve(UserProfileStore)
lazyModuleLoader = await module.resolve(LazyModuleLoader)

orbitDbDir = await module.resolve(ORBIT_DB_DIR)
Expand Down Expand Up @@ -262,16 +264,17 @@ describe('StorageService', () => {
const certificatesDbAddress = certificatesStore.getAddress()
const certificatesRequestsDbAddress = certificatesRequestsStore.getAddress()
const communityMetadataDbAddress = communityMetadataStore.getAddress()
const userProfileDbAddress = userProfileStore.getAddress()
expect(channelsDbAddress).not.toBeFalsy()
expect(certificatesDbAddress).not.toBeFalsy()
expect(subscribeToPubSubSpy).toBeCalledTimes(2)
// Storage initialization:
expect(subscribeToPubSubSpy).toHaveBeenNthCalledWith(1, [
StorageService.dbAddress(communityMetadataDbAddress),
StorageService.dbAddress(channelsDbAddress),
StorageService.dbAddress(certificatesDbAddress),
StorageService.dbAddress(certificatesRequestsDbAddress),
StorageService.dbAddress(communityMetadataDbAddress),
'/orbitdb/zdpuAyScVHonV7KUdb3rdNmC9ZurssGdfgveYm3ds7KNJ6CpU/user-profiles',
StorageService.dbAddress(userProfileDbAddress),
])
// Creating channel:
expect(subscribeToPubSubSpy).toHaveBeenNthCalledWith(2, [StorageService.dbAddress(db.address)])
Expand Down
7 changes: 3 additions & 4 deletions packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ export class StorageService extends EventEmitter {

private async startReplicate() {
const dbs = []

if (this.communityMetadataStore?.getAddress()) {
dbs.push(this.communityMetadataStore.getAddress())
}
if (this.channels?.address) {
dbs.push(this.channels.address)
}
Expand All @@ -163,9 +165,6 @@ export class StorageService extends EventEmitter {
if (this.certificatesRequestsStore.getAddress()) {
dbs.push(this.certificatesRequestsStore.getAddress())
}
if (this.communityMetadataStore?.getAddress()) {
dbs.push(this.communityMetadataStore.getAddress())
}
if (this.userProfileStore.getAddress()) {
dbs.push(this.userProfileStore.getAddress())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common'
import { ServerProxyService } from './storageServerProxy.service'

@Module({
providers: [ServerProxyService],
exports: [ServerProxyService],
})
export class ServerProxyServiceModule {}
Loading
Loading