@@ -20,7 +20,7 @@ module.exports.create = function(port) {
2020 var prefix = "[server:" + port + "]" ;
2121 var index = 0 ;
2222 var log = function ( ) {
23- var date = "[" + ( new Date ( ) ) . valueOf ( ) + ":" + pad ( ( ++ index ) , 6 ) + "]" ;
23+ var date = "[" + ( new Date ( ) ) . toISOString ( ) + ":" + pad ( ( ++ index ) , 6 ) + "]" ;
2424 var args = _ . toArray ( arguments ) ;
2525 args . unshift ( prefix + date + "[" + port + "]" ) ;
2626 console . log . apply ( console , args ) ;
@@ -340,6 +340,7 @@ module.exports.create = function(port) {
340340 // then we start over
341341 if ( numAccepted >= ( numPeers / 2 + 1 ) ) {
342342 log ( "majority accepted" , accepted ) ;
343+ finalResponse ( null , { accepted : true , instance : instance } ) ;
343344 }
344345 else {
345346 log ( "majority rejected" , accepted ) ;
@@ -435,15 +436,20 @@ module.exports.create = function(port) {
435436 // We now send the ACCEPT requests to each acceptor.
436437 log ( "Proposal accepted by majority" ) ;
437438
438- // Initiate the ACCEPT phase
439- initiateAccept ( instance , proposal , value , originalValue , finalResponse ) ;
440-
441439 if ( value !== originalValue ) {
442440 // If we changed values, we still need to try and store
443441 // the original value the user sent us,
444442 // so we simply go again
445443 initiateProposal ( currentInstance ++ , originalValue , finalResponse ) ;
444+
445+ // We reset the final response in the case where the value changed,
446+ // so that we only respond for the original request coming in from the
447+ // client, not for this intermediate value we are storing
448+ finalResponse = function ( ) { } ;
446449 }
450+
451+ // Initiate the ACCEPT phase, but if we changed
452+ initiateAccept ( instance , proposal , value , originalValue , finalResponse ) ;
447453 }
448454 else {
449455 // We failed to update because somebody beat us in terms
@@ -490,9 +496,14 @@ module.exports.create = function(port) {
490496
491497 // Get the next proposal number and build the proposal
492498 var instance = currentInstance ++ ;
493- initiateProposal ( instance , value , res ) ;
494-
495- res . send ( ) ;
499+ initiateProposal ( instance , value , function ( err , result ) {
500+ if ( err ) {
501+ res . send ( err ) ;
502+ }
503+ else {
504+ res . send ( result ) ;
505+ }
506+ } ) ;
496507 } ) ;
497508
498509 app . post ( '/fetch' , function ( req , res ) {
0 commit comments