summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox.hs')
-rw-r--r--dht/src/Network/Tox.hs32
1 files changed, 17 insertions, 15 deletions
diff --git a/dht/src/Network/Tox.hs b/dht/src/Network/Tox.hs
index 97b97bad..69c56e24 100644
--- a/dht/src/Network/Tox.hs
+++ b/dht/src/Network/Tox.hs
@@ -278,10 +278,10 @@ newOnionClient crypto net r toks keydb orouter map_var store load = c
278newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for. 278newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for.
279 -> [String] -- ^ Bind-address to listen on. Must provide at least one. 279 -> [String] -- ^ Bind-address to listen on. Must provide at least one.
280 -> ( ContactInfo extra -> SockAddr -> Session -> IO () ) 280 -> ( ContactInfo extra -> SockAddr -> Session -> IO () )
281 -> Maybe SecretKey -- ^ Optional DHT secret key to use. 281 -> (TransportCrypto, ContactInfo extra)
282 -> ( Int -> Onion.OnionMessage Encrypted -> IO () ) -- ^ TCP-bound onion responses. 282 -> ( Int -> Onion.OnionMessage Encrypted -> IO () ) -- ^ TCP-bound onion responses.
283 -> IO (Tox extra) 283 -> IO (Tox extra)
284newTox keydb bindspecs onsess suppliedDHTKey tcp = do 284newTox keydb bindspecs onsess crypto tcp = do
285 addrs <- mapM (`getBindAddress` True) bindspecs 285 addrs <- mapM (`getBindAddress` True) bindspecs
286 let tryBind addr next _ = udpTransport' addr `catchIOError` (next . Just) 286 let tryBind addr next _ = udpTransport' addr `catchIOError` (next . Just)
287 failedBind mbe = do 287 failedBind mbe = do
@@ -291,21 +291,14 @@ newTox keydb bindspecs onsess suppliedDHTKey tcp = do
291 throwIO $ userError "Tox UDP listen port?" 291 throwIO $ userError "Tox UDP listen port?"
292 (udp,sock) <- foldr tryBind failedBind addrs Nothing 292 (udp,sock) <- foldr tryBind failedBind addrs Nothing
293 addr <- getSocketName sock 293 addr <- getSocketName sock
294 (relay,sendTCP) <- tcpRelay addr (\a x -> sendMessage udp a $ S.runPut $ Onion.putRequest x) 294 (relay,sendTCP) <- tcpRelay (fst crypto) addr (\a x -> sendMessage udp a $ S.runPut $ Onion.putRequest x)
295 tox <- newToxOverTransport keydb addr onsess suppliedDHTKey udp sendTCP 295 tox <- newToxOverTransport keydb addr onsess crypto udp sendTCP
296 return tox { toxAnnounceToLan = announceToLan sock (key2id $ transportPublic $ toxCryptoKeys tox) 296 return tox { toxAnnounceToLan = announceToLan sock (key2id $ transportPublic $ toxCryptoKeys tox)
297 , toxRelayServer = Just relay 297 , toxRelayServer = Just relay
298 } 298 }
299 299
300-- | This version of 'newTox' is useful for automated tests using 'testPairTransport'. 300newToxCrypto :: Maybe SecretKey -> IO (TransportCrypto, ContactInfo extra)
301newToxOverTransport :: TVar Onion.AnnouncedKeys 301newToxCrypto suppliedDHTKey = do
302 -> SockAddr
303 -> ( ContactInfo extra -> SockAddr -> Session -> IO () )
304 -> Maybe SecretKey
305 -> Onion.UDPTransport
306 -> ( Int -> Onion.OnionMessage Encrypted -> IO () ) -- ^ TCP-bound onion responses.
307 -> IO (Tox extra)
308newToxOverTransport keydb addr onNewSession suppliedDHTKey udp tcp = do
309 roster <- newContactInfo 302 roster <- newContactInfo
310 crypto0 <- newCrypto 303 crypto0 <- newCrypto
311 let -- patch in supplied DHT key 304 let -- patch in supplied DHT key
@@ -316,12 +309,21 @@ newToxOverTransport keydb addr onNewSession suppliedDHTKey udp tcp = do
316 , transportPublic = toPublic k 309 , transportPublic = toPublic k
317 } 310 }
318 -- patch in newly allocated roster state. 311 -- patch in newly allocated roster state.
319 crypto = crypto1 { userKeys = myKeyPairs roster }
320 forM_ suppliedDHTKey $ \k -> do 312 forM_ suppliedDHTKey $ \k -> do
321 maybe (dput XMisc "failed to encode suppliedDHTKey") 313 maybe (dput XMisc "failed to encode suppliedDHTKey")
322 (dputB XMisc . C8.append "Using suppliedDHTKey: ") 314 (dputB XMisc . C8.append "Using suppliedDHTKey: ")
323 $ encodeSecret k 315 $ encodeSecret k
316 return (crypto1 { userKeys = myKeyPairs roster }, roster )
324 317
318-- | This version of 'newTox' is useful for automated tests using 'testPairTransport'.
319newToxOverTransport :: TVar Onion.AnnouncedKeys
320 -> SockAddr
321 -> ( ContactInfo extra -> SockAddr -> Session -> IO () )
322 -> (TransportCrypto, ContactInfo extra)
323 -> Onion.UDPTransport
324 -> ( Int -> Onion.OnionMessage Encrypted -> IO () ) -- ^ TCP-bound onion responses.
325 -> IO (Tox extra)
326newToxOverTransport keydb addr onNewSession (crypto,roster) udp tcp = do
325 drg <- drgNew 327 drg <- drgNew
326 let lookupClose _ = return Nothing 328 let lookupClose _ = return Nothing
327 329