summaryrefslogtreecommitdiff
path: root/src/main/clojure/org
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2011-10-22 19:00:47 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2011-10-22 19:00:47 -0500
commit60f0c36810787ef41602c702dac2668b3e31f9d0 (patch)
tree4181eb034a9f24d494df0d047c42c2c6b4e9b188 /src/main/clojure/org
parent92c382cc7dd0ba664b6c1b4baa004f2564921b6f (diff)
Some work on handling core compressed type map messages.
Diffstat (limited to 'src/main/clojure/org')
-rw-r--r--src/main/clojure/org/gnu/clojure/gnunet/core.clj33
-rw-r--r--src/main/clojure/org/gnu/clojure/gnunet/zip.clj23
2 files changed, 48 insertions, 8 deletions
diff --git a/src/main/clojure/org/gnu/clojure/gnunet/core.clj b/src/main/clojure/org/gnu/clojure/gnunet/core.clj
index 2017121..709cbea 100644
--- a/src/main/clojure/org/gnu/clojure/gnunet/core.clj
+++ b/src/main/clojure/org/gnu/clojure/gnunet/core.clj
@@ -1,5 +1,5 @@
(ns org.gnu.clojure.gnunet.core
- (:use (org.gnu.clojure.gnunet crypto exception message parser peer util)
+ (:use (org.gnu.clojure.gnunet crypto exception message parser peer util zip)
clojure.contrib.monads)
(:import (java.util Date Calendar)))
@@ -7,6 +7,9 @@
(def message-type-core-encrypted-message 82)
(def message-type-core-ping 83)
(def message-type-core-pong 84)
+(def message-type-core-hangup 85)
+(def message-type-core-compressed-type-map 86)
+(def message-type-core-binary-type-map 87)
(def signature-purpose-set-key 3)
@@ -172,6 +175,12 @@
:when message]
message))
+(def parse-compressed-type-map
+ (domonad
+ parser-m
+ [compressed-bytes (zero-or-more item)]
+ :type-map (inflate compressed-bytes)))
+
(defn emit-messages!
[peer remote-peer messages]
(let [state (deref (:state-agent remote-peer))
@@ -288,14 +297,22 @@
(assoc % :status peer-status-key-confirmed)
%))))))
+(defn handle-compressed-type-map!
+ [peer remote-peer message]
+ (when-let [type-map (first ((parse-core-compressed-type-map)
+ (:bytes message)))
+ (.write *out* (str "Got type map :" type-map "\n"))
+
(defn admit-core-message!
[peer remote-peer message]
- (if-let [dispatchers ((deref (:dispatch-agent peer))
- (:message-type message))]
- (doseq [dispatcher! dispatchers]
- (dispatcher! peer remote-peer message))
- (.write *out* (str "No dispatcher for message type "
- (:message-type message) "\n"))))
+ (let [message-type (:message-type message)]
+ (condp = message-type
+ message-type-core-compressed-type-map (handle-compressed-type-map!
+ peer remote-peer message)
+ (if-let [dispatchers ((deref (:dispatch-agent peer)) message-type)]
+ (do-callbacks! dispatchers peer remote-peer message)
+ (.write *out*
+ (str "No dispatcher for message type " message-type "\n"))))))
(defn handle-core-encrypted-message!
[peer remote-peer message]
@@ -334,7 +351,7 @@
[peer state]
(conj state
{:status peer-status-down
- :decrypt-key-created (Date. (long 0))
+ :decrypt-key-created (Date. Long/MIN_VALUE)
:encrypt-key (generate-aes-key! (:random peer))
:encrypt-key-created (Date.)
:ping-challenge (.nextInt (:random peer))
diff --git a/src/main/clojure/org/gnu/clojure/gnunet/zip.clj b/src/main/clojure/org/gnu/clojure/gnunet/zip.clj
new file mode 100644
index 0000000..0c38d2e
--- /dev/null
+++ b/src/main/clojure/org/gnu/clojure/gnunet/zip.clj
@@ -0,0 +1,23 @@
+(ns org.gnu.clojure.gnunet.zip
+ (:import java.util.zip.Inflater))
+
+(defn- inflate!
+ [inflater byte-seq]
+ (if (.needsInput inflater)
+ (when-not (empty? byte-seq)
+ (let [input (take 256 byte-seq)
+ byte-seq (drop 256 byte-seq)
+ _ (.setInput inflater (byte-array input))
+ output (byte-array 256)
+ output-length (.inflate inflater output)]
+ (lazy-seq (concat (take output-length output)
+ (inflate! inflater byte-seq)))))
+ (let [output (byte-array 256)
+ output-length (.inflate inflater output)]
+ (lazy-seq (concat (take output-length output)
+ (inflate! inflater byte-seq))))))
+
+(defn inflate
+ [byte-seq]
+ (let [inflater (Inflater.)]
+ (inflate! inflater byte-seq)))