whatap 0.5.26 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/darwin/arm64/whatap_nodejs +0 -0
- package/agent/linux/amd64/whatap_nodejs +0 -0
- package/agent/linux/arm64/whatap_nodejs +0 -0
- package/build.txt +4 -0
- package/lib/conf/config-default.js +3 -10
- package/lib/conf/configure.js +349 -369
- package/lib/conf/license.js +1 -1
- package/lib/control/packagectr-helper.js +3 -34
- package/lib/core/agent.js +882 -176
- package/lib/core/interceptor.js +6 -6
- package/lib/core/shimmer.js +36 -82
- package/lib/counter/counter-manager.js +8 -79
- package/lib/counter/task/activetransaction.js +17 -68
- package/lib/io/data-inputx.js +3 -13
- package/lib/io/data-outputx.js +206 -268
- package/lib/logger.js +6 -6
- package/lib/net/security-master.js +20 -139
- package/lib/observers/apollo-server-observer.js +27 -33
- package/lib/observers/global-observer.js +80 -155
- package/lib/observers/http-observer.js +236 -666
- package/lib/observers/ioredis-observer.js +294 -0
- package/lib/observers/maria-observer.js +362 -204
- package/lib/observers/mongodb-observer.js +226 -169
- package/lib/observers/mongoose-observer.js +323 -518
- package/lib/observers/mssql-observer.js +418 -177
- package/lib/observers/mysql-observer.js +449 -342
- package/lib/observers/mysql2-observer.js +358 -396
- package/lib/observers/oracle-observer.js +384 -559
- package/lib/observers/pgsql-observer.js +489 -231
- package/lib/observers/prisma-observer.js +92 -303
- package/lib/observers/process-observer.js +35 -79
- package/lib/observers/redis-observer.js +331 -166
- package/lib/observers/socket.io-observer.js +187 -226
- package/lib/observers/websocket-observer.js +301 -175
- package/lib/pack/counter-pack.js +0 -3
- package/lib/pack/log-sink-pack.js +52 -14
- package/lib/pack/tagcount-pack.js +4 -4
- package/lib/{counter/task → system}/gc-action.js +74 -27
- package/lib/trace/trace-context-manager.js +25 -113
- package/lib/trace/trace-context.js +7 -21
- package/lib/trace/trace-httpc.js +11 -17
- package/lib/trace/trace-sql.js +21 -29
- package/lib/udp/async_sender.js +119 -0
- package/lib/udp/index.js +17 -0
- package/lib/udp/packet_enum.js +52 -0
- package/lib/udp/packet_queue.js +69 -0
- package/lib/udp/packet_type_enum.js +33 -0
- package/lib/udp/param_def.js +72 -0
- package/lib/udp/udp_session.js +336 -0
- package/lib/util/escape-literal-sql.js +5 -5
- package/lib/util/hashutil.js +18 -18
- package/lib/util/keygen.js +3 -0
- package/lib/util/linkedset.js +2 -1
- package/lib/util/nodeutil.js +1 -2
- package/lib/util/sql-util.js +178 -0
- package/lib/util/trace-helper.js +91 -0
- package/lib/util/transfer.js +58 -0
- package/lib/value/map-value.js +2 -3
- package/package.json +5 -10
- package/lib/conf/conf-sys-mon.js +0 -101
- package/lib/control/cmd-config.js +0 -24
- package/lib/control/control-handler.js +0 -367
- package/lib/core/request-agent.js +0 -27
- package/lib/counter/meter/meter-activex.js +0 -67
- package/lib/counter/meter/meter-httpc.js +0 -57
- package/lib/counter/meter/meter-resource.js +0 -9
- package/lib/counter/meter/meter-service.js +0 -168
- package/lib/counter/meter/meter-socket.io.js +0 -51
- package/lib/counter/meter/meter-sql.js +0 -71
- package/lib/counter/meter/meter-users.js +0 -58
- package/lib/counter/meter.js +0 -183
- package/lib/counter/task/agentinfo.js +0 -107
- package/lib/counter/task/gcstat.js +0 -34
- package/lib/counter/task/heapmem.js +0 -25
- package/lib/counter/task/httpc.js +0 -76
- package/lib/counter/task/metering-info.js +0 -125
- package/lib/counter/task/proc-cpu.js +0 -29
- package/lib/counter/task/realtimeuser.js +0 -31
- package/lib/counter/task/res/systemECSTask.js +0 -39
- package/lib/counter/task/res/systemKubeTask.js +0 -53
- package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
- package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
- package/lib/counter/task/res-sys-cpu.js +0 -62
- package/lib/counter/task/service.js +0 -202
- package/lib/counter/task/socketio.js +0 -30
- package/lib/counter/task/sql.js +0 -105
- package/lib/counter/task/systemperf.js +0 -43
- package/lib/data/datapack-sender.js +0 -289
- package/lib/data/dataprofile-agent.js +0 -162
- package/lib/data/datatext-agent.js +0 -135
- package/lib/data/event-level.js +0 -15
- package/lib/data/test.js +0 -49
- package/lib/data/zipprofile.js +0 -197
- package/lib/env/constants.js +0 -21
- package/lib/error/error-handler.js +0 -437
- package/lib/kube/kube-client.js +0 -144
- package/lib/lang/text-types.js +0 -58
- package/lib/logsink/line-log-util.js +0 -87
- package/lib/logsink/line-log.js +0 -12
- package/lib/logsink/log-sender.js +0 -78
- package/lib/logsink/log-tracer.js +0 -40
- package/lib/logsink/sender-util.js +0 -56
- package/lib/logsink/zip/zip-send.js +0 -177
- package/lib/net/netflag.js +0 -55
- package/lib/net/receiver.js +0 -66
- package/lib/net/sender.js +0 -141
- package/lib/net/tcp-return.js +0 -18
- package/lib/net/tcp-session.js +0 -286
- package/lib/net/tcpreq-client-proxy.js +0 -70
- package/lib/net/tcprequest-mgr.js +0 -58
- package/lib/observers/cluster-observer.js +0 -22
- package/lib/observers/express-observer.js +0 -215
- package/lib/observers/file-observer.js +0 -184
- package/lib/observers/grpc-observer.js +0 -336
- package/lib/observers/memcached-observer.js +0 -56
- package/lib/observers/mongo-observer.js +0 -317
- package/lib/observers/net-observer.js +0 -77
- package/lib/observers/promise-observer.js +0 -31
- package/lib/observers/schedule-observer.js +0 -67
- package/lib/observers/stream-observer.js +0 -19
- package/lib/observers/thrift-observer.js +0 -197
- package/lib/pack/activestack-pack.js +0 -55
- package/lib/pack/apenum.js +0 -8
- package/lib/pack/errorsnap-pack.js +0 -69
- package/lib/pack/event-pack.js +0 -54
- package/lib/pack/hitmap-pack.js +0 -63
- package/lib/pack/hitmap-pack1.js +0 -152
- package/lib/pack/netstat.js +0 -15
- package/lib/pack/otype.js +0 -7
- package/lib/pack/profile-pack.js +0 -49
- package/lib/pack/realtimeuser-pack.js +0 -41
- package/lib/pack/stat-general-pack.js +0 -96
- package/lib/pack/staterror-pack.js +0 -120
- package/lib/pack/stathttpc-pack.js +0 -66
- package/lib/pack/stathttpc-rec.js +0 -78
- package/lib/pack/statremote-pack.js +0 -46
- package/lib/pack/statservice-pack.js +0 -63
- package/lib/pack/statservice-pack1.js +0 -88
- package/lib/pack/statservice-rec.js +0 -292
- package/lib/pack/statservice-rec_dep.js +0 -151
- package/lib/pack/statsql-pack.js +0 -69
- package/lib/pack/statsql-rec.js +0 -100
- package/lib/pack/statuseragent-pack.js +0 -44
- package/lib/pack/tagctr.js +0 -15
- package/lib/pack/text-pack.js +0 -50
- package/lib/pack/time-count.js +0 -25
- package/lib/pack/websocket.js +0 -15
- package/lib/pack/zip-pack.js +0 -70
- package/lib/pii/pii-item.js +0 -31
- package/lib/pii/pii-mask.js +0 -174
- package/lib/plugin/plugin-loadermanager.js +0 -57
- package/lib/plugin/plugin.js +0 -75
- package/lib/service/tx-record.js +0 -332
- package/lib/stat/stat-error.js +0 -116
- package/lib/stat/stat-httpc.js +0 -98
- package/lib/stat/stat-remote-ip.js +0 -46
- package/lib/stat/stat-remote-ipurl.js +0 -88
- package/lib/stat/stat-sql.js +0 -113
- package/lib/stat/stat-tranx.js +0 -58
- package/lib/stat/stat-tx-caller.js +0 -160
- package/lib/stat/stat-tx-domain.js +0 -111
- package/lib/stat/stat-tx-referer.js +0 -112
- package/lib/stat/stat-useragent.js +0 -48
- package/lib/stat/timingsender.js +0 -76
- package/lib/step/activestack-step.js +0 -38
- package/lib/step/dbc-step.js +0 -36
- package/lib/step/http-stepx.js +0 -67
- package/lib/step/message-step.js +0 -40
- package/lib/step/method-stepx.js +0 -45
- package/lib/step/resultset-step.js +0 -40
- package/lib/step/securemsg-step.js +0 -44
- package/lib/step/socket-step.js +0 -46
- package/lib/step/sql-stepx.js +0 -68
- package/lib/step/sqlxtype.js +0 -16
- package/lib/step/step.js +0 -66
- package/lib/step/stepenum.js +0 -54
- package/lib/topology/link.js +0 -63
- package/lib/topology/nodeinfo.js +0 -123
- package/lib/topology/status-detector.js +0 -111
- package/lib/util/anylist.js +0 -103
- package/lib/util/cardinality/hyperloglog.js +0 -106
- package/lib/util/cardinality/murmurhash.js +0 -31
- package/lib/util/cardinality/registerset.js +0 -75
- package/lib/util/errordata.js +0 -21
- package/lib/util/iputil_x.js +0 -527
- package/lib/util/kube-util.js +0 -73
- package/lib/util/paramsecurity.js +0 -80
- package/lib/util/pre-process.js +0 -13
- package/lib/util/process-seq.js +0 -166
- package/lib/util/property-util.js +0 -36
- package/lib/util/request-queue.js +0 -70
- package/lib/util/requestdouble-queue.js +0 -72
- package/lib/util/resourceprofile.js +0 -157
- package/lib/util/stop-watch.js +0 -30
- package/lib/util/system-util.js +0 -10
- package/lib/util/userid-util.js +0 -57
package/lib/net/sender.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
-
* Use of this source code is governed by a license that
|
|
4
|
-
* can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var conf = require('./../conf/configure'),
|
|
8
|
-
DataOutputX = require('./../io/data-outputx'),
|
|
9
|
-
EventPack = require('./../pack/event-pack'),
|
|
10
|
-
PackEnum = require('./../pack/packenum'),
|
|
11
|
-
EventLevel = require('./../data/event-level'),
|
|
12
|
-
NetFlag = require('./netflag').NetFlag,
|
|
13
|
-
TcpSession = require('./tcp-session'),
|
|
14
|
-
Logger = require('../logger'),
|
|
15
|
-
Long = require('long');
|
|
16
|
-
|
|
17
|
-
var Sender = function(agent, requestMgr){
|
|
18
|
-
this._agent = agent;
|
|
19
|
-
this._mgr = requestMgr;
|
|
20
|
-
this.next_time_sync = Date.now() + conf.getProperty('time_sync_interval_ms', 300000);
|
|
21
|
-
this.isProcessing = false;
|
|
22
|
-
this.ddd=Date.now()%100000;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
Sender.prototype.startCheckQueue = function(){
|
|
26
|
-
var self = this;
|
|
27
|
-
if(this._interval) return;
|
|
28
|
-
this.cypher_level = conf.cypher_level;
|
|
29
|
-
this._interval = setInterval(function(){
|
|
30
|
-
self.start();
|
|
31
|
-
}, 100, 'whatap');
|
|
32
|
-
};
|
|
33
|
-
Sender.prototype.stopCheckQueue = function(){
|
|
34
|
-
if(this._interval){
|
|
35
|
-
clearInterval(this._interval);
|
|
36
|
-
delete this._interval;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
Sender.prototype.start = function(){
|
|
40
|
-
var self = this;
|
|
41
|
-
this.isProcessing = true;
|
|
42
|
-
var hasNext = self._mgr.pool.hasNext();
|
|
43
|
-
|
|
44
|
-
if(!hasNext) {
|
|
45
|
-
if(this._interval){
|
|
46
|
-
return ;
|
|
47
|
-
}else{
|
|
48
|
-
this.startCheckQueue();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
this.stopCheckQueue();
|
|
52
|
-
self.send();
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
Sender.prototype.send = function(){
|
|
57
|
-
var self = this;
|
|
58
|
-
var w = TcpSession;
|
|
59
|
-
var p = self._mgr.pool.get();
|
|
60
|
-
if(p == null) {return this.startCheckQueue();}
|
|
61
|
-
if(w.out == null) {return this.startCheckQueue();}
|
|
62
|
-
|
|
63
|
-
if(this.cypher_level != conf.cypher_level) {
|
|
64
|
-
this.cypher_level = conf.cypher_level;
|
|
65
|
-
w.close();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
var len = 0;
|
|
69
|
-
try{
|
|
70
|
-
var now = Date.now();
|
|
71
|
-
if( now > self.next_time_sync ){
|
|
72
|
-
self.next_time_sync = now + conf.getProperty('time_sync_interval_ms', 300000);
|
|
73
|
-
w.send(NetFlag.TIME_SYNC, DataOutputX.toBytesLong(Long.fromValue(now)));
|
|
74
|
-
}
|
|
75
|
-
if(conf.debug_tcpsend){
|
|
76
|
-
try{
|
|
77
|
-
var qsize=JSON.stringify(self._mgr.pool.size());
|
|
78
|
-
var packName= PackEnum.PACK_NAME[p.pack.getPackType()] ;
|
|
79
|
-
var m = packName + "\t" +qsize;
|
|
80
|
-
Logger.printAll("TCPSEND", m);
|
|
81
|
-
}catch(e){
|
|
82
|
-
Logger.printError('WHATAP-251', 'Sender(send)', e);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
p.pack.apType = 2;
|
|
87
|
-
|
|
88
|
-
if(conf.cypher_level == 0){
|
|
89
|
-
var b = DataOutputX.toBytesPack(p.pack);
|
|
90
|
-
w.send(p.flag, b);
|
|
91
|
-
len = b.length;
|
|
92
|
-
} else {
|
|
93
|
-
switch( NetFlag.getSecureMask(p.flag) ) {
|
|
94
|
-
case NetFlag.SECURE_HIDE:
|
|
95
|
-
if(conf.cypher != null){
|
|
96
|
-
var b = DataOutputX.toBytesPack(p.pack);
|
|
97
|
-
b = conf.cypher.hide(b);
|
|
98
|
-
len = b.length;
|
|
99
|
-
w.send(p.flag, b);
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case NetFlag.SECURE_CYPHER:
|
|
103
|
-
if(conf.cypher !== null){
|
|
104
|
-
var b = DataOutputX.toBytesPack(p.pack, conf.cypher_level / 8);
|
|
105
|
-
b = conf.cypher.encryptBlock(b);
|
|
106
|
-
len = b.length;
|
|
107
|
-
w.send(p.flag, b);
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
default:
|
|
111
|
-
var b = DataOutputX.toBytesPack(p.pack);
|
|
112
|
-
w.send(p.flag, b);
|
|
113
|
-
len = b.length;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if(len > conf.net_send_max_bytes){
|
|
119
|
-
var e = new EventPack();
|
|
120
|
-
e.level = EventLevel.FATAL;
|
|
121
|
-
errorOverflow(p.pack.constructor + '('+ p.pack.getPackType() + ')');
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
self._mgr.sendBytes += len;
|
|
126
|
-
self._mgr.sendPack++;
|
|
127
|
-
} catch(e) {
|
|
128
|
-
Logger.printError('WHATAP-121', 'Sender error', e);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
process.nextTick(function(){
|
|
132
|
-
self.start();
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
var errorOverflow = function(packName){
|
|
136
|
-
var e = new EventPack();
|
|
137
|
-
e.title = "NEW_OVERFLOW";
|
|
138
|
-
e.message = "Too big data: " + packName;
|
|
139
|
-
};
|
|
140
|
-
//PackEnum.PACK_NAME[p.pack.getPackType()]
|
|
141
|
-
module.exports = Sender;
|
package/lib/net/tcp-return.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
-
* Use of this source code is governed by a license that
|
|
4
|
-
* can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function TcpReturn() {
|
|
8
|
-
this.code = 0;
|
|
9
|
-
this.data = null; /*Buffer*/
|
|
10
|
-
this.transfer_key = 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
TcpReturn.prototype.toString = function () {
|
|
14
|
-
return "TcpReturn [code=" + this.code + ", transfer_key=" + this.transfer_key + ", data="
|
|
15
|
-
+ (this.data != null ? this.data.toString('hex') : null) + "]";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = TcpReturn;
|
package/lib/net/tcp-session.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
-
* Use of this source code is governed by a license that
|
|
4
|
-
* can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var net = require('net'),
|
|
8
|
-
netflag = require('./netflag').NetFlag,
|
|
9
|
-
netsrc = require('./netflag').NetSrc,
|
|
10
|
-
secu = require('./security-master'),
|
|
11
|
-
conf = require('./../conf/configure'),
|
|
12
|
-
DataOutputX = require('./../io/data-outputx'),
|
|
13
|
-
DataInputX = require('./../io/data-inputx'),
|
|
14
|
-
IPUtil = require('./../util/iputil'),
|
|
15
|
-
TcpReturn = require('./tcp-return'),
|
|
16
|
-
Receiver = require('./receiver'),
|
|
17
|
-
OidUtil = require('../util/oidutil'),
|
|
18
|
-
Logger = require('../logger'),
|
|
19
|
-
Long = require('long');
|
|
20
|
-
|
|
21
|
-
function TcpSession() {
|
|
22
|
-
if(typeof TcpSession.instance === 'object') {
|
|
23
|
-
return TcpSession.instance;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.in = null;
|
|
27
|
-
this.out = null;
|
|
28
|
-
this.receiver = new Receiver();
|
|
29
|
-
this._cb = null;
|
|
30
|
-
this.reconnectCnt = 0;
|
|
31
|
-
TcpSession.instance = this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
TcpSession.prototype.open = function(cb){
|
|
35
|
-
var self = this;
|
|
36
|
-
|
|
37
|
-
if(cb) this._cb = cb;
|
|
38
|
-
|
|
39
|
-
self.auto_oname_reset = conf.auto_oname_reset;
|
|
40
|
-
if(secu.PCODE == null || secu.PCODE === 0) {
|
|
41
|
-
if(cb) return cb(new Error('PCODE is not defined..'));
|
|
42
|
-
}
|
|
43
|
-
if(this.isOpen()) {
|
|
44
|
-
++self.reconnectCnt;
|
|
45
|
-
if(self.reconnectCnt >= 3) {
|
|
46
|
-
self.close();
|
|
47
|
-
}
|
|
48
|
-
return cb(new Error('Already connected..'));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var host = conf.getWhatapServerHost();
|
|
52
|
-
var port = conf.whatap_server_port || 6600;
|
|
53
|
-
var connection_timeout = conf.tcp_connection_timeout;
|
|
54
|
-
|
|
55
|
-
var options = {
|
|
56
|
-
host: host,
|
|
57
|
-
port: port
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
Logger.print('WHATAP-180', "Try to connect to " + JSON.stringify(options), false);
|
|
61
|
-
this.out = net.connect(options, function() {
|
|
62
|
-
var localAddr = (this.localAddress || IPUtil.getIp());
|
|
63
|
-
|
|
64
|
-
if(conf.auto_oname_enabled === true) {
|
|
65
|
-
var oname = conf["whatap.oname"];
|
|
66
|
-
if((oname == null || oname.length === 0)
|
|
67
|
-
&& self.auto_oname_reset === conf.auto_oname_reset) {
|
|
68
|
-
self.prepareAutoOnameByServer(localAddr);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
secu.decideAgentOnameOid(localAddr);
|
|
74
|
-
if(conf.cipher_net_enabled){
|
|
75
|
-
try {
|
|
76
|
-
self.out.write( self.keyReset() );
|
|
77
|
-
} catch(e) {
|
|
78
|
-
Logger.printError("WHATAP-125", "KeyReset " + host + ":" + port, e, true);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
this.out.setKeepAlive(true , 60000);
|
|
84
|
-
this.out.setTimeout(connection_timeout);
|
|
85
|
-
|
|
86
|
-
this.out.on('error', function (err) {
|
|
87
|
-
Logger.printError("WHATAP-127", 'Failed to connect to ' + JSON.stringify(options), err);
|
|
88
|
-
self.close();
|
|
89
|
-
cb(err);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
this.out.on('timeout' , function () {
|
|
93
|
-
Logger.print("WHATAP-184", "Socket timeout. WhaTap will retry connect after " + (connection_timeout/1000) + " sec.", false);
|
|
94
|
-
self.close();
|
|
95
|
-
setTimeout(function() {
|
|
96
|
-
self.open(cb);
|
|
97
|
-
} , 500);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
var firstReceived = false;
|
|
101
|
-
this.out.on('data', function(data) {
|
|
102
|
-
if(self.PREPARE_AGENT) {
|
|
103
|
-
var din = new DataInputX(data);
|
|
104
|
-
var source = din.readByte();
|
|
105
|
-
var code = din.readByte();
|
|
106
|
-
var pcode = din.readLong();
|
|
107
|
-
var oid = din.readInt();
|
|
108
|
-
var transfer_key = din.readInt();
|
|
109
|
-
var _data = din.readIntBytes(8 * 1024 * 1024);
|
|
110
|
-
if (conf.cypher_level > 0) {
|
|
111
|
-
_data = secu.cypher.decrypt(_data);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
var oname = new DataInputX(_data).readText();
|
|
115
|
-
|
|
116
|
-
var localAddr = (this.localAddress || IPUtil.getIp());
|
|
117
|
-
secu.setAgentOnameOid(oname, localAddr);
|
|
118
|
-
self.PREPARE_AGENT = false;
|
|
119
|
-
if(conf.cipher_net_enabled) {
|
|
120
|
-
try {
|
|
121
|
-
self.out.write( self.keyReset() );
|
|
122
|
-
} catch(e) {
|
|
123
|
-
Logger.printError("WHATAP-125", "KeyReset " + host + ":" + port, e, true);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if(firstReceived) {
|
|
130
|
-
self.read(data);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
var d = self.readKeyReset(data);
|
|
134
|
-
if( d && d.length != 0 ) {
|
|
135
|
-
conf.updateNetCypherKey(d);
|
|
136
|
-
firstReceived = true;
|
|
137
|
-
if(cb) cb();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
this.out.on('end', function(){
|
|
142
|
-
Logger.print("WHATAP-183", "Disconnected from server, please check your network or Whatap Server!!!!!", false);
|
|
143
|
-
self.close();
|
|
144
|
-
setTimeout(function() {
|
|
145
|
-
cb(new Error('Socket end Event!!!!!'));
|
|
146
|
-
return;
|
|
147
|
-
},500);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
TcpSession.prototype.close = function(){
|
|
152
|
-
if(this.out){
|
|
153
|
-
this.out.destroy();
|
|
154
|
-
this.out = null;
|
|
155
|
-
this.reconnectCnt = 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
TcpSession.prototype.send = function(code , b ){
|
|
160
|
-
try{
|
|
161
|
-
if(this.out == null ){
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
var out = new DataOutputX();
|
|
165
|
-
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
166
|
-
out.writeByte(code);
|
|
167
|
-
out.writeLong(secu.PCODE);
|
|
168
|
-
out.writeInt(secu.OID);
|
|
169
|
-
out.writeInt(conf.TRANSFER_KEY);
|
|
170
|
-
out.writeIntBytes(b);
|
|
171
|
-
/*if(this.out === null ){
|
|
172
|
-
if(this._cb) {
|
|
173
|
-
setTimeout(function() {
|
|
174
|
-
this._cb(new Error('[Send Error] Socket is null !! TCP Session Reconnection......'));
|
|
175
|
-
return;
|
|
176
|
-
},100);
|
|
177
|
-
}
|
|
178
|
-
} */
|
|
179
|
-
this.out.write(out.toByteArray());
|
|
180
|
-
return true;
|
|
181
|
-
} catch(e) {
|
|
182
|
-
Logger.printError('WHATAP-126', 'TcpSession Error', e);
|
|
183
|
-
}
|
|
184
|
-
this.close();
|
|
185
|
-
return false;
|
|
186
|
-
};
|
|
187
|
-
TcpSession.prototype.readKeyReset = function( inPS /* DataInputX */){
|
|
188
|
-
try {
|
|
189
|
-
if( inPS.constructor === Buffer){
|
|
190
|
-
inPS = new DataInputX(inPS);
|
|
191
|
-
}
|
|
192
|
-
var source = inPS.readByte();
|
|
193
|
-
var code = inPS.readByte();
|
|
194
|
-
var pcode = inPS.readLong();
|
|
195
|
-
var oid = inPS.readInt();
|
|
196
|
-
var transfer_key = inPS.readInt();
|
|
197
|
-
var data = inPS.readIntBytes(1024);
|
|
198
|
-
|
|
199
|
-
if( pcode != secu.PCODE || oid != secu.OID){
|
|
200
|
-
return null;
|
|
201
|
-
} else {
|
|
202
|
-
return data;
|
|
203
|
-
}
|
|
204
|
-
} catch(e) {
|
|
205
|
-
Logger.printError("WHATAP-189", 'License key or invalid agent version error(fail key)', e, true);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
TcpSession.prototype.keyReset = function(){
|
|
210
|
-
var msg = new DataOutputX().writeText("hello").writeText(secu.ONAME).writeInt8(secu.IP).toByteArray();
|
|
211
|
-
if( conf.cypher_level > 0 ){
|
|
212
|
-
msg = secu.cypher.encrypt(msg);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
var out = new DataOutputX();
|
|
216
|
-
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
217
|
-
out.writeByte(netflag.KEY_RESET);
|
|
218
|
-
out.writeLong(Long.fromValue(secu.PCODE));
|
|
219
|
-
out.writeInt(secu.OID);
|
|
220
|
-
out.writeInt(0);
|
|
221
|
-
out.writeIntBytes(msg);
|
|
222
|
-
return out.toByteArray();
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
TcpSession.prototype.isOpen = function(){
|
|
226
|
-
return this.out != null;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
TcpSession.prototype.read = function (data) {
|
|
230
|
-
var din = new DataInputX(data);
|
|
231
|
-
var out = new TcpReturn();
|
|
232
|
-
var source = din.readByte();
|
|
233
|
-
|
|
234
|
-
out.code = din.readByte();
|
|
235
|
-
var pcode = din.readLong();
|
|
236
|
-
var oid = din.readInt();
|
|
237
|
-
out.transfer_key = din.readInt();
|
|
238
|
-
out.data = din.readIntBytes();
|
|
239
|
-
|
|
240
|
-
if(pcode != secu.PCODE || oid != secu.OID) {
|
|
241
|
-
Logger.printError('WHATAP-190', 'Received data is not mine..', new Error('Receive data error'));
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
this.receiver.read(out);
|
|
245
|
-
};
|
|
246
|
-
TcpSession.prototype.prepareAutoOnameByServer = function (localAddr) {
|
|
247
|
-
var self = this;
|
|
248
|
-
try {
|
|
249
|
-
var auto_oname_prefix = conf.auto_oname_prefix;
|
|
250
|
-
|
|
251
|
-
if(auto_oname_prefix.indexOf('{') >= 0) {
|
|
252
|
-
OidUtil.setIp(localAddr);
|
|
253
|
-
OidUtil.setPort(port);
|
|
254
|
-
OidUtil.setPid(process.pid);
|
|
255
|
-
OidUtil.setHostName(require('os').hostname());
|
|
256
|
-
auto_oname_prefix = OidUtil.mkOname(conf.auto_oname_prefix);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
var pout = new DataOutputX();
|
|
260
|
-
pout.writeText(auto_oname_prefix);
|
|
261
|
-
pout.writeInt(IPUtil.stringToInt(localAddr));
|
|
262
|
-
var msg = pout.toByteArray();
|
|
263
|
-
|
|
264
|
-
var trkey = 0;
|
|
265
|
-
if(conf.cypher_level > 0) {
|
|
266
|
-
msg = secu.cypher.encrypt(msg);
|
|
267
|
-
var b0 = 1;
|
|
268
|
-
var b1 = (conf.cypher_level / 8);
|
|
269
|
-
trkey = DataInputX.toInt([b0, b1, 0, 0], 0);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
var out = new DataOutputX();
|
|
273
|
-
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
274
|
-
out.writeByte(netflag.PREPARE_AGENT);
|
|
275
|
-
out.writeLong(secu.PCODE);
|
|
276
|
-
out.writeInt(0);
|
|
277
|
-
out.writeInt(trkey);
|
|
278
|
-
out.writeIntBytes(msg);
|
|
279
|
-
self.PREPARE_AGENT = true;
|
|
280
|
-
self.out.write(out.toByteArray());
|
|
281
|
-
} catch(e) {
|
|
282
|
-
Logger.printError("WHATAP-003", "Prepare oname error", e, false);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
module.exports = new TcpSession();
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var net = require('net'),
|
|
2
|
-
DataOutputX = require('../io/data-outputx'),
|
|
3
|
-
DataInputX = require('../io/data-inputx'),
|
|
4
|
-
Logger = require('../logger')
|
|
5
|
-
;
|
|
6
|
-
var READ_MAX = 8 * 1024 * 1024;
|
|
7
|
-
|
|
8
|
-
var TcpRequestClientProxy = function(msg){
|
|
9
|
-
this.msg = msg;
|
|
10
|
-
this.failConLog = true;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
TcpRequestClientProxy.prototype.close = function(){
|
|
14
|
-
if(!this.client) return;
|
|
15
|
-
|
|
16
|
-
this.client.destroy();
|
|
17
|
-
this.client = undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
TcpRequestClientProxy.prototype.isOpen = function(){
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
TcpRequestClientProxy.prototype.send = function(din){
|
|
25
|
-
if(!this.client) return;
|
|
26
|
-
|
|
27
|
-
var out = new DataOutputX();
|
|
28
|
-
out.write(ss(0XCAFE));
|
|
29
|
-
out.writeIntBytes(din.toByteArray())
|
|
30
|
-
|
|
31
|
-
this.client.write( out.toByteArray()
|
|
32
|
-
, function(error, data){
|
|
33
|
-
if(error){
|
|
34
|
-
return Logger.printError('WHATAP-996', 'TcpRequestClientProxy (send)', e, true);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
TcpRequestClientProxy.prototype.open = function(host, port, connectCb, dataCb){
|
|
41
|
-
var self = this;
|
|
42
|
-
|
|
43
|
-
this.client = net.connect({host: host, port: port}, connectCb);
|
|
44
|
-
this.client.on('data', function(data) {
|
|
45
|
-
var din = new DataInputX(data);
|
|
46
|
-
var cafe = din.readUInt16BE();
|
|
47
|
-
var bytes = din.readIntBytes(READ_MAX);
|
|
48
|
-
|
|
49
|
-
if(dataCb) dataCb(undefined, bytes);
|
|
50
|
-
self.close();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
this.client.on('error', function (err) {
|
|
54
|
-
Logger.printError("WHATAP-128", 'Failed to connect to ' + self.msg , err, true);
|
|
55
|
-
if(dataCb) dataCb(err);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this.client.on('close', function() {
|
|
59
|
-
self.close();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function ss(v) {
|
|
64
|
-
var buf = new Array(2);
|
|
65
|
-
buf[0] = ((v >>> 8) & 0xFF);
|
|
66
|
-
buf[1] = ((v >>> 0) & 0xFF);
|
|
67
|
-
return buf;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
module.exports = TcpRequestClientProxy;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
-
* Use of this source code is governed by a license that
|
|
4
|
-
* can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var Sender = require('./sender'),
|
|
8
|
-
Receiver = require('./receiver'),
|
|
9
|
-
conf = require('./../conf/configure'),
|
|
10
|
-
Logger = require('../logger'),
|
|
11
|
-
RequestDoubleQueue = require('./../util/requestdouble-queue');
|
|
12
|
-
|
|
13
|
-
var TcpRequestManager = function(agent){
|
|
14
|
-
if(TcpRequestManager.instance === 'object') {
|
|
15
|
-
return TcpRequestManager.instance;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.agent = agent;
|
|
19
|
-
this.sender1 = new Sender(agent, this);
|
|
20
|
-
this.sender2 = new Sender(agent, this);
|
|
21
|
-
this.receiver = new Receiver(agent, this);
|
|
22
|
-
this.pool = new RequestDoubleQueue(conf.net_send_queue1_size, conf.net_send_queue2_size);
|
|
23
|
-
this.sendDropped = 0;
|
|
24
|
-
this.isExistData = false;
|
|
25
|
-
|
|
26
|
-
TcpRequestManager.instance = this;
|
|
27
|
-
};
|
|
28
|
-
TcpRequestManager.prototype.add = function(flag, p){
|
|
29
|
-
var _this = this;
|
|
30
|
-
var ok = this.pool.put1({flag: flag, pack: p});
|
|
31
|
-
if(ok === false){
|
|
32
|
-
this.sendDropped++;
|
|
33
|
-
Logger.print("WHATAP-201", 'Data[1] drop count : ' + this.sendDropped)
|
|
34
|
-
} else {
|
|
35
|
-
process.nextTick(function () {
|
|
36
|
-
_this.notify();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
TcpRequestManager.prototype.addProfile = function(flag, p) {
|
|
41
|
-
var self = this;
|
|
42
|
-
var ok = this.pool.put2({flag: flag, pack: p});
|
|
43
|
-
|
|
44
|
-
if(ok === false){
|
|
45
|
-
this.sendDropped++;
|
|
46
|
-
Logger.print("WHATAP-201", 'Data[2] drop count : ' + this.sendDropped)
|
|
47
|
-
}else{
|
|
48
|
-
process.nextTick(function () {
|
|
49
|
-
self.notify();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
TcpRequestManager.prototype.notify = function(){
|
|
54
|
-
this.sender1.startCheckQueue();
|
|
55
|
-
this.sender2.startCheckQueue();
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
module.exports = new TcpRequestManager();
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
-
* Use of this source code is governed by a license that
|
|
4
|
-
* can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var ClusterObserver = function(agent){
|
|
8
|
-
this.agent = agent;
|
|
9
|
-
this.packages = ['cluster'];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
ClusterObserver.prototype.inject = function( mod ){
|
|
13
|
-
var aop = this.agent.aop;
|
|
14
|
-
|
|
15
|
-
aop.before(mod, 'fork', function(obj, args, result){
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
aop.after(mod, 'fork', function(obj, args, result){
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
exports.ClusterObserver = ClusterObserver;
|