-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelay.js
29 lines (27 loc) · 819 Bytes
/
relay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const DHT = require("@hyperswarm/dht");
const crypto = require("hypercore-crypto");
var net = require("net");
var pump = require("pump");
const node = new DHT({});
module.exports = () => {
return {
serve: (key, port, secureport, addr) => {
const keyPair = crypto.keyPair(crypto.data(Buffer.from(key)));
const server = node.createServer();
server.on("connection", function(servsock) {
console.log('connection');
servsock.once("data", function(data) {
if(data == 'http') {
socket = net.connect(port, addr);
}
if(data == 'https') {
socket = net.connect(secureport, addr);
}
pump(servsock, socket, servsock);
});
});
server.listen(keyPair);
return keyPair.publicKey;
}
};
};