@@ -34,7 +34,7 @@ function Server(remote, opts) {
34
34
throw new TypeError ( 'Server configuration is not an Object' ) ;
35
35
}
36
36
37
- if ( ! Server . domainRE . test ( opts . host ) ) {
37
+ if ( ! Server . DOMAIN_RE . test ( opts . host ) ) {
38
38
throw new Error ( 'Server host is malformed, use "host" and "port" server configuration' ) ;
39
39
}
40
40
@@ -128,7 +128,22 @@ function Server(remote, opts) {
128
128
129
129
util . inherits ( Server , EventEmitter ) ;
130
130
131
- Server . domainRE = / ^ (? = .{ 1 , 255 } $ ) [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | [ - _ ] ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? (?: \. [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | [ - _ ] ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? ) * \. ? $ / ;
131
+ Server . DOMAIN_RE = / ^ (? = .{ 1 , 255 } $ ) [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | [ - _ ] ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? (?: \. [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | [ - _ ] ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? ) * \. ? $ / ;
132
+
133
+ Server . TLS_ERRORS = [
134
+ 'UNABLE_TO_GET_ISSUER_CERT' , 'UNABLE_TO_GET_CRL' ,
135
+ 'UNABLE_TO_DECRYPT_CERT_SIGNATURE' , 'UNABLE_TO_DECRYPT_CRL_SIGNATURE' ,
136
+ 'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY' , 'CERT_SIGNATURE_FAILURE' ,
137
+ 'CRL_SIGNATURE_FAILURE' , 'CERT_NOT_YET_VALID' , 'CERT_HAS_EXPIRED' ,
138
+ 'CRL_NOT_YET_VALID' , 'CRL_HAS_EXPIRED' , 'ERROR_IN_CERT_NOT_BEFORE_FIELD' ,
139
+ 'ERROR_IN_CERT_NOT_AFTER_FIELD' , 'ERROR_IN_CRL_LAST_UPDATE_FIELD' ,
140
+ 'ERROR_IN_CRL_NEXT_UPDATE_FIELD' , 'OUT_OF_MEM' ,
141
+ 'DEPTH_ZERO_SELF_SIGNED_CERT' , 'SELF_SIGNED_CERT_IN_CHAIN' ,
142
+ 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' , 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' ,
143
+ 'CERT_CHAIN_TOO_LONG' , 'CERT_REVOKED' , 'INVALID_CA' ,
144
+ 'PATH_LENGTH_EXCEEDED' , 'INVALID_PURPOSE' , 'CERT_UNTRUSTED' ,
145
+ 'CERT_REJECTED'
146
+ ] ;
132
147
133
148
/**
134
149
* Server states that we will treat as the server being online.
@@ -434,6 +449,11 @@ Server.prototype.connect = function() {
434
449
log . info ( self . getServerID ( ) , 'onerror:' , e . data || e ) ;
435
450
}
436
451
452
+ if ( Server . TLS_ERRORS . indexOf ( e . message ) !== - 1 ) {
453
+ // Unrecoverable
454
+ throw e ;
455
+ }
456
+
437
457
// Most connection errors for WebSockets are conveyed as 'close' events with
438
458
// code 1006. This is done for security purposes and therefore unlikely to
439
459
// ever change.
@@ -636,14 +656,21 @@ Server.prototype._handlePathFind = function(message) {
636
656
} ;
637
657
638
658
/**
639
- * Handle subscription response messages. Subscription response
640
- * messages indicate that a connection to the server is ready
659
+ * Handle initial subscription response message. The server is considered
660
+ * `connected` after it has received a response to initial subscription to
661
+ * ledger and server streams
641
662
*
642
663
* @param {Object } message
643
664
* @api private
644
665
*/
645
666
646
667
Server . prototype . _handleResponseSubscribe = function ( message ) {
668
+ if ( this . isConnected ( ) ) {
669
+ // This function only concerns initializing the server's internal
670
+ // state after a connection
671
+ return ;
672
+ }
673
+
647
674
if ( ! this . _remote . _allow_partial_history
648
675
&& ! Server . hasFullLedgerHistory ( message ) ) {
649
676
// Server has partial history and Remote has been configured to disallow
0 commit comments