diff --git a/packages/backend/package-lock.json b/packages/backend/package-lock.json index 43868588fa..a074fea11c 100644 --- a/packages/backend/package-lock.json +++ b/packages/backend/package-lock.json @@ -26,8 +26,8 @@ "dotenv": "8.2.0", "events": "^3.2.0", "express": "^4.17.1", - "fetch-retry": "^6.0.0", "fastq": "^1.17.1", + "fetch-retry": "^6.0.0", "get-port": "^5.1.1", "go-ipfs": "npm:mocked-go-ipfs@0.17.0", "http-server": "^0.12.3", 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 988d73fdf9..47b037f9da 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -19,17 +19,17 @@ import { ChannelsReplicatedPayload, Community, CommunityMetadata, - CommunityOwnership, ConnectionProcessInfo, CreateChannelPayload, CreateChannelResponse, - CreateNetworkPayload, DeleteFilesFromChannelSocketPayload, DownloadStatus, ErrorMessages, FileMetadata, GetMessagesPayload, InitCommunityPayload, + InvitationDataV2, + InvitationDataVersion, MessagesLoadedPayload, NetworkDataPayload, NetworkInfo, @@ -39,7 +39,6 @@ import { SaveCSRPayload, SendCertificatesResponse, SendMessagePayload, - ServerInvitationData, SocketActionTypes, UploadFilePayload, type DeleteChannelResponse, @@ -393,7 +392,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI return community } - public async downloadCommunityData(inviteData: ServerInvitationData) { + public async downloadCommunityData(inviteData: InvitationDataV2) { this.logger('Downloading invite data', inviteData) this.storageServerProxyService.setServerAddress(inviteData.serverAddress) let downloadedData: ServerStoredCommunityMetadata @@ -420,17 +419,21 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI const inviteData = payload.inviteData if (inviteData) { - const downloadedData = await this.downloadCommunityData(inviteData) - if (!downloadedData) { - emitError(this.serverIoProvider.io, { - type: SocketActionTypes.LAUNCH_COMMUNITY, - message: ErrorMessages.STORAGE_SERVER_CONNECTION_FAILED, - }) - return + this.logger(`Joining community: inviteData version: ${inviteData.version}`) + switch (inviteData.version) { + case InvitationDataVersion.v2: + const downloadedData = await this.downloadCommunityData(inviteData) + if (!downloadedData) { + emitError(this.serverIoProvider.io, { + type: SocketActionTypes.LAUNCH_COMMUNITY, + message: ErrorMessages.STORAGE_SERVER_CONNECTION_FAILED, + }) + return + } + metadata = downloadedData + break } - metadata = downloadedData } - this.logger('Joining community: metadata:', metadata) if (!metadata.peers || metadata.peers.length === 0) { this.logger.error('Joining community: Peers required') diff --git a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts index 6c4f4c2a26..2e86861a29 100644 --- a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts +++ b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.test.ts @@ -45,6 +45,7 @@ describe('createNetwork', () => { ...community, psk: inviteData.psk, ownerOrbitDbIdentity: inviteData.ownerOrbitDbIdentity, + inviteData, } const reducer = combineReducers(reducers) @@ -136,6 +137,7 @@ describe('createNetwork', () => { name: 'rockets', CA, rootCa: CA.rootCertString, + inviteData: undefined, } const reducer = combineReducers(reducers) diff --git a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts index 6205ee573b..76527c4905 100644 --- a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts +++ b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts @@ -54,6 +54,7 @@ export function* createNetworkSaga( name: payload.name, CA, rootCa: CA?.rootCertString, + inviteData: payload.inviteData, } if (payload.inviteData) { @@ -66,9 +67,6 @@ export function* createNetworkSaga( yield* put(communitiesActions.setInvitationCodes(invitationPeers)) } break - case InvitationDataVersion.v2: - community.inviteData = payload.inviteData - break } } diff --git a/packages/types/src/community.ts b/packages/types/src/community.ts index bbe8e54481..5c450c07ac 100644 --- a/packages/types/src/community.ts +++ b/packages/types/src/community.ts @@ -1,5 +1,5 @@ import { type HiddenService, type PeerId, type Identity, type UserCsr } from './identity' -import { InvitationData, InvitationDataV2, InvitationPair } from './network' +import { InvitationData } from './network' export interface Community { id: string @@ -13,7 +13,7 @@ export interface Community { onionAddress?: string ownerCertificate?: string psk?: string - inviteData?: InvitationDataV2 + inviteData?: InvitationData | null ownerOrbitDbIdentity?: string } @@ -25,18 +25,9 @@ export enum CommunityOwnership { export interface CreateNetworkPayload { ownership: CommunityOwnership name?: string - // peers?: InvitationPair[] - // psk?: string - // ownerOrbitDbIdentity?: string inviteData?: InvitationData } -export interface ServerInvitationData { - serverAddress: string - cid: string - token?: string -} - export interface NetworkInfo { hiddenService: HiddenService peerId: PeerId @@ -64,7 +55,7 @@ export interface InitCommunityPayload { psk?: string ownerOrbitDbIdentity?: string ownerCsr?: UserCsr - inviteData?: ServerInvitationData + inviteData?: InvitationData | null } export interface StorePeerListPayload {