8
8
BlockchainEventTypes,
9
9
FilterDeletionReasons,
10
10
} = require ( '../common/constants' ) ;
11
+ const CommonUtil = require ( '../common/common-util' ) ;
11
12
const EventHandlerError = require ( './event-handler-error' ) ;
12
13
const { EventHandlerErrorCode } = require ( '../common/result-code' ) ;
13
14
const BlockchainEvent = require ( './blockchain-event' ) ;
@@ -40,6 +41,7 @@ class EventChannelManager {
40
41
return {
41
42
maxNumEventChannels : NodeConfigs . MAX_NUM_EVENT_CHANNELS ,
42
43
numEventChannels : this . getNumEventChannels ( ) ,
44
+ channelLifeTimeLimitSecs : NodeConfigs . EVENT_HANDLER_CHANNEL_LIFE_TIME_LIMIT_SECS ,
43
45
channelIdleTimeLimitSecs : NodeConfigs . EVENT_HANDLER_CHANNEL_IDLE_TIME_LIMIT_SECS ,
44
46
maxChannelLifeTimeMs : channelStats . maxLifeTimeMs ,
45
47
maxChannelIdleTimeMs : channelStats . maxIdleTimeMs ,
@@ -157,6 +159,18 @@ class EventChannelManager {
157
159
}
158
160
}
159
161
162
+ handleSetCustomClientId ( channel , messageData ) {
163
+ const LOG_HEADER = 'handleSetCustomClientId' ;
164
+ const customClientId = messageData . customClientId ;
165
+ if ( ! CommonUtil . isString ( customClientId ) ) {
166
+ throw new EventHandlerError ( EventHandlerErrorCode . INVALID_CUSTOM_CLIENT_ID ,
167
+ `Invalid custom client id: ${ customClientId } ` ) ;
168
+ }
169
+ const normalized = customClientId . slice ( 0 , NodeConfigs . EVENT_HANDLER_MAX_CUSTOM_CLIENT_ID_LENGTH ) ;
170
+ logger . info ( `[${ LOG_HEADER } ] Setting custom client id: ${ normalized } for channel: ${ channel . id } ` ) ;
171
+ channel . setCustomClientId ( normalized ) ;
172
+ }
173
+
160
174
handleRegisterFilterMessage ( channel , messageData ) {
161
175
const LOG_HEADER = 'handleRegisterFilterMessage' ;
162
176
const clientFilterId = messageData . id ;
@@ -292,6 +306,9 @@ class EventChannelManager {
292
306
// TODO(cshcomcom): Manage EVENT_PROTOCOL_VERSION.
293
307
handleMessage ( channel , messageType , messageData ) {
294
308
switch ( messageType ) {
309
+ case BlockchainEventMessageTypes . SET_CUSTOM_CLIENT_ID :
310
+ this . handleSetCustomClientId ( channel , messageData ) ;
311
+ break ;
295
312
case BlockchainEventMessageTypes . REGISTER_FILTER :
296
313
this . handleRegisterFilterMessage ( channel , messageData ) ;
297
314
break ;
@@ -300,7 +317,7 @@ class EventChannelManager {
300
317
break ;
301
318
default :
302
319
throw new EventHandlerError ( EventHandlerErrorCode . INVALID_MESSAGE_TYPE ,
303
- `Invalid message type ( ${ messageType } ) ` ) ;
320
+ `Invalid message type: ${ messageType } ` ) ;
304
321
}
305
322
}
306
323
0 commit comments