Skip to content

Commit

Permalink
fix: external NodeAddress scope has been renamed to global and …
Browse files Browse the repository at this point in the history
…holepunching is now only enabled when an address has this scope
  • Loading branch information
amydevs committed Nov 9, 2023
1 parent 6841b02 commit 4f0ae2a
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/client/handlers/NodesAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NodesAdd extends UnaryHandler<
if (
(input.ping ?? false) &&
!(await nodeManager.pingNode(nodeId, [
{ host, port, scopes: ['external'] },
{ host, port, scopes: ['global'] },
]))
) {
throw new nodeErrors.ErrorNodePingFailed(
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const testnet: Record<string, NodeAddress> = {
v7v9ptvcdbdf8p4upok3prpmu3938ns8v4g45dib7sm5hqvvehv70: {
host: 'testnet.polykey.com' as Host,
port: 1314 as Port,
scopes: ['external'],
scopes: ['global'],
},
v270ktdd3cs3mp1r3q3dkmick92bn927mii9or4sgroeogd1peqb0: {
host: 'testnet.polykey.com' as Host,
port: 1314 as Port,
scopes: ['external'],
scopes: ['global'],
},
};

Expand Down
16 changes: 8 additions & 8 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,10 @@ class NodeConnectionManager {
let timeoutDivisions = 0;
const addressGroups: {
local: Array<NodeAddress>;
external: Array<NodeAddress>;
} = { local: [], external: [] };
global: Array<NodeAddress>;
} = { local: [], global: [] };
for (const address of addresses) {
const scope = address.scopes.includes('local') ? 'local' : 'external';
const scope = address.scopes.includes('local') ? 'local' : 'global';
// If this is the first time an addressGroup has had an address added, the timeout divisions must be incremented.
if (addressGroups[scope].length === 0) {
timeoutDivisions++;
Expand Down Expand Up @@ -860,7 +860,7 @@ class NodeConnectionManager {
if (results == null || results.size === 0) {
results = await this.establishMultiConnection(
[targetNodeId],
addressGroups.external,
addressGroups.global,
{
signal: ctx.signal,
timer: timeout,
Expand Down Expand Up @@ -1019,7 +1019,7 @@ class NodeConnectionManager {
this.logger.debug(
`establishing single connection for address ${address.host}:${address.port}`,
);
const iceProm = !address.scopes?.includes('local')
const iceProm = address.scopes.includes('global')
? this.initiateHolePunch(nodeIds, ctx)
: undefined;
const connection =
Expand Down Expand Up @@ -1592,7 +1592,7 @@ class NodeConnectionManager {
{
host: nextNodeAddress.address.host,
port: nextNodeAddress.address.port,
scopes: ['external'],
scopes: ['global'],
},
],
{
Expand Down Expand Up @@ -1633,7 +1633,7 @@ class NodeConnectionManager {
{
host: nodeData.address.host,
port: nodeData.address.port,
scopes: ['external'],
scopes: ['global'],
},
],
{
Expand Down Expand Up @@ -1715,7 +1715,7 @@ class NodeConnectionManager {
address: {
host: result.host as Host | Hostname,
port: result.port as Port,
scopes: ['external'],
scopes: ['global'],
},
// Not really needed
// But if it's needed then we need to add the information to the proto definition
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class NodeManager {
never();
}
if (
await this.pingNode(nodeId, [{ host, port, scopes: ['external'] }], {
await this.pingNode(nodeId, [{ host, port, scopes: ['global'] }], {
signal: ctx.signal,
})
) {
await this.setNode(
nodeId,
{ host, port, scopes: ['external'] },
{ host, port, scopes: ['global'] },
false,
false,
2000,
Expand Down Expand Up @@ -215,7 +215,7 @@ class NodeManager {
{
host: e.detail.remoteHost,
port: e.detail.remotePort,
scopes: ['external'],
scopes: ['global'],
},
false,
false,
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/agent/handlers/NodesConnectionSignalInitial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NodesConnectionSignalInitial extends UnaryHandler<
const address: NodeAddress = {
host: remoteHost as Host,
port: remotePort as Port,
scopes: ['external'],
scopes: ['global'],
};
nodeConnectionManager.handleNodesConnectionSignalInitial(
requestingNodeId,
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Host, Hostname, Port } from '../network/types';
*/
type NodeGraphSpace = '0' | '1';

type NodeAddressScope = 'local' | 'external';
type NodeAddressScope = 'local' | 'global';

type NodeAddress = {
host: Host | Hostname;
Expand Down
2 changes: 1 addition & 1 deletion tests/client/handlers/gestalts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ describe('gestaltsGestaltTrustByNode', () => {
await nodeManager.setNode(nodeIdRemote, {
host: node.agentServiceHost,
port: node.agentServicePort,
scopes: ['external'],
scopes: ['global'],
});
discovery = await Discovery.createDiscovery({
db,
Expand Down
2 changes: 1 addition & 1 deletion tests/discovery/Discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('Discovery', () => {
await nodeGraph.setNode(nodeA.keyRing.getNodeId(), {
host: nodeA.agentServiceHost,
port: nodeA.agentServicePort,
scopes: ['external'],
scopes: ['global'],
});
await nodeB.acl.setNodeAction(nodeA.keyRing.getNodeId(), 'claim');
await nodeA.nodeManager.claimNode(nodeB.keyRing.getNodeId());
Expand Down
20 changes: 10 additions & 10 deletions tests/nodes/NodeConnectionManager.general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
serverAddressA = {
host: remotePolykeyAgentA.agentServiceHost as Host,
port: remotePolykeyAgentA.agentServicePort as Port,
scopes: ['external'],
scopes: ['global'],
};
remotePolykeyAgentB = await PolykeyAgent.createPolykeyAgent({
password,
Expand Down Expand Up @@ -228,7 +228,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
const nodeAddress: NodeAddress = {
host: localHost as Host,
port: 11111 as Port,
scopes: ['external'],
scopes: ['global'],
};
await nodeGraph.setNode(nodeId, nodeAddress);
// Expect no error thrown
Expand Down Expand Up @@ -268,7 +268,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
const nodeAddress: NodeAddress = {
host: localHost as Host,
port: 11111 as Port,
scopes: ['external'],
scopes: ['global'],
};
await remotePolykeyAgentA.nodeGraph.setNode(nodeId, nodeAddress);

Expand Down Expand Up @@ -347,7 +347,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
const nodeAddress: NodeAddress = {
host: (i + '.' + i + '.' + i + '.' + i) as Host,
port: i as Port,
scopes: ['external'],
scopes: ['global'],
};
await remotePolykeyAgentA.nodeGraph.setNode(closeNodeId, nodeAddress);
addedClosestNodes.push([
Expand Down Expand Up @@ -421,7 +421,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
{
host: remotePolykeyAgentB.agentServiceHost,
port: remotePolykeyAgentB.agentServicePort,
scopes: ['external'],
scopes: ['global'],
},
],
),
Expand Down Expand Up @@ -451,7 +451,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
const serverAddress: NodeAddress = {
host: remotePolykeyAgentA.agentServiceHost as Host,
port: remotePolykeyAgentA.agentServicePort as Port,
scopes: ['external'],
scopes: ['global'],
};
await nodeGraph.setNode(serverNodeId, serverAddress);

Expand Down Expand Up @@ -505,7 +505,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
const serverAddress: NodeAddress = {
host: remotePolykeyAgentA.agentServiceHost,
port: remotePolykeyAgentA.agentServicePort,
scopes: ['external'],
scopes: ['global'],
};
await nodeGraph.setNode(serverNodeId, serverAddress);
// Establish connection between remote A and B
Expand All @@ -516,7 +516,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
{
host: remotePolykeyAgentB.agentServiceHost,
port: remotePolykeyAgentB.agentServicePort,
scopes: ['external'],
scopes: ['global'],
},
],
),
Expand Down Expand Up @@ -642,7 +642,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
{
host: remotePolykeyAgentB.agentServiceHost,
port: remotePolykeyAgentB.agentServicePort,
scopes: ['external'],
scopes: ['global'],
},
],
),
Expand All @@ -660,7 +660,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
{
host: '127.0.0.1' as Host,
port: 55555 as Port,
scopes: ['external'],
scopes: ['global'],
},
signature.toString('base64url'),
);
Expand Down
36 changes: 18 additions & 18 deletions tests/nodes/NodeConnectionManager.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
serverAddress1 = {
host: nodeConnectionManagerPeer1.host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
};
});

Expand Down Expand Up @@ -260,7 +260,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
const clientAddress: NodeAddress = {
host: nodeConnectionManager.host,
port: nodeConnectionManager.port,
scopes: ['external'],
scopes: ['global'],
};

const forwardConnectP = nodeConnectionManager.getMultiConnection(
Expand Down Expand Up @@ -592,17 +592,17 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.2' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.3' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
],
{ timer: 200 },
Expand Down Expand Up @@ -634,32 +634,32 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.2' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.3' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.2' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.3' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
],
{ timer: 200 },
Expand Down Expand Up @@ -693,7 +693,7 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
],
{ timer: 200 },
Expand Down Expand Up @@ -728,32 +728,32 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => {
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.2' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.3' as Host,
port: nodeConnectionManagerPeer1.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.1' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.2' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
{
host: '127.0.0.3' as Host,
port: nodeConnectionManagerPeer2.port,
scopes: ['external'],
scopes: ['global'],
},
],
{ timer: 2000 },
Expand Down
8 changes: 4 additions & 4 deletions tests/nodes/NodeConnectionManager.seednodes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => {
remoteAddress1 = {
host: remotePolykeyAgent1.agentServiceHost,
port: remotePolykeyAgent1.agentServicePort,
scopes: ['external'],
scopes: ['global'],
};

const nodePathB = path.join(dataDir, 'agentB');
Expand All @@ -111,7 +111,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => {
remoteAddress2 = {
host: remotePolykeyAgent2.agentServiceHost,
port: remotePolykeyAgent2.agentServicePort,
scopes: ['external'],
scopes: ['global'],
};

// Setting up client dependencies
Expand Down Expand Up @@ -303,7 +303,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => {
[nodesUtils.encodeNodeId(localNodeId)]: {
host: '127.0.0.1' as Host,
port: 55123 as Port,
scopes: ['external'],
scopes: ['global'],
},
};
nodeConnectionManager = new NodeConnectionManager({
Expand Down Expand Up @@ -357,7 +357,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => {
[nodesUtils.encodeNodeId(remoteNodeId2)]: {
host: '127.0.0.1' as Host,
port: 55124 as Port,
scopes: ['external'],
scopes: ['global'],
},
};
nodeConnectionManager = new NodeConnectionManager({
Expand Down
Loading

0 comments on commit 4f0ae2a

Please sign in to comment.