@@ -84,6 +84,9 @@ var nmCln = exports = module.exports = function(options, fn){
84
84
options = { } ;
85
85
}
86
86
87
+ // check on version
88
+ self . version = 2 ;
89
+
87
90
/////////////////////////////////////////////////////////////////
88
91
// arguments check
89
92
if ( options === undefined || options . usrinfo === undefined ) {
@@ -315,8 +318,8 @@ nmCln.prototype._getValidIPAddr = function(proto, fn){
315
318
{
316
319
httpp : true , hole : { addr : laddr } ,
317
320
// SSL related info
318
- rejectUnauthorized : self . secmode ? true : false ,
319
- ca : self . secmode ? vCA : false ,
321
+ /// rejectUnauthorized: self.secmode ? true : false,
322
+ /// ca: self.secmode ? vCA : false,
320
323
321
324
// NACL cert info
322
325
naclinfo : {
@@ -335,12 +338,15 @@ nmCln.prototype._getValidIPAddr = function(proto, fn){
335
338
if ( Debug ) console . log ( 'connect to NS from ' + laddr + ' ... timeout' ) ;
336
339
} , 2000 ) ; // 2s timeout
337
340
338
- nscon . once ( 'open' , function ( ) {
341
+ nscon . on ( 'open' , function ( ) {
339
342
clearTimeout ( nstmo ) ;
340
343
fn ( 1 , laddr ) ;
341
344
nscon . close ( ) ;
342
345
///console.log('connect to NS from '+laddr+' ... ok');
343
346
} ) ;
347
+ nscon . on ( 'error' , function ( err ) {
348
+ console . log ( 'connect to NS from ' + laddr + ' ... err:' + err ) ;
349
+ } ) ;
344
350
}
345
351
346
352
// 0.2
@@ -407,8 +413,8 @@ nmCln.prototype._LSM_connectTurnAgent = function(fn, tmo){
407
413
{
408
414
httpp : true , hole : { port : self . port , addr : self . ipaddr } ,
409
415
// SSL related info
410
- rejectUnauthorized : self . secmode ? true : false ,
411
- ca : self . secmode ? vCA : false ,
416
+ /// rejectUnauthorized: self.secmode ? true : false,
417
+ /// ca: self.secmode ? vCA : false,
412
418
413
419
// NACL cert info
414
420
naclinfo : {
@@ -432,7 +438,7 @@ nmCln.prototype._LSM_connectTurnAgent = function(fn, tmo){
432
438
fn ( 'connect TURN agent server timeout' ) ;
433
439
} , ( tmo || 30 ) * 1000 ) ; // 30s timeout in default
434
440
435
- self . turnagentConn . once ( 'open' , function ( ) {
441
+ self . turnagentConn . on ( 'open' , function ( ) {
436
442
if ( Debug ) console . log ( 'connected to turn agent server successfully' ) ;
437
443
438
444
// 1.1
@@ -533,7 +539,7 @@ nmCln.prototype._LSM_connectTurnAgent = function(fn, tmo){
533
539
534
540
// 4.
535
541
// handle close event with reconnect
536
- self . turnagentConn . once ( 'close' , function ( ) {
542
+ self . turnagentConn . on ( 'close' , function ( ) {
537
543
if ( Debug ) console . log ( 'turn agent client closed' ) ;
538
544
539
545
// 4.1
@@ -612,7 +618,7 @@ nmCln.prototype._LSM_setupSdpSession = function() {
612
618
// 2.1.2
613
619
// enable vURL if TURN ready
614
620
if ( self . turnagentReady ) {
615
- var vurlproto = 'https://' ;
621
+ var vurlproto = self . secmode ? 'https://' : 'http ://';
616
622
617
623
if ( self . vmode === vURL . URL_MODE_PATH ) {
618
624
// vpath-based turn vURL
@@ -683,6 +689,9 @@ nmCln.prototype._LSM_setupSdpSession = function() {
683
689
// 2.2
684
690
// return sdp info to user
685
691
rsdp = {
692
+ // protocol info
693
+ version : self . version ,
694
+
686
695
// GID of name-client
687
696
gid : self . gid ,
688
697
vpath : self . vpath ,
@@ -988,8 +997,8 @@ nmCln.prototype._LSM_setupSdpSession = function() {
988
997
{
989
998
httpp : true , hole : { addr : self . ipaddr , port : self . port } ,
990
999
// SSL related info
991
- rejectUnauthorized : self . secmode ? true : false ,
992
- ca : self . secmode ? vCA : false ,
1000
+ /// rejectUnauthorized: self.secmode ? true : false,
1001
+ /// ca: self.secmode ? vCA : false,
993
1002
994
1003
// NACL cert info
995
1004
naclinfo : {
@@ -1008,8 +1017,8 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1008
1017
{
1009
1018
httpp : true , hole : { addr : self . ipaddr } ,
1010
1019
// SSL related info
1011
- rejectUnauthorized : self . secmode ? true : false ,
1012
- ca : self . secmode ? vCA : false ,
1020
+ /// rejectUnauthorized: self.secmode ? true : false,
1021
+ /// ca: self.secmode ? vCA : false,
1013
1022
1014
1023
// NACL cert info
1015
1024
naclinfo : {
@@ -1048,7 +1057,7 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1048
1057
}
1049
1058
} , ( self . srvinfo . timeout || 20 ) * 1000 ) ; // 20s timeout in default
1050
1059
1051
- conn . once ( 'open' , function ( ) {
1060
+ conn . on ( 'open' , function ( ) {
1052
1061
///console.log('connection to the first name-server');
1053
1062
1054
1063
// increase opened client count
@@ -1060,17 +1069,17 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1060
1069
1061
1070
// 3.
1062
1071
// record binding on port/ip/fd, then start alternate connections
1063
- self . fd = conn . _socket . address ( ) . fd ;
1064
- self . port = conn . _socket . address ( ) . port ;
1072
+ self . fd = conn . address ( ) . fd ;
1073
+ self . port = conn . address ( ) . port ;
1065
1074
if ( Debug ) console . log ( 'nmclnt binding on %s:%d with fd:%d' , self . ipaddr , self . port , self . fd ) ;
1066
1075
1067
1076
for ( var i = 1 ; i < self . srvs . length ; i ++ ) {
1068
1077
var connalt = new SecureWebSocket ( wsproto + self . srvs [ i ] . ip + ':' + self . srvs [ i ] . port + SEP . SEP_CTRLPATH_NS ,
1069
1078
{
1070
1079
httpp : true , hole : { port : self . port , addr : self . ipaddr } ,
1071
1080
// SSL related info
1072
- rejectUnauthorized : self . secmode ? true : false ,
1073
- ca : self . secmode ? vCA : false ,
1081
+ /// rejectUnauthorized: self.secmode ? true : false,
1082
+ /// ca: self.secmode ? vCA : false,
1074
1083
1075
1084
// NACL cert info
1076
1085
naclinfo : {
@@ -1093,7 +1102,7 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1093
1102
1094
1103
// 4.
1095
1104
// all connection ready, then emit nmCln ready event
1096
- connalt . once ( 'open' , function ( ) {
1105
+ connalt . on ( 'open' , function ( ) {
1097
1106
// increase opened connection count
1098
1107
self . ocnt ++ ;
1099
1108
@@ -1128,7 +1137,7 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1128
1137
1129
1138
// 6.
1130
1139
// handle close event with reconnect
1131
- connalt . once ( 'close' , function ( ) {
1140
+ connalt . on ( 'close' , function ( ) {
1132
1141
if ( Debug ) console . log ( 'name-server alternate client close' ) ;
1133
1142
1134
1143
// 6
@@ -1148,7 +1157,7 @@ nmCln.prototype._LSM_setupSdpSession = function() {
1148
1157
conn . on ( 'message' , onMessage ) ;
1149
1158
1150
1159
// on close with reconnect
1151
- conn . once ( 'close' , function ( ) {
1160
+ conn . on ( 'close' , function ( ) {
1152
1161
if ( Debug ) console . log ( 'name-server primary client close' ) ;
1153
1162
1154
1163
// trigger reconnect event
@@ -1277,13 +1286,13 @@ nmCln.prototype._LSM_setupBusinessServer = function(){
1277
1286
1278
1287
self . bsrv . hpsrv . on ( 'connection' , function ( client ) {
1279
1288
console . log ( 'new ws connection: ' +
1280
- client . _socket . remoteAddress + ':' + client . _socket . remotePort + ' -> ' +
1281
- client . _socket . address ( ) . address + ':' + client . _socket . address ( ) . port ) ;
1289
+ client . remoteAddress + ':' + client . remotePort + ' -> ' +
1290
+ client . address ( ) . address + ':' + client . address ( ) . port ) ;
1282
1291
1283
1292
// 1.2.2
1284
1293
// send peer's connection info back
1285
1294
try {
1286
- var coninfo = { peeraddr : client . _socket . remoteAddress , peerport : client . _socket . remotePort } ;
1295
+ var coninfo = { peeraddr : client . remoteAddress , peerport : client . remotePort } ;
1287
1296
1288
1297
// V2 use msgpack
1289
1298
client . send ( MSGPACK . encode ( coninfo ) , { binary : true , mask : false } , function ( err ) {
@@ -1307,7 +1316,7 @@ nmCln.prototype._LSM_setupBusinessServer = function(){
1307
1316
clearTimeout ( clrtmo ) ; clrtmo = null ;
1308
1317
}
1309
1318
} ) ;
1310
- client . once ( 'close' , function ( ) {
1319
+ client . on ( 'close' , function ( ) {
1311
1320
if ( Debug ) console . log ( 'hole-punch client closed' ) ;
1312
1321
1313
1322
if ( clrtmo ) {
@@ -1469,7 +1478,7 @@ nmCln.prototype.createConnection = function(to, fn){
1469
1478
conn . close ( ) ;
1470
1479
} , ( to . timeout || 10 ) * 1000 ) ; // 10s timeout in default
1471
1480
1472
- conn . once ( 'open' , function ( ) {
1481
+ conn . on ( 'open' , function ( ) {
1473
1482
clearTimeout ( t ) ;
1474
1483
fn ( null , conn ) ;
1475
1484
@@ -1486,7 +1495,7 @@ nmCln.prototype.createConnection = function(to, fn){
1486
1495
console . error ( 'new peer connection failure to ' + JSON . stringify ( peer ) + err ) ;
1487
1496
} ) ;
1488
1497
1489
- conn . once ( 'close' , function ( ) {
1498
+ conn . on ( 'close' , function ( ) {
1490
1499
// TBD...
1491
1500
/*if (self.peer[JSON.stringify(conn.peer)]) {
1492
1501
self.peer[JSON.stringify(conn.peer)] = null;
@@ -1601,7 +1610,7 @@ nmCln.prototype.punchHole = function(to, fn){
1601
1610
( to . isInitiator ) ? 'initiator' : 'peer' ) ;
1602
1611
} , ( to . timeout || 6 ) * 1000 ) ; // 6s timeout in default
1603
1612
1604
- conn . once ( 'open' , function ( ) {
1613
+ conn . on ( 'open' , function ( ) {
1605
1614
clearTimeout ( t ) ;
1606
1615
1607
1616
console . log ( 'punch hole successfully in %s mode from %s' ,
@@ -1618,8 +1627,8 @@ nmCln.prototype.punchHole = function(to, fn){
1618
1627
1619
1628
// 1.3.1
1620
1629
// pass connection external ip/port info back to name-server
1621
- fn ( null , { moaddr : coninfo . peerip , moport : coninfo . peerport ,
1622
- poaddr : conn . _socket . remoteAddress , poport : conn . _socket . remotePort } ) ;
1630
+ fn ( null , { moaddr : coninfo . peerip , moport : coninfo . peerport ,
1631
+ poaddr : conn . remoteAddress , poport : conn . remotePort } ) ;
1623
1632
1624
1633
// 1.3.2
1625
1634
// maintain or close hole-punch connection
@@ -1670,7 +1679,7 @@ nmCln.prototype.punchHole = function(to, fn){
1670
1679
( to . isInitiator ) ? 'initiator' : 'peer' ) ;
1671
1680
} ) ;
1672
1681
1673
- conn . once ( 'close' , function ( ) {
1682
+ conn . on ( 'close' , function ( ) {
1674
1683
if ( Debug )
1675
1684
console . log ( 'punch hole closed in %s mode from %s' ,
1676
1685
( to . mode === SEP . SEP_MODE_PP ) ? 'p2p' : 'c/s' ,
@@ -1790,7 +1799,7 @@ nmCln.prototype.punchHole = function(to, fn){
1790
1799
( to . isInitiator ) ? 'initiator' : 'peer' ) ;
1791
1800
} , ( to . timeout || 6 ) * 1000 ) ; // 6s timeout in default
1792
1801
1793
- conn . once ( 'open' , function ( ) {
1802
+ conn . on ( 'open' , function ( ) {
1794
1803
clearTimeout ( t ) ;
1795
1804
1796
1805
console . log ( 'punch hole successfully in %s mode from %s @symmetric' ,
@@ -1807,8 +1816,8 @@ nmCln.prototype.punchHole = function(to, fn){
1807
1816
1808
1817
// 2.1.4.1
1809
1818
// pass connection external ip/port info back to name-server
1810
- fn ( null , { moaddr : coninfo . peerip , moport : coninfo . peerport ,
1811
- poaddr : conn . _socket . remoteAddress , poport : conn . _socket . remotePort } ) ;
1819
+ fn ( null , { moaddr : coninfo . peerip , moport : coninfo . peerport ,
1820
+ poaddr : conn . remoteAddress , poport : conn . remotePort } ) ;
1812
1821
1813
1822
// 2.1.4.2
1814
1823
// maintain or close hole-punch connection
@@ -1859,7 +1868,7 @@ nmCln.prototype.punchHole = function(to, fn){
1859
1868
( to . isInitiator ) ? 'initiator' : 'peer' ) ;
1860
1869
} ) ;
1861
1870
1862
- conn . once ( 'close' , function ( ) {
1871
+ conn . on ( 'close' , function ( ) {
1863
1872
if ( Debug )
1864
1873
console . log ( 'punch hole closed in %s mode from %s @symmetric' ,
1865
1874
( to . mode === SEP . SEP_MODE_PP ) ? 'p2p' : 'c/s' ,
@@ -2328,9 +2337,7 @@ nmCln.prototype.sendOpcMsg = function(opc_msg, fn){
2328
2337
var con0 = JSON . stringify ( self . srvs [ 0 ] ) ; // connection to the first name-server
2329
2338
2330
2339
// check connection status
2331
- if ( ( self . conn [ con0 ] && self . conn [ con0 ] . socket ) &&
2332
- ( self . conn [ con0 ] . socket . readyState != undefined ) &&
2333
- ( self . conn [ con0 ] . socket . readyState === self . conn [ con0 ] . socket . OPEN ) ) {
2340
+ if ( self . conn [ con0 ] && self . conn [ con0 ] . socket ) {
2334
2341
// send opc message
2335
2342
try {
2336
2343
// fill offer message count as sequence number
0 commit comments