|
|
@ -1,5 +1,3 @@ |
|
|
|
var url = "ws://127.0.0.1:7665"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var l = document.getElementById("log"); |
|
|
|
var l = document.getElementById("log"); |
|
|
|
var c = document.getElementById("main"); |
|
|
|
var c = document.getElementById("main"); |
|
|
|
var nodes = { |
|
|
|
var nodes = { |
|
|
@ -130,7 +128,7 @@ function tunnelCreated(tid) { |
|
|
|
|
|
|
|
|
|
|
|
function logit(msg) { |
|
|
|
function logit(msg) { |
|
|
|
console.log(msg); |
|
|
|
console.log(msg); |
|
|
|
var t = document.createTextNode(leftpad(msg, 25)); |
|
|
|
var t = document.createTextNode(msg); |
|
|
|
var e = document.createElement("div"); |
|
|
|
var e = document.createElement("div"); |
|
|
|
e.appendChild(t); |
|
|
|
e.appendChild(t); |
|
|
|
l.appendChild(e); |
|
|
|
l.appendChild(e); |
|
|
@ -138,38 +136,63 @@ function logit(msg) { |
|
|
|
l.removeChild(l.children[0]); |
|
|
|
l.removeChild(l.children[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var ws = new WebSocket(url); |
|
|
|
function socketClosed() { |
|
|
|
ws.onclose = function (ev) { |
|
|
|
var b = document.getElementById("connect-button"); |
|
|
|
nodes = { length: 0 }; |
|
|
|
b.onclick = startui |
|
|
|
tpeers = { length: 0 }; |
|
|
|
b.value = "connect"; |
|
|
|
} |
|
|
|
} |
|
|
|
ws.onmessage = function(ev) { |
|
|
|
|
|
|
|
var j = JSON.parse(ev.data); |
|
|
|
function startui() { |
|
|
|
if (j) { |
|
|
|
var el = document.getElementById("ws-url"); |
|
|
|
console.log(j); |
|
|
|
var url; |
|
|
|
if(j.type == "transport.connected") { |
|
|
|
if(el) |
|
|
|
nodeConnected(j.ident); |
|
|
|
url = el.value; |
|
|
|
} else if (j.type == "transport.disconnected") { |
|
|
|
else |
|
|
|
nodeDisconnected(j.ident); |
|
|
|
url = "ws://127.0.0.1:7666"; |
|
|
|
} else if (j.type == "transport.sendmsg") { |
|
|
|
|
|
|
|
nodeSend(j.ident, j.number); |
|
|
|
var ws = new WebSocket(url); |
|
|
|
} else if (j.type == "transport.recvmsg") { |
|
|
|
ws.onclose = function (ev) { |
|
|
|
nodeRecv(j.ident, j.number); |
|
|
|
logit("failed to connect to "+url); |
|
|
|
} else if (j.type == "tunnel.build") { |
|
|
|
nodes = { length: 0 }; |
|
|
|
tunnelBuild(j.value, j.tid, j.inbound); |
|
|
|
tpeers = { length: 0 }; |
|
|
|
} else if (j.type == "tunnel.latency") { |
|
|
|
socketClosed(); |
|
|
|
tunnelLatency(j.tid, j.value); |
|
|
|
} |
|
|
|
} else if (j.type == "tunnel.state") { |
|
|
|
ws.onopen = function(ev) { |
|
|
|
tunnelState(j.tid, j.value); |
|
|
|
logit("connected to "+url); |
|
|
|
} else if (j.type == "tunnels.created") { |
|
|
|
} |
|
|
|
tunnelCreated(j.tid); |
|
|
|
ws.onmessage = function(ev) { |
|
|
|
} else if (j.type == "tunnels.expired") { |
|
|
|
var j = JSON.parse(ev.data); |
|
|
|
tunnelExpiring(j.tid); |
|
|
|
if (j) { |
|
|
|
} else { |
|
|
|
console.log(j); |
|
|
|
logit("message: "+j.type); |
|
|
|
if(j.type == "transport.connected") { |
|
|
|
|
|
|
|
nodeConnected(j.ident); |
|
|
|
|
|
|
|
} else if (j.type == "transport.disconnected") { |
|
|
|
|
|
|
|
nodeDisconnected(j.ident); |
|
|
|
|
|
|
|
} else if (j.type == "transport.sendmsg") { |
|
|
|
|
|
|
|
nodeSend(j.ident, j.number); |
|
|
|
|
|
|
|
} else if (j.type == "transport.recvmsg") { |
|
|
|
|
|
|
|
nodeRecv(j.ident, j.number); |
|
|
|
|
|
|
|
} else if (j.type == "tunnel.build") { |
|
|
|
|
|
|
|
tunnelBuild(j.value, j.tid, j.inbound); |
|
|
|
|
|
|
|
} else if (j.type == "tunnel.latency") { |
|
|
|
|
|
|
|
tunnelLatency(j.tid, j.value); |
|
|
|
|
|
|
|
} else if (j.type == "tunnel.state") { |
|
|
|
|
|
|
|
tunnelState(j.tid, j.value); |
|
|
|
|
|
|
|
} else if (j.type == "tunnels.created") { |
|
|
|
|
|
|
|
tunnelCreated(j.tid); |
|
|
|
|
|
|
|
} else if (j.type == "tunnels.expired") { |
|
|
|
|
|
|
|
tunnelExpiring(j.tid); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
logit("message: "+j.type); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var b = document.getElementById("connect-button"); |
|
|
|
|
|
|
|
b.onclick = function() { |
|
|
|
|
|
|
|
ws.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
b.value = "disconnect"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getPeer(h, us) { |
|
|
|
function getPeer(h, us) { |
|
|
|
if (tpeers[h]) { |
|
|
|
if (tpeers[h]) { |
|
|
|