11import os from 'os' ;
22import path from 'path' ;
33import fs from 'fs' ;
4- import readline from 'readline' ;
54import Logger , { LogLevel , StreamHandler } from '@matrixai/logger' ;
65import * as testNatUtils from './utils' ;
7- import { generateRandomNodeId } from '../utils' ;
8- import { encodeNodeId } from '@/nodes/utils' ;
96
107describe ( 'endpoint independent NAT traversal' , ( ) => {
11- const logger = new Logger ( 'EIM NAT test' , LogLevel . DEBUG , [
8+ const logger = new Logger ( 'EIM NAT test' , LogLevel . WARN , [
129 new StreamHandler ( ) ,
1310 ] ) ;
1411 let dataDir : string ;
@@ -139,7 +136,7 @@ describe('endpoint independent NAT traversal', () => {
139136 } ,
140137 global . defaultTimeout * 2 ,
141138 ) ;
142- test . only (
139+ test (
143140 'Node1 behind EIM NAT connects to Node2 behind EIM NAT' ,
144141 async ( ) => {
145142 const {
@@ -151,109 +148,13 @@ describe('endpoint independent NAT traversal', () => {
151148 agent1NodePath,
152149 agent2NodePath,
153150 agent1NodeId,
154- agent1Host,
155- agent1ProxyPort,
156151 agent2NodeId,
157- agent2Host,
158- agent2ProxyPort,
159152 tearDownNAT,
160153 } = await testNatUtils . setupNATWithSeedNode ( 'eim' , 'eim' , logger ) ;
161- // Add information of other node to both nodes
162- const out1 = await testNatUtils . pkExecNs (
163- userPid ,
164- agent2Pid ,
165- [ 'nodes' , 'add' , agent1NodeId , agent1Host , agent1ProxyPort ] ,
166- {
167- PK_NODE_PATH : agent2NodePath ,
168- PK_PASSWORD : password ,
169- } ,
170- dataDir ,
171- ) ;
172- console . log ( out1 ) ;
173- const out2 = await testNatUtils . pkExecNs (
174- userPid ,
175- agent1Pid ,
176- [ 'nodes' , 'add' , agent2NodeId , agent2Host , agent2ProxyPort ] ,
177- {
178- PK_NODE_PATH : agent1NodePath ,
179- PK_PASSWORD : password ,
180- } ,
181- dataDir ,
182- ) ;
183- console . log ( out2 ) ;
184- const randomNode = encodeNodeId ( generateRandomNodeId ( ) ) ;
185- await testNatUtils . pkExecNs (
186- userPid ,
187- agent1Pid ,
188- [ 'nodes' , 'add' , randomNode , '198.168.0.3' , '55555' ] ,
189- {
190- PK_NODE_PATH : agent1NodePath ,
191- PK_PASSWORD : password ,
192- } ,
193- dataDir ,
194- ) ;
195154 // Since node2 is behind a NAT we need it to attempt to contact us first
196155 // This won't be successfull, but will allow to get past its router with
197156 // our own ping
198- const rl = readline . createInterface ( {
199- input : process . stdin ,
200- output : process . stdout
201- } ) ;
202- const pauser = ( ) => {
203- return new Promise ( ( resolve : ( value : void ) => void ) => {
204- rl . question ( 'Ready to continue? ' , ( ) => {
205- console . log ( 'Continuing' ) ;
206- resolve ( ) ;
207- } ) ;
208- } ) ;
209- }
210- await pauser ( ) ;
211- rl . close ( ) ;
212- // const test = await testNatUtils.pkExecNs(
213- // userPid,
214- // agent1Pid,
215- // ['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
216- // {
217- // PK_NODE_PATH: agent1NodePath,
218- // PK_PASSWORD: password,
219- // },
220- // dataDir,
221- // );
222- // console.log(test);
223- const out3 = await testNatUtils . pkExecNs (
224- userPid ,
225- agent2Pid ,
226- [ 'nodes' , 'ping' , agent1NodeId , '--format' , 'json' , '-vv' ] ,
227- {
228- PK_NODE_PATH : agent2NodePath ,
229- PK_PASSWORD : password ,
230- } ,
231- dataDir ,
232- ) ;
233- console . log ( out3 ) ;
234- const { exitCode, stdout, stderr } = await testNatUtils . pkExecNs (
235- userPid ,
236- agent1Pid ,
237- [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' , '-vv' ] ,
238- {
239- PK_NODE_PATH : agent1NodePath ,
240- PK_PASSWORD : password ,
241- } ,
242- dataDir ,
243- ) ;
244- console . log ( stderr ) ;
245- const out4 = await testNatUtils . pkExecNs (
246- userPid ,
247- agent1Pid ,
248- [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' , '-vv' ] ,
249- {
250- PK_NODE_PATH : agent1NodePath ,
251- PK_PASSWORD : password ,
252- } ,
253- dataDir ,
254- ) ;
255- console . log ( out4 ) ;
256- const out5 = await testNatUtils . pkExecNs (
157+ await testNatUtils . pkExecNs (
257158 userPid ,
258159 agent2Pid ,
259160 [ 'nodes' , 'ping' , agent1NodeId , '--format' , 'json' , '-vv' ] ,
@@ -263,8 +164,7 @@ describe('endpoint independent NAT traversal', () => {
263164 } ,
264165 dataDir ,
265166 ) ;
266- console . log ( out5 ) ;
267- const out6 = await testNatUtils . pkExecNs (
167+ const { exitCode, stdout } = await testNatUtils . pkExecNs (
268168 userPid ,
269169 agent1Pid ,
270170 [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' , '-vv' ] ,
@@ -274,7 +174,6 @@ describe('endpoint independent NAT traversal', () => {
274174 } ,
275175 dataDir ,
276176 ) ;
277- console . log ( out6 ) ;
278177 expect ( exitCode ) . toBe ( 0 ) ;
279178 expect ( JSON . parse ( stdout ) ) . toEqual ( {
280179 success : true ,
@@ -284,39 +183,6 @@ describe('endpoint independent NAT traversal', () => {
284183 } ,
285184 global . defaultTimeout * 20 ,
286185 ) ;
287- test . skip (
288- 'Node1 behind EIM NAT connects to Node2 behind EIM NAT via seed node' ,
289- async ( ) => {
290- const {
291- userPid,
292- agent1Pid,
293- password,
294- dataDir,
295- agent1NodePath,
296- agent2NodeId,
297- tearDownNAT,
298- } = await testNatUtils . setupNATWithSeedNode ( 'eim' , 'eim' , logger ) ;
299- // Since we have a seed node we should be able to ping the other node
300- // straight away
301- const { exitCode, stdout } = await testNatUtils . pkExecNs (
302- userPid ,
303- agent1Pid ,
304- [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' ] ,
305- {
306- PK_NODE_PATH : agent1NodePath ,
307- PK_PASSWORD : password ,
308- } ,
309- dataDir ,
310- ) ;
311- expect ( exitCode ) . toBe ( 0 ) ;
312- expect ( JSON . parse ( stdout ) ) . toEqual ( {
313- success : true ,
314- message : 'Node is Active.' ,
315- } ) ;
316- await tearDownNAT ( ) ;
317- } ,
318- global . defaultTimeout * 4 ,
319- ) ;
320186 test . skip (
321187 'Node1 behind EIM NAT cannot connect to Node2 behind EDM NAT' ,
322188 async ( ) => {
0 commit comments