actually start a server, idk

canary
Marcus 2021-04-01 01:19:00 -04:00
parent d3c33cd113
commit dc25be448b
2 changed files with 13 additions and 3 deletions

View File

@ -10,9 +10,12 @@ class Node extends EventEmitter {
hash = null; hash = null;
name = null; name = null;
readyPromise = null; readyPromise = null;
port = null;
identity;
constructor(identity) { constructor(identity) {
super(); super();
this.identity = identity;
this.hash = md5(identity.publicKey); this.hash = md5(identity.publicKey);
this.name = `valnet node - ${this.hash}`; this.name = `valnet node - ${this.hash}`;
// stp.createServer({ // stp.createServer({
@ -45,13 +48,17 @@ class Node extends EventEmitter {
if(takenPorts.indexOf(port) === -1) { if(takenPorts.indexOf(port) === -1) {
console.log('registering to port ' + port); console.log('registering to port ' + port);
await upnp.mapIndefinite(port, this.name); await upnp.mapIndefinite(port, this.name);
this.port = port;
break; break;
} else { } else {
console.log('port ' + port + ' is taken...'); console.log('port ' + port + ' is taken...');
} }
} }
stp.createServer(this.identity, (connection) => {
console.log('incomming connection...');
console.dir(connection);
})
// console.log(mappings, this.hash); // console.log(mappings, this.hash);
} }

View File

@ -21,10 +21,13 @@ const node = new Node(identity);
function connectNetwork(t = 1000) { function connectNetwork(t = 1000) {
if(t > 60000) t /= 2; if(t > 60000) t /= 2;
const poopoo = config.endpoints[0].split(':');
console.log(poopoo);
const client = stp.connect({ const client = stp.connect({
identity, identity,
port: config.endpoints[0].split(':')[1], port: parseInt(poopoo[1]),
ip: config.endpoints[0].split(':')[0] ip: poopoo[0]
}); });
client.on('ready', () => { client.on('ready', () => {
log.success('connected to relay!'); log.success('connected to relay!');