blob: 2a1b107d49060071f7ceb00fa8c766b39efc1f45 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
;; index.cljs.hl - The gnunet-web website
;; Copyright (C) 2013,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/>.
(page "index.html"
(:require [amatus.code :as code]
[gnunet-web.core :as core]
[gnunet-web.filesharing :as filesharing]
[gnunet-web.hostlist :as hostlist]
[gnunet-web.service :as service]
[gnunet-web.transport :as transport]))
(set! *print-fn* #(.log js/console %))
(defn peer-id-short
[peer]
(.substr (code/base32-crockford peer) 0 4))
(defc my-id [])
(transport/monitor (fn [message] (reset! my-id (:public-key message))))
(defc peers {})
(transport/monitor-peers (fn [message]
(swap! peers
#(-> %
(assoc-in [(:peer message) :transport-state]
(:state message))
(assoc-in [(:peer message) :address]
(:address message))
(assoc-in [(:peer message) :plugin]
(:plugin message))))))
(core/monitor-peers (fn [message]
(if (not (= 6 (:state message)))
(swap! peers assoc-in [(:peer message) :core-state]
(:state message)))))
(defc search-results [])
(defn handle-search-result
[message]
(let [u-block (:u-block message)
data (js/Uint8Array. (into-array (filesharing/decrypt (:data u-block))))
data (.-v (filesharing/parse-encrypted-u-block data))]
(js/console.warn (clj->js data))
(if (coll? data)
(swap! search-results conj (:uri (first data))))))
(def topology-worker (service/start-worker "topology"
"js/gnunet-daemon-topology.js"))
(def fs-worker (service/start-worker "fs" "js/gnunet-service-fs.js"))
(hostlist/fetch-and-process!)
(defelem ui-button
[attr kids]
((div :class "ui button") attr kids))
(html
(head
(link :rel "stylesheet" :type "text/css" :href "css/semantic.min.css")
(script :src "js/semantic.min.js"))
;(script :src "js/cryptojs.js"))
;(script :src "js/rollups/aes.js")
;(script :src "js/components/mode-cfb-min.js")
;(script :src "js/components/lib-typedarrays-min.js")
;(script :src "js/twofish.js"))
(body
(ui-button :click (partial filesharing/search
{:callback handle-search-result
:type 9
:query [ 53 121 14 108 192 19 9 179
77 1 248 77 167 241 208 83
233 78 200 212 162 207 229 193
41 182 99 190 234 253 228 4
24 187 100 174 69 187 14 23
37 148 251 75 163 18 33 137
88 69 38 120 84 62 172 78
117 36 196 3 27 231 33 45]})
"Search `test'")
(ul
(loop-tpl :bindings [result search-results]
(li :text result)))
(div :class "ui header"
:title (cell= (code/base32-crockford my-id))
(text "My Peer ID: ~(peer-id-short my-id)\u2026"))
(table :class "ui table segment"
(thead
(tr
(th :text "Peer ID")
(th :text "Transport State")
(th :text "Core State")
(th :text "Address")))
(tbody
(loop-tpl :bindings [[peer info] peers]
(tr
(td :width "25%"
:title (cell= (code/base32-crockford peer))
(text "~(peer-id-short peer)\u2026"))
(td :width "25%"
:text (cell= (transport/state->string
(:transport-state info))))
(td :width "25%"
:text (cell= (core/state->string
(:core-state info))))
(td :width "25%"
:text (cell= (transport/addr->string
(:address info))))))))
(div :class "ui active inline loader")))
;; vim: set expandtab ts=2 sw=2 filetype=clojure :
|