Updated metadata and modified amt-lme to hook newListener for 'connect' because JS HECI is much faster than old implementation
Bryan Roe committed
May 28, 2020 at 13:30 UTC
156f22e50de3350f038c2a0905df361679121b9b
5 files changed
+38
-8
agents/meshcore.js
+6
@@ -173,6 +173,12 @@ function createMeshCore(agent) {
173
case 'connection':
174
data.result = require('MeshAgent').ConnectedServer;
175
this._send(data);
176
+ case 'descriptors':
177
+ require('ChainViewer').getSnapshot().then(function (f)
178
+ {
179
+ this.tag.payload.result = f;
180
+ this.tag.ipc._send(this.tag.payload);
181
+ }).parentPromise.tag = { ipc: this, payload: data };
182
break;
183
}
184
break;
agents/modules_meshcmd/amt-lme.js
+7
-1
@@ -117,6 +117,7 @@ function lme_heci(options) {
117
emitterUtils.createEvent('notify');
118
emitterUtils.createEvent('bind');
119
120
+ this.on('newListener', function (name, func) { if (name == 'connect' && this._LME._connected == true) { func.call(this);} });
121
if ((options != null) && (options.debug == true)) { lme_port_offset = -100; } // LMS debug mode
122
123
var heci = require('heci');
@@ -124,10 +125,14 @@ function lme_heci(options) {
125
126
this._ObjectID = "lme";
127
this._LME = heci.create();
128
+ this._LME._connected = false;
129
+ this._LME.descriptorMetadata = "amt-lme";
130
this._LME._binded = {};
131
this._LME.LMS = this;
132
this._LME.on('error', function (e) { this.LMS.emit('error', e); });
130
- this._LME.on('connect', function () {
133
+ this._LME.on('connect', function ()
134
+ {
135
+ this._connected = true;
136
this.on('data', function (chunk) {
137
// this = HECI
138
var cmd = chunk.readUInt8(0);
@@ -173,6 +178,7 @@ function lme_heci(options) {
178
try {
179
// Bind a new server socket if not already present
180
this[name][port] = require('net').createServer();
181
+ this[name][port].descriptorMetadata = 'amt-lme (port: ' + port + ')';
182
this[name][port].HECI = this;
183
if (lme_port_offset == 0) {
184
this[name][port].listen({ port: port, host: '127.0.0.1' }); // Normal mode
agents/modules_meshcmd/amt-mei.js
+9
-3
@@ -27,6 +27,7 @@ function amt_heci() {
27
this._setupPTHI = function _setupPTHI()
28
{
29
this._amt = heci.create();
30
+ this._amt.descriptorMetadata = "amt-pthi";
31
this._amt.BiosVersionLen = 65;
32
this._amt.UnicodeStringLen = 20;
33
@@ -397,20 +398,25 @@ function amt_heci() {
398
fn.apply(this, opt);
399
}, callback, optional);
400
}
400
- this.getProtocolVersion = function getProtocolVersion(callback) {
401
+ this.getProtocolVersion = function getProtocolVersion(callback)
402
+ {
403
var optional = [];
404
for (var i = 1; i < arguments.length; ++i) { opt.push(arguments[i]); }
405
404
- heci.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt) {
406
+ if (!this._tmpSession) { this._tmpSession = heci.create(); this._tmpSession.parent = this;}
407
+ this._tmpSession.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt)
408
+ {
409
if (status == 0) {
410
var result = buffer.readUInt8(0).toString() + '.' + buffer.readUInt8(1).toString() + '.' + buffer.readUInt8(2).toString() + '.' + buffer.readUInt16BE(3).toString();
411
opt.unshift(result);
412
fn.apply(self, opt);
413
}
410
- else {
414
+ else
415
+ {
416
opt.unshift(null);
417
fn.apply(self, opt);
418
}
419
+
420
}, this, callback, optional);
421
}
422
}
agents/modules_meshcore/amt-lme.js
+7
-1
@@ -117,6 +117,7 @@ function lme_heci(options) {
117
emitterUtils.createEvent('notify');
118
emitterUtils.createEvent('bind');
119
120
+ this.on('newListener', function (name, func) { if (name == 'connect' && this._LME._connected == true) { func.call(this);} });
121
if ((options != null) && (options.debug == true)) { lme_port_offset = -100; } // LMS debug mode
122
123
var heci = require('heci');
@@ -124,10 +125,14 @@ function lme_heci(options) {
125
126
this._ObjectID = "lme";
127
this._LME = heci.create();
128
+ this._LME._connected = false;
129
+ this._LME.descriptorMetadata = "amt-lme";
130
this._LME._binded = {};
131
this._LME.LMS = this;
132
this._LME.on('error', function (e) { this.LMS.emit('error', e); });
130
- this._LME.on('connect', function () {
133
+ this._LME.on('connect', function ()
134
+ {
135
+ this._connected = true;
136
this.on('data', function (chunk) {
137
// this = HECI
138
var cmd = chunk.readUInt8(0);
@@ -173,6 +178,7 @@ function lme_heci(options) {
178
try {
179
// Bind a new server socket if not already present
180
this[name][port] = require('net').createServer();
181
+ this[name][port].descriptorMetadata = 'amt-lme (port: ' + port + ')';
182
this[name][port].HECI = this;
183
if (lme_port_offset == 0) {
184
this[name][port].listen({ port: port, host: '127.0.0.1' }); // Normal mode
agents/modules_meshcore/amt-mei.js
+9
-3
@@ -27,6 +27,7 @@ function amt_heci() {
27
this._setupPTHI = function _setupPTHI()
28
{
29
this._amt = heci.create();
30
+ this._amt.descriptorMetadata = "amt-pthi";
31
this._amt.BiosVersionLen = 65;
32
this._amt.UnicodeStringLen = 20;
33
@@ -397,20 +398,25 @@ function amt_heci() {
398
fn.apply(this, opt);
399
}, callback, optional);
400
}
400
- this.getProtocolVersion = function getProtocolVersion(callback) {
401
+ this.getProtocolVersion = function getProtocolVersion(callback)
402
+ {
403
var optional = [];
404
for (var i = 1; i < arguments.length; ++i) { opt.push(arguments[i]); }
405
404
- heci.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt) {
406
+ if (!this._tmpSession) { this._tmpSession = heci.create(); this._tmpSession.parent = this;}
407
+ this._tmpSession.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt)
408
+ {
409
if (status == 0) {
410
var result = buffer.readUInt8(0).toString() + '.' + buffer.readUInt8(1).toString() + '.' + buffer.readUInt8(2).toString() + '.' + buffer.readUInt16BE(3).toString();
411
opt.unshift(result);
412
fn.apply(self, opt);
413
}
410
- else {
414
+ else
415
+ {
416
opt.unshift(null);
417
fn.apply(self, opt);
418
}
419
+
420
}, this, callback, optional);
421
}
422
}