@@ -50,31 +50,43 @@ var sendForAWhile = (function() {
5050 var options ;
5151 var tries ;
5252 var parsedUrl ;
53+ var success ;
5354
54- var tryInform = function ( ) {
55- debug ( "inform: " + hftUrl ) ;
56- io . sendJSON ( hftUrl , data , options , function ( err ) {
57- // do I care?
58- if ( err ) {
59- ++ tries ;
60- console . error ( "Try " + tries + " of " + config . getSettings ( ) . settings . rendezvousRetryTimes + ": Could not contact: " + parsedUrl . host ) ;
61- console . error ( err ) ;
62- if ( tries <= config . getSettings ( ) . settings . rendezvousRetryTimes ) {
63- setTimeout ( tryInform , config . getSettings ( ) . settings . rendezvousRetryTimeout * 1000 ) ;
55+ var tryInform = function ( tryOptions ) {
56+ var tryUntilSuccess = function ( ) {
57+ var localOptions = JSON . parse ( JSON . stringify ( options ) ) ;
58+ localOptions . family = tryOptions . family ;
59+ debug ( "inform: " + hftUrl + " family: " + localOptions . family ) ;
60+ io . sendJSON ( hftUrl , data , localOptions , function ( err ) {
61+ // do I care?
62+ if ( err ) {
63+ ++ tries [ localOptions . family ] ;
64+ console . error ( "Try " + tries [ localOptions . family ] + " of " + config . getSettings ( ) . settings . rendezvousRetryTimes + ": Could not contact: " + parsedUrl . host + " family: " + localOptions . family ) ;
65+ console . error ( err ) ;
66+ if ( tries [ localOptions . family ] <= config . getSettings ( ) . settings . rendezvousRetryTimes ) {
67+ // If one family succeeds then the other only needs 1 try.
68+ if ( ! success ) {
69+ setTimeout ( tryUntilSuccess , config . getSettings ( ) . settings . rendezvousRetryTimeout * 1000 ) ;
70+ }
71+ }
72+ } else {
73+ success = true ;
74+ console . log ( "registered:" , data . addresses . join ( ", " ) , "with" , parsedUrl . hostname , "family:" , localOptions . family ) ;
6475 }
65- } else {
66- console . log ( "registered:" , data . addresses . join ( ", " ) , "with" , parsedUrl . hostname ) ;
67- }
68- } ) ;
76+ } ) ;
77+ } ;
78+ tryUntilSuccess ( ) ;
6979 } ;
7080
7181 return function ( _url , _data , _options ) {
7282 hftUrl = _url ;
7383 parsedUrl = url . parse ( _url ) ;
7484 data = _data ;
75- options = _options ;
76- tries = 0 ;
77- tryInform ( ) ;
85+ options = JSON . parse ( JSON . stringify ( _options ) ) ;
86+ tries = { 4 : 0 , 6 : 0 } ;
87+ success = false ;
88+ tryInform ( { family :4 } ) ;
89+ tryInform ( { family :6 } ) ;
7890 } ;
7991} ( ) ) ;
8092
@@ -96,7 +108,7 @@ var inform = (function() {
96108 lastPort = g . port ;
97109 var hftUrl = process . env . HFT_RENDEZVOUS_URL || config . getSettings ( ) . settings . rendezvousUrl ;
98110 debug ( "ping: " + hftUrl ) ;
99- var options = { headers : { } } ;
111+ var options = { headers : { } , } ;
100112 var rendezvousIp = process . env . HFT_RENDEZVOUS_IP ;
101113 if ( rendezvousIp ) {
102114 options . headers [ "x-forwarded-for" ] = rendezvousIp ;
0 commit comments