Skip to content

Commit

Permalink
Translate JavaOnionProxyManager.startWithRepeat
Browse files Browse the repository at this point in the history
  • Loading branch information
edne committed Sep 8, 2016
1 parent 038ee98 commit bef0965
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/hidden_pod/tor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
JavaOnionProxyManager)))


(defn- start-proxy [proxy-manager]
(if-not (.startWithRepeat proxy-manager 30 5)
(defn start-with-timeout [proxy-manager proxy-context
timeout-secs]
{:pre [(> timeout-secs 0)]}
(when (.installAndStartTorOp proxy-manager)
(.enableNetwork proxy-manager true)
(or (->> #(or (.isBootstrapped proxy-manager)
(Thread/sleep 1000))
(take timeout-secs)
(filter identity)
#(if % (first %)))
(do (.stop proxy-manager)
(.deleteAllFilesButHiddenServices proxy-context)
false))))


(defn- start-proxy [proxy-manager proxy-context]
(if-not (start-with-timeout proxy-manager proxy-context 30)
(throw (Exception. "Failed to run Tor"))))


(defn- new-proxy-manager []
(let [proxy-manager (->> (into-array java.nio.file.attribute.FileAttribute [])
(let [proxy-context (->> (into-array java.nio.file.attribute.FileAttribute [])
(Files/createTempDirectory "tor-folder") .toFile
(new JavaOnionProxyContext)
(new JavaOnionProxyManager))]
(start-proxy proxy-manager)
(new JavaOnionProxyContext))
proxy-manager (new JavaOnionProxyManager proxy-context)]
(start-proxy proxy-manager proxy-context)
proxy-manager))


Expand Down

0 comments on commit bef0965

Please sign in to comment.