@@ -9,7 +9,7 @@ import { CustomEvent, EventEmitter } from '@libp2p/interface/events';
9
9
import { NodeKeyJson , PeerOptions } from '@windingtree/sdk-types' ;
10
10
import { centerSub , CenterSub } from '@windingtree/sdk-pubsub' ;
11
11
import { decodeText } from '@windingtree/sdk-utils' ;
12
- import { StorageInitializer } from '@windingtree/sdk-storage' ;
12
+ import { Storage , StorageInitializer } from '@windingtree/sdk-storage' ;
13
13
import { createLogger } from '@windingtree/sdk-logger' ;
14
14
15
15
const logger = createLogger ( 'Server' ) ;
@@ -65,6 +65,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
65
65
private peerKey : NodeKeyJson ;
66
66
private libp2p ?: Libp2p ;
67
67
private messagesStorageInit : StorageInitializer ;
68
+ private messagesStorage ?: Storage ;
68
69
69
70
/**
70
71
* Creates an instance of CoordinationServer.
@@ -103,7 +104,8 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
103
104
* @memberof CoordinationServer
104
105
*/
105
106
async start ( ) : Promise < void > {
106
- const messagesStorage = await this . messagesStorageInit ( ) ;
107
+ this . messagesStorage = await this . messagesStorageInit ( ) ;
108
+ await this . messagesStorage . open ( ) ;
107
109
108
110
const config : Libp2pOptions = {
109
111
start : false ,
@@ -115,7 +117,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
115
117
connectionEncryption : [ noise ( ) ] ,
116
118
services : {
117
119
pubsub : centerSub ( {
118
- messagesStorage,
120
+ messagesStorage : this . messagesStorage ,
119
121
} ) ,
120
122
} ,
121
123
connectionManager : {
@@ -151,6 +153,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
151
153
* @memberof CoordinationServer
152
154
*/
153
155
async stop ( ) : Promise < void > {
156
+ await this . messagesStorage ?. close ( ) ;
154
157
if ( ! this . libp2p ) {
155
158
throw new Error ( 'libp2p not initialized yet' ) ;
156
159
}
0 commit comments