Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/platfowner/cross shard #121

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/protocol_versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.3.0": {
"0.3.1": {
"min": "0.3.1",
"max": "0.3.1"
}
Expand Down
8 changes: 8 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const NETWORK_ID = process.env.NETWORK_ID || 'Testnet';
// HOSTING_ENV is a variable used in extracting the ip address of the host machine,
// of which value could be either 'local', 'default', or 'gcp'.
const HOSTING_ENV = process.env.HOSTING_ENV || 'default';
const COMCOM_HOST_EXTERNAL_IP = process.env.COMCOM_HOST_EXTERNAL_IP ?
process.env.COMCOM_HOST_EXTERNAL_IP : '';
const COMCOM_HOST_INTERNAL_IP_MAP = {
'aincom1': '192.168.1.13',
'aincom2': '192.168.1.14',
}
const ACCOUNT_INDEX = process.env.ACCOUNT_INDEX || null;
const TRACKER_WS_ADDR = process.env.TRACKER_WS_ADDR || 'ws://localhost:5000';
const PORT = process.env.PORT || getPortNumber(8080, 8081);
Expand Down Expand Up @@ -452,6 +458,8 @@ module.exports = {
TRANSACTION_TRACKER_TIME_OUT_MS,
NETWORK_ID,
HOSTING_ENV,
COMCOM_HOST_EXTERNAL_IP,
COMCOM_HOST_INTERNAL_IP_MAP,
ACCOUNT_INDEX,
PORT,
P2P_PORT,
Expand Down
18 changes: 18 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const axios = require('axios');
const semver = require('semver');
const disk = require('diskusage');
const os = require('os');
const _ = require('lodash');
const ainUtil = require('@ainblockchain/ain-util');
const logger = require('../logger');
const Consensus = require('../consensus');
Expand All @@ -17,6 +18,8 @@ const {
P2P_PORT,
TRACKER_WS_ADDR,
HOSTING_ENV,
COMCOM_HOST_EXTERNAL_IP,
COMCOM_HOST_INTERNAL_IP_MAP,
MessageTypes,
PredefinedDbPaths,
WriteDbOperations,
Expand Down Expand Up @@ -167,6 +170,21 @@ class P2pServer {
logger.error(`[${P2P_PREFIX}] Failed to get ip address: ${JSON.stringify(err, null, 2)}`);
process.exit(0);
});
} else if (HOSTING_ENV === 'comcom') {
let ipAddr = null;
if (internal) {
const hostname = _.toLower(os.hostname());
logger.info(`[${P2P_PREFIX}] Hostname: ${hostname}`);
ipAddr = COMCOM_HOST_INTERNAL_IP_MAP[hostname];
} else {
ipAddr = COMCOM_HOST_EXTERNAL_IP;
}
if (ipAddr) {
return ipAddr;
}
logger.error(
`[${P2P_PREFIX}] Failed to get ${internal ? 'internal' : 'external'} ip address.`);
process.exit(0);
} else if (HOSTING_ENV === 'local') {
return ip.address();
} else {
Expand Down