aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2014-07-02 22:54:07 -0500
committerDavid Barksdale <amatus@amatus.name>2014-07-02 22:54:07 -0500
commitc3e22d33f26319b4b2b7e3931b9e8e63dfaa896a (patch)
tree39aa6f166635eaeccad93d8b455e053f636aff6f
parentd4c28f06a431cf54acc915772820eb6abed2954d (diff)
Build and run peerinfo service
Instead of the cljs version just run the peerinfo service and use IDBFS mounted on /hosts for persistence.
-rw-r--r--gnunet-build/packages/gnunet/gnunet/Buildrules22
-rw-r--r--src/cljs/gnunet_web/peerinfo.cljs118
-rw-r--r--src/cljs/gnunet_web/ui.cljs1
-rw-r--r--src/js/configuration.js3
-rw-r--r--src/js/pre.js8
-rw-r--r--src/js/server.js5
6 files changed, 43 insertions, 114 deletions
diff --git a/gnunet-build/packages/gnunet/gnunet/Buildrules b/gnunet-build/packages/gnunet/gnunet/Buildrules
index cd107d0..6019823 100644
--- a/gnunet-build/packages/gnunet/gnunet/Buildrules
+++ b/gnunet-build/packages/gnunet/gnunet/Buildrules
@@ -59,6 +59,28 @@ pkg_compile() {
"${S}/src/fs/libgnunet_plugin_block_fs.js" \
"${D}/var/lib/gnunet/js/"
#
+ # Peerinfo
+ #
+ ./libtool --tag=CC --mode=link \
+ emcc -fno-strict-aliasing -Wall \
+ -s EXPORTED_FUNCTIONS='["_main", "_GNUNET_log_setup"]' \
+ "-I${SYSROOT}/usr/include" "-L${SYSROOT}/usr/lib" \
+ -o "${S}/src/peerinfo/gnunet-service-peerinfo.js" \
+ "${S}/src/peerinfo/gnunet-service-peerinfo.o" \
+ "${S}/src/hello/libgnunethello.la" \
+ "${S}/src/statistics/libgnunetstatistics.la" \
+ "${S}/src/util/libgnunetutil.la" \
+ "${SYSROOT}/usr/lib/libgcrypt.la" \
+ "${SYSROOT}/usr/lib/libgpg-error.la" \
+ -lz \
+ --js-library "${BUILDROOT}/src/js/configuration.js" \
+ --js-library "${BUILDROOT}/src/js/scheduler.js" \
+ --js-library "${BUILDROOT}/src/js/server.js" \
+ --js-library "${BUILDROOT}/src/js/service.js" \
+ --pre-js "${BUILDROOT}/src/js/pre.js"
+ cp "${S}/src/peerinfo/.libs/gnunet-service-peerinfo.js" \
+ "${D}/var/lib/gnunet/js/"
+ #
# libdatacache plugin
#
./libtool --tag=CC --mode=link \
diff --git a/src/cljs/gnunet_web/peerinfo.cljs b/src/cljs/gnunet_web/peerinfo.cljs
index d4e141e..8532209 100644
--- a/src/cljs/gnunet_web/peerinfo.cljs
+++ b/src/cljs/gnunet_web/peerinfo.cljs
@@ -21,7 +21,7 @@
[gnunet-web.message :only (encode-message parse-message-types
parse-peer-identity)]
[gnunet-web.parser :only (parser parse-uint32)]
- [gnunet-web.service :only (add-service)]
+ [gnunet-web.service :only (client-connect)]
[gnunet-web.util :only (now)]
[tailrecursion.cljson :only (clj->cljson cljson->clj)])
(:require-macros [monads.macros :as monadic]))
@@ -68,118 +68,10 @@
(def info-end-message
(encode-message {:message-type message-type-peerinfo-info-end}))
-(def hostmap (atom nil))
-(def notify-clients (atom #{}))
-(def notify-clients-friend-only (atom #{}))
-
-(defn notify-all
- [entry]
- (let [msg-pub (encode-info-message (:identity entry)
- (:hello entry))
- msg-friend (encode-info-message (:identity entry)
- (:friend-only-hello entry))]
- (doseq [nc @notify-clients]
- (.postMessage nc (to-array msg-pub)))
- (doseq [nc @notify-clients-friend-only]
- (.postMessage nc (to-array msg-friend)))))
-
-(defn update-friend-hello
- [hello friend-hello]
- (merge-hello hello (or friend-hello {:public-key (:public-key hello)
- :friend-only true})))
-
-(defn update-hello
- [hello]
- (let [peer (:public-key hello)
- host (get @hostmap peer)
- dest (if (:friend-only hello)
- :friend-only-hello
- :hello)
- merged (merge-hello hello (dest host))
- delta (equals-hello merged (dest host) (now))]
- (when-not (= :equal delta)
- (swap! hostmap assoc-in [peer dest] merged)
- (when-not (:friend-only hello)
- (swap! hostmap assoc-in [peer :friend-only-hello]
- (update-friend-hello merged (:friend-only-hello host))))
- (let [host (get @hostmap peer)]
- (.setItem js/localStorage
- (str "hello:" peer)
- (clj->cljson (:hello host)))
- (.setItem js/localStorage
- (str "friend-only-hello:" peer)
- (clj->cljson (:friend-only-hello host)))
- (notify-all host)))))
-
-(defn add-host-to-known-hosts
- [public-key]
- (let [host {:identity public-key}]
- (swap! hostmap
- (fn [hostmap]
- (if (contains? hostmap public-key)
- hostmap
- (assoc hostmap public-key host))))
- (notify-all host)
- (when-let [hello (cljson->clj
- (.getItem js/localStorage (str "hello:" public-key)))]
- (update-hello hello))
- (when-let [hello (cljson->clj
- (.getItem js/localStorage (str "friend-only-hello:"
- public-key)))]
- (update-hello hello))))
+(def peerinfo-message-channel (js/MessageChannel.))
+(client-connect "peerinfo" (.-port2 peerinfo-message-channel))
(defn process-hello
[hello]
- (println "processing hello:" (clj->cljson hello))
- (add-host-to-known-hosts (:public-key hello))
- (update-hello hello))
-
-(def peerinfo-message-channel (js/MessageChannel.))
-(def clients (atom #{}))
-
-(defn client-get-message
- [event]
- (let [message (first (.-v ((parse-message-types #{parse-hello
- parse-peerinfo-notify
- parse-list-peer
- parse-list-peer-all})
- (.-data event))))]
- (println "peerinfo-msg:" (js/JSON.stringify (clj->js message)))
- (condp = (:message-type message)
- message-type-hello (process-hello (:message message))
- message-type-peerinfo-notify
- (swap!
- (if (:include-friend-only (:message message))
- notify-clients-friend-only
- notify-clients)
- conj (.-target event))
- message-type-peerinfo-get
- (let [get-message {:message message}
- peer (:public-key get-message)
- hello-type (if (:include-friend-only get-message)
- :friend-only-hello
- :hello)
- hello (hello-type (get @hostmap peer))]
- (.postMessage (.-target event)
- (encode-info-message peer hello))
- (.postMessage (.-target event) info-end-message))
- message-type-peerinfo-get-all
- (let [hello-type (if (:include-friend-only (:message message))
- :friend-only-hello
- :hello)]
- (doseq [entry @hostmap]
- (.postMessage (.-target event)
- (encode-info-message (key entry)
- (hello-type (val entry)))))
- (.postMessage (.-target event) info-end-message)))))
-
-(defn start-peerinfo
- []
- (set! (.-onmessage (.-port1 peerinfo-message-channel))
- (fn [event]
- ;; This must be a connect message
- (let [port (.-port (.-data event))]
- (swap! clients conj port)
- (set! (.-onmessage port) client-get-message))))
- (add-service "peerinfo" (.-port2 peerinfo-message-channel)))
-
+ (.postMessage (.-port1 peerinfo-message-channel)
+ (into-array (encode-hello hello))))
diff --git a/src/cljs/gnunet_web/ui.cljs b/src/cljs/gnunet_web/ui.cljs
index 3c25721..33a4a8a 100644
--- a/src/cljs/gnunet_web/ui.cljs
+++ b/src/cljs/gnunet_web/ui.cljs
@@ -29,7 +29,6 @@
(str (.-textContent output) string)))))
;;(set! *print-fn* #(.log js/console %))
-(start-peerinfo)
(def topology-worker (start-worker "topology" "js/gnunet-daemon-topology.js"))
(def fs-worker (start-worker "fs" "js/gnunet-service-fs.js"))
diff --git a/src/js/configuration.js b/src/js/configuration.js
index cc4de0d..146d35f 100644
--- a/src/js/configuration.js
+++ b/src/js/configuration.js
@@ -76,6 +76,9 @@ mergeInto(LibraryManager.library, {
MAX_CADET_CLIENTS: 128,
RESPECT: '/fs/credit/',
},
+ peerinfo: {
+ HOSTS: '/hosts/',
+ },
},
GNUNET_CONFIGURATION_get_value__deps: ['$CONFIG'],
GNUNET_CONFIGURATION_get_value: function(section, option) {
diff --git a/src/js/pre.js b/src/js/pre.js
index 9023013..97803c8 100644
--- a/src/js/pre.js
+++ b/src/js/pre.js
@@ -52,6 +52,14 @@ gnunet_prerun = function() {
// addRunDependency("randomness")
// <gather randomness>
// removeRunDependency("randomness")
+ FS.mkdir('/hosts');
+ FS.mount(IDBFS, {}, '/hosts');
+ addRunDependency('syncfs');
+ FS.syncfs(true, function() { removeRunDependency('syncfs'); });
+ var sync_callback = function() {
+ setTimeout(function() { FS.syncfs(false, sync_callback); }, 5000);
+ };
+ sync_callback();
}
if (typeof(Module) === "undefined") Module = { preRun: [] };
Module.preRun.push(gnunet_prerun);
diff --git a/src/js/server.js b/src/js/server.js
index cb85d65..d718212 100644
--- a/src/js/server.js
+++ b/src/js/server.js
@@ -139,6 +139,11 @@ mergeInto(LibraryManager.library, {
GNUNET_SERVER_resume: function(server) {
// TODO: see GNUNET_SERVER_suspend
},
+ GNUNET_SERVER_client_mark_monitor: function(client) {
+ // Mark the client as a 'monitor' so we don't wait for it to disconnect
+ // when we are shutting down.
+ // Since we don't handle shutdown this is a noop for now.
+ },
});
// vim: set expandtab ts=2 sw=2: