whatap 1.0.1 → 1.0.2

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.
Files changed (198) hide show
  1. package/README.md +32 -78
  2. package/lib/conf/conf-sys-mon.js +101 -0
  3. package/lib/conf/config-default.js +10 -3
  4. package/lib/conf/configure.js +369 -349
  5. package/lib/conf/license.js +1 -1
  6. package/lib/control/cmd-config.js +24 -0
  7. package/lib/control/control-handler.js +367 -0
  8. package/lib/control/packagectr-helper.js +34 -3
  9. package/lib/core/agent.js +176 -882
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/request-agent.js +27 -0
  12. package/lib/core/shimmer.js +82 -36
  13. package/lib/counter/counter-manager.js +79 -8
  14. package/lib/counter/meter/meter-activex.js +67 -0
  15. package/lib/counter/meter/meter-httpc.js +57 -0
  16. package/lib/counter/meter/meter-resource.js +9 -0
  17. package/lib/counter/meter/meter-service.js +168 -0
  18. package/lib/counter/meter/meter-socket.io.js +51 -0
  19. package/lib/counter/meter/meter-sql.js +71 -0
  20. package/lib/counter/meter/meter-users.js +58 -0
  21. package/lib/counter/meter.js +183 -0
  22. package/lib/counter/task/activetransaction.js +68 -17
  23. package/lib/counter/task/agentinfo.js +107 -0
  24. package/lib/{system → counter/task}/gc-action.js +27 -74
  25. package/lib/counter/task/gcstat.js +34 -0
  26. package/lib/counter/task/heapmem.js +25 -0
  27. package/lib/counter/task/httpc.js +76 -0
  28. package/lib/counter/task/metering-info.js +125 -0
  29. package/lib/counter/task/proc-cpu.js +29 -0
  30. package/lib/counter/task/realtimeuser.js +31 -0
  31. package/lib/counter/task/res/systemECSTask.js +39 -0
  32. package/lib/counter/task/res/systemKubeTask.js +53 -0
  33. package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
  34. package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
  35. package/lib/counter/task/res-sys-cpu.js +62 -0
  36. package/lib/counter/task/service.js +202 -0
  37. package/lib/counter/task/socketio.js +30 -0
  38. package/lib/counter/task/sql.js +105 -0
  39. package/lib/counter/task/systemperf.js +43 -0
  40. package/lib/data/datapack-sender.js +289 -0
  41. package/lib/data/dataprofile-agent.js +162 -0
  42. package/lib/data/datatext-agent.js +135 -0
  43. package/lib/data/event-level.js +15 -0
  44. package/lib/data/test.js +49 -0
  45. package/lib/data/zipprofile.js +197 -0
  46. package/lib/env/constants.js +21 -0
  47. package/lib/error/error-handler.js +437 -0
  48. package/lib/io/data-inputx.js +13 -3
  49. package/lib/io/data-outputx.js +268 -206
  50. package/lib/kube/kube-client.js +144 -0
  51. package/lib/lang/text-types.js +58 -0
  52. package/lib/logger.js +6 -6
  53. package/lib/logsink/line-log-util.js +87 -0
  54. package/lib/logsink/line-log.js +12 -0
  55. package/lib/logsink/log-sender.js +78 -0
  56. package/lib/logsink/log-tracer.js +40 -0
  57. package/lib/logsink/sender-util.js +56 -0
  58. package/lib/logsink/zip/zip-send.js +177 -0
  59. package/lib/net/netflag.js +55 -0
  60. package/lib/net/receiver.js +66 -0
  61. package/lib/net/security-master.js +139 -20
  62. package/lib/net/sender.js +141 -0
  63. package/lib/net/tcp-return.js +18 -0
  64. package/lib/net/tcp-session.js +286 -0
  65. package/lib/net/tcpreq-client-proxy.js +70 -0
  66. package/lib/net/tcprequest-mgr.js +58 -0
  67. package/lib/observers/apollo-server-observer.js +33 -27
  68. package/lib/observers/cluster-observer.js +22 -0
  69. package/lib/observers/express-observer.js +215 -0
  70. package/lib/observers/file-observer.js +184 -0
  71. package/lib/observers/global-observer.js +155 -80
  72. package/lib/observers/grpc-observer.js +336 -0
  73. package/lib/observers/http-observer.js +666 -236
  74. package/lib/observers/maria-observer.js +204 -362
  75. package/lib/observers/memcached-observer.js +56 -0
  76. package/lib/observers/mongo-observer.js +317 -0
  77. package/lib/observers/mongodb-observer.js +169 -226
  78. package/lib/observers/mongoose-observer.js +518 -323
  79. package/lib/observers/mssql-observer.js +177 -418
  80. package/lib/observers/mysql-observer.js +342 -449
  81. package/lib/observers/mysql2-observer.js +396 -358
  82. package/lib/observers/net-observer.js +77 -0
  83. package/lib/observers/oracle-observer.js +559 -384
  84. package/lib/observers/pgsql-observer.js +231 -489
  85. package/lib/observers/prisma-observer.js +303 -92
  86. package/lib/observers/process-observer.js +79 -35
  87. package/lib/observers/promise-observer.js +31 -0
  88. package/lib/observers/redis-observer.js +166 -331
  89. package/lib/observers/schedule-observer.js +67 -0
  90. package/lib/observers/socket.io-observer.js +226 -187
  91. package/lib/observers/stream-observer.js +19 -0
  92. package/lib/observers/thrift-observer.js +197 -0
  93. package/lib/observers/websocket-observer.js +175 -301
  94. package/lib/pack/activestack-pack.js +55 -0
  95. package/lib/pack/apenum.js +8 -0
  96. package/lib/pack/counter-pack.js +3 -0
  97. package/lib/pack/errorsnap-pack.js +69 -0
  98. package/lib/pack/event-pack.js +54 -0
  99. package/lib/pack/hitmap-pack.js +63 -0
  100. package/lib/pack/hitmap-pack1.js +152 -0
  101. package/lib/pack/log-sink-pack.js +14 -52
  102. package/lib/pack/netstat.js +15 -0
  103. package/lib/pack/otype.js +7 -0
  104. package/lib/pack/profile-pack.js +49 -0
  105. package/lib/pack/realtimeuser-pack.js +41 -0
  106. package/lib/pack/stat-general-pack.js +96 -0
  107. package/lib/pack/staterror-pack.js +120 -0
  108. package/lib/pack/stathttpc-pack.js +66 -0
  109. package/lib/pack/stathttpc-rec.js +78 -0
  110. package/lib/pack/statremote-pack.js +46 -0
  111. package/lib/pack/statservice-pack.js +63 -0
  112. package/lib/pack/statservice-pack1.js +88 -0
  113. package/lib/pack/statservice-rec.js +292 -0
  114. package/lib/pack/statservice-rec_dep.js +151 -0
  115. package/lib/pack/statsql-pack.js +69 -0
  116. package/lib/pack/statsql-rec.js +100 -0
  117. package/lib/pack/statuseragent-pack.js +44 -0
  118. package/lib/pack/tagcount-pack.js +4 -4
  119. package/lib/pack/tagctr.js +15 -0
  120. package/lib/pack/text-pack.js +50 -0
  121. package/lib/pack/time-count.js +25 -0
  122. package/lib/pack/websocket.js +15 -0
  123. package/lib/pack/zip-pack.js +70 -0
  124. package/lib/pii/pii-item.js +31 -0
  125. package/lib/pii/pii-mask.js +174 -0
  126. package/lib/plugin/plugin-loadermanager.js +57 -0
  127. package/lib/plugin/plugin.js +75 -0
  128. package/lib/service/tx-record.js +332 -0
  129. package/lib/stat/stat-error.js +116 -0
  130. package/lib/stat/stat-httpc.js +98 -0
  131. package/lib/stat/stat-remote-ip.js +46 -0
  132. package/lib/stat/stat-remote-ipurl.js +88 -0
  133. package/lib/stat/stat-sql.js +113 -0
  134. package/lib/stat/stat-tranx.js +58 -0
  135. package/lib/stat/stat-tx-caller.js +160 -0
  136. package/lib/stat/stat-tx-domain.js +111 -0
  137. package/lib/stat/stat-tx-referer.js +112 -0
  138. package/lib/stat/stat-useragent.js +48 -0
  139. package/lib/stat/timingsender.js +76 -0
  140. package/lib/step/activestack-step.js +38 -0
  141. package/lib/step/dbc-step.js +36 -0
  142. package/lib/step/http-stepx.js +67 -0
  143. package/lib/step/message-step.js +40 -0
  144. package/lib/step/method-stepx.js +45 -0
  145. package/lib/step/resultset-step.js +40 -0
  146. package/lib/step/securemsg-step.js +44 -0
  147. package/lib/step/socket-step.js +46 -0
  148. package/lib/step/sql-stepx.js +68 -0
  149. package/lib/step/sqlxtype.js +16 -0
  150. package/lib/step/step.js +66 -0
  151. package/lib/step/stepenum.js +54 -0
  152. package/lib/topology/link.js +63 -0
  153. package/lib/topology/nodeinfo.js +123 -0
  154. package/lib/topology/status-detector.js +111 -0
  155. package/lib/trace/trace-context-manager.js +113 -25
  156. package/lib/trace/trace-context.js +21 -7
  157. package/lib/trace/trace-httpc.js +17 -11
  158. package/lib/trace/trace-sql.js +29 -21
  159. package/lib/util/anylist.js +103 -0
  160. package/lib/util/cardinality/hyperloglog.js +106 -0
  161. package/lib/util/cardinality/murmurhash.js +31 -0
  162. package/lib/util/cardinality/registerset.js +75 -0
  163. package/lib/util/errordata.js +21 -0
  164. package/lib/util/escape-literal-sql.js +5 -5
  165. package/lib/util/hashutil.js +18 -18
  166. package/lib/util/iputil_x.js +527 -0
  167. package/lib/util/keygen.js +0 -3
  168. package/lib/util/kube-util.js +73 -0
  169. package/lib/util/linkedset.js +1 -2
  170. package/lib/util/nodeutil.js +2 -1
  171. package/lib/util/paramsecurity.js +80 -0
  172. package/lib/util/pre-process.js +13 -0
  173. package/lib/util/process-seq.js +166 -0
  174. package/lib/util/property-util.js +36 -0
  175. package/lib/util/request-queue.js +70 -0
  176. package/lib/util/requestdouble-queue.js +72 -0
  177. package/lib/util/resourceprofile.js +157 -0
  178. package/lib/util/stop-watch.js +30 -0
  179. package/lib/util/system-util.js +10 -0
  180. package/lib/util/userid-util.js +57 -0
  181. package/lib/value/map-value.js +3 -2
  182. package/package.json +9 -4
  183. package/whatap.conf +1 -4
  184. package/agent/darwin/arm64/whatap_nodejs +0 -0
  185. package/agent/linux/amd64/whatap_nodejs +0 -0
  186. package/agent/linux/arm64/whatap_nodejs +0 -0
  187. package/build.txt +0 -4
  188. package/lib/observers/ioredis-observer.js +0 -294
  189. package/lib/udp/async_sender.js +0 -119
  190. package/lib/udp/index.js +0 -17
  191. package/lib/udp/packet_enum.js +0 -52
  192. package/lib/udp/packet_queue.js +0 -69
  193. package/lib/udp/packet_type_enum.js +0 -33
  194. package/lib/udp/param_def.js +0 -72
  195. package/lib/udp/udp_session.js +0 -336
  196. package/lib/util/sql-util.js +0 -178
  197. package/lib/util/trace-helper.js +0 -91
  198. package/lib/util/transfer.js +0 -58
@@ -0,0 +1,55 @@
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 NetFlag = function(flag){
8
+ this.flag = flag;
9
+ }
10
+
11
+ NetFlag.SECURE_HIDE = 0x0001;
12
+ NetFlag.SECURE_CYPHER = 0x0002;
13
+ NetFlag.RESERVED1 = 0x0004;
14
+ NetFlag.RESERVED2 = 0x0008;
15
+ NetFlag.RESERVED3 = 0x0010;
16
+ NetFlag.RESERVED4 = 0x0020;
17
+ NetFlag.RESERVED5 = 0x0040;
18
+ NetFlag.RESERVED6 = 0x0080;
19
+ NetFlag.TIME_SYNC = 0xfe;
20
+ NetFlag.KEY_RESET = 0xff;
21
+ NetFlag.PREPARE_AGENT = 0xfc;
22
+
23
+ NetFlag.getSecureMask = function(code){
24
+ if(code === NetFlag.KEY_RESET) return 0;
25
+ return (code & NetFlag.SECURE_HIDE ) | ( code & NetFlag.SECURE_CYPHER);
26
+ };
27
+
28
+ NetFlag.isSecure = function(code) {
29
+ if(code === NetFlag.KEY_RESET) return false;
30
+ return (code & NetFlag.SECURE_HIDE) | (code & NetFlag.SECURE_CYPHER);
31
+ };
32
+
33
+ NetFlag.prototype.set = function(mask){
34
+ this.flag = (this.flag | mask);
35
+ return this;
36
+ };
37
+
38
+ NetFlag.prototype.isA = function(m){
39
+ return (this.falg & m) != 0;
40
+ };
41
+
42
+ NetFlag.prototype.getFlag = function() {
43
+ return this.flag;
44
+ };
45
+
46
+ module.exports.NetFlag = NetFlag;
47
+
48
+ var NetSrc = {
49
+ AGENT_JAVA_EMBED : 1,
50
+ AGENT_JAVA_WATCHER : 2,
51
+ SERVER_YARD : 3,
52
+ SERVER_PROXY : 4
53
+ };
54
+
55
+ module.exports.NetSrc = NetSrc;
@@ -0,0 +1,66 @@
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
+
8
+ const conf = require('../conf/configure');
9
+ var NetFlag = require('./netflag').NetFlag,
10
+ ControlHandler = require('./../control/control-handler'),
11
+ DateUtil = require('./../util/dateutil'),
12
+ DataInputX = require('../io/data-inputx'),
13
+ Logger = require('../logger');
14
+
15
+ function Receiver(){};
16
+
17
+ Receiver.prototype.read = function(out /*TcpReturn*/){
18
+ try {
19
+ if(conf.network_debug_enabled){
20
+ Logger.print("[Receiver] input Data " ,out.code + " // " + out.transfer_key , false);
21
+ }
22
+ if(out.code === NetFlag.TIME_SYNC) {
23
+ var din = new DataInputX(out.data);
24
+ var prevAgentTime = din.readLong().toNumber();
25
+ var serverTime = din.readLong().toNumber();
26
+ var now = Date.now();
27
+ var turnaroundTime = (now - prevAgentTime);
28
+
29
+ if(turnaroundTime < 500) {
30
+ DateUtil.setServerTime(serverTime, 1);
31
+ }
32
+ return;
33
+ }
34
+
35
+ if(conf.cypher_level > 0) {
36
+ if(out.transfer_key != conf.TRANSFER_KEY) { return; }
37
+
38
+ switch (NetFlag.getSecureMask(out.code)) {
39
+ case NetFlag.SECURE_HIDE:
40
+ if(conf.cypher != null) {
41
+ out.data = conf.cypher.hide(out.data);
42
+ } else {
43
+ return;
44
+ }
45
+ break;
46
+ case NetFlag.SECURE_CYPHER:
47
+ if(conf.cypher != null) {
48
+ out.data = conf.cypher.decrypt(out.data);
49
+ } else {
50
+ return;
51
+ }
52
+ break;
53
+ default:
54
+ out.data = null;
55
+ }
56
+ }
57
+
58
+ if(out.data != null && out.data.length > 0) {
59
+ ControlHandler.add(new DataInputX(out.data).readPack());
60
+ }
61
+ } catch (e) {
62
+ Logger.printError('WHATAP-195', 'Receiver error', e);
63
+ }
64
+ };
65
+
66
+ module.exports = Receiver;
@@ -9,9 +9,11 @@ var DataInputX = require('./../io/data-inputx'),
9
9
  Cypher = require('./../util/cypher'),
10
10
  IPUtil = require('./../util/iputil'),
11
11
  OidUtil = require('./../util/oidutil'),
12
+ ProcessSeq = require('./../util/process-seq'),
12
13
  HashUtil = require('./../util/hashutil');
13
14
 
14
15
  var cluster = require('cluster');
16
+ const Configuration = require("../conf/configure");
15
17
 
16
18
  var lastOid = 0;
17
19
 
@@ -24,46 +26,163 @@ var SecurityMaster = {
24
26
  ONODE : 0,
25
27
  ONODE_NAME : null,
26
28
  OID: 0 ,
27
- decideAgentOnameOid: function() {
29
+ run : function(cb){
28
30
  var conf = require('./../conf/configure');
29
- const myIp = IPUtil.getIp();
30
- conf.setProperty('whatap.ip', myIp);
31
+ if( this.resetLicense( conf.license )) {
32
+ require('../logger').print('WHATAP-110', "[pcode=" + this.PCODE
33
+ + ",SECURE_KEY=" + this.SECURE_KEY.toString('hex')
34
+ + "]", false);
35
+ this.getClusterId(cb);
36
+ } else {
37
+ if(cb) cb(new Error('Invalid license'));
38
+ }
39
+ },
40
+ resetLicense: function(lic /* String */){
41
+ try {
42
+ var key = License.getKey(lic);
43
+ if(key.pcode == null || key.security_key == null) {
44
+ throw new Error('Invalid license');
45
+ }
46
+ this.PCODE = key.pcode;
47
+ this.SECURE_KEY = key.security_key;
48
+ this.cypher = new Cypher(this.SECURE_KEY, 0);
49
+ return true;
50
+ } catch(e) {
51
+ require('../logger').printError('WHATAP-606', 'LicenseKey is invalid ' + lic, e, true);
52
+ }
53
+ return false;
54
+ },
55
+ updateLocalIp: function(myIp){
56
+ process.env["whatap.ip"] = myIp;
57
+ this.IP = 0;
58
+ },
59
+ decideAgentOnameOid: function(myIp) {
60
+ var Configuration = require('./../conf/configure');
61
+ Configuration.setProperty('whatap.ip', myIp);
31
62
 
32
63
  this.IP = IPUtil.stringToInt(myIp);
33
- var port = conf.getProperty("whatap.port");
64
+ var port = Configuration.getProperty("whatap.port");
34
65
  OidUtil.setIp(IPUtil.intToString(this.IP));
35
66
  OidUtil.setPort(port);
36
67
  OidUtil.setPid(process.pid);
37
68
  OidUtil.setHostName(require('os').hostname());
38
- OidUtil.setType(process.env.name || conf.getProperty("whatap.type", "NODE"));
69
+ //OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"));
70
+ OidUtil.setType(process.env.name || Configuration.getProperty("whatap.type", "NODE"));
39
71
 
40
- this.OID = conf.getProperty("OID", 0);
41
- this.ONAME = conf.getProperty("app_name", "");
72
+ var name_pattern;
73
+ if(Configuration.getProperty('whatap_micro_enabled', false) === true || process.env.WHATAP_MICRO_ENABLED === "true"){
74
+ name_pattern = process.env.WHATAP_NAME || "{okind}-{ip2}-{ip3}";
75
+ }else if(require('cluster').isMaster){
76
+ name_pattern=process.env.WHATAP_NAME || "{type}-{ip2}-{ip3}";
77
+ }else{
78
+ name_pattern=process.env.WHATAP_NAME || "{type}{cluster}-{ip2}-{ip3}";
79
+ var cid = Configuration.getProperty('node.clusterId');
80
+ OidUtil.setCluster(cid);
81
+ }
42
82
 
43
- this.OKIND_NAME = conf.getProperty("whatap.okind", "")
44
- if(!this.OKIND_NAME){
45
- this.OKIND_NAME = process.env.WHATAP_OKIND || "";
83
+ var okindStr= process.env.WHATAP_OKIND || Configuration.getProperty('whatap.okind');
84
+ if(okindStr && okindStr.length>0){
85
+ this.OKIND = HashUtil.hashFromString(okindStr);
86
+ this.OKIND_NAME=okindStr;
87
+ OidUtil.setOkind(okindStr);
88
+ }else{
89
+ this.OKIND = 0;
90
+ this.OKIND_NAME=null;
46
91
  }
47
- if(!this.OKIND_NAME){
48
- this.OKIND_NAME = process.env.POD_NAME || ""
92
+
93
+ const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
94
+ const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
95
+
96
+ if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
97
+ var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
98
+ if(onodeStr && onodeStr.length>0){
99
+ this.ONODE = HashUtil.hashFromString(onodeStr);
100
+ this.ONODE_NAME=onodeStr;
101
+ }else{
102
+ this.ONODE = 0;
103
+ this.ONODE_NAME=null;
104
+ }
49
105
  }
50
- if(this.OKIND_NAME){
51
- this.OKIND = HashUtil.hashFromString(this.OKIND_NAME);
106
+
107
+ //OidUtil.setCmd(Configuration.getProperty("sun.java.command"));
108
+ this.ONAME = OidUtil.mkOname(Configuration.getProperty("whatap.name", name_pattern), port);
109
+ this.OID = OidUtil.mkOid(this.ONAME);
110
+
111
+ if (lastOid != this.OID) {
112
+ lastOid = this.OID;
113
+ require('../logger').print('WHATAP-968', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
52
114
  }
115
+ },
116
+ setAgentOnameOid :function (oname, myIp) {
117
+ var Configuration = require('./../conf/configure');
118
+ Configuration.setProperty('whatap.ip', myIp);
53
119
 
54
- this.ONODE_NAME = conf.getProperty("whatap.onode", "");
55
- if(!this.ONODE_NAME){
56
- this.ONODE_NAME = process.env.NODE_NAME || "";
120
+ this.IP = IPUtil.stringToInt(myIp);//DataInputX.toInt(IPUtil.toBytes(myIp), 0);
121
+ var port = Configuration.getProperty("whatap.port");
122
+ OidUtil.setIp(IPUtil.intToString(this.IP));
123
+ OidUtil.setPort(port);
124
+ OidUtil.setPid(process.pid);
125
+ OidUtil.setHostName(require('os').hostname());
126
+ if(require('cluster').isMaster){
127
+ OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"));
128
+ }else{
129
+ OidUtil.setType(Configuration.getProperty("whatap.type", "NODE"+ Configuration.getProperty('node.clusterId') ) );
57
130
  }
58
- if(this.ONODE_NAME){
59
- this.ONODE = HashUtil.hashFromString(this.ONODE_NAME);
131
+
132
+ OidUtil.setCmd(Configuration.getProperty("sun.java.command"));
133
+ this.ONAME = oname;
134
+ this.OID = OidUtil.mkOid(this.ONAME);
135
+
136
+ var okindStr= process.env.WHATAP_OKIND || Configuration.getProperty('whatap.okind');
137
+ if(okindStr && okindStr.length>0){
138
+ this.OKIND = HashUtil.hashFromString(okindStr);
139
+ this.OKIND_NAME=okindStr;
140
+ }else{
141
+ this.OKIND = 0;
142
+ this.OKIND_NAME=null;
60
143
  }
61
144
 
145
+ const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
146
+ const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
147
+
148
+ if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
149
+ var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
150
+ if(onodeStr && onodeStr.length>0){
151
+ this.ONODE = HashUtil.hashFromString(onodeStr);
152
+ this.ONODE_NAME=onodeStr;
153
+ }else{
154
+ this.ONODE = 0;
155
+ this.ONODE_NAME=null;
156
+ }
157
+ }
62
158
 
63
159
  if (lastOid != this.OID) {
64
160
  lastOid = this.OID;
65
- require('../logger').print('WHATAP-401', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
161
+ require('../logger').print('WHATAP-168', "OID: " + this.OID + " ONAME: " + this.ONAME + " IP: " + IPUtil.intToString(this.IP), false);
66
162
  }
163
+ },
164
+ getClusterId: function(cb){
165
+ var conf = require('./../conf/configure');
166
+ if(cluster.isMaster){
167
+ //console.log('현재 프로젝트는 MASTER 입니다!!!!');
168
+ conf.setProperty('node.clusterId', '');
169
+ if(cb) cb();
170
+ }else{
171
+ conf.setProperty('node.clusterId', cluster.worker.id);
172
+ if(cb) cb();
173
+ //console.log('현재 프로젝트는 ' + cluster.worker.id + ' 입니다!!!!');
174
+ /*
175
+ ProcessSeq('whatap').accessAuth(function(pseq){
176
+ if(!pseq){
177
+ return;
178
+ }
179
+ var conf = require('./../conf/configure');
180
+ conf.setProperty('node.clusterId', pseq);
181
+ if(cb) cb();
182
+ });
183
+ */
184
+ }
185
+
67
186
  }
68
187
  };
69
188
 
@@ -0,0 +1,141 @@
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;
@@ -0,0 +1,18 @@
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;