diff options
Diffstat (limited to 'src/Network/Tox')
-rw-r--r-- | src/Network/Tox/AggregateSession.hs | 9 | ||||
-rw-r--r-- | src/Network/Tox/NodeId.hs | 3 |
2 files changed, 8 insertions, 4 deletions
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 | ||
590 | solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId | 590 | solveBase64NoSpamID :: String -> PublicKey -> Either String NoSpamId |
591 | solveBase64NoSpamID b64digits pub = do | 591 | solveBase64NoSpamID 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 |