@vrtmrz/livesync-commonlib 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/API/DirectFileManipulator.d.ts +2 -0
- package/dist/API/DirectFileManipulator.js +4 -0
- package/dist/API/DirectFileManipulatorV2.d.ts +150 -0
- package/dist/API/DirectFileManipulatorV2.js +424 -0
- package/dist/API/processSetting.d.ts +41 -0
- package/dist/API/processSetting.js +140 -0
- package/dist/ContentSplitter/ContentSplitter.d.ts +28 -0
- package/dist/ContentSplitter/ContentSplitter.js +5 -0
- package/dist/ContentSplitter/ContentSplitterBase.d.ts +51 -0
- package/dist/ContentSplitter/ContentSplitterBase.js +83 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.js +32 -0
- package/dist/ContentSplitter/ContentSplitterV1.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV1.js +34 -0
- package/dist/ContentSplitter/ContentSplitterV2.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV2.js +34 -0
- package/dist/ContentSplitter/ContentSplitters.d.ts +12 -0
- package/dist/ContentSplitter/ContentSplitters.js +29 -0
- package/dist/bureau/bureau.d.ts +7 -0
- package/dist/bureau/bureau.js +5 -0
- package/dist/common/ConnectionString.d.ts +30 -0
- package/dist/common/ConnectionString.js +179 -0
- package/dist/common/LSError.d.ts +48 -0
- package/dist/common/LSError.js +112 -0
- package/dist/common/configForDoc.d.ts +79 -0
- package/dist/common/configForDoc.js +312 -0
- package/dist/common/coreEnvFunctions.d.ts +21 -0
- package/dist/common/coreEnvFunctions.js +22 -0
- package/dist/common/coreEnvVars.d.ts +3 -0
- package/dist/common/coreEnvVars.js +6 -0
- package/dist/common/i18n.d.ts +18 -0
- package/dist/common/i18n.js +7193 -0
- package/dist/common/logger.d.ts +2 -0
- package/dist/common/logger.js +1 -0
- package/dist/common/messages/combinedMessages.dev.d.ts +7 -0
- package/dist/common/messages/combinedMessages.dev.js +44 -0
- package/dist/common/messages/combinedMessages.prod.d.ts +9264 -0
- package/dist/common/messages/combinedMessages.prod.js +9271 -0
- package/dist/common/messages/de.d.ts +297 -0
- package/dist/common/messages/de.js +7 -0
- package/dist/common/messages/def.d.ts +1119 -0
- package/dist/common/messages/def.js +7 -0
- package/dist/common/messages/es.d.ts +689 -0
- package/dist/common/messages/es.js +7 -0
- package/dist/common/messages/fr.d.ts +582 -0
- package/dist/common/messages/fr.js +7 -0
- package/dist/common/messages/he.d.ts +583 -0
- package/dist/common/messages/he.js +7 -0
- package/dist/common/messages/ja.d.ts +838 -0
- package/dist/common/messages/ja.js +7 -0
- package/dist/common/messages/ko.d.ts +800 -0
- package/dist/common/messages/ko.js +7 -0
- package/dist/common/messages/ru.d.ts +858 -0
- package/dist/common/messages/ru.js +7 -0
- package/dist/common/messages/zh-tw.d.ts +384 -0
- package/dist/common/messages/zh-tw.js +7 -0
- package/dist/common/messages/zh.d.ts +1093 -0
- package/dist/common/messages/zh.js +7 -0
- package/dist/common/messagesJson/de.json +295 -0
- package/dist/common/messagesJson/en.json +1117 -0
- package/dist/common/messagesJson/es.json +687 -0
- package/dist/common/messagesJson/fr.json +580 -0
- package/dist/common/messagesJson/he.json +581 -0
- package/dist/common/messagesJson/ja.json +836 -0
- package/dist/common/messagesJson/ko.json +798 -0
- package/dist/common/messagesJson/ru.json +856 -0
- package/dist/common/messagesJson/zh-tw.json +382 -0
- package/dist/common/messagesJson/zh.json +1091 -0
- package/dist/common/models/auth.type.d.ts +41 -0
- package/dist/common/models/auth.type.js +0 -0
- package/dist/common/models/db.const.d.ts +20 -0
- package/dist/common/models/db.const.js +28 -0
- package/dist/common/models/db.definition.d.ts +56 -0
- package/dist/common/models/db.definition.js +6 -0
- package/dist/common/models/db.type.d.ts +142 -0
- package/dist/common/models/db.type.js +0 -0
- package/dist/common/models/diff.definition.d.ts +16 -0
- package/dist/common/models/diff.definition.js +0 -0
- package/dist/common/models/fileaccess.const.d.ts +7 -0
- package/dist/common/models/fileaccess.const.js +16 -0
- package/dist/common/models/fileaccess.type.d.ts +72 -0
- package/dist/common/models/fileaccess.type.js +0 -0
- package/dist/common/models/redflag.const.d.ts +32 -0
- package/dist/common/models/redflag.const.js +27 -0
- package/dist/common/models/setting.const.d.ts +49 -0
- package/dist/common/models/setting.const.defaults.d.ts +3 -0
- package/dist/common/models/setting.const.defaults.js +185 -0
- package/dist/common/models/setting.const.js +68 -0
- package/dist/common/models/setting.const.preferred.d.ts +5 -0
- package/dist/common/models/setting.const.preferred.js +35 -0
- package/dist/common/models/setting.const.qr.d.ts +2 -0
- package/dist/common/models/setting.const.qr.js +174 -0
- package/dist/common/models/setting.type.d.ts +900 -0
- package/dist/common/models/setting.type.js +8 -0
- package/dist/common/models/shared.const.behabiour.d.ts +28 -0
- package/dist/common/models/shared.const.behabiour.js +36 -0
- package/dist/common/models/shared.const.d.ts +5 -0
- package/dist/common/models/shared.const.js +12 -0
- package/dist/common/models/shared.const.symbols.d.ts +9 -0
- package/dist/common/models/shared.const.symbols.js +20 -0
- package/dist/common/models/shared.definition.configNames.d.ts +36 -0
- package/dist/common/models/shared.definition.configNames.js +203 -0
- package/dist/common/models/shared.definition.d.ts +22 -0
- package/dist/common/models/shared.definition.js +24 -0
- package/dist/common/models/shared.type.util.d.ts +8 -0
- package/dist/common/models/shared.type.util.js +0 -0
- package/dist/common/models/sync.definition.d.ts +18 -0
- package/dist/common/models/sync.definition.js +20 -0
- package/dist/common/models/tweak.definition.d.ts +191 -0
- package/dist/common/models/tweak.definition.js +77 -0
- package/dist/common/rosetta.d.ts +42 -0
- package/dist/common/rosetta.js +57 -0
- package/dist/common/settingConstants.d.ts +216 -0
- package/dist/common/settingConstants.js +434 -0
- package/dist/common/typeUtils.d.ts +17 -0
- package/dist/common/typeUtils.js +51 -0
- package/dist/common/types.d.ts +107 -0
- package/dist/common/types.js +212 -0
- package/dist/common/utils.d.ts +129 -0
- package/dist/common/utils.doc.d.ts +11 -0
- package/dist/common/utils.doc.js +35 -0
- package/dist/common/utils.js +583 -0
- package/dist/common/utils.object.d.ts +2 -0
- package/dist/common/utils.object.js +14 -0
- package/dist/common/utils.patch.d.ts +8 -0
- package/dist/common/utils.patch.js +178 -0
- package/dist/common/utils.type.d.ts +1 -0
- package/dist/common/utils.type.js +0 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +14 -0
- package/dist/databases/IndexedDBKeyValueDatabase.d.ts +26 -0
- package/dist/databases/IndexedDBKeyValueDatabase.js +130 -0
- package/dist/dataobject/StoredMap.d.ts +12 -0
- package/dist/dataobject/StoredMap.js +47 -0
- package/dist/dev/checks.d.ts +5 -0
- package/dist/dev/checks.js +38 -0
- package/dist/encryption/encryptHKDF.d.ts +3 -0
- package/dist/encryption/encryptHKDF.js +7 -0
- package/dist/encryption/stringEncryption.d.ts +27 -0
- package/dist/encryption/stringEncryption.js +59 -0
- package/dist/events/coreEvents.d.ts +54 -0
- package/dist/events/coreEvents.js +46 -0
- package/dist/hub/hub.d.ts +11 -0
- package/dist/hub/hub.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/AsyncActivityRunner.d.ts +18 -0
- package/dist/interfaces/AsyncActivityRunner.js +7 -0
- package/dist/interfaces/Confirm.d.ts +17 -0
- package/dist/interfaces/Confirm.js +0 -0
- package/dist/interfaces/DatabaseFileAccess.d.ts +14 -0
- package/dist/interfaces/DatabaseFileAccess.js +0 -0
- package/dist/interfaces/DatabaseRebuilder.d.ts +13 -0
- package/dist/interfaces/DatabaseRebuilder.js +0 -0
- package/dist/interfaces/FileHandler.d.ts +13 -0
- package/dist/interfaces/FileHandler.js +0 -0
- package/dist/interfaces/KeyValueDatabase.d.ts +11 -0
- package/dist/interfaces/KeyValueDatabase.js +0 -0
- package/dist/interfaces/ServiceModule.d.ts +59 -0
- package/dist/interfaces/ServiceModule.js +19 -0
- package/dist/interfaces/StorageAccess.d.ts +44 -0
- package/dist/interfaces/StorageAccess.js +0 -0
- package/dist/interfaces/StorageEventManager.d.ts +16 -0
- package/dist/interfaces/StorageEventManager.js +5 -0
- package/dist/managers/ChangeManager.d.ts +61 -0
- package/dist/managers/ChangeManager.js +104 -0
- package/dist/managers/ChunkDeliveryCoordinator.d.ts +51 -0
- package/dist/managers/ChunkDeliveryCoordinator.js +136 -0
- package/dist/managers/ChunkFetcher.d.ts +44 -0
- package/dist/managers/ChunkFetcher.js +251 -0
- package/dist/managers/ChunkManager.d.ts +2 -0
- package/dist/managers/ChunkManager.js +4 -0
- package/dist/managers/ConflictManager.d.ts +37 -0
- package/dist/managers/ConflictManager.js +322 -0
- package/dist/managers/EntryManager/EntryManager.d.ts +37 -0
- package/dist/managers/EntryManager/EntryManager.js +73 -0
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +74 -0
- package/dist/managers/EntryManager/EntryManagerImpls.js +499 -0
- package/dist/managers/HashManager/HashManager.d.ts +60 -0
- package/dist/managers/HashManager/HashManager.js +97 -0
- package/dist/managers/HashManager/HashManagerCore.d.ts +114 -0
- package/dist/managers/HashManager/HashManagerCore.js +99 -0
- package/dist/managers/HashManager/PureJSHashManager.d.ts +77 -0
- package/dist/managers/HashManager/PureJSHashManager.js +84 -0
- package/dist/managers/HashManager/XXHashHashManager.d.ts +96 -0
- package/dist/managers/HashManager/XXHashHashManager.js +111 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +30 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +115 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.d.ts +59 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.js +161 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.d.ts +37 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.js +0 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +14 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +78 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.d.ts +11 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.js +43 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.d.ts +9 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.js +8 -0
- package/dist/managers/LayeredChunkManager/types.d.ts +39 -0
- package/dist/managers/LayeredChunkManager/types.js +0 -0
- package/dist/managers/LayeredChunkManager.d.ts +53 -0
- package/dist/managers/LayeredChunkManager.js +240 -0
- package/dist/managers/LiveSyncManagers.d.ts +48 -0
- package/dist/managers/LiveSyncManagers.js +136 -0
- package/dist/managers/StorageEventManager.d.ts +135 -0
- package/dist/managers/StorageEventManager.js +564 -0
- package/dist/managers/StorageProcessingManager.d.ts +14 -0
- package/dist/managers/StorageProcessingManager.js +48 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.d.ts +18 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.d.ts +15 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.d.ts +13 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.d.ts +21 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.js +0 -0
- package/dist/managers/adapters/index.d.ts +6 -0
- package/dist/managers/adapters/index.js +0 -0
- package/dist/mock_and_interop/stores.d.ts +21 -0
- package/dist/mock_and_interop/stores.js +15 -0
- package/dist/mock_and_interop/wrapper.d.ts +7 -0
- package/dist/mock_and_interop/wrapper.js +37 -0
- package/dist/mods.d.ts +1 -0
- package/dist/mods.js +18 -0
- package/dist/platform/browser/index.d.ts +1 -0
- package/dist/platform/browser/index.js +10 -0
- package/dist/platform/browser/storage.d.ts +35 -0
- package/dist/platform/browser/storage.js +139 -0
- package/dist/platform/node/index.d.ts +23 -0
- package/dist/platform/node/index.js +33 -0
- package/dist/platform/node/storage.d.ts +31 -0
- package/dist/platform/node/storage.js +104 -0
- package/dist/platform/storagePath.d.ts +7 -0
- package/dist/platform/storagePath.js +20 -0
- package/dist/pouchdb/LiveSyncDBFunctions.d.ts +14 -0
- package/dist/pouchdb/LiveSyncDBFunctions.js +129 -0
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +196 -0
- package/dist/pouchdb/LiveSyncLocalDB.js +381 -0
- package/dist/pouchdb/PouchDBConstructor.d.ts +3 -0
- package/dist/pouchdb/PouchDBConstructor.js +0 -0
- package/dist/pouchdb/ReplicatorShim.d.ts +51 -0
- package/dist/pouchdb/ReplicatorShim.js +109 -0
- package/dist/pouchdb/StreamingFetch.d.ts +19 -0
- package/dist/pouchdb/StreamingFetch.js +263 -0
- package/dist/pouchdb/chunks.d.ts +38 -0
- package/dist/pouchdb/chunks.js +314 -0
- package/dist/pouchdb/compress.d.ts +11 -0
- package/dist/pouchdb/compress.js +99 -0
- package/dist/pouchdb/encryption.d.ts +20 -0
- package/dist/pouchdb/encryption.js +458 -0
- package/dist/pouchdb/negotiation.d.ts +9 -0
- package/dist/pouchdb/negotiation.js +109 -0
- package/dist/pouchdb/pouchdb-browser.d.ts +2 -0
- package/dist/pouchdb/pouchdb-browser.js +96 -0
- package/dist/pouchdb/pouchdb-http.d.ts +2 -0
- package/dist/pouchdb/pouchdb-http.js +94 -0
- package/dist/pouchdb/pouchdb-test.d.ts +2 -0
- package/dist/pouchdb/pouchdb-test.js +12 -0
- package/dist/pouchdb/utils_couchdb.d.ts +4 -0
- package/dist/pouchdb/utils_couchdb.js +38 -0
- package/dist/replication/LiveSyncAbstractReplicator.d.ts +69 -0
- package/dist/replication/LiveSyncAbstractReplicator.js +92 -0
- package/dist/replication/SyncParamsHandler.d.ts +35 -0
- package/dist/replication/SyncParamsHandler.js +118 -0
- package/dist/replication/couchdb/LiveSyncReplicator.d.ts +85 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +1132 -0
- package/dist/replication/httplib.d.ts +75 -0
- package/dist/replication/httplib.js +187 -0
- package/dist/replication/journal/JournalSyncCore.d.ts +70 -0
- package/dist/replication/journal/JournalSyncCore.js +737 -0
- package/dist/replication/journal/JournalSyncTypes.d.ts +9 -0
- package/dist/replication/journal/JournalSyncTypes.js +11 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +40 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.js +294 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.d.ts +3 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.js +0 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.d.ts +15 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.js +0 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.d.ts +21 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.js +204 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +90 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +380 -0
- package/dist/replication/trystero/P2PLogCollector.d.ts +8 -0
- package/dist/replication/trystero/P2PLogCollector.js +91 -0
- package/dist/replication/trystero/P2PReplicatorBase.d.ts +19 -0
- package/dist/replication/trystero/P2PReplicatorBase.js +0 -0
- package/dist/replication/trystero/P2PReplicatorCore.d.ts +12 -0
- package/dist/replication/trystero/P2PReplicatorCore.js +126 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.d.ts +41 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.js +20 -0
- package/dist/replication/trystero/ProxiedDB.d.ts +13 -0
- package/dist/replication/trystero/ProxiedDB.js +20 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +152 -0
- package/dist/replication/trystero/TrysteroReplicator.js +683 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.d.ts +19 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.js +80 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.d.ts +2 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.js +4 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +117 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +540 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.d.ts +11 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.js +0 -0
- package/dist/replication/trystero/addP2PEventHandlers.d.ts +35 -0
- package/dist/replication/trystero/addP2PEventHandlers.js +43 -0
- package/dist/replication/trystero/rpcCompat.d.ts +1 -0
- package/dist/replication/trystero/rpcCompat.js +9 -0
- package/dist/replication/trystero/types.d.ts +95 -0
- package/dist/replication/trystero/types.js +27 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.d.ts +7 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.js +25 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.d.ts +17 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.js +82 -0
- package/dist/rpc/RpcRoom.d.ts +24 -0
- package/dist/rpc/RpcRoom.js +300 -0
- package/dist/rpc/RpcSession.d.ts +9 -0
- package/dist/rpc/RpcSession.js +32 -0
- package/dist/rpc/chunking.d.ts +11 -0
- package/dist/rpc/chunking.js +58 -0
- package/dist/rpc/errors.d.ts +8 -0
- package/dist/rpc/errors.js +26 -0
- package/dist/rpc/index.d.ts +6 -0
- package/dist/rpc/index.js +12 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.d.ts +75 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.js +115 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.d.ts +16 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.js +55 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.d.ts +24 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.js +208 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.d.ts +64 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.js +12 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.d.ts +33 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.js +217 -0
- package/dist/rpc/transports/TrysteroTransport.d.ts +216 -0
- package/dist/rpc/transports/TrysteroTransport.js +134 -0
- package/dist/rpc/transports/trysteroUtils.d.ts +3 -0
- package/dist/rpc/transports/trysteroUtils.js +37 -0
- package/dist/rpc/types.d.ts +75 -0
- package/dist/rpc/types.js +6 -0
- package/dist/serviceFeatures/checkRemoteSize.d.ts +28 -0
- package/dist/serviceFeatures/checkRemoteSize.js +178 -0
- package/dist/serviceFeatures/offlineScanner.d.ts +128 -0
- package/dist/serviceFeatures/offlineScanner.js +553 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.d.ts +20 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.js +39 -0
- package/dist/serviceFeatures/remoteConfig.d.ts +46 -0
- package/dist/serviceFeatures/remoteConfig.js +247 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.d.ts +4 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.js +67 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.d.ts +7 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.js +70 -0
- package/dist/serviceFeatures/setupObsidian/types.d.ts +2 -0
- package/dist/serviceFeatures/setupObsidian/types.js +0 -0
- package/dist/serviceFeatures/targetFilter.d.ts +24 -0
- package/dist/serviceFeatures/targetFilter.js +178 -0
- package/dist/serviceModules/FileAccessBase.d.ts +93 -0
- package/dist/serviceModules/FileAccessBase.js +219 -0
- package/dist/serviceModules/Rebuilder.d.ts +92 -0
- package/dist/serviceModules/Rebuilder.js +449 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +40 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +306 -0
- package/dist/serviceModules/ServiceFileAccessBase.d.ts +64 -0
- package/dist/serviceModules/ServiceFileAccessBase.js +312 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +52 -0
- package/dist/serviceModules/ServiceFileHandlerBase.js +493 -0
- package/dist/serviceModules/ServiceModuleBase.d.ts +10 -0
- package/dist/serviceModules/ServiceModuleBase.js +13 -0
- package/dist/serviceModules/adapters/IConversionAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IConversionAdapter.js +0 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.d.ts +47 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.js +0 -0
- package/dist/serviceModules/adapters/IPathAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IPathAdapter.js +0 -0
- package/dist/serviceModules/adapters/IStorageAdapter.d.ts +56 -0
- package/dist/serviceModules/adapters/IStorageAdapter.js +0 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.d.ts +14 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.js +0 -0
- package/dist/serviceModules/adapters/IVaultAdapter.d.ts +51 -0
- package/dist/serviceModules/adapters/IVaultAdapter.js +0 -0
- package/dist/serviceModules/adapters/index.d.ts +6 -0
- package/dist/serviceModules/adapters/index.js +0 -0
- package/dist/services/BrowserServices.d.ts +36 -0
- package/dist/services/BrowserServices.js +123 -0
- package/dist/services/HeadlessServices.d.ts +14 -0
- package/dist/services/HeadlessServices.js +144 -0
- package/dist/services/InjectableServices.d.ts +1 -0
- package/dist/services/InjectableServices.js +4 -0
- package/dist/services/ServiceHub.d.ts +82 -0
- package/dist/services/ServiceHub.js +66 -0
- package/dist/services/base/APIService.d.ts +93 -0
- package/dist/services/base/APIService.js +44 -0
- package/dist/services/base/AppLifecycleService.d.ts +132 -0
- package/dist/services/base/AppLifecycleService.js +123 -0
- package/dist/services/base/ConfigService.d.ts +7 -0
- package/dist/services/base/ConfigService.js +6 -0
- package/dist/services/base/ConflictService.d.ts +54 -0
- package/dist/services/base/ConflictService.js +22 -0
- package/dist/services/base/ControlService.d.ts +54 -0
- package/dist/services/base/ControlService.js +103 -0
- package/dist/services/base/DatabaseEventService.d.ts +38 -0
- package/dist/services/base/DatabaseEventService.js +38 -0
- package/dist/services/base/DatabaseService.d.ts +40 -0
- package/dist/services/base/DatabaseService.js +79 -0
- package/dist/services/base/FileProcessingService.d.ts +25 -0
- package/dist/services/base/FileProcessingService.js +28 -0
- package/dist/services/base/IService.d.ts +284 -0
- package/dist/services/base/IService.js +1 -0
- package/dist/services/base/KeyValueDBService.d.ts +42 -0
- package/dist/services/base/KeyValueDBService.js +133 -0
- package/dist/services/base/MessageTranslator.d.ts +6 -0
- package/dist/services/base/MessageTranslator.js +4 -0
- package/dist/services/base/PathService.d.ts +38 -0
- package/dist/services/base/PathService.js +66 -0
- package/dist/services/base/RemoteService.d.ts +61 -0
- package/dist/services/base/RemoteService.js +212 -0
- package/dist/services/base/ReplicationService.d.ts +92 -0
- package/dist/services/base/ReplicationService.js +261 -0
- package/dist/services/base/ReplicatorService.d.ts +66 -0
- package/dist/services/base/ReplicatorService.js +164 -0
- package/dist/services/base/ServiceBase.d.ts +33 -0
- package/dist/services/base/ServiceBase.js +27 -0
- package/dist/services/base/SettingService.d.ts +112 -0
- package/dist/services/base/SettingService.js +543 -0
- package/dist/services/base/TestService.d.ts +28 -0
- package/dist/services/base/TestService.js +19 -0
- package/dist/services/base/TweakValueService.d.ts +40 -0
- package/dist/services/base/TweakValueService.js +6 -0
- package/dist/services/base/UnresolvedErrorManager.d.ts +15 -0
- package/dist/services/base/UnresolvedErrorManager.js +44 -0
- package/dist/services/base/VaultService.d.ts +69 -0
- package/dist/services/base/VaultService.js +70 -0
- package/dist/services/implements/base/SvelteDialog.d.ts +79 -0
- package/dist/services/implements/base/SvelteDialog.js +134 -0
- package/dist/services/implements/base/UIService.d.ts +24 -0
- package/dist/services/implements/base/UIService.js +37 -0
- package/dist/services/implements/browser/BrowserAPIService.d.ts +54 -0
- package/dist/services/implements/browser/BrowserAPIService.js +298 -0
- package/dist/services/implements/browser/BrowserDatabaseService.d.ts +7 -0
- package/dist/services/implements/browser/BrowserDatabaseService.js +10 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.d.ts +16 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.js +23 -0
- package/dist/services/implements/headless/HeadlessAPIService.d.ts +52 -0
- package/dist/services/implements/headless/HeadlessAPIService.js +127 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.d.ts +7 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.js +10 -0
- package/dist/services/implements/injectable/InjectableAPIService.d.ts +7 -0
- package/dist/services/implements/injectable/InjectableAPIService.js +18 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.js +14 -0
- package/dist/services/implements/injectable/InjectableConflictService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableConflictService.js +14 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.js +7 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.js +6 -0
- package/dist/services/implements/injectable/InjectablePathService.d.ts +12 -0
- package/dist/services/implements/injectable/InjectablePathService.js +36 -0
- package/dist/services/implements/injectable/InjectableRemoteService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableRemoteService.js +7 -0
- package/dist/services/implements/injectable/InjectableReplicationService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicationService.js +6 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.js +7 -0
- package/dist/services/implements/injectable/InjectableServiceHub.d.ts +72 -0
- package/dist/services/implements/injectable/InjectableServiceHub.js +125 -0
- package/dist/services/implements/injectable/InjectableServices.d.ts +36 -0
- package/dist/services/implements/injectable/InjectableServices.js +1 -0
- package/dist/services/implements/injectable/InjectableSettingService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableSettingService.js +33 -0
- package/dist/services/implements/injectable/InjectableTestService.d.ts +5 -0
- package/dist/services/implements/injectable/InjectableTestService.js +8 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.d.ts +15 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.js +12 -0
- package/dist/services/implements/injectable/InjectableVaultService.d.ts +9 -0
- package/dist/services/implements/injectable/InjectableVaultService.js +20 -0
- package/dist/services/lib/HandlerUtils.d.ts +374 -0
- package/dist/services/lib/HandlerUtils.js +412 -0
- package/dist/services/lib/logUtils.d.ts +13 -0
- package/dist/services/lib/logUtils.js +28 -0
- package/dist/services/lib/remoteActivity.d.ts +13 -0
- package/dist/services/lib/remoteActivity.js +11 -0
- package/dist/string_and_binary/chunks.d.ts +10 -0
- package/dist/string_and_binary/chunks.js +561 -0
- package/dist/string_and_binary/convert.d.ts +8 -0
- package/dist/string_and_binary/convert.js +46 -0
- package/dist/string_and_binary/hash.d.ts +2 -0
- package/dist/string_and_binary/hash.js +1 -0
- package/dist/string_and_binary/path.d.ts +35 -0
- package/dist/string_and_binary/path.js +240 -0
- package/dist/worker/bg.common.d.ts +2 -0
- package/dist/worker/bg.common.js +6 -0
- package/dist/worker/bg.worker.d.ts +1 -0
- package/dist/worker/bg.worker.encryption.d.ts +7 -0
- package/dist/worker/bg.worker.encryption.js +30 -0
- package/dist/worker/bg.worker.js +14 -0
- package/dist/worker/bg.worker.splitting.d.ts +6 -0
- package/dist/worker/bg.worker.splitting.js +36 -0
- package/dist/worker/bgWorker.d.ts +25 -0
- package/dist/worker/bgWorker.direct.d.ts +40 -0
- package/dist/worker/bgWorker.direct.js +65 -0
- package/dist/worker/bgWorker.encryption.d.ts +22 -0
- package/dist/worker/bgWorker.encryption.js +40 -0
- package/dist/worker/bgWorker.js +348 -0
- package/dist/worker/bgWorker.splitting.d.ts +27 -0
- package/dist/worker/bgWorker.splitting.js +123 -0
- package/dist/worker/universalTypes.d.ts +63 -0
- package/dist/worker/universalTypes.js +4 -0
- package/docs/development.md +51 -0
- package/docs/platform-storage.md +60 -0
- package/docs/releasing.md +69 -0
- package/package.json +693 -0
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
import { TweakValuesShouldMatchedTemplate } from "../../common/types.js";
|
|
2
|
+
import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, Logger } from "octagonal-wheels/common/logger";
|
|
3
|
+
import { replicateShim } from "../../pouchdb/ReplicatorShim.js";
|
|
4
|
+
import {} from "./types.js";
|
|
5
|
+
import { TrysteroConnection } from "./TrysteroReplicatorP2PConnection.js";
|
|
6
|
+
import { scheduleOnceIfDuplicated, serialized, skipIfDuplicated } from "octagonal-wheels/concurrency/lock_v2";
|
|
7
|
+
import { delay, fireAndForget } from "octagonal-wheels/promises";
|
|
8
|
+
import { EVENT_P2P_REPLICATOR_PROGRESS, EVENT_P2P_REPLICATOR_STATUS, P2PHost } from "./TrysteroReplicatorP2PServer.js";
|
|
9
|
+
import { encryptWithEphemeralSalt, decryptWithEphemeralSalt } from "octagonal-wheels/encryption/hkdf";
|
|
10
|
+
import { sha1 } from "octagonal-wheels/hash/purejs";
|
|
11
|
+
import { isObjectDifferent } from "octagonal-wheels/object";
|
|
12
|
+
import { getRelaySockets, pauseRelayReconnection, resumeRelayReconnection } from "@trystero-p2p/nostr";
|
|
13
|
+
async function encrypt(data, passphrase) {
|
|
14
|
+
return await encryptWithEphemeralSalt(data, passphrase, true);
|
|
15
|
+
}
|
|
16
|
+
async function decrypt(encryptedData, passphrase) {
|
|
17
|
+
return await decryptWithEphemeralSalt(encryptedData, passphrase);
|
|
18
|
+
}
|
|
19
|
+
async function getHashedStringWithCurrentTime(source) {
|
|
20
|
+
const salt = (~~((/* @__PURE__ */ new Date()).getTime() / 1e3 / 180)).toString(36);
|
|
21
|
+
const salt2 = await sha1(salt);
|
|
22
|
+
return await sha1(salt2 + source);
|
|
23
|
+
}
|
|
24
|
+
class TrysteroReplicator {
|
|
25
|
+
_env;
|
|
26
|
+
server;
|
|
27
|
+
replicationStatus() {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
get settings() {
|
|
31
|
+
return this._env.settings;
|
|
32
|
+
}
|
|
33
|
+
get db() {
|
|
34
|
+
return this._env.db;
|
|
35
|
+
}
|
|
36
|
+
get deviceName() {
|
|
37
|
+
return this._env.deviceName;
|
|
38
|
+
}
|
|
39
|
+
get platform() {
|
|
40
|
+
return this._env.platform;
|
|
41
|
+
}
|
|
42
|
+
get confirm() {
|
|
43
|
+
return this._env.confirm;
|
|
44
|
+
}
|
|
45
|
+
get translate() {
|
|
46
|
+
return this._env.translate;
|
|
47
|
+
}
|
|
48
|
+
async runFiniteReplicationActivity(task) {
|
|
49
|
+
if (this._env.runFiniteReplicationActivity) {
|
|
50
|
+
return await this._env.runFiniteReplicationActivity(task, { label: "replication" });
|
|
51
|
+
}
|
|
52
|
+
return await task();
|
|
53
|
+
}
|
|
54
|
+
constructor(env, server) {
|
|
55
|
+
this._env = env;
|
|
56
|
+
if (server) {
|
|
57
|
+
this.server = server;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
if (!this.settings.P2P_Enabled) {
|
|
62
|
+
Logger("P2P is not enabled", LOG_LEVEL_VERBOSE);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!this.settings.P2P_AppID) {
|
|
66
|
+
throw new Error("P2P App ID is not provided. We need it to establish the P2P connection");
|
|
67
|
+
}
|
|
68
|
+
if (!this.settings.P2P_roomID || !this.settings.P2P_passphrase) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"Room ID and/or P2P Passphrase have not provided. We need them to establish the P2P connection"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (!this.settings.P2P_relays || this.settings.P2P_relays.length === 0) {
|
|
74
|
+
throw new Error("No relay URIs provided. We need them to establish the P2P connection");
|
|
75
|
+
}
|
|
76
|
+
this.server = new TrysteroConnection(env);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
Logger(e instanceof Error ? e.message : "Error while creating TrysteroReplicator", LOG_LEVEL_NOTICE);
|
|
79
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async close() {
|
|
84
|
+
this.requestStatus();
|
|
85
|
+
await this.server?.shutdown();
|
|
86
|
+
this._replicateFromPeers.clear();
|
|
87
|
+
this._replicateToPeers.clear();
|
|
88
|
+
this._watchingPeers.clear();
|
|
89
|
+
this.requestStatus();
|
|
90
|
+
this.disconnectFromServer();
|
|
91
|
+
}
|
|
92
|
+
async open() {
|
|
93
|
+
this.allowReconnection();
|
|
94
|
+
await this.server?.start([this.getCommands()]);
|
|
95
|
+
this.dispatchStatus();
|
|
96
|
+
if (this.settings.P2P_AutoBroadcast) {
|
|
97
|
+
this.enableBroadcastChanges();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async makeSureOpened() {
|
|
101
|
+
if (!this.server?.isServing) {
|
|
102
|
+
await this.open();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
get autoSyncPeers() {
|
|
106
|
+
const peers = this.settings.P2P_AutoSyncPeers.split(",").map((e) => e.trim()).filter((e) => e.length > 0).map((e) => e.startsWith("~") ? new RegExp(e.substring(1), "i") : new RegExp(`^${e}$`, "i"));
|
|
107
|
+
return peers;
|
|
108
|
+
}
|
|
109
|
+
get autoWatchPeers() {
|
|
110
|
+
const peers = this.settings.P2P_AutoWatchPeers.split(",").map((e) => e.trim()).filter((e) => e.length > 0).map((e) => e.startsWith("~") ? new RegExp(e.substring(1), "i") : new RegExp(`^${e}$`, "i"));
|
|
111
|
+
return peers;
|
|
112
|
+
}
|
|
113
|
+
async onNewPeer(peer) {
|
|
114
|
+
const peerName = peer.name;
|
|
115
|
+
if (this.autoSyncPeers.some((e) => e.test(peerName))) {
|
|
116
|
+
await this.runFiniteReplicationActivity(() => this.sync(peer.peerId));
|
|
117
|
+
}
|
|
118
|
+
if (this.autoWatchPeers.some((e) => e.test(peerName))) {
|
|
119
|
+
this.watchPeer(peer.peerId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
onPeerLeaved(peerId) {
|
|
123
|
+
void this.unwatchPeer(peerId);
|
|
124
|
+
}
|
|
125
|
+
_onSetup = false;
|
|
126
|
+
setOnSetup() {
|
|
127
|
+
this._onSetup = true;
|
|
128
|
+
}
|
|
129
|
+
clearOnSetup() {
|
|
130
|
+
this._onSetup = false;
|
|
131
|
+
}
|
|
132
|
+
async getTweakSettings(fromPeerId) {
|
|
133
|
+
const allSettings = JSON.parse(JSON.stringify(this.settings));
|
|
134
|
+
for (const key in allSettings) {
|
|
135
|
+
if (key == "encrypt") {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (key == "passphrase") {
|
|
139
|
+
allSettings[key] = await getHashedStringWithCurrentTime(allSettings[key] ?? "");
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (!(key in TweakValuesShouldMatchedTemplate)) {
|
|
143
|
+
delete allSettings[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return allSettings;
|
|
147
|
+
}
|
|
148
|
+
getCommands() {
|
|
149
|
+
return {
|
|
150
|
+
reqSync: async (fromPeerId) => {
|
|
151
|
+
if (this._onSetup) {
|
|
152
|
+
return { error: new Error("The setup is in progress") };
|
|
153
|
+
}
|
|
154
|
+
const result = await this.runFiniteReplicationActivity(() => this.replicateFrom(fromPeerId));
|
|
155
|
+
return result;
|
|
156
|
+
},
|
|
157
|
+
"!reqAuth": async (fromPeerId) => {
|
|
158
|
+
return await this.server?.isAcceptablePeer(fromPeerId);
|
|
159
|
+
},
|
|
160
|
+
getTweakSettings: async (fromPeerId) => {
|
|
161
|
+
return await this.getTweakSettings(fromPeerId);
|
|
162
|
+
},
|
|
163
|
+
onProgress: async (fromPeerId) => {
|
|
164
|
+
if (this._onSetup) {
|
|
165
|
+
return { error: new Error("The setup is in progress") };
|
|
166
|
+
}
|
|
167
|
+
await this.onUpdateDatabase(fromPeerId);
|
|
168
|
+
},
|
|
169
|
+
getAllConfig: async (fromPeerId) => {
|
|
170
|
+
if (this._onSetup) {
|
|
171
|
+
return { error: new Error("The setup is in progress") };
|
|
172
|
+
}
|
|
173
|
+
const passphrase = await skipIfDuplicated(`getAllConfig-${fromPeerId}`, async () => {
|
|
174
|
+
return await this.confirm.askString(
|
|
175
|
+
"Passphrase required",
|
|
176
|
+
this.translate("P2P.AskPassphraseForShare"),
|
|
177
|
+
"something you only know",
|
|
178
|
+
true
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
const setting = {
|
|
182
|
+
...this.settings,
|
|
183
|
+
configPassphraseStore: "",
|
|
184
|
+
encryptedCouchDBConnection: "",
|
|
185
|
+
encryptedPassphrase: "",
|
|
186
|
+
pluginSyncExtendedSetting: {}
|
|
187
|
+
};
|
|
188
|
+
if (!passphrase || passphrase.trim() == "") {
|
|
189
|
+
Logger(
|
|
190
|
+
"Passphrase is required to transfer the configuration. The peer cannot be decrypt the config\nIf you repeatedly receive unintended configuration-sharing requests, change the RPC channel immediately. It allows you to leave the connection and disappear, while they are trying brute force attack for the decoy on their local.",
|
|
191
|
+
LOG_LEVEL_NOTICE
|
|
192
|
+
);
|
|
193
|
+
const r = JSON.stringify(
|
|
194
|
+
Object.fromEntries(
|
|
195
|
+
Object.entries(setting).map(([key, value]) => {
|
|
196
|
+
return [key, "******".repeat(Math.ceil(Math.random() * 10) + 2)];
|
|
197
|
+
})
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
const randomString = Math.random().toString(36).substring(7);
|
|
201
|
+
return encrypt(r, randomString);
|
|
202
|
+
}
|
|
203
|
+
return encrypt(JSON.stringify(setting), passphrase.trim());
|
|
204
|
+
},
|
|
205
|
+
onProgressAcknowledged: async (fromPeerId, info) => {
|
|
206
|
+
try {
|
|
207
|
+
await Promise.resolve(this.onProgressAcknowledged(fromPeerId, info));
|
|
208
|
+
} catch (e) {
|
|
209
|
+
Logger("Error while acknowledging the progress", LOG_LEVEL_VERBOSE);
|
|
210
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
getIsBroadcasting: () => {
|
|
214
|
+
return Promise.resolve(this._isBroadcasting);
|
|
215
|
+
},
|
|
216
|
+
requestBroadcasting: async (peerId) => {
|
|
217
|
+
if (this._onSetup) {
|
|
218
|
+
return { error: new Error("The setup is in progress") };
|
|
219
|
+
}
|
|
220
|
+
if (this._isBroadcasting) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
if (await skipIfDuplicated(
|
|
224
|
+
`requested-${peerId}`,
|
|
225
|
+
async () => await this.confirm.askYesNoDialog(
|
|
226
|
+
"The remote peer requested to broadcast the changes. Do you want to allow it?",
|
|
227
|
+
{ defaultOption: "No" }
|
|
228
|
+
)
|
|
229
|
+
) === "yes") {
|
|
230
|
+
this.enableBroadcastChanges();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async requestAuthenticate(peerId) {
|
|
236
|
+
if (!this.server) return false;
|
|
237
|
+
try {
|
|
238
|
+
const connection = this.server.getConnection(peerId);
|
|
239
|
+
const selfPeerId = this.server.serverPeerId;
|
|
240
|
+
const r = await connection.invokeRemoteObjectFunction(
|
|
241
|
+
"!reqAuth",
|
|
242
|
+
[selfPeerId],
|
|
243
|
+
2e4
|
|
244
|
+
);
|
|
245
|
+
return r;
|
|
246
|
+
} catch (e) {
|
|
247
|
+
Logger("Error while requesting authentication", LOG_LEVEL_VERBOSE);
|
|
248
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// async selectPeer() {
|
|
253
|
+
// if (!this.server) return false;
|
|
254
|
+
// const knownPeers = this.server.knownAdvertisements;
|
|
255
|
+
// if (knownPeers.length === 0) {
|
|
256
|
+
// Logger("No known peers", LOG_LEVEL_VERBOSE);
|
|
257
|
+
// return false;
|
|
258
|
+
// }
|
|
259
|
+
// const peers = [...Object.entries(knownPeers)].map(([peerId, info]) => {
|
|
260
|
+
// return `${info.peerId}\u2001: (${info.name})`;
|
|
261
|
+
// });
|
|
262
|
+
// const selectedPeer = await this.confirm.askSelectString("Select a peer to replicate", peers);
|
|
263
|
+
// if (selectedPeer) return selectedPeer.split("\u2001")[0];
|
|
264
|
+
// return false;
|
|
265
|
+
// }
|
|
266
|
+
lastSeq = "";
|
|
267
|
+
async requestSynchroniseToPeer(peerId) {
|
|
268
|
+
await delay(25);
|
|
269
|
+
if (!this.server) throw new Error("Server is not available");
|
|
270
|
+
const conn = this.server.getConnection(peerId);
|
|
271
|
+
const result = await conn.invokeRemoteFunction("reqSync", [this.server.serverPeerId], 0);
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
async requestSynchroniseToAllAvailablePeers() {
|
|
275
|
+
await scheduleOnceIfDuplicated("requestSynchroniseToAllAvailablePeers", async () => {
|
|
276
|
+
await delay(25);
|
|
277
|
+
const replications = [...this.availableReplicationPairs].map((peerId) => {
|
|
278
|
+
return this.requestSynchroniseToPeer(peerId);
|
|
279
|
+
});
|
|
280
|
+
await Promise.all(replications);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
dispatchStatus() {
|
|
284
|
+
this._env.events.emitEvent(EVENT_P2P_REPLICATOR_STATUS, {
|
|
285
|
+
isBroadcasting: this._isBroadcasting,
|
|
286
|
+
replicatingTo: [...this._replicateToPeers],
|
|
287
|
+
replicatingFrom: [...this._replicateFromPeers],
|
|
288
|
+
watchingPeers: [...this._watchingPeers]
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
requestStatus() {
|
|
292
|
+
this.dispatchStatus();
|
|
293
|
+
void this.server?.dispatchConnectionStatus();
|
|
294
|
+
}
|
|
295
|
+
changes;
|
|
296
|
+
_isBroadcasting = false;
|
|
297
|
+
disableBroadcastChanges() {
|
|
298
|
+
this.changes?.cancel();
|
|
299
|
+
this._isBroadcasting = false;
|
|
300
|
+
this.dispatchStatus();
|
|
301
|
+
}
|
|
302
|
+
enableBroadcastChanges() {
|
|
303
|
+
if (this._isBroadcasting) return;
|
|
304
|
+
this._isBroadcasting = true;
|
|
305
|
+
this.dispatchStatus();
|
|
306
|
+
if (this.changes) {
|
|
307
|
+
void this.changes.cancel();
|
|
308
|
+
void this.changes.removeAllListeners();
|
|
309
|
+
}
|
|
310
|
+
this.changes = this.db.changes({
|
|
311
|
+
since: "now",
|
|
312
|
+
live: true,
|
|
313
|
+
include_docs: false,
|
|
314
|
+
selector: {
|
|
315
|
+
_id: {
|
|
316
|
+
$gt: "_local/"
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
void this.changes.on("change", async (change) => {
|
|
321
|
+
this.lastSeq = change.seq;
|
|
322
|
+
await this.notifyProgress();
|
|
323
|
+
});
|
|
324
|
+
const closeChanges = (reason) => {
|
|
325
|
+
if (reason) {
|
|
326
|
+
if (reason instanceof Error) {
|
|
327
|
+
Logger(`Error while broadcasting the changes`, LOG_LEVEL_INFO);
|
|
328
|
+
Logger(reason, LOG_LEVEL_VERBOSE);
|
|
329
|
+
} else {
|
|
330
|
+
Logger(`Broadcasting the changes has been finished`, LOG_LEVEL_INFO);
|
|
331
|
+
Logger(reason, LOG_LEVEL_VERBOSE);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
void this.changes?.cancel();
|
|
335
|
+
void this.changes?.removeAllListeners();
|
|
336
|
+
this.changes = void 0;
|
|
337
|
+
this._isBroadcasting = false;
|
|
338
|
+
this.dispatchStatus();
|
|
339
|
+
};
|
|
340
|
+
void this.changes.on("error", closeChanges);
|
|
341
|
+
void this.changes.on("complete", closeChanges);
|
|
342
|
+
fireAndForget(async () => await this.notifyProgress());
|
|
343
|
+
}
|
|
344
|
+
get knownAdvertisements() {
|
|
345
|
+
return this.server?.knownAdvertisements ?? [];
|
|
346
|
+
}
|
|
347
|
+
availableReplicationPairs = /* @__PURE__ */ new Set();
|
|
348
|
+
async sync(remotePeer, showNotice = false) {
|
|
349
|
+
const from = await this.replicateFrom(remotePeer, showNotice);
|
|
350
|
+
if (!from || from.error) {
|
|
351
|
+
Logger("Error while replicating from the remote", LOG_LEVEL_VERBOSE);
|
|
352
|
+
Logger(from.error, LOG_LEVEL_VERBOSE);
|
|
353
|
+
return from;
|
|
354
|
+
}
|
|
355
|
+
const logLevel = showNotice ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
|
356
|
+
Logger(`P2P Replication has been requested to ${remotePeer}`, logLevel, "p2p-replicator");
|
|
357
|
+
const res = await this.requestSynchroniseToPeer(remotePeer);
|
|
358
|
+
if (res.ok) {
|
|
359
|
+
Logger("P2P Replication has been done", logLevel, "p2p-replicator");
|
|
360
|
+
}
|
|
361
|
+
if (res.error) {
|
|
362
|
+
Logger("Error while syncing from the remote", logLevel, "p2p-replicator");
|
|
363
|
+
Logger(res.error, LOG_LEVEL_VERBOSE);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
_replicateToPeers = /* @__PURE__ */ new Set();
|
|
367
|
+
// async replicateTo() {
|
|
368
|
+
// await this.makeSureOpened();
|
|
369
|
+
// const remotePeer = await this.selectPeer();
|
|
370
|
+
// if (!remotePeer) {
|
|
371
|
+
// Logger("No peer selected", LOG_LEVEL_VERBOSE);
|
|
372
|
+
// return;
|
|
373
|
+
// }
|
|
374
|
+
// Logger(`P2P Replicating to ${remotePeer}`, LOG_LEVEL_INFO);
|
|
375
|
+
// try {
|
|
376
|
+
// if (this._replicateToPeers.has(remotePeer)) {
|
|
377
|
+
// Logger(`Replication to ${remotePeer} is already in progress`, LOG_LEVEL_VERBOSE);
|
|
378
|
+
// return;
|
|
379
|
+
// }
|
|
380
|
+
// this._replicateToPeers.add(remotePeer);
|
|
381
|
+
// this.dispatchStatus();
|
|
382
|
+
// return await this.requestSynchroniseToPeer(remotePeer);
|
|
383
|
+
// } finally {
|
|
384
|
+
// this._replicateToPeers.delete(remotePeer);
|
|
385
|
+
// this.dispatchStatus();
|
|
386
|
+
// }
|
|
387
|
+
// }
|
|
388
|
+
_replicateFromPeers = /* @__PURE__ */ new Set();
|
|
389
|
+
dispatchReplicationProgress(peerId, info) {
|
|
390
|
+
this.onReplicationProgress(peerId, info);
|
|
391
|
+
}
|
|
392
|
+
onReplicationProgress(peerId, info) {
|
|
393
|
+
const name = this.server?._knownAdvertisements.get(peerId)?.name || peerId;
|
|
394
|
+
const stat = {
|
|
395
|
+
peerId,
|
|
396
|
+
peerName: name,
|
|
397
|
+
fetching: {
|
|
398
|
+
max: 0,
|
|
399
|
+
current: 0,
|
|
400
|
+
isActive: false
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
if (info) {
|
|
404
|
+
stat.fetching = {
|
|
405
|
+
max: info.maxSeqInBatch,
|
|
406
|
+
current: info.lastSeq,
|
|
407
|
+
isActive: true
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
this._env.events.emitEvent(EVENT_P2P_REPLICATOR_PROGRESS, stat);
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
onProgressAcknowledged(peerId, info) {
|
|
414
|
+
const name = this.server?._knownAdvertisements.get(peerId)?.name || peerId;
|
|
415
|
+
const ack = {
|
|
416
|
+
peerId,
|
|
417
|
+
peerName: name,
|
|
418
|
+
sending: {
|
|
419
|
+
max: 0,
|
|
420
|
+
current: 0,
|
|
421
|
+
isActive: false
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
if (info) {
|
|
425
|
+
ack.sending = {
|
|
426
|
+
max: info.maxSeqInBatch,
|
|
427
|
+
current: info.lastSeq,
|
|
428
|
+
isActive: true
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
this._env.events.emitEvent(EVENT_P2P_REPLICATOR_PROGRESS, ack);
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
// Sending the progress to the remote peer
|
|
435
|
+
acknowledgeProgress(remotePeerId, info) {
|
|
436
|
+
if (!this.server) return;
|
|
437
|
+
const connection = this.server.getConnection(remotePeerId);
|
|
438
|
+
void connection.invokeRemoteFunction("onProgressAcknowledged", [this.server.serverPeerId, info], 500).catch((ex) => {
|
|
439
|
+
Logger("Error while acknowledging the progress", LOG_LEVEL_VERBOSE);
|
|
440
|
+
Logger(ex, LOG_LEVEL_VERBOSE);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
async replicateFrom(remotePeer, showNotice = false, fromStart = false) {
|
|
444
|
+
const logLevel = showNotice ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
|
445
|
+
Logger(`P2P Requesting Authentication to ${remotePeer}`, logLevel, "p2p-replicator");
|
|
446
|
+
if (await this.requestAuthenticate(remotePeer) !== true) {
|
|
447
|
+
Logger("Peer rejected the connection", LOG_LEVEL_NOTICE, "p2p-replicator");
|
|
448
|
+
return { error: new Error("Peer rejected the connection") };
|
|
449
|
+
}
|
|
450
|
+
if (await this.checkTweakValues(remotePeer) !== true) {
|
|
451
|
+
Logger("Tweak values are not matched", LOG_LEVEL_NOTICE, "p2p-replicator");
|
|
452
|
+
return { error: new Error("Tweak values are not matched") };
|
|
453
|
+
}
|
|
454
|
+
Logger(`P2P Replicating from ${remotePeer}`, logLevel, "p2p-replicator");
|
|
455
|
+
if (this._replicateFromPeers.has(remotePeer)) {
|
|
456
|
+
Logger(`Replication from ${remotePeer} is already in progress`, LOG_LEVEL_NOTICE, "p2p-replicator");
|
|
457
|
+
return { error: new Error("Replication from this peer is already in progress") };
|
|
458
|
+
}
|
|
459
|
+
this._replicateFromPeers.add(remotePeer);
|
|
460
|
+
this.dispatchStatus();
|
|
461
|
+
try {
|
|
462
|
+
if (!this.server) {
|
|
463
|
+
throw new Error("Server is not available");
|
|
464
|
+
}
|
|
465
|
+
const connection = this.server.getConnection(remotePeer);
|
|
466
|
+
const remoteDB = connection.remoteDB;
|
|
467
|
+
Logger(`P2P replicateFrom preparing remote DB info for ${remotePeer}`, LOG_LEVEL_VERBOSE, "p2p-replicator");
|
|
468
|
+
const remoteDBInfo = await remoteDB.info();
|
|
469
|
+
Logger(
|
|
470
|
+
`P2P replicateFrom remote DB info for ${remotePeer}: ${remoteDBInfo.db_name} seq=${remoteDBInfo.update_seq}`,
|
|
471
|
+
LOG_LEVEL_VERBOSE,
|
|
472
|
+
"p2p-replicator"
|
|
473
|
+
);
|
|
474
|
+
const localDBInfo = await this.db.info();
|
|
475
|
+
Logger(
|
|
476
|
+
`P2P replicateFrom local DB info for ${remotePeer}: ${localDBInfo.db_name} seq=${localDBInfo.update_seq}`,
|
|
477
|
+
LOG_LEVEL_VERBOSE,
|
|
478
|
+
"p2p-replicator"
|
|
479
|
+
);
|
|
480
|
+
Logger(`P2P replicateFrom entering replicateShim for ${remotePeer}`, LOG_LEVEL_VERBOSE, "p2p-replicator");
|
|
481
|
+
await replicateShim(
|
|
482
|
+
this.db,
|
|
483
|
+
remoteDB,
|
|
484
|
+
async (docs, info) => {
|
|
485
|
+
await this._env.processReplicatedDocs(docs);
|
|
486
|
+
void this.dispatchReplicationProgress(remotePeer, info);
|
|
487
|
+
void this.acknowledgeProgress(remotePeer, info);
|
|
488
|
+
void this.notifyProgress(remotePeer);
|
|
489
|
+
Logger(
|
|
490
|
+
`P2P Replication from ${remotePeer}
|
|
491
|
+
${info.lastSeq} / ${info.maxSeqInBatch})`,
|
|
492
|
+
logLevel,
|
|
493
|
+
"p2p-replicator"
|
|
494
|
+
);
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
live: false,
|
|
498
|
+
rewind: fromStart
|
|
499
|
+
/*, batch_size: batchSize */
|
|
500
|
+
}
|
|
501
|
+
);
|
|
502
|
+
Logger(`P2P replicateFrom replicateShim returned for ${remotePeer}`, LOG_LEVEL_VERBOSE, "p2p-replicator");
|
|
503
|
+
void this.acknowledgeProgress(remotePeer, void 0);
|
|
504
|
+
Logger(`P2P Replication from ${remotePeer} has been completed`, logLevel, "p2p-replicator");
|
|
505
|
+
} catch (e) {
|
|
506
|
+
Logger("Error while P2P replicating", logLevel, "p2p-replicator");
|
|
507
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
508
|
+
return { error: e };
|
|
509
|
+
} finally {
|
|
510
|
+
this._replicateFromPeers.delete(remotePeer);
|
|
511
|
+
this.dispatchStatus();
|
|
512
|
+
}
|
|
513
|
+
return { ok: true };
|
|
514
|
+
}
|
|
515
|
+
notifyProgress(excludePeerId) {
|
|
516
|
+
if (!this._isBroadcasting) return;
|
|
517
|
+
if (!this.server) return;
|
|
518
|
+
for (const peer of this.server.knownAdvertisements) {
|
|
519
|
+
const peerId = peer.peerId;
|
|
520
|
+
if (peerId === excludePeerId) continue;
|
|
521
|
+
void serialized(`notifyProgress-${peerId}`, async () => {
|
|
522
|
+
const isAcceptable = await this.server?.isAcceptablePeer(peerId);
|
|
523
|
+
if (isAcceptable) {
|
|
524
|
+
try {
|
|
525
|
+
const ret = await this.server?.getConnection(peerId).invokeRemoteFunction("onProgress", [this.server?.serverPeerId], 0);
|
|
526
|
+
return ret;
|
|
527
|
+
} catch (e) {
|
|
528
|
+
Logger(`Error while notifying progress to ${peerId}`, LOG_LEVEL_VERBOSE);
|
|
529
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
Logger(`Peer ${peerId} is not acceptable to notify progress`, LOG_LEVEL_VERBOSE);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
return Promise.resolve();
|
|
537
|
+
}
|
|
538
|
+
async requestBroadcastChanges(peerId) {
|
|
539
|
+
return await this.server?.getConnection(peerId).invokeRemoteFunction("requestBroadcasting", [this.server.serverPeerId], 0);
|
|
540
|
+
}
|
|
541
|
+
async getRemoteIsBroadcasting(peerId) {
|
|
542
|
+
try {
|
|
543
|
+
return await this.server?.getConnection(peerId).invokeRemoteFunction("getIsBroadcasting", [], 0);
|
|
544
|
+
} catch (e) {
|
|
545
|
+
Logger("Error while getting remote is broadcasting", LOG_LEVEL_VERBOSE);
|
|
546
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
_watchingPeers = /* @__PURE__ */ new Set();
|
|
550
|
+
watchPeer(peerId) {
|
|
551
|
+
this._watchingPeers.add(peerId);
|
|
552
|
+
this.dispatchStatus();
|
|
553
|
+
}
|
|
554
|
+
unwatchPeer(peerId) {
|
|
555
|
+
this._watchingPeers.delete(peerId);
|
|
556
|
+
this.dispatchStatus();
|
|
557
|
+
}
|
|
558
|
+
async onUpdateDatabase(fromPeerId) {
|
|
559
|
+
if (this._watchingPeers.has(fromPeerId)) {
|
|
560
|
+
Logger(`Progress notification from ${fromPeerId}`, LOG_LEVEL_VERBOSE);
|
|
561
|
+
return await serialized(`onProgress-${fromPeerId}`, async () => {
|
|
562
|
+
return await this.runFiniteReplicationActivity(() => this.replicateFrom(fromPeerId));
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
async getRemoteConfig(peerId) {
|
|
568
|
+
if (!this.server) {
|
|
569
|
+
Logger("Server is not available", LOG_LEVEL_NOTICE);
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
const connection = this.server.getConnection(peerId);
|
|
573
|
+
const encryptedConfig = await connection.invokeRemoteFunction("getAllConfig", [this.server.serverPeerId], 0);
|
|
574
|
+
const passphrase = await this.confirm.askString(
|
|
575
|
+
"Passphrase required",
|
|
576
|
+
this.translate("P2P.AskPassphraseForDecrypt"),
|
|
577
|
+
"something you only know",
|
|
578
|
+
true
|
|
579
|
+
);
|
|
580
|
+
if (!passphrase || passphrase.trim() == "") {
|
|
581
|
+
Logger(
|
|
582
|
+
"Passphrase is required to decrypt the configuration. The config cannot be decrypted",
|
|
583
|
+
LOG_LEVEL_NOTICE
|
|
584
|
+
);
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
const decryptedConfig = JSON.parse(
|
|
589
|
+
await decrypt(encryptedConfig, passphrase)
|
|
590
|
+
);
|
|
591
|
+
return decryptedConfig;
|
|
592
|
+
} catch (e) {
|
|
593
|
+
Logger("Error while decrypting the configuration", LOG_LEVEL_NOTICE);
|
|
594
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
async checkTweakValues(peerId) {
|
|
599
|
+
if (!this.server) {
|
|
600
|
+
Logger("Server is not available", LOG_LEVEL_NOTICE);
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
const peerPlatform = this.server.knownAdvertisements.find((e) => e.peerId == peerId)?.platform;
|
|
604
|
+
if (peerPlatform == null) {
|
|
605
|
+
Logger("Peer is not found", LOG_LEVEL_NOTICE);
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
if (this.platform === "pseudo-replicator") {
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
if (peerPlatform === "pseudo-replicator") {
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
const connection = this.server.getConnection(peerId);
|
|
615
|
+
const tweakValues = await connection.invokeRemoteObjectFunction("getTweakSettings", [this.server.serverPeerId], 5e3);
|
|
616
|
+
const thisTweakValues = await this.getTweakSettings("");
|
|
617
|
+
if (!isObjectDifferent(thisTweakValues, tweakValues)) {
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
if (thisTweakValues.passphrase !== tweakValues.passphrase) {
|
|
621
|
+
Logger(
|
|
622
|
+
"Replication cancelled: Passphrase is not matched\nCannot replicate to a remote database until the problem is resolved.",
|
|
623
|
+
LOG_LEVEL_NOTICE
|
|
624
|
+
);
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
Logger(
|
|
628
|
+
"Some mismatched configuration have been detected... Please check settings for efficient replication.",
|
|
629
|
+
LOG_LEVEL_NOTICE
|
|
630
|
+
);
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
async replicateFromCommand(showResult = false) {
|
|
634
|
+
const r = await skipIfDuplicated("replicateFromCommand", async () => {
|
|
635
|
+
const logLevel = showResult ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO;
|
|
636
|
+
if (!this._env.settings.P2P_Enabled) {
|
|
637
|
+
Logger(this.translate("P2P.NotEnabled"), logLevel);
|
|
638
|
+
return Promise.resolve(false);
|
|
639
|
+
}
|
|
640
|
+
const peers = this._env.settings.P2P_SyncOnReplication.split(",").map((e) => e.trim()).filter((e) => e);
|
|
641
|
+
if (peers.length == 0) {
|
|
642
|
+
Logger(this.translate("P2P.NoAutoSyncPeers"), LOG_LEVEL_NOTICE);
|
|
643
|
+
return Promise.resolve(false);
|
|
644
|
+
}
|
|
645
|
+
for (const peer of peers) {
|
|
646
|
+
const peerId = this.knownAdvertisements.find((e) => e.name == peer)?.peerId;
|
|
647
|
+
if (!peerId) {
|
|
648
|
+
Logger(this.translate(`P2P.SeemsOffline`, { name: peer }), logLevel);
|
|
649
|
+
} else {
|
|
650
|
+
Logger(this.translate(`P2P.SyncStartedWith`, { name: peer }), logLevel);
|
|
651
|
+
await this.sync(peerId, showResult);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
Logger(this.translate("P2P.SyncCompleted"), logLevel);
|
|
655
|
+
return Promise.resolve(true);
|
|
656
|
+
});
|
|
657
|
+
if (r === null) {
|
|
658
|
+
Logger(this.translate("P2P.SyncAlreadyRunning"), LOG_LEVEL_NOTICE);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
disconnectFromServer() {
|
|
662
|
+
const connections = getRelaySockets();
|
|
663
|
+
const sockets = Object.entries(connections);
|
|
664
|
+
pauseRelayReconnection();
|
|
665
|
+
sockets.forEach(([, s]) => {
|
|
666
|
+
s.close();
|
|
667
|
+
s.onclose = () => {
|
|
668
|
+
void this.server?.dispatchConnectionStatus();
|
|
669
|
+
};
|
|
670
|
+
});
|
|
671
|
+
void this.pauseServe();
|
|
672
|
+
}
|
|
673
|
+
async pauseServe() {
|
|
674
|
+
await this.server?.close();
|
|
675
|
+
await this.server?.dispatchConnectionStatus();
|
|
676
|
+
}
|
|
677
|
+
allowReconnection() {
|
|
678
|
+
resumeRelayReconnection();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
export {
|
|
682
|
+
TrysteroReplicator
|
|
683
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PouchDBShim, SomeDocument } from "../../pouchdb/ReplicatorShim.js";
|
|
2
|
+
import type { TrysteroReplicatorP2PServer } from "./TrysteroReplicatorP2PServer.js";
|
|
3
|
+
import { type BindableObject, type NonPrivateMethodKeys, type Response } from "./types.js";
|
|
4
|
+
import type { JsonLike } from "../../rpc/index.js";
|
|
5
|
+
export declare class TrysteroReplicatorP2PClient {
|
|
6
|
+
_server: TrysteroReplicatorP2PServer;
|
|
7
|
+
_connectedPeerId: string;
|
|
8
|
+
_remoteDB: PouchDBShim<SomeDocument<object>>;
|
|
9
|
+
get remoteDB(): PouchDBShim<SomeDocument<object>>;
|
|
10
|
+
constructor(server: TrysteroReplicatorP2PServer, connectedPeerId: string);
|
|
11
|
+
_bindRemoteDB(): PouchDBShim<SomeDocument<object>>;
|
|
12
|
+
_sendRPC(type: string, args: JsonLike[], timeout?: number): Promise<JsonLike>;
|
|
13
|
+
__onResponse(_data: Response): void;
|
|
14
|
+
bindRemoteFunction<T extends unknown[], U>(type: string, timeout?: number): (...args: T) => Promise<U>;
|
|
15
|
+
invokeRemoteFunction<T extends unknown[], U>(type: string, args: T, timeout?: number): Promise<U>;
|
|
16
|
+
bindRemoteObjectFunctions<T extends BindableObject<any>, U extends keyof T>(key: U, timeout?: number): (...args: Parameters<T[U]>) => Promise<Awaited<ReturnType<T[U]>>>;
|
|
17
|
+
invokeRemoteObjectFunction<T extends BindableObject<any>, U extends NonPrivateMethodKeys<T>>(key: U, args: Parameters<T[U]>, timeout?: number): Promise<Awaited<ReturnType<T[U]>>>;
|
|
18
|
+
close(): void;
|
|
19
|
+
}
|