summaryrefslogtreecommitdiff
path: root/src/Network/DatagramServer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/DatagramServer.hs')
-rw-r--r--src/Network/DatagramServer.hs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/Network/DatagramServer.hs b/src/Network/DatagramServer.hs
index 91efa443..d478d667 100644
--- a/src/Network/DatagramServer.hs
+++ b/src/Network/DatagramServer.hs
@@ -324,16 +324,36 @@ query :: forall h a b raw msg. (SerializableTo raw b, Show (QueryMethod msg), Or
324query mgr meth addr params = queryK mgr meth addr params (\_ x _ -> x) 324query mgr meth addr params = queryK mgr meth addr params (\_ x _ -> x)
325 325
326-- | Like 'query' but possibly returns your externally routable IP address. 326-- | Like 'query' but possibly returns your externally routable IP address.
327query' :: forall h a b raw msg. (SerializableTo raw b, Show (QueryMethod msg), Ord (TransactionID msg), Serialize (TransactionID msg), SerializableTo raw a, WireFormat raw msg) => Manager raw msg -> QueryMethod msg -> SockAddr -> a -> IO (b, Maybe ReflectedIP) 327query' :: forall h a b raw msg.
328 ( SerializableTo raw b
329 , Show (QueryMethod msg)
330 , Ord (TransactionID msg)
331 , Serialize (TransactionID msg)
332 , SerializableTo raw a , WireFormat raw msg
333 ) => Manager raw msg -> QueryMethod msg -> SockAddr -> a -> IO (b , Maybe ReflectedIP)
328query' mgr meth addr params = queryK mgr meth addr params (const (,)) 334query' mgr meth addr params = queryK mgr meth addr params (const (,))
329 335
330-- | Enqueue a query, but give us the complete BEncoded content sent by the 336-- | Enqueue a query, but give us the complete BEncoded content sent by the
331-- remote Node. This is useful for handling extensions that this library does 337-- remote Node. This is useful for handling extensions that this library does
332-- not otherwise support. 338-- not otherwise support.
333queryRaw :: forall h a b raw msg. (SerializableTo raw b, Show (QueryMethod msg), Ord (TransactionID msg), Serialize (TransactionID msg), SerializableTo raw a, WireFormat raw msg) => Manager raw msg -> QueryMethod msg -> SockAddr -> a -> IO (b, raw) 339queryRaw :: forall h a b raw msg.
340 ( SerializableTo raw b
341 , Show (QueryMethod msg)
342 , Ord (TransactionID msg)
343 , Serialize (TransactionID msg)
344 , SerializableTo raw a
345 , WireFormat raw msg
346 ) => Manager raw msg -> QueryMethod msg -> SockAddr -> a -> IO (b , raw)
334queryRaw mgr meth addr params = queryK mgr meth addr params (\raw x _ -> (x,raw)) 347queryRaw mgr meth addr params = queryK mgr meth addr params (\raw x _ -> (x,raw))
335 348
336queryK :: forall h a b x raw msg. (SerializableTo raw b, Show (QueryMethod msg), Ord (TransactionID msg), Serialize (TransactionID msg), SerializableTo raw a, WireFormat raw msg) => 349queryK :: forall h a b x raw msg.
350 ( SerializableTo raw b
351 , SerializableTo raw a
352 , WireFormat raw msg
353 , Show (QueryMethod msg)
354 , Ord (TransactionID msg)
355 , Serialize (TransactionID msg)
356 ) =>
337 Manager raw msg -> QueryMethod msg -> SockAddr -> a -> (raw -> b -> Maybe ReflectedIP -> x) -> IO x 357 Manager raw msg -> QueryMethod msg -> SockAddr -> a -> (raw -> b -> Maybe ReflectedIP -> x) -> IO x
338queryK mgr@Manager{..} meth addr params kont = do 358queryK mgr@Manager{..} meth addr params kont = do
339 tid <- liftIO $ genTransactionId transactionCounter 359 tid <- liftIO $ genTransactionId transactionCounter
@@ -353,6 +373,7 @@ queryK mgr@Manager{..} meth addr params kont = do
353 `onException` unregisterQuery (tid, addr) pendingCalls 373 `onException` unregisterQuery (tid, addr) pendingCalls
354 374
355 timeout (optQueryTimeout options * 10 ^ (6 :: Int)) $ do 375 timeout (optQueryTimeout options * 10 ^ (6 :: Int)) $ do
376 -- TODO: Loop with polymorphic sanity-check (to handle Tox's nonces).
356 (raw,res) <- readMVar ares -- MVar (KQueryArgs, KResult) 377 (raw,res) <- readMVar ares -- MVar (KQueryArgs, KResult)
357 case res of 378 case res of
358 Left (KError c m _) -> throwIO $ QueryFailed c (T.decodeUtf8 m) 379 Left (KError c m _) -> throwIO $ QueryFailed c (T.decodeUtf8 m)