summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2010-10-18 23:28:23 -0700
committerDavid Barksdale <amatus.amongus@gmail.com>2010-10-18 23:28:23 -0700
commit9cf4b8184112da9392c7b66b787aaa6319c55c57 (patch)
tree67b7c230db6e4a290c6b7b5654f31cc5fe9af066 /src
parentf6445be6adb07426d0fe26f62bc2b88639f064af (diff)
Some work on CORE_PONG support. We now make it to peer-status-key-confirmed!
Diffstat (limited to 'src')
-rw-r--r--src/org/gnu/clojure/gnunet/core.clj38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/org/gnu/clojure/gnunet/core.clj b/src/org/gnu/clojure/gnunet/core.clj
index b7f476c..f768e71 100644
--- a/src/org/gnu/clojure/gnunet/core.clj
+++ b/src/org/gnu/clojure/gnunet/core.clj
@@ -58,7 +58,7 @@
(encode-int32 (:challenge ping))))
(def parse-core-ping
- (domonad parser-m [iv-seed parse-uint32
+ (domonad parser-m [iv-seed parse-int32
peer-id (items id-size)
challenge parse-int32]
{:iv-seed iv-seed
@@ -73,6 +73,16 @@
(encode-int32 (:inbound-bw-limit pong))
(:peer-id pong)))
+(def parse-core-pong
+ (domonad parser-m [iv-seed parse-int32
+ challenge parse-int32
+ inbound-bw-limit parse-uint32
+ peer-id (items id-size)]
+ {:iv-seed iv-seed
+ :challenge challenge
+ :inbound-bw-limit inbound-bw-limit
+ :peer-id peer-id}))
+
(defn derive-iv
[aes-key seed peer-id]
(derive-aes-iv aes-key
@@ -238,7 +248,29 @@
[{:message-type message-type-core-pong
:bytes encrypted-pong}])))))))
state)))
-
+
+(defn handle-core-pong!
+ [peer remote-peer message]
+ (send (:state-agent remote-peer)
+ (fn [state]
+ (if-let [decrypt-key (:decrypt-key state)]
+ (if-let [pong (first (parse-core-pong (:bytes message)))]
+ (let [iv (derive-pong-iv decrypt-key (:iv-seed pong)
+ (:ping-challenge state) (:id peer))
+ decrypted-message (decrypt-message decrypt-key iv
+ (:bytes message))]
+ (if-let [pong (first (parse-core-pong decrypted-message))]
+ (if (and (= (:peer-id pong) (:id remote-peer))
+ (= (:challenge pong) (:ping-challenge state)))
+ (condp = (:status state)
+ peer-status-key-received (assoc state :status
+ peer-status-key-confirmed)
+ state)
+ state)
+ state))
+ state)
+ state))))
+
(defn initialize-remote-peer-state
[peer state]
(conj state
@@ -261,6 +293,6 @@
message-type-core-set-key (handle-set-key! peer remote-peer message)
message-type-core-encrypted-message nil
message-type-core-ping (handle-core-ping! peer remote-peer message)
- message-type-core-pong nil
+ message-type-core-pong (handle-core-pong! peer remote-peer message)
nil)
state))))