@@ -31,6 +31,7 @@ const freePort = require("portastic");
3131const Stream = require ( "stream" ) ;
3232//import * as Ping from 'net-ping'
3333const buffer_1 = require ( "buffer" ) ;
34+ const timers_1 = require ( "timers" ) ;
3435const openpgp = require ( 'openpgp' ) ;
3536const Express = require ( 'express' ) ;
3637const cookieParser = require ( 'cookie-parser' ) ;
@@ -655,7 +656,8 @@ class localServer {
655656 requestSerial : Crypto1 . randomBytes ( 8 ) . toString ( 'hex' )
656657 } ;
657658 return this . QTClass . request ( com , ( err , res ) => {
658- this . config . freeUser = / f r e e / i. test ( res . dataTransfer . productionPackage ) ;
659+ if ( res && res . dataTransfer && res . dataTransfer . productionPackage )
660+ this . config . freeUser = / f r e e / i. test ( res . dataTransfer . productionPackage ) ;
659661 CallBack ( res . Args [ 0 ] , res . dataTransfer , this . config ) ;
660662 saveLog ( `getAvaliableRegion ${ JSON . stringify ( res ) } ` ) ;
661663 // Have gateway connect!
@@ -675,32 +677,35 @@ class localServer {
675677 } ) ;
676678 socket . on ( 'pingCheck' , CallBack => {
677679 if ( process . platform === 'linux' )
678- return CallBack ( new Error ( 'not support' ) ) ;
679- saveLog ( `socket.on ( 'pingCheck' )` ) ;
680- if ( ! this . regionV1 || this . pingChecking ) {
681- saveLog ( `!this.regionV1 [${ ! this . regionV1 } ] || this.pingChecking [${ this . pingChecking } ]` ) ;
682- return CallBack ( ) ;
680+ return CallBack ( - 1 ) ;
681+ /*
682+ saveLog (`socket.on ( 'pingCheck' )`)
683+ if ( !this.regionV1 || this.pingChecking ) {
684+ saveLog (`!this.regionV1 [${ !this.regionV1 }] || this.pingChecking [${ this.pingChecking }]`)
685+ return CallBack()
683686 }
684- this . pingChecking = true ;
687+
688+ this.pingChecking = true
685689 try {
686- const netPing = require ( 'net-ping' ) ;
687- const session = netPing . createSession ( ) ;
688- }
689- catch ( ex ) {
690- console . log ( `netPing.createSession err` , ex ) ;
691- return CallBack ( - 1 ) ;
690+ const netPing = require ('net-ping')
691+ const session = netPing.createSession ()
692+ } catch (ex) {
693+ console.log (`netPing.createSession err`, ex )
694+ return CallBack ( -1 )
692695 }
693- Async . eachSeries ( this . regionV1 , ( n , next ) => {
694- return testPing ( n . testHostIp , ( err , ping ) => {
695- saveLog ( `testPing [${ n . regionName } ] return ping [${ ping } ]` ) ;
696- socket . emit ( 'pingCheck' , n . regionName , err ? 9999 : ping ) ;
697- return next ( ) ;
698- } ) ;
696+ Async.eachSeries ( this.regionV1, ( n: regionV1, next ) => {
697+
698+ return testPing ( n.testHostIp, ( err, ping ) => {
699+ saveLog( `testPing [${ n.regionName }] return ping [${ ping }]`)
700+ socket.emit ( 'pingCheck', n.regionName, err? 9999: ping )
701+ return next ()
702+ })
699703 }, () => {
700- saveLog ( `pingCheck success!` ) ;
701- this . pingChecking = false ;
702- return CallBack ( ) ;
703- } ) ;
704+ saveLog (`pingCheck success!`)
705+ this.pingChecking = false
706+ return CallBack ()
707+ })
708+ */
704709 } ) ;
705710 socket . once ( 'downloadCheck' , CallBack => {
706711 if ( ! this . regionV1 )
@@ -1539,6 +1544,7 @@ const findQTGateImap = (imapPool) => {
15391544 } ) ;
15401545} ;
15411546const sentRequestMailWaitTimeOut = 1000 * 60 * 1.5 ;
1547+ const commandRequestTimeOutTime = 1000 * 30 ;
15421548class ImapConnect extends Imap . imapPeer {
15431549 constructor ( imapData , qtGateConnectEmitData , timeOutSendRequestMail , localServer , password , _exit , socket ) {
15441550 super ( imapData , imapData . clientFolder , imapData . serverFolder , ( text , CallBack ) => {
@@ -1613,12 +1619,13 @@ class ImapConnect extends Imap.imapPeer {
16131619 }
16141620 }
16151621 }
1616- const CallBack = this . commandCallBackPool . get ( ret . requestSerial ) ;
1617- if ( ! CallBack || typeof CallBack !== 'function' ) {
1622+ const poolData = this . commandCallBackPool . get ( ret . requestSerial ) ;
1623+ if ( ! poolData || typeof poolData . CallBack !== 'function' ) {
16181624 return saveLog ( `QTGateAPIRequestCommand got commandCallBackPool ret.requestSerial [${ ret . requestSerial } ] have not callback ` ) ;
16191625 }
1626+ timers_1 . clearTimeout ( poolData . timeOut ) ;
16201627 saveLog ( `QTGateAPIRequestCommand got [${ ret . requestSerial } ] callback` ) ;
1621- return CallBack ( null , ret ) ;
1628+ return poolData . CallBack ( null , ret ) ;
16221629 } ;
16231630 }
16241631 errNumber ( err ) {
@@ -1658,15 +1665,15 @@ class ImapConnect extends Imap.imapPeer {
16581665 */
16591666 makeTimeOutEvent ( ) {
16601667 saveLog ( `doing makeTimeOutEvent` ) ;
1661- clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
1662- return this . timeOutWhenSendConnectRequestMail = setTimeout ( ( ) => {
1668+ timers_1 . clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
1669+ return this . timeOutWhenSendConnectRequestMail = timers_1 . setTimeout ( ( ) => {
16631670 saveLog ( 'timeOutWhenSendConnectRequestMail UP!' ) ;
16641671 this . socket . emit ( 'checkActiveEmailError' , 2 ) ;
16651672 } , sentRequestMailWaitTimeOut ) ;
16661673 }
16671674 doSendConnectMail ( ) {
16681675 saveLog ( `doSendConnectMail` ) ;
1669- clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
1676+ timers_1 . clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
16701677 //this.clearServerListenFolder ()
16711678 return this . localServer . sendEmailTest ( this . imapData , err => {
16721679 if ( err ) {
@@ -1681,8 +1688,15 @@ class ImapConnect extends Imap.imapPeer {
16811688 }
16821689 request ( command , CallBack ) {
16831690 saveLog ( `request command [${ command . command } ] requestSerial [${ command . requestSerial } ]` ) ;
1684- if ( command . requestSerial )
1685- this . commandCallBackPool . set ( command . requestSerial , CallBack ) ;
1691+ if ( command . requestSerial ) {
1692+ const poolData = {
1693+ CallBack : CallBack ,
1694+ timeOut : timers_1 . setTimeout ( ( ) => {
1695+ return CallBack ( new Error ( 'timeout' ) ) ;
1696+ } , commandRequestTimeOutTime )
1697+ } ;
1698+ this . commandCallBackPool . set ( command . requestSerial , poolData ) ;
1699+ }
16861700 return this . _enCrypto ( JSON . stringify ( command ) , ( err1 , data ) => {
16871701 if ( err1 ) {
16881702 saveLog ( `request _deCrypto got error [${ JSON . stringify ( err1 ) } ]` ) ;
@@ -1700,7 +1714,7 @@ class ImapConnect extends Imap.imapPeer {
17001714 return this . once ( 'ready' , ( ) => {
17011715 CallBack ( ) ;
17021716 saveLog ( 'ImapConnect got response from QTGate imap server, connect ready!' ) ;
1703- clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
1717+ timers_1 . clearTimeout ( this . timeOutWhenSendConnectRequestMail ) ;
17041718 this . QTGateServerready = true ;
17051719 this . imapData . canDoDelete = false ;
17061720 this . qtGateConnectEmitData . qtGateConnecting = 2 ;
@@ -1723,31 +1737,36 @@ class ImapConnect extends Imap.imapPeer {
17231737 return this . doReady ( socket , ( ) => { } ) ;
17241738 }
17251739}
1726- const testPing = ( hostIp , CallBack ) => {
1727- let pingTime = 0 ;
1728- const test = new Array ( testPingTimes ) ;
1729- test . fill ( hostIp ) ;
1730- saveLog ( `start testPing [${ hostIp } ]` ) ;
1731- return Async . eachSeries ( test , ( n , next ) => {
1732- const netPing = require ( 'net-ping' ) ;
1733- const session = netPing . createSession ( ) ;
1734- session . pingHost ( hostIp , ( err , target , sent , rcvd ) => {
1735- session . close ( ) ;
1736- if ( err ) {
1737- saveLog ( `session.pingHost ERROR, ${ err . message } ` ) ;
1738- return next ( err ) ;
1740+ /*
1741+ const testPing = ( hostIp: string, CallBack ) => {
1742+ let pingTime = 0
1743+ const test = new Array ( testPingTimes )
1744+ test.fill ( hostIp )
1745+ saveLog (`start testPing [${ hostIp }]`)
1746+ return Async.eachSeries ( test, ( n, next ) => {
1747+ const netPing = require ('net-ping')
1748+ const session = netPing.createSession ()
1749+ session.pingHost ( hostIp, ( err, target, sent, rcvd ) => {
1750+
1751+ session.close ()
1752+ if ( err ) {
1753+ saveLog (`session.pingHost ERROR, ${ err.message }`)
1754+ return next ( err )
17391755 }
1740- const ping = rcvd . getTime ( ) - sent . getTime ( ) ;
1741- pingTime += ping ;
1742- return next ( ) ;
1743- } ) ;
1756+ const ping = rcvd.getTime () - sent.getTime ()
1757+ pingTime += ping
1758+ return next ()
1759+ })
17441760 }, err => {
1745- if ( err ) {
1746- return CallBack ( new Error ( 'ping error' ) ) ;
1761+ if ( err ) {
1762+ return CallBack ( new Error ('ping error'))
17471763 }
1748- return CallBack ( null , Math . round ( pingTime / testPingTimes ) ) ;
1749- } ) ;
1750- } ;
1764+
1765+ return CallBack ( null, Math.round ( pingTime/testPingTimes ))
1766+ })
1767+
1768+ }
1769+ */
17511770const makeFeedBackDataToQTGateAPIRequestCommand = ( data , Callback ) => {
17521771 const ret = {
17531772 command : 'feedBackData' ,
0 commit comments