summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--OnionRouter.hs4
-rw-r--r--src/Crypto/Tox.hs5
-rw-r--r--src/Network/Tox/AggregateSession.hs9
-rw-r--r--src/Network/Tox/NodeId.hs3
4 files changed, 14 insertions, 7 deletions
diff --git a/OnionRouter.hs b/OnionRouter.hs
index b11a0bf6..f1b0b41c 100644
--- a/OnionRouter.hs
+++ b/OnionRouter.hs
@@ -286,7 +286,9 @@ handleEvent getnodes or e@(BuildRoute (RouteId rid)) = do
286 ts <- selectTrampolines or 286 ts <- selectTrampolines or
287 join . atomically $ do 287 join . atomically $ do
288 drg <- readTVar (onionDRG or) 288 drg <- readTVar (onionDRG or)
289 [av,bv,cv] <- sequence $ replicate 3 (newTVar Nothing) 289 av <- newTVar Nothing
290 bv <- newTVar Nothing
291 cv <- newTVar Nothing
290 let (getr, drg') = withDRG drg $ do 292 let (getr, drg') = withDRG drg $ do
291 asec <- generateSecretKey -- Three aliases 293 asec <- generateSecretKey -- Three aliases
292 bsec <- generateSecretKey 294 bsec <- generateSecretKey
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs
index 61a392e2..9b097c7e 100644
--- a/src/Crypto/Tox.hs
+++ b/src/Crypto/Tox.hs
@@ -470,8 +470,9 @@ instance Read Nonce32 where
470 '=':xs -> Right xs -- optional terminating '=' 470 '=':xs -> Right xs -- optional terminating '='
471 _ -> Right ss 471 _ -> Right ss
472 bs <- Base64.decode (C8.pack $ ds ++ ['=']) 472 bs <- Base64.decode (C8.pack $ ds ++ ['='])
473 guard $ B.length bs == 32 473 if B.length bs == 32
474 return [ (Nonce32 bs, ss') ] 474 then Right [ (Nonce32 bs, ss') ]
475 else Left "Insuffiicent base64 digits while parsing Nonce32."
475 476
476instance Serialize Nonce32 where 477instance Serialize Nonce32 where
477 get = Nonce32 <$> getBytes 32 478 get = Nonce32 <$> getBytes 32
diff --git a/src/Network/Tox/AggregateSession.hs b/src/Network/Tox/AggregateSession.hs
index 513896cc..df16dc4e 100644
--- a/src/Network/Tox/AggregateSession.hs
+++ b/src/Network/Tox/AggregateSession.hs
@@ -155,9 +155,12 @@ keepAlive s q = do
155 155
156 now <- getPOSIXTime 156 now <- getPOSIXTime
157 join $ atomically $ do 157 join $ atomically $ do
158 Just ( k :-> tm ) <- PSQ.findMin <$> readTVar q 158 PSQ.findMin <$> readTVar q >>= \case
159 return $ if now < tm then threadDelay (toMicroseconds $ tm - now) >> again 159 Nothing -> error "keepAlive: unexpected empty PSQ."
160 else doEvent again now (toEnum k) 160 Just ( k :-> tm ) ->
161 return $ if now < tm then threadDelay (toMicroseconds $ tm - now) >> again
162 else doEvent again now (toEnum k)
163
161 164
162-- | This function forks two threads: the 'keepAlive' beacon-sending thread and 165-- | This function forks two threads: the 'keepAlive' beacon-sending thread and
163-- a thread to read all packets from the provided 'Session' and forward them to 166-- a thread to read all packets from the provided 'Session' and forward them to
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs
index d5da692a..dc600db7 100644
--- a/src/Network/Tox/NodeId.hs
+++ b/src/Network/Tox/NodeId.hs
@@ -589,7 +589,8 @@ parseNoSpamJID jid = do
589 589
590solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId 590solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId
591solveBase64NoSpamID b64digits pub = do 591solveBase64NoSpamID b64digits pub = do
592 NoSpam nospam (Just x) <- readEither $ '$' : map (\case; '?' -> '0'; c -> c) b64digits 592 NoSpam nospam mx <- readEither $ '$' : map (\case; '?' -> '0'; c -> c) b64digits
593 maybe (const $ Left "missing checksum") (flip ($)) mx $ \x -> do
593 let nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 594 let nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16
594 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 595 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16
595 sum = x `xor` nlo `xor` nhi `xor` xorsum pub 596 sum = x `xor` nlo `xor` nhi `xor` xorsum pub