@@ -16,6 +16,7 @@ const defaultConfiguration = require('../../../../config/config.json').developme
1616const uuidRegex = / \b [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 1 - 5 ] [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } \b / gi;
1717const walletRegex = / \b 0 x [ 0 - 9 A - F ] { 40 } \b / gi;
1818const identityRegex = / \b [ 0 - 9 A - F ] { 40 } \b / gi;
19+ const identityWithPrefixRegex = / \b 0 x [ 0 - 9 A - F ] { 40 } \b / gi;
1920const offerIdRegex = / \b 0 x [ 0 - 9 A - F ] { 64 } \b / gi;
2021const dataSetRegex = / \b 0 x [ 0 - 9 A - F ] { 64 } \b / gi;
2122const walletAmountRegex = / \b \d + \b / g;
@@ -34,7 +35,8 @@ class OtNode extends EventEmitter {
3435 this . options . configDir = path . join ( appDataBaseDir || tmpdir , this . id ) ;
3536 this . options . nodeConfiguration = nodeConfiguration || { } ;
3637 this . options . nodeConfiguration = deepExtend (
37- Object . assign ( { } , defaultConfiguration ) , // deepExtend changes original object.
38+ { } ,
39+ defaultConfiguration ,
3840 this . options . nodeConfiguration ,
3941 ) ;
4042 this . logger = logger || console ;
@@ -62,9 +64,13 @@ class OtNode extends EventEmitter {
6264 this . state = { } ;
6365 this . state . addedBids = [ ] ; // List of offer IDs (DH side).
6466 this . state . takenBids = [ ] ; // List of offer IDs (DH side).
67+ this . state . pendingLitigationDhIdentities = [ ] ; // List of pending litigations (DHs)
68+ this . state . takenReplacements = [ ] ; // List of replacement offer IDs (DH side).
6569 // Valid replications (DH side). List of internal offer IDs and their replications DH IDs
6670 // in pairs. { internalOfferId, dhId }.
6771 this . state . replications = [ ] ;
72+ // Array of replacement offer IDs
73+ this . state . replacements = [ ] ;
6874 // Valid replications (DC side). List of objects { importId, dhWallet }.
6975 this . state . holdingData = [ ] ;
7076 // Offers finalized. List of offer IDs.
@@ -149,6 +155,7 @@ class OtNode extends EventEmitter {
149155 stop ( ) {
150156 this . logger . log ( `Stopping node ${ this . id } .` ) ;
151157 assert ( this . isRunning ) ;
158+ this . started = false ;
152159 this . process . kill ( 'SIGINT' ) ;
153160 }
154161
@@ -211,6 +218,8 @@ class OtNode extends EventEmitter {
211218 const offerId = line . match ( offerIdRegex ) [ 0 ] ;
212219 } else if ( line . match ( / M i n e r f o u n d a s o l u t i o n o f o f f e r .+ \. / gi) ) {
213220 const offerId = line . match ( offerIdRegex ) [ 0 ] ;
221+ } else if ( line . match ( / N o t e n o u g h D H s s u b m i t t e d / gi) ) {
222+ this . emit ( 'not-enough-dhs' ) ;
214223 } else if ( line . match ( / O f f e r .+ f i n a l i z e d / gi) ) {
215224 const offerId = line . match ( offerIdRegex ) [ 0 ] ;
216225 assert ( offerId ) ;
@@ -290,6 +299,51 @@ class OtNode extends EventEmitter {
290299 this . emit ( 'replication-window-closed' ) ;
291300 } else if ( line . match ( / O f f e r w i t h i n t e r n a l I D .+ f o r d a t a s e t .+ w r i t t e n t o b l o c k c h a i n . W a i t i n g f o r D H s \. \. \. / gi) ) {
292301 this . emit ( 'offer-written-blockchain' ) ;
302+ } else if ( line . match ( / C o m m a n d d h P a y O u t C o m m a n d a n d I D .+ p r o c e s s e d \. / gi) ) {
303+ this . emit ( 'dh-pay-out-finalized' ) ;
304+ } else if ( line . match ( / C o m m a n d d h O f f e r F i n a l i z e d C o m m a n d a n d I D .+ p r o c e s s e d \. / gi) ) {
305+ this . emit ( 'dh-offer-finalized' ) ;
306+ } else if ( line . match ( / L i t i g a t i o n i n i t i a t e d f o r D H .+ a n d o f f e r .+ \. / gi) ) {
307+ this . state . litigationStatus = 'LITIGATION_STARTED' ;
308+ this . emit ( 'dc-litigation-initiated' ) ;
309+ } else if ( line . match ( / L i t i g a t i o n a n s w e r e d f o r D H .+ a n d o f f e r .+ \. / gi) ) {
310+ this . emit ( 'dc-litigation-answered' ) ;
311+ } else if ( line . match ( / L i t i g a t i o n a n s w e r e d f o r o f f e r .+ \. D H i d e n t i t y .+ / gi) ) {
312+ this . emit ( 'dh-litigation-answered' ) ;
313+ } else if ( line . match ( / L i t i g a t i o n c o m p l e t e d f o r D H .+ a n d o f f e r .+ \. / gi) ) {
314+ this . state . litigationStatus = 'LITIGATION_COMPLETED' ;
315+ this . emit ( 'dc-litigation-completed' ) ;
316+ } else if ( line . match ( / L i t i g a t i o n a l r e a d y i n p r o g r e s s \. \. \. I t n e e d s t o b e c o m p l e t e d i n o r d e r t o l i t i g a t e .+ f o r o f f e r .+ / gi) ) {
317+ const dhIdentity = line . match ( identityWithPrefixRegex ) [ 0 ] ;
318+ this . state . pendingLitigationDhIdentities . push ( dhIdentity ) ;
319+ this . emit ( 'dc-litigation-pending' ) ;
320+ } else if ( line . match ( / D H .+ w a s p e n a l i z e d f o r t h e o f f e r .+ \. / gi) ) {
321+ this . emit ( 'dc-litigation-completed-dh-penalized' ) ;
322+ } else if ( line . match ( / D H .+ w a s n o t p e n a l i z e d f o r t h e o f f e r .+ \. / gi) ) {
323+ this . emit ( 'dc-litigation-completed-dh-not-penalized' ) ;
324+ } else if ( line . match ( / R e p l a c e m e n t f o r D H .+ a n d o f f e r .+ h a s b e e n s u c c e s s f u l l y s t a r t e d . W a i t i n g f o r D H s \. \. \. / gi) ) {
325+ this . emit ( 'dc-litigation-replacement-started' ) ;
326+ } else if ( line . match ( / R e p l a c e m e n t t r i g g e r e d f o r o f f e r .+ \. L i t i g a t o r .+ \. / gi) ) {
327+ const offerId = line . match ( offerIdRegex ) [ 0 ] ;
328+ this . state . replacements . push ( offerId ) ;
329+ } else if ( line . match ( / \[ D H ] R e p l a c e m e n t r e p l i c a t i o n f i n i s h e d f o r o f f e r I D .+ / gi) ) {
330+ const offerId = line . match ( offerIdRegex ) [ 0 ] ;
331+ assert ( offerId ) ;
332+ this . state . takenReplacements . push ( offerId ) ;
333+ this . emit ( 'dh-litigation-replacement-received' ) ;
334+ } else if ( line . match ( / S u c c e s s f u l l y r e p l a c e d D H .+ w i t h D H .+ f o r o f f e r .+ / gi) ) {
335+ this . emit ( 'dc-litigation-replacement-completed' ) ;
336+ } else if ( line . match ( / C h a l l e n g e a n s w e r .+ s e n t t o .+ \. / gi) ) {
337+ this . emit ( 'dh-challenge-sent' ) ;
338+ } else if ( line . match ( / N o t c h o s e n a s a r e p l a c e m e n t f o r o f f e r .+ \. / gi) ) {
339+ this . emit ( 'dh-not-chosen-as-replacement' ) ;
340+ } else if ( line . match ( / C h o s e n a s a r e p l a c e m e n t f o r o f f e r .+ \. / gi) ) {
341+ const offerId = line . match ( offerIdRegex ) [ 0 ] ;
342+ this . state . takenBids . push ( offerId ) ;
343+ this . emit ( 'dh-chosen-as-replacement' ) ;
344+ } else if ( line . match ( / R e p l i c a t i o n f i n i s h e d f o r D H n o d e .+ / gi) ) {
345+ const nodeId = line . match ( identityRegex ) [ 0 ] ;
346+ this . emit ( 'dh-replication-verified' , nodeId ) ;
293347 }
294348 }
295349
@@ -301,6 +355,21 @@ class OtNode extends EventEmitter {
301355 return this . initialized && this . started && ! ! this . process ;
302356 }
303357
358+ /**
359+ * Retruns path to the system.db.
360+ * @return {string } Path.
361+ */
362+ get systemDbPath ( ) {
363+ return path . join ( this . options . configDir , 'system.db' ) ;
364+ }
365+
366+ get erc725Identity ( ) {
367+ return JSON . parse ( fs . readFileSync ( path . join (
368+ this . options . configDir ,
369+ 'erc725_identity.json' ,
370+ ) ) ) . identity ;
371+ }
372+
304373 /**
305374 * Returns array of node IDs of nodes that confirmed possession of the data for
306375 * the given query,
0 commit comments