diff options
Diffstat (limited to 'src/Network/Tox/DHT/Handlers.hs')
-rw-r--r-- | src/Network/Tox/DHT/Handlers.hs | 32 |
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) | |||
188 | type Client = QR.Client String PacketKind TransactionId NodeInfo Message | 188 | type Client = QR.Client String PacketKind TransactionId NodeInfo Message |
189 | 189 | ||
190 | 190 | ||
191 | wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta | 191 | wrapAsymm :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Asymm dta |
192 | wrapAssym (TransactionId n8 n24) src dst dta = Assym | 192 | wrapAsymm (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 | ||
198 | serializer :: PacketKind | 198 | serializer :: 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) |
202 | serializer pktkind mkping mkpong = MethodSerializer | 202 | serializer 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 | ||
212 | unpong :: Message -> Maybe (Assym (Nonce8,Pong)) | 212 | unpong :: Message -> Maybe (Asymm (Nonce8,Pong)) |
213 | unpong (DHTPong assym) = Just assym | 213 | unpong (DHTPong asymm) = Just asymm |
214 | unpong _ = Nothing | 214 | unpong _ = Nothing |
215 | 215 | ||
216 | showHex :: BA.ByteArrayAccess ba => ba -> String | 216 | showHex :: 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 | ||
226 | unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes)) | 226 | unsendNodes :: Message -> Maybe (Asymm (Nonce8,SendNodes)) |
227 | unsendNodes (DHTSendNodes assym) = Just assym | 227 | unsendNodes (DHTSendNodes asymm) = Just asymm |
228 | unsendNodes _ = Nothing | 228 | unsendNodes _ = Nothing |
229 | 229 | ||
230 | unwrapNodes :: SendNodes -> ( [NodeInfo], [NodeInfo], () ) | 230 | unwrapNodes :: SendNodes -> ( [NodeInfo], [NodeInfo], () ) |
@@ -285,18 +285,18 @@ transitionCommittee committee _ = return $ return () | |||
285 | type Handler = MethodHandler String TransactionId NodeInfo Message | 285 | type Handler = MethodHandler String TransactionId NodeInfo Message |
286 | 286 | ||
287 | isPing :: (f Ping -> Ping) -> DHTMessage f -> Either String Ping | 287 | isPing :: (f Ping -> Ping) -> DHTMessage f -> Either String Ping |
288 | isPing unpack (DHTPing a) = Right $ unpack $ assymData a | 288 | isPing unpack (DHTPing a) = Right $ unpack $ asymmData a |
289 | isPing _ _ = Left "Bad ping" | 289 | isPing _ _ = Left "Bad ping" |
290 | 290 | ||
291 | mkPong :: TransactionId -> NodeInfo -> NodeInfo -> Pong -> DHTMessage ((,) Nonce8) | 291 | mkPong :: TransactionId -> NodeInfo -> NodeInfo -> Pong -> DHTMessage ((,) Nonce8) |
292 | mkPong tid src dst pong = DHTPong $ wrapAssym tid src dst (, pong) | 292 | mkPong tid src dst pong = DHTPong $ wrapAsymm tid src dst (, pong) |
293 | 293 | ||
294 | isGetNodes :: (f GetNodes -> GetNodes) -> DHTMessage f -> Either String GetNodes | 294 | isGetNodes :: (f GetNodes -> GetNodes) -> DHTMessage f -> Either String GetNodes |
295 | isGetNodes unpack (DHTGetNodes a) = Right $ unpack $ assymData a | 295 | isGetNodes unpack (DHTGetNodes a) = Right $ unpack $ asymmData a |
296 | isGetNodes _ _ = Left "Bad GetNodes" | 296 | isGetNodes _ _ = Left "Bad GetNodes" |
297 | 297 | ||
298 | mkSendNodes :: TransactionId -> NodeInfo -> NodeInfo -> SendNodes -> DHTMessage ((,) Nonce8) | 298 | mkSendNodes :: TransactionId -> NodeInfo -> NodeInfo -> SendNodes -> DHTMessage ((,) Nonce8) |
299 | mkSendNodes tid src dst sendnodes = DHTSendNodes $ wrapAssym tid src dst (, sendnodes) | 299 | mkSendNodes tid src dst sendnodes = DHTSendNodes $ wrapAsymm tid src dst (, sendnodes) |
300 | 300 | ||
301 | handlers :: Routing -> PacketKind -> Maybe Handler | 301 | handlers :: Routing -> PacketKind -> Maybe Handler |
302 | handlers routing PingType = Just $ MethodHandler (isPing snd) mkPong pingH | 302 | handlers routing PingType = Just $ MethodHandler (isPing snd) mkPong pingH |