aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2014-08-14 20:52:58 -0500
committerDavid Barksdale <amatus@amatus.name>2014-08-14 21:29:02 -0500
commitad7af88c9e029f47a25cf6544d852985001db8be (patch)
treea2ae4d1825962915db42e9e5c1890a706b3df07f /src
parentc9c7a100b7b19a63c5269b29165e27e0c108292c (diff)
Add a table with transport connection states
And automatically load hostlist.
Diffstat (limited to 'src')
-rw-r--r--src/cljs/amatus/code.cljs42
-rw-r--r--src/cljs/gnunet_web/transport.cljs31
-rw-r--r--src/hl/index.cljs.hl41
3 files changed, 103 insertions, 11 deletions
diff --git a/src/cljs/amatus/code.cljs b/src/cljs/amatus/code.cljs
new file mode 100644
index 0000000..92e201f
--- /dev/null
+++ b/src/cljs/amatus/code.cljs
@@ -0,0 +1,42 @@
+;; code.cljs - functions for encoding and decoding data
+;; Copyright (C) 2014 David Barksdale <amatus@amatus.name>
+;;
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(ns amatus.code)
+
+(defn pad
+ [n padding xs]
+ (take n (concat xs (repeat padding))))
+
+(defn base32-hex
+ [xs]
+ (.toUpperCase
+ (apply str
+ (mapcat (fn [x]
+ (pad (Math/ceil (/ (* 8 (count x)) 5)) "0"
+ (.toString (reduce (fn [a b] (+ b (* a 256)))
+ 0
+ (pad 5 0 x))
+ 32)))
+ (partition 5 5 [] xs)))))
+
+(defn base32-crockford
+ [xs]
+ (apply str
+ (map #(->> %
+ (.indexOf "0123456789ABCDEFGHIJKLMNOPQRSTUV")
+ (.charAt "0123456789ABCDEFGHJKMNPQRSTVWXYZ"))
+ (base32-hex xs))))
+
diff --git a/src/cljs/gnunet_web/transport.cljs b/src/cljs/gnunet_web/transport.cljs
index d027bbf..19b4b98 100644
--- a/src/cljs/gnunet_web/transport.cljs
+++ b/src/cljs/gnunet_web/transport.cljs
@@ -48,16 +48,14 @@
address-length parse-uint32
plugin-length parse-uint32
address (items address-length)
- plugin-bytes (items plugin-length)
- :let [plugin (goog.crypt/utf8ByteArrayToString
- (to-array (.apply js/Array (array)
- plugin-bytes)))]]
+ plugin (items plugin-length)]
{:peer peer
:state-timeout state-timeout
:local-address-info local-address-info
:state state
:address (vec (.apply js/Array (array) address))
- :plugin plugin}))
+ :plugin (goog.crypt/utf8ByteArrayToString
+ (.apply js/Array (array) plugin))}))
{:message-type message-type-peer-iterate-reply}))
(defn monitor-peers
@@ -68,7 +66,28 @@
(let [message (first (.-v ((parse-message-types
#{parse-peer-iterate-reply})
(.-data event))))]
- (callback message))))
+ (callback (:message message)))))
(client-connect "transport" "web app" (.-port2 message-channel))
(.postMessage (.-port1 message-channel)
(into-array (encode-monitor-peer-request-message {})))))
+
+(def state-strings
+ {0 "Not connected"
+ 1 "Waiting for ATS"
+ 2 "Waiting for CONNECT_ACK"
+ 3 "Waiting for ATS suggestion"
+ 4 "Waiting for SESSION_ACK"
+ 5 "Connected"
+ 6 "ATS Reconnect"
+ 7 "Reconnecting"
+ 8 "Switching address"
+ 9 "Disconnecting"
+ 10 "Disconnect finished"})
+
+(defn state->string
+ [state]
+ (get state-strings state))
+
+(defn addr->string
+ [address]
+ (goog.crypt/utf8ByteArrayToString (to-array (drop 8 address))))
diff --git a/src/hl/index.cljs.hl b/src/hl/index.cljs.hl
index 869678b..66edd7e 100644
--- a/src/hl/index.cljs.hl
+++ b/src/hl/index.cljs.hl
@@ -15,15 +15,24 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(page "index.html"
- (:use [gnunet-web.hostlist :only (fetch-and-process!)]
+ (:use [amatus.code :only (base32-crockford)]
+ [gnunet-web.hostlist :only (fetch-and-process!)]
[gnunet-web.service :only (start-worker)]
- [gnunet-web.transport :only (monitor-peers)]))
+ [gnunet-web.transport :only (addr->string monitor-peers
+ state->string)]))
(set! *print-fn* #(.log js/console %))
(def topology-worker (start-worker "topology" "js/gnunet-daemon-topology.js"))
(def fs-worker (start-worker "fs" "js/gnunet-service-fs.js"))
-(monitor-peers (fn [_]))
+
+(defc peers {})
+(monitor-peers (fn [message]
+ (swap! peers assoc (:peer message)
+ {:state (:state message)
+ :address (:address message)
+ :plugin (:plugin message)})))
+(fetch-and-process!)
(defelem ui-button
[attr kids]
@@ -31,10 +40,32 @@
(html
(head
- (link :rel "stylesheet" :type "text/css" :href "css/main.css")
(link :rel "stylesheet" :type "text/css" :href "css/semantic.min.css")
(script :src "js/semantic.min.js"))
(body
- (ui-button :click fetch-and-process! "Fetch hostlist")))
+ (table :class "ui table segment"
+ (thead
+ (tr
+ (th :text "Peer ID")
+ (th :text "State")
+ (th :text "Transport")
+ (th :text "Address")))
+ (tbody
+ (loop-tpl :bindings [[peer info] peers]
+ (tr
+ (td :width "25%"
+ :text (cell=
+ (apply str
+ (concat
+ (take 4 (base32-crockford peer))
+ "\u2026")))
+ :title (cell= (base32-crockford peer)))
+ (td :width "25%"
+ :text (cell= (state->string (:state info))))
+ (td :width "25%"
+ :text (cell= (:plugin info)))
+ (td :width "25%"
+ :text (cell= (addr->string (:address info))))))))
+ (div :class "ui active inline loader")))
;; vim: set expandtab ts=2 sw=2 filetype=clojure :