Skip to content

Commit 9ebf9a7

Browse files
committed
fix: updated function name
[ci skip]
1 parent bea91f5 commit 9ebf9a7

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/nodes/NodeConnectionManager.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,8 @@ class NodeConnectionManager {
14251425
const id = `${host}:${port}`;
14261426
if (this.activeHolePunchPs.has(id)) return;
14271427
// Checking for resource semaphore
1428-
let semaphore: Semaphore | undefined = this.activeHolePunchAddresses.get(host);
1428+
let semaphore: Semaphore | undefined =
1429+
this.activeHolePunchAddresses.get(host);
14291430
if (semaphore == null) {
14301431
semaphore = new Semaphore(3);
14311432
this.activeHolePunchAddresses.set(host, semaphore);
@@ -1507,12 +1508,19 @@ class NodeConnectionManager {
15071508
}
15081509

15091510
/**
1510-
* This till ask a signalling node to signal a target node to hole punch back to this node.
1511+
* Will make a connection to the signalling node and make a nodesConnectionSignalInitial` request.
1512+
*
1513+
* If the signalling node does not have an existing connection to the target then this will throw.
1514+
* If verification of the request fails then this will throw, but this shouldn't happen.
1515+
* The request contains a signature generated from `<sourceNodeId><targetNodeId>`.
1516+
*
1517+
*
1518+
*
15111519
* @param targetNodeId - NodeId of the node that needs to signal back.
15121520
* @param signallingNodeId - NodeId of the signalling node.
15131521
* @param ctx
15141522
*/
1515-
public holePunchSignalRequest(
1523+
public connectionSignalInitial(
15161524
targetNodeId: NodeId,
15171525
signallingNodeId: NodeId,
15181526
ctx?: Partial<ContextTimedInput>,
@@ -1523,7 +1531,7 @@ class NodeConnectionManager {
15231531
(nodeConnectionManager: NodeConnectionManager) =>
15241532
nodeConnectionManager.connectionConnectTimeoutTime,
15251533
)
1526-
public async holePunchSignalRequest(
1534+
public async connectionSignalInitial(
15271535
targetNodeId: NodeId,
15281536
signallingNodeId: NodeId,
15291537
@context ctx: ContextTimed,
@@ -1709,6 +1717,9 @@ class NodeConnectionManager {
17091717
*
17101718
* This is pretty simple, it will contact all known seed nodes and get them to
17111719
* relay a punch signal message.
1720+
*
1721+
* This doesn't care if the requests fail or succeed, so any errors or results are ignored.
1722+
*
17121723
*/
17131724
protected initiateHolePunch(
17141725
targetNodeIds: Array<NodeId>,
@@ -1726,7 +1737,7 @@ class NodeConnectionManager {
17261737
// Ask seed nodes to signal hole punching for target
17271738
const holePunchProms = seedNodes.map((seedNodeId) => {
17281739
return (
1729-
this.holePunchSignalRequest(targetNodeId, seedNodeId, ctx)
1740+
this.connectionSignalInitial(targetNodeId, seedNodeId, ctx)
17301741
// Ignore results
17311742
.then(
17321743
() => {},

tests/nodes/NodeConnectionManager.general.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
404404
const relayNodeId = remotePolykeyAgentA.keyRing.getNodeId();
405405

406406
await expect(
407-
nodeConnectionManager.holePunchSignalRequest(targetNodeId, relayNodeId),
407+
nodeConnectionManager.connectionSignalInitial(targetNodeId, relayNodeId),
408408
).rejects.toThrow();
409409
await nodeConnectionManager.stop();
410410
});
@@ -448,7 +448,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
448448
const targetNodeId = remotePolykeyAgentB.keyRing.getNodeId();
449449
const relayNodeId = remotePolykeyAgentA.keyRing.getNodeId();
450450

451-
await nodeConnectionManager.holePunchSignalRequest(
451+
await nodeConnectionManager.connectionSignalInitial(
452452
targetNodeId,
453453
relayNodeId,
454454
);
@@ -459,8 +459,9 @@ describe(`${NodeConnectionManager.name} general test`, () => {
459459
for (const p of signalMapA) {
460460
await p;
461461
}
462-
// @ts-ignore: kidnap protected property
463-
const punchMapB = remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
462+
const punchMapB =
463+
// @ts-ignore: kidnap protected property
464+
remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
464465
for await (const [, p] of punchMapB) {
465466
await p;
466467
}
@@ -509,7 +510,7 @@ describe(`${NodeConnectionManager.name} general test`, () => {
509510
const relayNodeId = remotePolykeyAgentA.keyRing.getNodeId();
510511
// Creating 5 concurrent attempts
511512
const holePunchSignalRequests = [1, 2, 3, 4, 5].map(() =>
512-
nodeConnectionManager.holePunchSignalRequest(targetNodeId, relayNodeId),
513+
nodeConnectionManager.connectionSignalInitial(targetNodeId, relayNodeId),
513514
);
514515
// All should resolve immediately and not block
515516
await Promise.all(holePunchSignalRequests);
@@ -522,8 +523,9 @@ describe(`${NodeConnectionManager.name} general test`, () => {
522523
await p;
523524
}
524525
// Only one attempt is being made
525-
// @ts-ignore: kidnap protected property
526-
const punchMapB = remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
526+
const punchMapB =
527+
// @ts-ignore: kidnap protected property
528+
remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
527529
expect(punchMapB.size).toBe(1);
528530
// Allow the attempt to complete
529531
waitResolveP();
@@ -649,8 +651,9 @@ describe(`${NodeConnectionManager.name} general test`, () => {
649651
for (const p of signalMapA.values()) {
650652
await p;
651653
}
652-
// @ts-ignore: kidnap protected property
653-
const punchMapB = remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
654+
const punchMapB =
655+
// @ts-ignore: kidnap protected property
656+
remotePolykeyAgentB.nodeConnectionManager.activeHolePunchPs;
654657
for (const [, p] of punchMapB) {
655658
await p;
656659
}

0 commit comments

Comments
 (0)