summaryrefslogtreecommitdiff
path: root/src/Network/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r--src/Network/Tox.hs44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index a13a4f10..efddc2a0 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -141,9 +141,9 @@ newCrypto = do
141 noncevar <- atomically $ newTVar $ fst $ withDRG drg drgNew 141 noncevar <- atomically $ newTVar $ fst $ withDRG drg drgNew
142 cookieKeys <- atomically $ newTVar [] 142 cookieKeys <- atomically $ newTVar []
143 cache <- newSecretsCache 143 cache <- newSecretsCache
144 hPutStrLn stderr $ "secret(tox) = " ++ DHT.showHex secret 144 dput XNetCrypto $ "secret(tox) = " ++ DHT.showHex secret
145 hPutStrLn stderr $ "public(tox) = " ++ DHT.showHex pubkey 145 dput XNetCrypto $ "public(tox) = " ++ DHT.showHex pubkey
146 hPutStrLn stderr $ "symmetric(tox) = " ++ DHT.showHex symkey 146 dput XNetCrypto $ "symmetric(tox) = " ++ DHT.showHex symkey
147 return TransportCrypto 147 return TransportCrypto
148 { transportSecret = secret 148 { transportSecret = secret
149 , transportPublic = pubkey 149 , transportPublic = pubkey
@@ -233,7 +233,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do
233 , lookupHandler = handlers -- var 233 , lookupHandler = handlers -- var
234 , tableMethods = modifytbl tbl 234 , tableMethods = modifytbl tbl
235 } 235 }
236 eprinter = printErrors stderr 236 eprinter = logErrors -- printErrors stderr
237 mkclient (tbl,var) handlers = 237 mkclient (tbl,var) handlers =
238 let client = Client 238 let client = Client
239 { clientNet = addHandler (reportParseError eprinter) (handleMessage client) $ modifynet client net 239 { clientNet = addHandler (reportParseError eprinter) (handleMessage client) $ modifynet client net
@@ -277,7 +277,7 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do
277 mbContactsVar <- fmap contacts . HashMap.lookup mykeyAsId <$> atomically (readTVar (accounts (toxContactInfo tox))) 277 mbContactsVar <- fmap contacts . HashMap.lookup mykeyAsId <$> atomically (readTVar (accounts (toxContactInfo tox)))
278 case mbContactsVar of 278 case mbContactsVar of
279 Nothing -> do 279 Nothing -> do
280 hPutStrLn stderr ("netCrypto: (" ++ show mykeyAsId ++") accounts lookup failed.") 280 dput XNetCrypto ("netCrypto: (" ++ show mykeyAsId ++") accounts lookup failed.")
281 return [] 281 return []
282 282
283 Just contactsVar -> do 283 Just contactsVar -> do
@@ -292,13 +292,13 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do
292 return (kp,sa,fr,cp) 292 return (kp,sa,fr,cp)
293 case tup of 293 case tup of
294 (Nothing,Nothing,Nothing,Nothing) -> do 294 (Nothing,Nothing,Nothing,Nothing) -> do
295 hPutStrLn stderr ("netCrypto: (" ++ show mykeyAsId ++") friend not found (" ++ show theirkeyAsId ++ ").") 295 dput XNetCrypto ("netCrypto: (" ++ show mykeyAsId ++") friend not found (" ++ show theirkeyAsId ++ ").")
296 return [] 296 return []
297 (mbKeyPkt,Nothing,mbFR,mbPolicy) -> do 297 (mbKeyPkt,Nothing,mbFR,mbPolicy) -> do
298 hPutStrLn stderr ("netCrypto: (" ++ show mykeyAsId ++") no SockAddr for friend (" ++ show theirkeyAsId ++ "). TODO: search their node?") 298 dput XNetCrypto ("netCrypto: (" ++ show mykeyAsId ++") no SockAddr for friend (" ++ show theirkeyAsId ++ "). TODO: search their node?")
299 return [] 299 return []
300 (Nothing,_,_,_) -> do 300 (Nothing,_,_,_) -> do
301 hPutStrLn stderr ("netCrypto: (" ++ show mykeyAsId ++") no DHT-key for friend (" ++ show theirkeyAsId ++ "). TODO: what?") 301 dput XNetCrypto ("netCrypto: (" ++ show mykeyAsId ++") no DHT-key for friend (" ++ show theirkeyAsId ++ "). TODO: what?")
302 return [] 302 return []
303 (Just (stamp_theirDhtKey,keyPkt),Just (stamp_saddr,saddr),mbFR,mbPolicy) 303 (Just (stamp_theirDhtKey,keyPkt),Just (stamp_saddr,saddr),mbFR,mbPolicy)
304 | theirDhtKey <- DHT.dhtpk keyPkt -> do 304 | theirDhtKey <- DHT.dhtpk keyPkt -> do
@@ -310,7 +310,7 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do
310 Just sessions | matchedSessions <- filter (sessionUsesIdentity (toPublic myseckey)) sessions 310 Just sessions | matchedSessions <- filter (sessionUsesIdentity (toPublic myseckey)) sessions
311 , not (null matchedSessions) 311 , not (null matchedSessions)
312 -> do 312 -> do
313 hPutStrLn stderr ("netCrypto: Already have a session for " ++ show mykeyAsId ++ "<-->" ++ show theirkeyAsId) 313 dput XNetCrypto ("netCrypto: Already have a session for " ++ show mykeyAsId ++ "<-->" ++ show theirkeyAsId)
314 return matchedSessions 314 return matchedSessions
315 -- if not, send handshake, this is separate session 315 -- if not, send handshake, this is separate session
316 _ -> do 316 _ -> do
@@ -319,16 +319,16 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do
319 let crypto = toxCryptoKeys tox 319 let crypto = toxCryptoKeys tox
320 client = toxDHT tox 320 client = toxDHT tox
321 case nodeInfo (key2id theirDhtKey) saddr of 321 case nodeInfo (key2id theirDhtKey) saddr of
322 Left e -> hPutStrLn stderr ("netCrypto: nodeInfo fail... " ++ e) >> return [] 322 Left e -> dput XNetCrypto ("netCrypto: nodeInfo fail... " ++ e) >> return []
323 Right ni -> do 323 Right ni -> do
324 mbCookie <- DHT.cookieRequest crypto client (toPublic myseckey) ni 324 mbCookie <- DHT.cookieRequest crypto client (toPublic myseckey) ni
325 case mbCookie of 325 case mbCookie of
326 Nothing -> do 326 Nothing -> do
327 hPutStrLn stderr ("netCrypto: (" ++ show mykeyAsId ++") <--> (" ++ show theirkeyAsId ++ ").") 327 dput XNetCrypto ("netCrypto: (" ++ show mykeyAsId ++") <--> (" ++ show theirkeyAsId ++ ").")
328 hPutStrLn stderr ("netCrypto: CookieRequest failed. TODO: dhtpkNodes thingy") 328 dput XNetCrypto ("netCrypto: CookieRequest failed. TODO: dhtpkNodes thingy")
329 return [] 329 return []
330 Just cookie -> do 330 Just cookie -> do
331 hPutStrLn stderr "Have cookie, creating handshake packet..." 331 dput XNetCrypto "Have cookie, creating handshake packet..."
332 let hp = HParam { hpOtherCookie = cookie 332 let hp = HParam { hpOtherCookie = cookie
333 , hpMySecretKey = myseckey 333 , hpMySecretKey = myseckey
334 , hpCookieRemotePubkey = theirpubkey 334 , hpCookieRemotePubkey = theirpubkey
@@ -349,12 +349,12 @@ netCryptoWithBackoff millisecs tox myseckey theirpubkey = do
349 delay = (millisecs * 5 `div` 4) 349 delay = (millisecs * 5 `div` 4)
350 if secnum < 20000000 350 if secnum < 20000000
351 then do 351 then do
352 hPutStrLn stderr $ "sent handshake, now delaying " ++ show (secnum * 1.25) ++ " second(s).." 352 dput XNetCrypto $ "sent handshake, now delaying " ++ show (secnum * 1.25) ++ " second(s).."
353 -- threadDelay delay 353 -- threadDelay delay
354 -- Commenting loop for simpler debugging 354 -- Commenting loop for simpler debugging
355 return [] -- netCryptoWithBackoff delay tox myseckey theirpubkey -- hopefully it will find an active session this time. 355 return [] -- netCryptoWithBackoff delay tox myseckey theirpubkey -- hopefully it will find an active session this time.
356 else do 356 else do
357 hPutStrLn stderr "Unable to establish session..." 357 dput XNetCrypto "Unable to establish session..."
358 return [] 358 return []
359 359
360-- | Create a DHTPublicKey packet to send to a remote contact. 360-- | Create a DHTPublicKey packet to send to a remote contact.
@@ -387,12 +387,12 @@ addVerbosity tr =
387 tr { awaitMessage = \kont -> awaitMessage tr $ \m -> do 387 tr { awaitMessage = \kont -> awaitMessage tr $ \m -> do
388 forM_ m $ mapM_ $ \(msg,addr) -> do 388 forM_ m $ mapM_ $ \(msg,addr) -> do
389 when (not (B.null msg || elem (B.head msg) [0,1,2,4,0x81,0x82,0x8c,0x8d])) $ do 389 when (not (B.null msg || elem (B.head msg) [0,1,2,4,0x81,0x82,0x8c,0x8d])) $ do
390 mapM_ (\x -> hPutStrLn stderr ( (show addr) ++ " --> " ++ x)) 390 mapM_ (\x -> dput XMisc ( (show addr) ++ " --> " ++ x))
391 $ xxd 0 msg 391 $ xxd 0 msg
392 kont m 392 kont m
393 , sendMessage = \addr msg -> do 393 , sendMessage = \addr msg -> do
394 when (not (B.null msg || elem (B.head msg) [0,1,2,4,0x81,0x8c,0x8d])) $ do 394 when (not (B.null msg || elem (B.head msg) [0,1,2,4,0x81,0x8c,0x8d])) $ do
395 mapM_ (\x -> hPutStrLn stderr ( (show addr) ++ " <-- " ++ x)) 395 mapM_ (\x -> dput XMisc ( (show addr) ++ " <-- " ++ x))
396 $ xxd 0 msg 396 $ xxd 0 msg
397 sendMessage tr addr msg 397 sendMessage tr addr msg
398 } 398 }
@@ -437,15 +437,15 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
437 -- patch in newly allocated roster state. 437 -- patch in newly allocated roster state.
438 crypto = crypto1 { userKeys = myKeyPairs roster } 438 crypto = crypto1 { userKeys = myKeyPairs roster }
439 forM_ suppliedDHTKey $ \k -> do 439 forM_ suppliedDHTKey $ \k -> do
440 maybe (hPutStrLn stderr "failed to encode suppliedDHTKey") 440 maybe (dput XMisc "failed to encode suppliedDHTKey")
441 (C8.hPutStrLn stderr . C8.append "Using suppliedDHTKey: ") 441 (dputB XMisc . C8.append "Using suppliedDHTKey: ")
442 $ encodeSecret k 442 $ encodeSecret k
443 443
444 drg <- drgNew 444 drg <- drgNew
445 let lookupClose _ = return Nothing 445 let lookupClose _ = return Nothing
446 446
447 mkrouting <- DHT.newRouting addr crypto updateIP updateIP 447 mkrouting <- DHT.newRouting addr crypto updateIP updateIP
448 let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. 448 let ignoreErrors _ = return () -- Set this to (dput XMisc) to debug onion route building.
449 orouter <- newOnionRouter ignoreErrors 449 orouter <- newOnionRouter ignoreErrors
450 (cryptonet,dhtcrypt,onioncrypt,dtacrypt,handshakes) <- toxTransport crypto orouter lookupClose udp 450 (cryptonet,dhtcrypt,onioncrypt,dtacrypt,handshakes) <- toxTransport crypto orouter lookupClose udp
451 451
@@ -493,8 +493,8 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
493 { toxDHT = dhtclient 493 { toxDHT = dhtclient
494 , toxOnion = onionclient 494 , toxOnion = onionclient
495 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt 495 , toxToRoute = onInbound (updateContactInfo roster) dtacrypt
496 , toxCrypto = addHandler (hPutStrLn stderr) (sessionPacketH sessionsState) cryptonet 496 , toxCrypto = addHandler (dput XMisc) (sessionPacketH sessionsState) cryptonet
497 , toxHandshakes = addHandler (hPutStrLn stderr) (handshakeH sessionsState) handshakes 497 , toxHandshakes = addHandler (dput XMisc) (handshakeH sessionsState) handshakes
498 , toxCryptoSessions = sessionsState 498 , toxCryptoSessions = sessionsState
499 , toxCryptoKeys = crypto 499 , toxCryptoKeys = crypto
500 , toxRouting = mkrouting dhtclient 500 , toxRouting = mkrouting dhtclient