first commit
This commit is contained in:
commit
ad36444918
24
README.txt
Normal file
24
README.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Origin Master Repo: https://github.com/lanmower/hyper-relay
|
||||||
|
|
||||||
|
HyperMC utilizes this server within its infrastructure to serve HTTP based traffic to our Hyper Proxy Service.
|
||||||
|
|
||||||
|
This package relays tcp listeners over hyperswarm, using the createServer/connect noise encrypted channel.
|
||||||
|
|
||||||
|
The cli tools are symetric topics, but one can
|
||||||
|
easily spawn a client programatically that uses
|
||||||
|
a public key instead of a topic, to make your
|
||||||
|
relayed process publicly available.
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
npm install --save hyper-relay -g
|
||||||
|
|
||||||
|
## TCP Relay
|
||||||
|
|
||||||
|
### remotely
|
||||||
|
### relay from a hyper-relay client to a local server
|
||||||
|
hyper-tcp-relay-server <topicname> <portnumber>
|
||||||
|
|
||||||
|
### locally
|
||||||
|
### relay from a local server to a hyper-relay server
|
||||||
|
hyper-tcp-relay-client <topicname> <portnumber>
|
||||||
|
|
12
client.js
Normal file
12
client.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const crypto = require('hypercore-crypto')
|
||||||
|
if(process.argv.length == 4) {
|
||||||
|
const key = process.argv[process.argv.length-1];
|
||||||
|
const port = parseInt(process.argv[process.argv.length-2]);
|
||||||
|
const tunnel = require('./relay.js')()
|
||||||
|
const keyPair = crypto.keyPair(crypto.data(Buffer.from(key)));
|
||||||
|
const pubKey = keyPair.publicKey;
|
||||||
|
tunnel.client(pubKey,port);
|
||||||
|
} else console.log("usage: hyper-relay-client <port> <key>");
|
||||||
|
|
40
package.json
Normal file
40
package.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "hyper-relay",
|
||||||
|
"version": "0.2.40",
|
||||||
|
"description": "TCP relay for hyperswarm (tunnel)",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node socks.js 1080 glitch"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@hyperswarm/dht": "latest",
|
||||||
|
"hi-base32": "^0.5.1",
|
||||||
|
"hypercore-crypto": "^3.4.0",
|
||||||
|
"pump": "^3.0.0",
|
||||||
|
"ssh2": "^1.5.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"hyper-tcp-relay-server": "server.js",
|
||||||
|
"hyper-tcp-relay-client": "client.js"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/lanmower/hyper-relay/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"engines": {
|
||||||
|
"node": "12.x"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/lanmower/hyper-relay#readme",
|
||||||
|
"keywords": [
|
||||||
|
"node",
|
||||||
|
"hyperswarm",
|
||||||
|
"tunnel",
|
||||||
|
"tcp",
|
||||||
|
"relay"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"url": "git+https://github.com/lanmower/hyper-relay.git"
|
||||||
|
}
|
||||||
|
}
|
45
relay.js
Normal file
45
relay.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
const DHT = require("@hyperswarm/dht");
|
||||||
|
const net = require("net");
|
||||||
|
const pump = require("pump");
|
||||||
|
const node = new DHT({});
|
||||||
|
module.exports = () => {
|
||||||
|
return {
|
||||||
|
serve: (keyPair, host, port) => {
|
||||||
|
const server = node.createServer();
|
||||||
|
server.on("connection", function (servsock) {
|
||||||
|
const socket = net.connect(port, host);
|
||||||
|
socket.on('serve error', console.error);
|
||||||
|
let open = { servsock: true, remote: true };
|
||||||
|
servsock.on('data', (d) => { socket.write(d) });
|
||||||
|
socket.on('data', (d) => { servsock.write(d) });
|
||||||
|
|
||||||
|
const remoteend = () => {
|
||||||
|
if (open.remote) socket.end();
|
||||||
|
open.remote = false;
|
||||||
|
}
|
||||||
|
const servsockend = () => {
|
||||||
|
if (open.servsock) servsock.end();
|
||||||
|
open.servsock = false;
|
||||||
|
}
|
||||||
|
servsock.on('error', remoteend)
|
||||||
|
servsock.on('finish', remoteend)
|
||||||
|
servsock.on('end', remoteend)
|
||||||
|
socket.on('finish', servsockend)
|
||||||
|
socket.on('error', servsockend)
|
||||||
|
socket.on('end', servsockend)
|
||||||
|
});
|
||||||
|
server.listen(keyPair);
|
||||||
|
return keyPair.publicKey;
|
||||||
|
},
|
||||||
|
client: (hexPublicKey, port) => {
|
||||||
|
const publicKey = Buffer.from(hexPublicKey, 'hex');
|
||||||
|
const server = net.createServer(function (local) {
|
||||||
|
const socket = node.connect(publicKey);
|
||||||
|
socket.on('client error', console.error);
|
||||||
|
pump(local, socket, local);
|
||||||
|
});
|
||||||
|
server.listen(port, "127.0.0.1");
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
7
server.js
Normal file
7
server.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const crypto = require("hypercore-crypto");
|
||||||
|
const node = require('./relay.js')();
|
||||||
|
const b32 = require("hi-base32");
|
||||||
|
const key = crypto.keyPair(crypto.data(Buffer.from(process.argv[3])));
|
||||||
|
const port = process.argv[2] || 80;
|
||||||
|
console.log(b32.encode(key.publicKey).replace('====', '').toLowerCase())
|
||||||
|
node.serve(key, "localhost", port)
|
Loading…
Reference in New Issue
Block a user