summaryrefslogtreecommitdiff
path: root/src/Network/Tox/DHT
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/DHT')
-rw-r--r--src/Network/Tox/DHT/Handlers.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs
index 238fb0d0..dd586430 100644
--- a/src/Network/Tox/DHT/Handlers.hs
+++ b/src/Network/Tox/DHT/Handlers.hs
@@ -5,6 +5,7 @@
5{-# LANGUAGE TupleSections #-} 5{-# LANGUAGE TupleSections #-}
6module Network.Tox.DHT.Handlers where 6module Network.Tox.DHT.Handlers where
7 7
8import Debug.Trace
8import Network.Tox.DHT.Transport as DHTTransport 9import Network.Tox.DHT.Transport as DHTTransport
9import Network.QueryResponse as QR hiding (Client) 10import Network.QueryResponse as QR hiding (Client)
10import qualified Network.QueryResponse as QR (Client) 11import qualified Network.QueryResponse as QR (Client)
@@ -234,6 +235,23 @@ createCookie crypto ni remoteUserKey = do
234 dput XNetCrypto $ "Created cookie with n24 = 0x" ++ show n24 ++ "\n sym=" ++ show sym 235 dput XNetCrypto $ "Created cookie with n24 = 0x" ++ show n24 ++ "\n sym=" ++ show sym
235 return $ Cookie n24 edta 236 return $ Cookie n24 edta
236 237
238createCookieSTM :: POSIXTime -> TransportCrypto -> NodeInfo -> PublicKey -> STM (Cookie Encrypted)
239createCookieSTM now crypto ni remoteUserKey = do
240 let dmsg msg = trace msg (return ())
241 (n24,sym) <- do
242 n24 <- transportNewNonce crypto
243 sym <- transportSymmetric crypto
244 return (n24,sym)
245 let timestamp = round (now * 1000000)
246 let dta = encodePlain $ CookieData
247 { cookieTime = timestamp
248 , longTermKey = remoteUserKey
249 , dhtKey = transportPublic crypto
250 }
251 edta = encryptSymmetric sym n24 dta
252 dmsg $ "(createCookieSTM) Created cookie with n24 = 0x" ++ show n24 ++ "\n sym=" ++ show sym
253 return $ Cookie n24 edta
254
237cookieRequestH :: TransportCrypto -> NodeInfo -> CookieRequest -> IO (Cookie Encrypted) 255cookieRequestH :: TransportCrypto -> NodeInfo -> CookieRequest -> IO (Cookie Encrypted)
238cookieRequestH crypto ni (CookieRequest remoteUserKey) = do 256cookieRequestH crypto ni (CookieRequest remoteUserKey) = do
239 dput XNetCrypto $ unlines 257 dput XNetCrypto $ unlines