summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox')
-rw-r--r--dht/src/Network/Tox/AggregateSession.hs12
-rw-r--r--dht/src/Network/Tox/DHT/Transport.hs8
2 files changed, 10 insertions, 10 deletions
diff --git a/dht/src/Network/Tox/AggregateSession.hs b/dht/src/Network/Tox/AggregateSession.hs
index 8c728660..999c7399 100644
--- a/dht/src/Network/Tox/AggregateSession.hs
+++ b/dht/src/Network/Tox/AggregateSession.hs
@@ -188,21 +188,21 @@ forkSession c s setStatus = forkIO $ do
188 now <- getPOSIXTime 188 now <- getPOSIXTime
189 atomically $ modifyTVar' q $ PSQ.insert (fromEnum DoTimeout) (now + 15) 189 atomically $ modifyTVar' q $ PSQ.insert (fromEnum DoTimeout) (now + 15)
190 190
191 onPacket body loop Nothing = return () 191 onPacket body loop Terminated = return ()
192 onPacket body loop (Just (Left e)) = inPrint e >> loop 192 onPacket body loop (ParseError e) = inPrint e >> loop
193 onPacket body loop (Just (Right x)) = body loop x 193 onPacket body loop (Arrival _ x) = body loop x
194 194
195 awaitPacket body = fix $ awaitMessage (sTransport s) . onPacket body 195 awaitPacket body = fix $ join . atomically . awaitMessage (sTransport s) . onPacket body
196 196
197 atomically $ setStatus $ InProgress AwaitingSessionPacket 197 atomically $ setStatus $ InProgress AwaitingSessionPacket
198 awaitPacket $ \_ (online,()) -> do 198 awaitPacket $ \_ online -> do
199 when (msgID online /= M ONLINE) $ do 199 when (msgID online /= M ONLINE) $ do
200 inPrint $ "Unexpected initial packet: " ++ show (msgID online) 200 inPrint $ "Unexpected initial packet: " ++ show (msgID online)
201 atomically $ do setStatus Established 201 atomically $ do setStatus Established
202 sendPacket online 202 sendPacket online
203 bump 203 bump
204 beacon <- forkIO $ keepAlive s q 204 beacon <- forkIO $ keepAlive s q
205 awaitPacket $ \awaitNext (x,()) -> do 205 awaitPacket $ \awaitNext x -> do
206 bump 206 bump
207 case msgID x of 207 case msgID x of
208 M ALIVE -> return () 208 M ALIVE -> return ()
diff --git a/dht/src/Network/Tox/DHT/Transport.hs b/dht/src/Network/Tox/DHT/Transport.hs
index 7475b3b1..7414343d 100644
--- a/dht/src/Network/Tox/DHT/Transport.hs
+++ b/dht/src/Network/Tox/DHT/Transport.hs
@@ -59,7 +59,7 @@ import GHC.Generics
59import Network.Socket 59import Network.Socket
60 60
61type DHTTransport = Transport String NodeInfo (DHTMessage Encrypted8) 61type DHTTransport = Transport String NodeInfo (DHTMessage Encrypted8)
62type HandleHi a = Maybe (Either String (DHTMessage Encrypted8, NodeInfo)) -> IO a 62type HandleHi a = Arrival String NodeInfo (DHTMessage Encrypted8) -> IO a
63 63
64 64
65data DHTMessage (f :: * -> *) 65data DHTMessage (f :: * -> *)
@@ -399,13 +399,13 @@ instance Serialize CookieRequest where
399forwardDHTRequests :: TransportCrypto -> (PublicKey -> IO (Maybe NodeInfo)) -> DHTTransport -> DHTTransport 399forwardDHTRequests :: TransportCrypto -> (PublicKey -> IO (Maybe NodeInfo)) -> DHTTransport -> DHTTransport
400forwardDHTRequests crypto closeLookup dht = dht { awaitMessage = await' } 400forwardDHTRequests crypto closeLookup dht = dht { awaitMessage = await' }
401 where 401 where
402 await' :: HandleHi a -> IO a 402 await' :: HandleHi a -> STM (IO a)
403 await' pass = awaitMessage dht $ \case 403 await' pass = awaitMessage dht $ \case
404 Just (Right (m@(DHTDHTRequest target payload),src)) | target /= transportPublic crypto 404 Arrival src m@(DHTDHTRequest target payload) | target /= transportPublic crypto
405 -> do mni <- closeLookup target 405 -> do mni <- closeLookup target
406 -- Forward the message if the target is in our close list. 406 -- Forward the message if the target is in our close list.
407 forM_ mni $ \ni -> sendMessage dht ni m 407 forM_ mni $ \ni -> sendMessage dht ni m
408 await' pass 408 join $ atomically (await' pass)
409 m -> pass m 409 m -> pass m
410 410
411encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> IO (DHTMessage Encrypted8, NodeInfo) 411encrypt :: TransportCrypto -> DHTMessage ((,) Nonce8) -> NodeInfo -> IO (DHTMessage Encrypted8, NodeInfo)