Skip to content

Commit

Permalink
Reuse existing ip addresses in event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
platfowner committed Aug 8, 2024
1 parent 81fef4f commit c5f7178
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions event-handler/event-channel-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ class EventChannelManager {
this.heartbeatInterval = null;
}

async getNetworkInfo() {
const ipAddr = await getIpAddress(NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL);
getNetworkInfo() {
const ipAddr = (NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL) ? this.node.ipAddrInternal : this.node.ipAddrExternal;
const eventHandlerUrl = new URL(`ws://${ipAddr}:${NodeConfigs.EVENT_HANDLER_PORT}`);
return {
url: eventHandlerUrl.toString(),
port: NodeConfigs.EVENT_HANDLER_PORT,
maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS,
numEventChannels: this.getNumEventChannels(),
maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS,
Expand Down
6 changes: 3 additions & 3 deletions json_rpc/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const { JSON_RPC_METHODS } = require('./constants');
module.exports = function getEventHandlerApis(eventHandler) {
return {
// NOTE(cshcomcom): Async function doesn't need a done parameter. (Ref: https://www.npmjs.com/package/jayson#promises)
[JSON_RPC_METHODS.NET_GET_EVENT_HANDLER_NETWORK_INFO]: async function(args) {
[JSON_RPC_METHODS.NET_GET_EVENT_HANDLER_NETWORK_INFO]: function(args, done) {
const beginTime = Date.now();
const result = await eventHandler.eventChannelManager.getNetworkInfo();
const result = eventHandler.eventChannelManager.getNetworkInfo();
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
return JsonRpcUtil.addProtocolVersion({ result });
done(null, JsonRpcUtil.addProtocolVersion({ result }));
},

[JSON_RPC_METHODS.AIN_GET_EVENT_HANDLER_FILTER_INFO]: function(args, done) {
Expand Down
5 changes: 2 additions & 3 deletions test/unit/event-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,13 @@ describe('EventHandler Test', () => {
it('getNetworkInfo', async () => {
const intIp = await getIpAddress(true);
const intUrl = new URL(`ws://${intIp}:${NodeConfigs.EVENT_HANDLER_PORT}`);
const networkInfo = await eventChannelManager.getNetworkInfo();
const networkInfo = eventChannelManager.getNetworkInfo();
assert.deepEqual(networkInfo, {
url: intUrl.toString(),
maxNumEventChannels: NodeConfigs.MAX_NUM_EVENT_CHANNELS,
numEventChannels: 0,
maxNumEventFilters: NodeConfigs.MAX_NUM_EVENT_FILTERS,
numEventFilters: 0,
url: intUrl.toString(),
port: NodeConfigs.EVENT_HANDLER_PORT,
});
});
});
Expand Down

0 comments on commit c5f7178

Please sign in to comment.