summaryrefslogtreecommitdiff
path: root/src/Network/Tox/DHT/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/DHT/Handlers.hs')
-rw-r--r--src/Network/Tox/DHT/Handlers.hs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs
index a3f13ac7..4f891316 100644
--- a/src/Network/Tox/DHT/Handlers.hs
+++ b/src/Network/Tox/DHT/Handlers.hs
@@ -188,29 +188,29 @@ type Message = DHTMessage ((,) Nonce8)
188type Client = QR.Client String PacketKind TransactionId NodeInfo Message 188type Client = QR.Client String PacketKind TransactionId NodeInfo Message
189 189
190 190
191wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta 191wrapAsymm :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Asymm dta
192wrapAssym (TransactionId n8 n24) src dst dta = Assym 192wrapAsymm (TransactionId n8 n24) src dst dta = Asymm
193 { senderKey = id2key $ nodeId src 193 { senderKey = id2key $ nodeId src
194 , assymNonce = n24 194 , asymmNonce = n24
195 , assymData = dta n8 195 , asymmData = dta n8
196 } 196 }
197 197
198serializer :: PacketKind 198serializer :: PacketKind
199 -> (Assym (Nonce8,ping) -> Message) 199 -> (Asymm (Nonce8,ping) -> Message)
200 -> (Message -> Maybe (Assym (Nonce8,pong))) 200 -> (Message -> Maybe (Asymm (Nonce8,pong)))
201 -> MethodSerializer TransactionId NodeInfo Message PacketKind ping (Maybe pong) 201 -> MethodSerializer TransactionId NodeInfo Message PacketKind ping (Maybe pong)
202serializer pktkind mkping mkpong = MethodSerializer 202serializer pktkind mkping mkpong = MethodSerializer
203 { methodTimeout = \tid addr -> return (addr, 5000000) 203 { methodTimeout = \tid addr -> return (addr, 5000000)
204 , method = pktkind 204 , method = pktkind
205 -- wrapQuery :: tid -> addr -> addr -> qry -> x 205 -- wrapQuery :: tid -> addr -> addr -> qry -> x
206 , wrapQuery = \tid src dst ping -> mkping $ wrapAssym tid src dst (, ping) 206 , wrapQuery = \tid src dst ping -> mkping $ wrapAsymm tid src dst (, ping)
207 -- unwrapResponse :: x -> b 207 -- unwrapResponse :: x -> b
208 , unwrapResponse = fmap (snd . assymData) . mkpong 208 , unwrapResponse = fmap (snd . asymmData) . mkpong
209 } 209 }
210 210
211 211
212unpong :: Message -> Maybe (Assym (Nonce8,Pong)) 212unpong :: Message -> Maybe (Asymm (Nonce8,Pong))
213unpong (DHTPong assym) = Just assym 213unpong (DHTPong asymm) = Just asymm
214unpong _ = Nothing 214unpong _ = Nothing
215 215
216showHex :: BA.ByteArrayAccess ba => ba -> String 216showHex :: BA.ByteArrayAccess ba => ba -> String
@@ -223,8 +223,8 @@ ping client addr = do
223 hPutStrLn stderr $ show addr ++ " -pong-> " ++ show reply 223 hPutStrLn stderr $ show addr ++ " -pong-> " ++ show reply
224 maybe (return False) (\Pong -> return True) $ join reply 224 maybe (return False) (\Pong -> return True) $ join reply
225 225
226unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes)) 226unsendNodes :: Message -> Maybe (Asymm (Nonce8,SendNodes))
227unsendNodes (DHTSendNodes assym) = Just assym 227unsendNodes (DHTSendNodes asymm) = Just asymm
228unsendNodes _ = Nothing 228unsendNodes _ = Nothing
229 229
230unwrapNodes :: SendNodes -> ( [NodeInfo], [NodeInfo], () ) 230unwrapNodes :: SendNodes -> ( [NodeInfo], [NodeInfo], () )
@@ -285,18 +285,18 @@ transitionCommittee committee _ = return $ return ()
285type Handler = MethodHandler String TransactionId NodeInfo Message 285type Handler = MethodHandler String TransactionId NodeInfo Message
286 286
287isPing :: (f Ping -> Ping) -> DHTMessage f -> Either String Ping 287isPing :: (f Ping -> Ping) -> DHTMessage f -> Either String Ping
288isPing unpack (DHTPing a) = Right $ unpack $ assymData a 288isPing unpack (DHTPing a) = Right $ unpack $ asymmData a
289isPing _ _ = Left "Bad ping" 289isPing _ _ = Left "Bad ping"
290 290
291mkPong :: TransactionId -> NodeInfo -> NodeInfo -> Pong -> DHTMessage ((,) Nonce8) 291mkPong :: TransactionId -> NodeInfo -> NodeInfo -> Pong -> DHTMessage ((,) Nonce8)
292mkPong tid src dst pong = DHTPong $ wrapAssym tid src dst (, pong) 292mkPong tid src dst pong = DHTPong $ wrapAsymm tid src dst (, pong)
293 293
294isGetNodes :: (f GetNodes -> GetNodes) -> DHTMessage f -> Either String GetNodes 294isGetNodes :: (f GetNodes -> GetNodes) -> DHTMessage f -> Either String GetNodes
295isGetNodes unpack (DHTGetNodes a) = Right $ unpack $ assymData a 295isGetNodes unpack (DHTGetNodes a) = Right $ unpack $ asymmData a
296isGetNodes _ _ = Left "Bad GetNodes" 296isGetNodes _ _ = Left "Bad GetNodes"
297 297
298mkSendNodes :: TransactionId -> NodeInfo -> NodeInfo -> SendNodes -> DHTMessage ((,) Nonce8) 298mkSendNodes :: TransactionId -> NodeInfo -> NodeInfo -> SendNodes -> DHTMessage ((,) Nonce8)
299mkSendNodes tid src dst sendnodes = DHTSendNodes $ wrapAssym tid src dst (, sendnodes) 299mkSendNodes tid src dst sendnodes = DHTSendNodes $ wrapAsymm tid src dst (, sendnodes)
300 300
301handlers :: Routing -> PacketKind -> Maybe Handler 301handlers :: Routing -> PacketKind -> Maybe Handler
302handlers routing PingType = Just $ MethodHandler (isPing snd) mkPong pingH 302handlers routing PingType = Just $ MethodHandler (isPing snd) mkPong pingH