forked from telehash/telehash-js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
wall.js
62 lines (51 loc) · 1.27 KB
/
wall.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var sys = require("sys");
var telehash = require("../index.js").telehash;
var hlib = require("../index.js").hash;
var running = false;
var stdin = process.openStdin();
stdin.setEncoding("UTF-8");
telehash.init({
mode: 2
}, function (err) {
if (err) {
return;
}
telehash.seed(function (status, info) {
if (status === 'offline' && info === 'snat-detected') {
console.log("SNAT detected. Exiting...");
process.exit();
}
if (status !== "online") {
console.log(status);
return;
}
if (!running) wall("42");
});
});
function wall(THEWALL) {
running = true;
var endHash = new hlib.Hash(THEWALL);
var tap = {};
tap.is = {};
tap.is["+end"] = endHash.toString();
tap.has = ["+wall"];
console.log("Write Something on the Wall: ", THEWALL);
telehash.tap(THEWALL, tap, function (from, telex) {
//TODO:Keep a short history of incoming telexes and drop duplicates
console.log(new Date() + " <" + from.ipp + "> " + telex["+wall"]);
});
stdin.on('data', function (chunk) {
telehash.dial(THEWALL);
console.log("local: " + chunk);
telehash.announce(THEWALL, {
'+wall': chunk,
'+guid': new Date().getTime()
});
});
}
process.on('SIGINT', function () {
console.log("Use Control-D to exit.");
});
stdin.on('end', function () {
telehash.shutdown();
});