Skip to content

Commit 7d4506e

Browse files
committed
chore: move nodes/agent/errors.ts into nodes/errors.ts
1 parent 1cc8ad1 commit 7d4506e

14 files changed

+38
-48
lines changed

src/nodes/NodeConnectionManager.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,9 +1710,9 @@ class NodeConnectionManager {
17101710

17111711
// Write the forward authentication message from this node
17121712
await writer.write(authenticateMessage);
1713-
const forwardMessageResultPair = await utils.resultOrAbort(
1713+
const forwardMessageResultPair = await utils.raceSignal(
17141714
reader.read(),
1715-
ctx,
1715+
ctx.signal,
17161716
);
17171717
if (forwardMessageResultPair.done) {
17181718
throw new nodesErrors.ErrorNodeAuthenticationInvalidProtocol(
@@ -1727,9 +1727,9 @@ class NodeConnectionManager {
17271727
}
17281728

17291729
// Read and process the authentication token sent by the connectee
1730-
const reverseMessageInPair = await utils.resultOrAbort(
1730+
const reverseMessageInPair = await utils.raceSignal(
17311731
reader.read(),
1732-
ctx,
1732+
ctx.signal,
17331733
);
17341734
if (reverseMessageInPair.done) {
17351735
throw new nodesErrors.ErrorNodeAuthenticationInvalidProtocol(
@@ -1750,7 +1750,7 @@ class NodeConnectionManager {
17501750
await writer.write({ type: 'success', success: true });
17511751

17521752
// Wait for other node to set its state
1753-
const ackPair = await utils.resultOrAbort(reader.read(), ctx);
1753+
const ackPair = await utils.raceSignal(reader.read(), ctx.signal);
17541754
if (ackPair.done) {
17551755
throw new nodesErrors.ErrorNodeAuthenticationInvalidProtocol(
17561756
'Stream ended prematurely',
@@ -1920,9 +1920,9 @@ class NodeConnectionManager {
19201920
if (connectionEntry == null) utils.never('Connection should be defined');
19211921

19221922
try {
1923-
const reverseMessageInPair = await utils.resultOrAbort(
1923+
const reverseMessageInPair = await utils.raceSignal(
19241924
inputIterator.next(),
1925-
ctx,
1925+
ctx.signal,
19261926
);
19271927
if (reverseMessageInPair.done === true) {
19281928
throw new nodesErrors.ErrorNodeAuthenticationInvalidProtocol(
@@ -1952,9 +1952,9 @@ class NodeConnectionManager {
19521952

19531953
// Generate and yield the forward token from this node
19541954
yield await this.authenticateNetworkForwardCallback(ctx);
1955-
const forwardMessageResultPair = await utils.resultOrAbort(
1955+
const forwardMessageResultPair = await utils.raceSignal(
19561956
inputIterator.next(),
1957-
ctx,
1957+
ctx.signal,
19581958
);
19591959
if (forwardMessageResultPair.done === true) {
19601960
throw new nodesErrors.ErrorNodeAuthenticationInvalidProtocol(

src/nodes/agent/errors.ts

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

src/nodes/agent/handlers/NodesAuthenticateConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {
88
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager.js';
99
import type { JSONValue } from '../../../types.js';
1010
import { DuplexHandler } from '@matrixai/rpc';
11-
import * as agentErrors from '../errors.js';
1211
import * as agentUtils from '../utils.js';
12+
import * as nodesErrors from '../../errors.js';
1313

1414
class NodesAuthenticateConnection extends DuplexHandler<
1515
{
@@ -39,7 +39,7 @@ class NodesAuthenticateConnection extends DuplexHandler<
3939
// Connections should always be validated
4040
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
4141
if (requestingNodeId == null) {
42-
throw new agentErrors.ErrorAgentNodeIdMissing();
42+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
4343
}
4444

4545
// This async generator handles the back-and-forth communication to

src/nodes/agent/handlers/NodesClaimNetworkSign.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type {
66
import type NodeManager from '../../../nodes/NodeManager.js';
77
import type { JSONValue } from '../../../types.js';
88
import { UnaryHandler } from '@matrixai/rpc';
9-
import * as agentErrors from '../errors.js';
109
import * as agentUtils from '../utils.js';
10+
import * as nodesErrors from '../../errors.js';
1111

1212
class NodesClaimNetworkSign extends UnaryHandler<
1313
{
@@ -25,7 +25,7 @@ class NodesClaimNetworkSign extends UnaryHandler<
2525
// Connections should always be validated
2626
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
2727
if (requestingNodeId == null) {
28-
throw new agentErrors.ErrorAgentNodeIdMissing();
28+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
2929
}
3030
return nodeManager.handleClaimNetwork(requestingNodeId, input);
3131
};

src/nodes/agent/handlers/NodesClaimNetworkVerify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type {
66
import type NodeManager from '../../../nodes/NodeManager.js';
77
import type { JSONValue } from '../../../types.js';
88
import { UnaryHandler } from '@matrixai/rpc';
9-
import * as agentErrors from '../errors.js';
109
import * as agentUtils from '../utils.js';
10+
import * as nodesErrors from '../../errors.js';
1111

1212
class NodesClaimNetworkVerify extends UnaryHandler<
1313
{
@@ -24,7 +24,7 @@ class NodesClaimNetworkVerify extends UnaryHandler<
2424
const { nodeManager }: { nodeManager: NodeManager } = this.container;
2525
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
2626
if (requestingNodeId == null) {
27-
throw new agentErrors.ErrorAgentNodeIdMissing();
27+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
2828
}
2929
return nodeManager.handleVerifyClaimNetwork(requestingNodeId, input);
3030
};

src/nodes/agent/handlers/NodesConnectionSignalFinal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { validateSync } from '../../../validation/index.js';
1313
import { matchSync } from '../../../utils/index.js';
1414
import * as keysUtils from '../../../keys/utils/index.js';
1515
import * as ids from '../../../ids/index.js';
16-
import * as agentErrors from '../errors.js';
1716
import * as agentUtils from '../utils.js';
1817
import * as nodesErrors from '../../errors.js';
1918

@@ -56,7 +55,7 @@ class NodesConnectionSignalFinal extends UnaryHandler<
5655
);
5756
const relayingNodeId = agentUtils.nodeIdFromMeta(meta);
5857
if (relayingNodeId == null) {
59-
throw new agentErrors.ErrorAgentNodeIdMissing();
58+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
6059
}
6160
const requestSignature = Buffer.from(input.requestSignature, 'base64url');
6261
// Checking request requestSignature, requestData is just `<sourceNodeId><targetNodeId>` concatenated

src/nodes/agent/handlers/NodesConnectionSignalInitial.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { UnaryHandler } from '@matrixai/rpc';
1212
import { validateSync } from '../../../validation/index.js';
1313
import { matchSync } from '../../../utils/index.js';
1414
import { never } from '../../../utils/index.js';
15-
import * as agentErrors from '../errors.js';
1615
import * as agentUtils from '../utils.js';
1716
import * as nodesErrors from '../../errors.js';
1817
import * as keysUtils from '../../../keys/utils/index.js';
@@ -38,7 +37,7 @@ class NodesConnectionSignalInitial extends UnaryHandler<
3837
// Connections should always be validated
3938
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
4039
if (requestingNodeId == null) {
41-
throw new agentErrors.ErrorAgentNodeIdMissing();
40+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
4241
}
4342
const { targetNodeId }: { targetNodeId: NodeId } = validateSync(
4443
(keyPath, value) => {

src/nodes/agent/handlers/NodesCrossSignClaim.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
import type NodeManager from '../../NodeManager.js';
88
import type ACL from '../../../acl/ACL.js';
99
import { DuplexHandler } from '@matrixai/rpc';
10-
import * as agentErrors from '../errors.js';
1110
import * as agentUtils from '../utils.js';
1211
import * as nodesErrors from '../../errors.js';
1312

@@ -36,7 +35,7 @@ class NodesCrossSignClaim extends DuplexHandler<
3635
} = this.container;
3736
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
3837
if (requestingNodeId == null) {
39-
throw new agentErrors.ErrorAgentNodeIdMissing();
38+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
4039
}
4140
// Check the ACL for permissions
4241
const permissions = await acl.getNodePerm(requestingNodeId);

src/nodes/agent/handlers/VaultsGitInfoGet.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type VaultManager from '../../../vaults/VaultManager.js';
77
import type { JSONValue } from '../../../types.js';
88
import { ReadableStream } from 'stream/web';
99
import { RawHandler } from '@matrixai/rpc';
10-
import * as agentErrors from '../errors.js';
10+
import * as agentUtils from '../utils.js';
11+
import * as nodesErrors from '../../errors.js';
12+
import * as nodesUtils from '../../utils.js';
1113
import * as vaultsUtils from '../../../vaults/utils.js';
1214
import * as vaultsErrors from '../../../vaults/errors.js';
13-
import * as nodesUtils from '../../utils.js';
14-
import * as agentUtils from '../utils.js';
1515
import * as utils from '../../../utils/index.js';
1616

1717
/**
@@ -65,7 +65,7 @@ class VaultsGitInfoGet extends RawHandler<{
6565
// Getting the NodeId from the connection metadata
6666
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
6767
if (requestingNodeId == null) {
68-
throw new agentErrors.ErrorAgentNodeIdMissing();
68+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
6969
}
7070
const nodeIdEncoded = nodesUtils.encodeNodeId(requestingNodeId);
7171
const permissions = await acl.getNodePerm(requestingNodeId, tran);

src/nodes/agent/handlers/VaultsGitPackGet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type ACL from '../../../acl/ACL.js';
66
import type VaultManager from '../../../vaults/VaultManager.js';
77
import { ReadableStream } from 'stream/web';
88
import { RawHandler } from '@matrixai/rpc';
9-
import * as agentErrors from '../errors.js';
109
import * as agentUtils from '../utils.js';
10+
import * as nodesErrors from '../../errors.js';
1111
import * as nodesUtils from '../../utils.js';
1212
import * as vaultsUtils from '../../../vaults/utils.js';
1313
import * as vaultsErrors from '../../../vaults/errors.js';
@@ -31,7 +31,7 @@ class VaultsGitPackGet extends RawHandler<{
3131
const [headerMessage, inputStream] = input;
3232
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
3333
if (requestingNodeId == null) {
34-
throw new agentErrors.ErrorAgentNodeIdMissing();
34+
throw new nodesErrors.ErrorNodeConnectionInvalidIdentity();
3535
}
3636
const nodeIdEncoded = nodesUtils.encodeNodeId(requestingNodeId);
3737
const params = headerMessage.params;

0 commit comments

Comments
 (0)