Skip to content

Commit b50f226

Browse files
committed
Merge tag '0.1.6' into develop
0.1.6
2 parents 7f23a06 + 92af843 commit b50f226

File tree

4 files changed

+76
-27
lines changed

4 files changed

+76
-27
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [0.1.5] - 2018-03-27
11+
1012
### Added
1113

1214
* Multiple Field Servers support

dist/field.js

+39-19
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ var fieldIDFilePath = path.join(os.homedir(), '.carriota-field.id');
3838

3939
var DEFAULT_OPTIONS = {
4040
name: null,
41-
bindAddress: '0.0.0.0',
4241
port: 21310,
43-
fieldHostname: 'field.carriota.com',
42+
fieldHostname: ['field.carriota.com'],
4443
IRIHostname: 'localhost',
4544
IRIPort: 14265,
4645
logIdent: 'FIELD',
@@ -82,12 +81,19 @@ var Field = function (_Base) {
8281
_this.iriData = null;
8382
_this.id = id;
8483
_this.publicId = publicId;
85-
_this.log(('Field Client v.' + version).bold.green);
86-
_this.log('Field ID: ' + _this.id);
87-
_this.log('Public ID: ' + _this.publicId);
88-
if (_this.opts.disableIRI) {
89-
_this.log('Public IRI access through the Field is disabled');
84+
85+
_this.log(('Field Client v.' + version).bold.green);
86+
_this.log('Field ID: ' + _this.id + ' (do NOT share online!)');
87+
_this.log('Public ID: ' + _this.publicId);
88+
_this.log('Field Server(s): ' + _this.opts.fieldHostname.join(' '));
89+
_this.log('Donations: ' + (_this.opts.seed || _this.opts.address ? 'ENABLED' : 'DISABLED'));
90+
if (_this.opts.seed || _this.opts.address) {
91+
var donationsString = _this.opts.address ? 'Static IOTA donations address: ' + _this.opts.address : 'Seed for dynamic IOTA address generation: ' + _this.opts.seed.slice(0, 3) + '*****';
92+
_this.log('Donations: ' + donationsString);
9093
}
94+
_this.log('IRI: Public access through the Field is ' + (_this.opts.disableIRI ? 'DISABLED' : 'ENABLED'));
95+
_this.log('IRI: PoW (attachToTangle) jobs are ' + (_this.opts.pow ? 'ENABLED' : 'DISABLED'));
96+
9197
_this.connRefused = function (reason) {
9298
if (reason.code === 'ECONNREFUSED') {
9399
_this.log(('Proxy error: IRI connection refused: http://' + _this.opts.IRIHostname + ':' + _this.opts.IRIPort).red);
@@ -110,7 +116,7 @@ var Field = function (_Base) {
110116
// 1: Start the proxy server
111117
this.proxy = hoxy.createServer({
112118
upstreamProxy: this.opts.IRIHostname + ':' + this.opts.IRIPort
113-
}).listen(this.opts.port, this.opts.bindAddress);
119+
}).listen(this.opts.port);
114120
this.proxy._server.timeout = 0;
115121
this.proxy.intercept({
116122
phase: 'request',
@@ -166,7 +172,10 @@ var Field = function (_Base) {
166172
}, 20000);
167173

168174
return new Promise(function (resolve) {
169-
_this2.checkIRI(resolve);
175+
_this2.checkIRI(function () {
176+
_this2.sendUpdates();
177+
resolve();
178+
});
170179
});
171180
}
172181

@@ -252,15 +261,22 @@ var Field = function (_Base) {
252261
address: address
253262
}
254263
};
255-
request({
256-
url: 'http://' + _this4.opts.fieldHostname + '/api/v1/update',
257-
method: 'POST',
258-
json: json
259-
}, function (err, resp, body) {
260-
if (err || resp.statusCode !== 200) {
261-
_this4.log(('Field update error to ' + _this4.opts.fieldHostname + ':').red, resp && resp.statusCode, err && err.code, body);
262-
}
263-
//this.log('Update response:', body);
264+
_this4.opts.fieldHostname.forEach(function (fieldHostname) {
265+
request({
266+
url: 'http://' + fieldHostname + '/api/v1/update',
267+
method: 'POST',
268+
json: json
269+
}, function (err, resp, body) {
270+
if (err || resp.statusCode !== 200) {
271+
_this4.log(('ERROR pinging Field Server ' + fieldHostname + ':').red);
272+
if (err && err.code) {
273+
_this4.log('- LOCAL Client error message: ' + err.code);
274+
}
275+
if (body && body.error) {
276+
_this4.log('- REMOTE Server error message (HTTP Code ' + (resp && resp.statusCode) + '): ' + body.error);
277+
}
278+
}
279+
});
264280
});
265281
});
266282
}
@@ -283,6 +299,10 @@ var Field = function (_Base) {
283299
resolve(null);
284300
}
285301
_this5.api.getNewAddress(_this5.opts.seed, { checksum: true }, function (err, address) {
302+
if (err) {
303+
_this5.log('ERROR: Could not generate a donation address with your seed:', err);
304+
_this5.log('...pinging without a donation address');
305+
}
286306
resolve(err ? null : address);
287307
});
288308
});
@@ -331,4 +351,4 @@ function getID(customFieldId) {
331351
module.exports = {
332352
DEFAULT_OPTIONS: DEFAULT_OPTIONS,
333353
Field: Field
334-
};
354+
};

dist/index.js

+34-7
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,52 @@
44
require('colors');
55

66
var ini = require('ini');
7+
8+
var _require = require('iota.lib.js/lib/utils/inputValidator'),
9+
isTrytes = _require.isTrytes;
10+
11+
var _require2 = require('iota.lib.js/lib/utils/utils'),
12+
isValidChecksum = _require2.isValidChecksum;
13+
714
var fs = require('fs');
815
var program = require('commander');
916

10-
var _require = require('./field'),
11-
DEFAULT_OPTIONS = _require.DEFAULT_OPTIONS,
12-
Field = _require.Field;
17+
var _require3 = require('./field'),
18+
DEFAULT_OPTIONS = _require3.DEFAULT_OPTIONS,
19+
Field = _require3.Field;
1320

14-
var _require2 = require('./base'),
15-
DEFAULT_BASE_OPTIONS = _require2.DEFAULT_OPTIONS;
21+
var _require4 = require('./base'),
22+
DEFAULT_BASE_OPTIONS = _require4.DEFAULT_OPTIONS;
1623

1724
var version = require('../package.json').version;
1825

1926
var parseNumber = function parseNumber(v) {
2027
return parseInt(v);
2128
};
29+
var parseServers = function parseServers(val) {
30+
return val.split(' ');
31+
};
32+
var parseSeed = function parseSeed(seed) {
33+
if (seed && !isTrytes(seed, 81)) {
34+
throw new Error('Wrong seed format provided! Has to be a 81-trytes string!');
35+
}
36+
return seed;
37+
};
38+
39+
var parseAddress = function parseAddress(address) {
40+
if (address) {
41+
if (!isTrytes(address, 90)) {
42+
throw new Error('Wrong donation address provided. Has to be a 90-trytes string (81+checksum)!');
43+
}
44+
if (!isValidChecksum(address)) {
45+
throw new Error('Please check your donation address: wrong checksum!');
46+
}
47+
}
48+
return address;
49+
};
2250

2351
// TODO: write tests
24-
// TODO: write README
25-
program.version(version).option('-a, --address [value]', 'Optional IOTA address for donations', null).option('-b, --seed [value]', 'Optional IOTA seed for automatic donation address generation', null).option('-c, --config [value]', 'Config file path', null).option('-d, --disableIRI [value]', 'Do not allow public IRI connections through the Field', DEFAULT_OPTIONS.disableIRI).option('-f, --fieldHostname [value]', 'Hostname of the Field endpoint', process.env.FIELD_HOSTNAME || DEFAULT_OPTIONS.fieldHostname).option('-h, --IRIHostname [value]', 'IRI API hostname', process.env.IRI_HOSTNAME || DEFAULT_OPTIONS.IRIHostname).option('-i, --IRIPort [value]', 'IRI API port', parseNumber, process.env.IRI_PORT || DEFAULT_OPTIONS.IRIPort).option('-n, --name [value]', 'Name of your node instance', DEFAULT_OPTIONS.name).option('-p, --port [value]', 'Field port', parseNumber, DEFAULT_OPTIONS.port).option('-s, --silent [value]', 'Silent', DEFAULT_BASE_OPTIONS.silent).option('-w, --pow [value]', 'Allow attachToTange / PoW', DEFAULT_OPTIONS.pow).option('-y, --customFieldId [value]', 'Generate a custom field ID, instead of using machine ID').parse(process.argv);
52+
program.version(version).option('-a, --address [value]', 'Optional IOTA address for donations', parseAddress, null).option('-b, --seed [value]', 'Optional IOTA seed for automatic donation address generation', parseSeed, null).option('-c, --config [value]', 'Config file path', null).option('-d, --disableIRI [value]', 'Do not allow public IRI connections through the Field', DEFAULT_OPTIONS.disableIRI).option('-f, --fieldHostname [value]', 'Hostname of the Field endpoint', parseServers, process.env.FIELD_HOSTNAME ? parseServers(process.env.FIELD_HOSTNAME) : DEFAULT_OPTIONS.fieldHostname).option('-h, --IRIHostname [value]', 'IRI API hostname', process.env.IRI_HOSTNAME || DEFAULT_OPTIONS.IRIHostname).option('-i, --IRIPort [value]', 'IRI API port', parseNumber, process.env.IRI_PORT || DEFAULT_OPTIONS.IRIPort).option('-n, --name [value]', 'Name of your node instance', DEFAULT_OPTIONS.name).option('-p, --port [value]', 'Field port', parseNumber, DEFAULT_OPTIONS.port).option('-s, --silent [value]', 'Silent', parseSeed, DEFAULT_BASE_OPTIONS.silent).option('-w, --pow [value]', 'Allow attachToTange / PoW', DEFAULT_OPTIONS.pow).option('-y, --customFieldId [value]', 'Generate a custom field ID, instead of using machine ID').parse(process.argv);
2653

2754
var configPath = process.env.FIELD_CONFIG || program.config;
2855

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "field.cli",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "CarrIOTA Field Client",
55
"main": "dist/field.js",
66
"homepage": "https://semkodev.com",

0 commit comments

Comments
 (0)