UNPKG

2.05 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const log_1 = require("../common/log");
4const log = log_1.create('ccp');
5const route_broadcaster_1 = require("../services/route-broadcaster");
6const ilp_protocol_ccp_1 = require("ilp-protocol-ccp");
7class CcpController {
8 constructor(deps) {
9 this.routeBroadcaster = deps(route_broadcaster_1.default);
10 }
11 async handle(data, sourceAccount, { parsedPacket }) {
12 switch (parsedPacket.destination) {
13 case ilp_protocol_ccp_1.CCP_CONTROL_DESTINATION:
14 return this.handleRouteControl(data, sourceAccount);
15 case ilp_protocol_ccp_1.CCP_UPDATE_DESTINATION:
16 return this.handleRouteUpdate(data, sourceAccount);
17 default:
18 throw new Error('unrecognized ccp message. destination=' + parsedPacket.destination);
19 }
20 }
21 async handleRouteControl(data, sourceAccount) {
22 const routeControl = ilp_protocol_ccp_1.deserializeCcpRouteControlRequest(data);
23 log.trace('received route control message. sender=%s, tableId=%s epoch=%s features=%s', sourceAccount, routeControl.lastKnownRoutingTableId, routeControl.lastKnownEpoch, routeControl.features.join(','));
24 this.routeBroadcaster.handleRouteControl(sourceAccount, routeControl);
25 return ilp_protocol_ccp_1.serializeCcpResponse();
26 }
27 async handleRouteUpdate(data, sourceAccount) {
28 const routeUpdate = ilp_protocol_ccp_1.deserializeCcpRouteUpdateRequest(data);
29 log.trace('received routes. sender=%s speaker=%s currentEpoch=%s fromEpoch=%s toEpoch=%s newRoutes=%s withdrawnRoutes=%s', sourceAccount, routeUpdate.speaker, routeUpdate.currentEpochIndex, routeUpdate.fromEpochIndex, routeUpdate.toEpochIndex, routeUpdate.newRoutes.length, routeUpdate.withdrawnRoutes.length);
30 this.routeBroadcaster.handleRouteUpdate(sourceAccount, routeUpdate);
31 return ilp_protocol_ccp_1.serializeCcpResponse();
32 }
33}
34exports.default = CcpController;
35//# sourceMappingURL=ccp.js.map
\No newline at end of file