Skip to content

Commit

Permalink
refactor: converting agent handlers
Browse files Browse the repository at this point in the history
* Related #512
* Related #495

[ci skip]
  • Loading branch information
tegefaulkes committed Jul 20, 2023
1 parent 93bcab7 commit 045be37
Show file tree
Hide file tree
Showing 31 changed files with 829 additions and 1,171 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@matrixai/resources": "^1.1.5",
"@matrixai/timer": "^1.1.1",
"@matrixai/workers": "^1.3.7",
"@matrixai/quic": "0.0.7-alpha.0",
"@peculiar/asn1-pkcs8": "^2.3.0",
"@peculiar/asn1-schema": "^2.3.0",
"@peculiar/asn1-x509": "^2.3.0",
Expand Down
249 changes: 0 additions & 249 deletions src/agent/GRPCClientAgent.ts

This file was deleted.

25 changes: 2 additions & 23 deletions src/agent/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,9 @@ import { ErrorPolykey, sysexits } from '../errors';

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

class ErrorAgentRunning<T> extends ErrorPolykey<T> {
static description = 'Agent Client is running';
exitCode = sysexits.USAGE;
}

class ErrorAgentClientNotStarted<T> extends ErrorAgent<T> {
static description = 'Agent Client is not started';
exitCode = sysexits.USAGE;
}

class ErrorAgentClientDestroyed<T> extends ErrorAgent<T> {
static description = 'Agent Client is destroyed';
exitCode = sysexits.USAGE;
}

class ErrorConnectionInfoMissing<T> extends ErrorAgent<T> {
static description = 'Vault already exists';
static description = 'Connection info was missing from connection metadata';
exitCode = sysexits.UNAVAILABLE;
}

export {
ErrorAgent,
ErrorAgentClientNotStarted,
ErrorAgentRunning,
ErrorAgentClientDestroyed,
ErrorConnectionInfoMissing,
};
export { ErrorConnectionInfoMissing };
96 changes: 96 additions & 0 deletions src/agent/handlers/clientManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
import type { EchoMessage } from './types';
import type {
AgentClaimMessage,
ClaimIdMessage,
GitPackMessage,
HolePunchRelayMessage,
NodeAddressMessage,
NodeIdMessage,
SignedNotificationEncoded,
VaultInfo,
VaultsGitInfoGetMessage,
VaultsGitPackGetMessage,
VaultsScanMessage,
} from './types';
import { DuplexCaller, ServerCaller, UnaryCaller } from '../../rpc/callers';

const echo = new UnaryCaller<
AgentRPCRequestParams<EchoMessage>,
AgentRPCResponseResult<EchoMessage>
>();

const nodeChainDataGet = new ServerCaller<
AgentRPCRequestParams<ClaimIdMessage>,
AgentRPCResponseResult<AgentClaimMessage>
>();

// Const nodesClaimsGet = new UnaryCaller<
// AgentRPCRequestParams,
// AgentRPCResponseResult
// >();

const nodesClosestLocalNodesGet = new ServerCaller<
AgentRPCRequestParams<NodeIdMessage>,
AgentRPCResponseResult<NodeAddressMessage>
>();

// TODO: still to be completed
const nodesCrossSignClaim = new DuplexCaller<
AgentRPCRequestParams<EchoMessage>,
AgentRPCResponseResult<EchoMessage>
>();

// TODO: still to be completed
const nodesHolePunchMessageSend = new UnaryCaller<
AgentRPCRequestParams<HolePunchRelayMessage>,
AgentRPCResponseResult
>();

const notificationsSend = new UnaryCaller<
AgentRPCRequestParams<SignedNotificationEncoded>,
AgentRPCResponseResult
>();

const vaultsGitInfoGet = new ServerCaller<
AgentRPCRequestParams<VaultsGitInfoGetMessage>,
AgentRPCResponseResult<VaultInfo | GitPackMessage>
>();

const vaultsGitPackGet = new ServerCaller<
AgentRPCRequestParams<VaultsGitPackGetMessage>,
AgentRPCResponseResult<GitPackMessage>
>();

const vaultsScan = new ServerCaller<
AgentRPCRequestParams,
AgentRPCResponseResult<VaultsScanMessage>
>();

// No type used here, it will override type inference
const clientManifest = {
echo,
nodeChainDataGet,
// NodeClaimsGet,
nodesClosestLocalNodesGet,
nodesCrossSignClaim,
nodesHolePunchMessageSend,
notificationsSend,
vaultsGitInfoGet,
vaultsGitPackGet,
vaultsScan,
};

export {
clientManifest,
echo,
nodeChainDataGet,
// NodeClaimsGet,
nodesClosestLocalNodesGet,
nodesCrossSignClaim,
nodesHolePunchMessageSend,
notificationsSend,
vaultsGitInfoGet,
vaultsGitPackGet,
vaultsScan,
};
Loading

0 comments on commit 045be37

Please sign in to comment.