Skip to content

Commit d72393e

Browse files
committed
fix: moved nodeIdFromMeta to agent domain
[ci skip]
1 parent 3427f5b commit d72393e

8 files changed

Lines changed: 32 additions & 28 deletions

File tree

src/agent/handlers/nodesCrossSignClaim.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { AgentClaimMessage } from './types';
22
import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
33
import type ACL from '../../acl/ACL';
44
import type NodeManager from '../../nodes/NodeManager';
5-
import * as networkUtils from '../../network/utils';
65
import * as nodesErrors from '../../nodes/errors';
76
import { DuplexHandler } from '../../rpc/handlers';
87
import * as agentErrors from '../errors';
8+
import * as agentUtils from '../utils';
99

1010
class NodesCrossSignClaimHandler extends DuplexHandler<
1111
{
@@ -21,7 +21,7 @@ class NodesCrossSignClaimHandler extends DuplexHandler<
2121
meta,
2222
): AsyncGenerator<AgentRPCResponseResult<AgentClaimMessage>> {
2323
const { acl, nodeManager } = this.container;
24-
const requestingNodeId = networkUtils.nodeIdFromMeta(meta);
24+
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
2525
if (requestingNodeId == null) {
2626
throw new agentErrors.ErrorAgentNodeIdMissing();
2727
}

src/agent/handlers/nodesHolePunchMessageSend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
88
import type { NodeId } from '../../ids';
99
import type { HolePunchRelayMessage } from './types';
1010
import * as agentErrors from '../errors';
11-
import * as networkUtils from '../../network/utils';
1211
import { validateSync } from '../../validation';
1312
import { matchSync } from '../../utils';
1413
import * as validationUtils from '../../validation/utils';
1514
import * as nodesUtils from '../../nodes/utils';
15+
import * as agentUtils from '../utils';
1616
import { UnaryHandler } from '../../rpc/handlers';
1717

1818
class NodesHolePunchMessageSendHandler extends UnaryHandler<
@@ -56,7 +56,7 @@ class NodesHolePunchMessageSendHandler extends UnaryHandler<
5656
},
5757
);
5858
// Connections should always be validated
59-
const requestingNodeId = networkUtils.nodeIdFromMeta(meta);
59+
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
6060
if (requestingNodeId == null) {
6161
throw new agentErrors.ErrorAgentNodeIdMissing();
6262
}

src/agent/handlers/vaultsGitInfoGet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import type Logger from '@matrixai/logger';
77
import type { VaultsGitInfoGetMessage } from './types';
88
import type { VaultAction } from '../../vaults/types';
99
import * as agentErrors from '../errors';
10-
import * as networkUtils from '../../network/utils';
1110
import * as vaultsUtils from '../../vaults/utils';
1211
import * as vaultsErrors from '../../vaults/errors';
1312
import { ServerHandler } from '../../rpc/handlers';
1413
import { validateSync } from '../../validation';
1514
import { matchSync } from '../../utils';
1615
import * as validationUtils from '../../validation/utils';
1716
import * as nodesUtils from '../../nodes/utils';
17+
import * as agentUtils from '../utils';
1818

1919
class VaultsGitInfoGetHandler extends ServerHandler<
2020
{
@@ -65,7 +65,7 @@ class VaultsGitInfoGetHandler extends ServerHandler<
6565
throw new vaultsErrors.ErrorVaultsVaultUndefined();
6666
}
6767
// Getting the NodeId from the connection metadata
68-
const requestingNodeId = networkUtils.nodeIdFromMeta(meta);
68+
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
6969
if (requestingNodeId == null) {
7070
throw new agentErrors.ErrorAgentNodeIdMissing();
7171
}

src/agent/handlers/vaultsGitPackGet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import type { DB } from '@matrixai/db';
55
import type { GitPackMessage, VaultsGitPackGetMessage } from './types';
66
import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
77
import * as agentErrors from '../errors';
8-
import * as networkUtils from '../../network/utils';
98
import * as nodesUtils from '../../nodes/utils';
109
import * as vaultsUtils from '../../vaults/utils';
1110
import * as vaultsErrors from '../../vaults/errors';
1211
import { validateSync } from '../../validation';
1312
import { matchSync } from '../../utils';
1413
import * as validationUtils from '../../validation/utils';
1514
import { ServerHandler } from '../../rpc/handlers';
15+
import * as agentUtils from '../utils';
1616

1717
class VaultsGitPackGetHandler extends ServerHandler<
1818
{
@@ -29,7 +29,7 @@ class VaultsGitPackGetHandler extends ServerHandler<
2929
meta,
3030
): AsyncGenerator<AgentRPCResponseResult<GitPackMessage>> {
3131
const { vaultManager, acl, db } = this.container;
32-
const requestingNodeId = networkUtils.nodeIdFromMeta(meta);
32+
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
3333
if (requestingNodeId == null) {
3434
throw new agentErrors.ErrorAgentNodeIdMissing();
3535
}

src/agent/handlers/vaultsScan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { AgentRPCRequestParams, AgentRPCResponseResult } from '../types';
33
import type VaultManager from '../../vaults/VaultManager';
44
import type { DB } from '@matrixai/db';
55
import * as agentErrors from '../errors';
6-
import * as networkUtils from '../../network/utils';
76
import { ServerHandler } from '../../rpc/handlers';
87
import * as vaultsUtils from '../../vaults/utils';
8+
import * as agentUtils from '../utils';
99

1010
class VaultsScanHandler extends ServerHandler<
1111
{
@@ -21,7 +21,7 @@ class VaultsScanHandler extends ServerHandler<
2121
meta,
2222
): AsyncGenerator<AgentRPCResponseResult<VaultsScanMessage>> {
2323
const { vaultManager, db } = this.container;
24-
const requestingNodeId = networkUtils.nodeIdFromMeta(meta);
24+
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
2525
if (requestingNodeId == null) {
2626
throw new agentErrors.ErrorAgentNodeIdMissing();
2727
}

src/agent/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './handlers';
22
export * as types from './types';
3+
export * as utils from './utils';

src/agent/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { NodeId } from '../ids/types';
2+
import * as keysUtils from '../keys/utils';
3+
4+
/**
5+
* Used to extract the NodeId from the connection metadata.
6+
* Used by the RPC handlers when they need to know the NodeId of the requester.
7+
* @param meta
8+
*/
9+
function nodeIdFromMeta(meta: any): NodeId | undefined {
10+
const remoteCerts = meta.remoteCertificates;
11+
if (remoteCerts == null) return;
12+
const leafCertPEM = remoteCerts[0];
13+
if (leafCertPEM == null) return;
14+
const leafCert = keysUtils.certFromPEM(leafCertPEM);
15+
if (leafCert == null) return;
16+
const nodeId = keysUtils.certNodeId(leafCert);
17+
if (nodeId == null) return;
18+
return nodeId;
19+
}
20+
21+
export { nodeIdFromMeta };

src/network/utils.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,6 @@ async function resolveHostnames(
462462
return final;
463463
}
464464

465-
/**
466-
* Used to extract the NodeId from the connection metadata.
467-
* Used by the RPC handlers when they need to know the NodeId of the requester.
468-
* @param meta
469-
*/
470-
function nodeIdFromMeta(meta: any): NodeId | undefined {
471-
const remoteCerts = meta.remoteCertificates;
472-
if (remoteCerts == null) return;
473-
const leafCertPEM = remoteCerts[0];
474-
if (leafCertPEM == null) return;
475-
const leafCert = keysUtils.certFromPEM(leafCertPEM);
476-
if (leafCert == null) return;
477-
const nodeId = keysUtils.certNodeId(leafCert);
478-
if (nodeId == null) return;
479-
return nodeId;
480-
}
481-
482465
export {
483466
isHost,
484467
isHostWildcard,
@@ -492,5 +475,4 @@ export {
492475
verifyServerCertificateChain,
493476
verifyClientCertificateChain,
494477
resolveHostnames,
495-
nodeIdFromMeta,
496478
};

0 commit comments

Comments
 (0)