-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNodesSyncGraph.ts
More file actions
48 lines (46 loc) · 1.44 KB
/
NodesSyncGraph.ts
File metadata and controls
48 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { ContextTimed } from '@matrixai/contexts';
import type { JSONValue } from '@matrixai/rpc';
import type NodeManager from '../../nodes/NodeManager.js';
import type {
ClientRPCRequestParams,
ClientRPCResponseResult,
NodesSyncGraphMessage,
} from '../types.js';
import type { AgentClientManifest } from '../../nodes/agent/callers/index.js';
import type { NodeId, NodeAddress } from '../../nodes/types.js';
import { UnaryHandler } from '@matrixai/rpc';
import * as nodesUtils from '../../nodes/utils.js';
class NodesSyncGraph extends UnaryHandler<
{
nodeManager: NodeManager<AgentClientManifest>;
},
ClientRPCRequestParams<NodesSyncGraphMessage>,
ClientRPCResponseResult
> {
public handle = async (
input: ClientRPCRequestParams<NodesSyncGraphMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult> => {
const {
nodeManager,
}: {
nodeManager: NodeManager<AgentClientManifest>;
} = this.container;
// Convert the encoded node id to the binary one we expect
const parsedInitialNodes = input.initialNodes.map(
(value) =>
[nodesUtils.decodeNodeId(value[0]), value[1]] as [NodeId, NodeAddress],
);
await nodeManager.syncNodeGraph(
input.network,
parsedInitialNodes,
input.connectionTimeout,
true,
ctx,
);
return {};
};
}
export default NodesSyncGraph;