Skip to content

Commit 045be37

Browse files
committed
refactor: converting agent handlers
* Related #512 * Related #495 [ci skip]
1 parent 93bcab7 commit 045be37

31 files changed

+829
-1171
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@matrixai/resources": "^1.1.5",
9292
"@matrixai/timer": "^1.1.1",
9393
"@matrixai/workers": "^1.3.7",
94+
"@matrixai/quic": "0.0.7-alpha.0",
9495
"@peculiar/asn1-pkcs8": "^2.3.0",
9596
"@peculiar/asn1-schema": "^2.3.0",
9697
"@peculiar/asn1-x509": "^2.3.0",

src/agent/GRPCClientAgent.ts

Lines changed: 0 additions & 249 deletions
This file was deleted.

src/agent/errors.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,9 @@ import { ErrorPolykey, sysexits } from '../errors';
22

33
class ErrorAgent<T> extends ErrorPolykey<T> {}
44

5-
class ErrorAgentRunning<T> extends ErrorPolykey<T> {
6-
static description = 'Agent Client is running';
7-
exitCode = sysexits.USAGE;
8-
}
9-
10-
class ErrorAgentClientNotStarted<T> extends ErrorAgent<T> {
11-
static description = 'Agent Client is not started';
12-
exitCode = sysexits.USAGE;
13-
}
14-
15-
class ErrorAgentClientDestroyed<T> extends ErrorAgent<T> {
16-
static description = 'Agent Client is destroyed';
17-
exitCode = sysexits.USAGE;
18-
}
19-
205
class ErrorConnectionInfoMissing<T> extends ErrorAgent<T> {
21-
static description = 'Vault already exists';
6+
static description = 'Connection info was missing from connection metadata';
227
exitCode = sysexits.UNAVAILABLE;
238
}
249

25-
export {
26-
ErrorAgent,
27-
ErrorAgentClientNotStarted,
28-
ErrorAgentRunning,
29-
ErrorAgentClientDestroyed,
30-
ErrorConnectionInfoMissing,
31-
};
10+
export { ErrorConnectionInfoMissing };

src/agent/handlers/clientManifest.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
2+
import type { EchoMessage } from './types';
3+
import type {
4+
AgentClaimMessage,
5+
ClaimIdMessage,
6+
GitPackMessage,
7+
HolePunchRelayMessage,
8+
NodeAddressMessage,
9+
NodeIdMessage,
10+
SignedNotificationEncoded,
11+
VaultInfo,
12+
VaultsGitInfoGetMessage,
13+
VaultsGitPackGetMessage,
14+
VaultsScanMessage,
15+
} from './types';
16+
import { DuplexCaller, ServerCaller, UnaryCaller } from '../../rpc/callers';
17+
18+
const echo = new UnaryCaller<
19+
AgentRPCRequestParams<EchoMessage>,
20+
AgentRPCResponseResult<EchoMessage>
21+
>();
22+
23+
const nodeChainDataGet = new ServerCaller<
24+
AgentRPCRequestParams<ClaimIdMessage>,
25+
AgentRPCResponseResult<AgentClaimMessage>
26+
>();
27+
28+
// Const nodesClaimsGet = new UnaryCaller<
29+
// AgentRPCRequestParams,
30+
// AgentRPCResponseResult
31+
// >();
32+
33+
const nodesClosestLocalNodesGet = new ServerCaller<
34+
AgentRPCRequestParams<NodeIdMessage>,
35+
AgentRPCResponseResult<NodeAddressMessage>
36+
>();
37+
38+
// TODO: still to be completed
39+
const nodesCrossSignClaim = new DuplexCaller<
40+
AgentRPCRequestParams<EchoMessage>,
41+
AgentRPCResponseResult<EchoMessage>
42+
>();
43+
44+
// TODO: still to be completed
45+
const nodesHolePunchMessageSend = new UnaryCaller<
46+
AgentRPCRequestParams<HolePunchRelayMessage>,
47+
AgentRPCResponseResult
48+
>();
49+
50+
const notificationsSend = new UnaryCaller<
51+
AgentRPCRequestParams<SignedNotificationEncoded>,
52+
AgentRPCResponseResult
53+
>();
54+
55+
const vaultsGitInfoGet = new ServerCaller<
56+
AgentRPCRequestParams<VaultsGitInfoGetMessage>,
57+
AgentRPCResponseResult<VaultInfo | GitPackMessage>
58+
>();
59+
60+
const vaultsGitPackGet = new ServerCaller<
61+
AgentRPCRequestParams<VaultsGitPackGetMessage>,
62+
AgentRPCResponseResult<GitPackMessage>
63+
>();
64+
65+
const vaultsScan = new ServerCaller<
66+
AgentRPCRequestParams,
67+
AgentRPCResponseResult<VaultsScanMessage>
68+
>();
69+
70+
// No type used here, it will override type inference
71+
const clientManifest = {
72+
echo,
73+
nodeChainDataGet,
74+
// NodeClaimsGet,
75+
nodesClosestLocalNodesGet,
76+
nodesCrossSignClaim,
77+
nodesHolePunchMessageSend,
78+
notificationsSend,
79+
vaultsGitInfoGet,
80+
vaultsGitPackGet,
81+
vaultsScan,
82+
};
83+
84+
export {
85+
clientManifest,
86+
echo,
87+
nodeChainDataGet,
88+
// NodeClaimsGet,
89+
nodesClosestLocalNodesGet,
90+
nodesCrossSignClaim,
91+
nodesHolePunchMessageSend,
92+
notificationsSend,
93+
vaultsGitInfoGet,
94+
vaultsGitPackGet,
95+
vaultsScan,
96+
};

0 commit comments

Comments
 (0)