UNPKG

1.67 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const accounts_1 = require("../services/accounts");
4const config_1 = require("../services/config");
5const forwarding_routing_table_1 = require("../services/forwarding-routing-table");
6const ccp_sender_1 = require("./ccp-sender");
7const ccp_receiver_1 = require("./ccp-receiver");
8class Peer {
9 constructor({ deps, accountId, sendRoutes, receiveRoutes }) {
10 this.getAccountRelation = (accountId) => {
11 return accountId ? this.accounts.getInfo(accountId).relation : 'local';
12 };
13 this.config = deps(config_1.default);
14 this.accounts = deps(accounts_1.default);
15 this.accountId = accountId;
16 const plugin = this.accounts.getPlugin(accountId);
17 const forwardingRoutingTable = deps(forwarding_routing_table_1.default);
18 if (sendRoutes) {
19 this.ccpSender = new ccp_sender_1.default({
20 accountId,
21 plugin,
22 forwardingRoutingTable,
23 getOwnAddress: () => this.accounts.getOwnAddress(),
24 getAccountRelation: this.getAccountRelation,
25 routeExpiry: this.config.routeExpiry,
26 routeBroadcastInterval: this.config.routeBroadcastInterval
27 });
28 }
29 if (receiveRoutes) {
30 this.ccpReceiver = new ccp_receiver_1.default({ accountId, plugin });
31 }
32 }
33 getAccountId() {
34 return this.accountId;
35 }
36 getReceiver() {
37 return this.ccpReceiver;
38 }
39 getSender() {
40 return this.ccpSender;
41 }
42}
43exports.default = Peer;
44//# sourceMappingURL=peer.js.map
\No newline at end of file