aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2015-03-01 17:21:06 -0600
committerDavid Barksdale <amatus@amatus.name>2015-03-01 17:21:06 -0600
commita46b0ef3f33df59546123023ffb244d07427399d (patch)
tree5a7e33d9e822adfdc686dd551a9b4dc5176c1c93 /src
parentd5c13428ce2823f379d217f8496ce5f1e1fa5df8 (diff)
Don't let out peer map grow without bound
Diffstat (limited to 'src')
-rw-r--r--src/cljs/gnunet_web/core.cljs4
-rw-r--r--src/cljs/gnunet_web/transport.cljs3
-rw-r--r--src/hl/index.cljs.hl36
3 files changed, 30 insertions, 13 deletions
diff --git a/src/cljs/gnunet_web/core.cljs b/src/cljs/gnunet_web/core.cljs
index 22d5a43..d7944d8 100644
--- a/src/cljs/gnunet_web/core.cljs
+++ b/src/cljs/gnunet_web/core.cljs
@@ -56,6 +56,10 @@
4 "Re-keying"
5 "Disconnected"})
+(def state-connected 3)
+(def state-disconnected 5)
+(def iteration-finished 6)
+
(defn state->string
[state]
(get state-strings state))
diff --git a/src/cljs/gnunet_web/transport.cljs b/src/cljs/gnunet_web/transport.cljs
index 471df8e..61d1740 100644
--- a/src/cljs/gnunet_web/transport.cljs
+++ b/src/cljs/gnunet_web/transport.cljs
@@ -37,6 +37,9 @@
9 "Disconnecting"
10 "Disconnect finished"})
+(def state-connected 5)
+(def state-disconnected 10)
+
(defn state->string
[state]
(get state-strings state))
diff --git a/src/hl/index.cljs.hl b/src/hl/index.cljs.hl
index 2004b72..382eb65 100644
--- a/src/hl/index.cljs.hl
+++ b/src/hl/index.cljs.hl
@@ -44,21 +44,31 @@
(defc peers {})
(defc= connection-count (count (filter (fn [[_ info]]
(and
- (= 5 (:transport-state info))
- (= 3 (:core-state info))))
+ (= transport/state-connected
+ (:transport-state info))
+ (= core/state-connected
+ (:core-state info))))
peers)))
-(transport/monitor-peers (fn [message]
- (swap! peers
- #(-> %
- (assoc-in [(:peer message) :transport-state]
- (:state message))
- (assoc-in [(:peer message) :address]
- (:address message))))))
-(core/monitor-peers (fn [message]
- (if (not (= 6 (:state message)))
- (swap! peers assoc-in [(:peer message) :core-state]
- (:state message)))))
+(transport/monitor-peers
+ (fn [message]
+ (swap! peers
+ (fn [peers]
+ (if (= transport/state-disconnected (:state message))
+ (dissoc peers (:peer message))
+ (-> peers
+ (assoc-in [(:peer message) :transport-state] (:state message))
+ (assoc-in [(:peer message) :address] (:address message))))))))
+
+(core/monitor-peers
+ (fn [message]
+ (if (not (= core/iteration-finished (:state message)))
+ (swap! peers
+ (fn [peers]
+ (if (get peers (:peer message))
+ (assoc-in peers [(:peer message) :core-state]
+ (:state message))
+ peers))))))
(defc active-search nil)
(defc search-results [])