diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-03 17:12:14 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-03 17:26:06 -0500 |
commit | 5181c77ce7dd73d622ff3921b90bf2741bedb646 (patch) | |
tree | 16ba93b83ad0c137a013e47f593d7d40ace68ce6 /dht/src/Network/BitTorrent/MainlineDHT.hs | |
parent | 31b799222cb76cd0002d9a3cc5b340a7b6fed139 (diff) |
QueryResponse: Use three-way sum to distinguish Canceled and Timedout.
Diffstat (limited to 'dht/src/Network/BitTorrent/MainlineDHT.hs')
-rw-r--r-- | dht/src/Network/BitTorrent/MainlineDHT.hs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/dht/src/Network/BitTorrent/MainlineDHT.hs b/dht/src/Network/BitTorrent/MainlineDHT.hs index bb556bc6..e604f5e5 100644 --- a/dht/src/Network/BitTorrent/MainlineDHT.hs +++ b/dht/src/Network/BitTorrent/MainlineDHT.hs | |||
@@ -1033,21 +1033,22 @@ announceH (SwarmsDatabase peers toks _) naddr announcement = do | |||
1033 | isReadonlyClient :: MainlineClient -> Bool | 1033 | isReadonlyClient :: MainlineClient -> Bool |
1034 | isReadonlyClient client = False -- TODO | 1034 | isReadonlyClient client = False -- TODO |
1035 | 1035 | ||
1036 | mainlineSend :: ( BEncode a | 1036 | mainlineSend :: ( BEncode xqry |
1037 | , BEncode a2 | 1037 | , BEncode xrsp |
1038 | ) => Method | 1038 | ) => Method |
1039 | -> (a2 -> b) | 1039 | -> (xrsp -> rsp) |
1040 | -> (t -> a) | 1040 | -> (qry -> xqry) |
1041 | -> MainlineClient | 1041 | -> MainlineClient |
1042 | -> t | 1042 | -> qry |
1043 | -> NodeInfo | 1043 | -> NodeInfo |
1044 | -> IO (Maybe b) | 1044 | -> IO (Maybe rsp) |
1045 | mainlineSend meth unwrap msg client nid addr = do | 1045 | mainlineSend meth unwrap msg client nid addr = do |
1046 | reply <- sendQuery client serializer (msg nid) addr | 1046 | reply <- sendQuery client serializer (msg nid) addr |
1047 | -- sendQuery will return (Just (Left _)) on a parse error. We're going to | 1047 | return $ case reply of |
1048 | -- blow it away with the join-either sequence. | 1048 | Success (Right x) -> Just x |
1049 | -- TODO: Do something with parse errors. | 1049 | Success (Left e) -> Nothing -- TODO: Do something with parse errors. |
1050 | return $ join $ either (const Nothing) Just <$> reply | 1050 | Canceled -> Nothing |
1051 | TimedOut -> Nothing | ||
1051 | where | 1052 | where |
1052 | serializer = MethodSerializer | 1053 | serializer = MethodSerializer |
1053 | { methodTimeout = \ni -> return (ni, 5000000) | 1054 | { methodTimeout = \ni -> return (ni, 5000000) |