UNPKG

1.25 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const IlpPacket = require("ilp-packet");
4const ildcp_host_1 = require("./ildcp-host");
5const ccp_1 = require("./ccp");
6const { InvalidPacketError } = IlpPacket.Errors;
7const PEER_PROTOCOL_CONDITION = Buffer.from('Zmh6rfhivXdsj8GLjp+OIAiXFIVu4jOzkCpZHQ1fKSU=', 'base64');
8class PeerProtocolController {
9 constructor(deps) {
10 this.ildcpHostController = deps(ildcp_host_1.default);
11 this.ccpController = deps(ccp_1.default);
12 }
13 async handle(data, sourceAccount, { parsedPacket }) {
14 if (!PEER_PROTOCOL_CONDITION.equals(parsedPacket.executionCondition)) {
15 throw new InvalidPacketError('condition must be peer protocol condition.');
16 }
17 if (parsedPacket.destination === 'peer.config') {
18 return this.ildcpHostController.handle(data, sourceAccount);
19 }
20 else if (parsedPacket.destination.startsWith('peer.route')) {
21 return this.ccpController.handle(data, sourceAccount, { parsedPacket });
22 }
23 else {
24 throw new InvalidPacketError('unknown peer protocol.');
25 }
26 }
27}
28exports.default = PeerProtocolController;
29//# sourceMappingURL=peer-protocol.js.map
\No newline at end of file