diff options
author | David Barksdale <amatus@amatus.name> | 2014-07-30 22:45:21 -0500 |
---|---|---|
committer | David Barksdale <amatus@amatus.name> | 2014-07-30 22:45:21 -0500 |
commit | 1d3344c9825318127ea71647aa0d3a4e54e149d9 (patch) | |
tree | becca3847323a7ff868681a7a7db50384029e433 /src/cljs/gnunet_web/transport.cljs | |
parent | f4dda5ee27c1c8aa46c554938e972eba9a6d25e6 (diff) |
Start monitoring transport peers
Diffstat (limited to 'src/cljs/gnunet_web/transport.cljs')
-rw-r--r-- | src/cljs/gnunet_web/transport.cljs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cljs/gnunet_web/transport.cljs b/src/cljs/gnunet_web/transport.cljs new file mode 100644 index 0000000..b90a5b1 --- /dev/null +++ b/src/cljs/gnunet_web/transport.cljs @@ -0,0 +1,41 @@ +;; transport.cljs - transport service for gnunet-web website +;; 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 gnunet-web.transport + (:use [gnunet-web.encoder :only (encode-uint32)] + [gnunet-web.message :only (encode-message)] + [gnunet-web.service :only (client-connect)])) + +(def message-type-monitor-peer-request 380) + +(defn encode-monitor-peer-request-message + [{:keys [one-shot peer] :or {one-shot false peer (repeat 32 0)}}] + (encode-message + {:message-type message-type-monitor-peer-request + :message + (concat + (encode-uint32 one-shot) + peer)})) + +(defn monitor-peers + [callback] + (let [message-channel (js/MessageChannel.)] + (set! (.-onmessage (.-port1 message-channel)) + (fn [event] + (.log js/console "monitor-peers" event))) + (client-connect "transport" "web app" (.-port2 message-channel)) + (.postMessage (.-port1 message-channel) + (into-array (encode-monitor-peer-request-message {}))))) |