summaryrefslogtreecommitdiff
path: root/src/Network/DHT
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-02 16:41:11 -0400
committerjoe <joe@jerkface.net>2017-07-02 16:41:11 -0400
commitbe15a1ceba3b87f845d3b56915207457a94394ee (patch)
treee0d0bc153dab2ebbcb23a8a4a16b03efe2e43de5 /src/Network/DHT
parentde4a5fd744b4744a80e3403f914886ff7df10526 (diff)
Abstract facility to represent Tox encrypted nonces.
Diffstat (limited to 'src/Network/DHT')
-rw-r--r--src/Network/DHT/Mainline.hs8
-rw-r--r--src/Network/DHT/Types.hs11
2 files changed, 10 insertions, 9 deletions
diff --git a/src/Network/DHT/Mainline.hs b/src/Network/DHT/Mainline.hs
index 6ef6d450..e5517a3a 100644
--- a/src/Network/DHT/Mainline.hs
+++ b/src/Network/DHT/Mainline.hs
@@ -155,7 +155,7 @@ read_only_key = "ro"
155instance BEncode a => BEncode (Query KMessageOf a) where 155instance BEncode a => BEncode (Query KMessageOf a) where
156 toBEncode Query {..} = toDict $ 156 toBEncode Query {..} = toDict $
157 BDict.union ( node_id_key .=! queringNodeId 157 BDict.union ( node_id_key .=! queringNodeId
158 .: read_only_key .=? bool Nothing (Just (1 :: Integer)) queryIsReadOnly 158 .: read_only_key .=? bool Nothing (Just (1 :: Integer)) (queryIsReadOnly queryExtra)
159 .: endDict) 159 .: endDict)
160 (dict (toBEncode queryParams)) 160 (dict (toBEncode queryParams))
161 where 161 where
@@ -164,7 +164,7 @@ instance BEncode a => BEncode (Query KMessageOf a) where
164 164
165 fromBEncode v = do 165 fromBEncode v = do
166 Query <$> fromDict (field (req node_id_key)) v 166 Query <$> fromDict (field (req node_id_key)) v
167 <*> fromDict (fromMaybe False <$>? read_only_key) v 167 <*> fromDict (IsReadOnlyQuery . fromMaybe False <$>? read_only_key) v
168 <*> fromBEncode v 168 <*> fromBEncode v
169#else 169#else
170data Query a = Query a 170data Query a = Query a
@@ -174,11 +174,11 @@ data Query a = Query a
174instance BEncode a => BEncode (Response KMessageOf a) where 174instance BEncode a => BEncode (Response KMessageOf a) where
175 toBEncode = toBEncode . toQuery 175 toBEncode = toBEncode . toQuery
176 where 176 where
177 toQuery (Response nid a) = Query nid False a 177 toQuery (Response nid MainlineResponseData a) = Query nid (IsReadOnlyQuery False) a
178 178
179 fromBEncode b = fromQuery <$> fromBEncode b 179 fromBEncode b = fromQuery <$> fromBEncode b
180 where 180 where
181 fromQuery (Query nid _ a) = Response nid a 181 fromQuery (Query nid _ a) = Response nid MainlineResponseData a
182#else 182#else
183data Response KMessageOf a = Response KMessageOf a 183data Response KMessageOf a = Response KMessageOf a
184#endif 184#endif
diff --git a/src/Network/DHT/Types.hs b/src/Network/DHT/Types.hs
index 73a7be65..bd2825fb 100644
--- a/src/Network/DHT/Types.hs
+++ b/src/Network/DHT/Types.hs
@@ -27,22 +27,23 @@ data TableParameters msg ip u = TableParameters
27-- of the querying node. 27-- of the querying node.
28data Query dht a = Query 28data Query dht a = Query
29 { queringNodeId :: NodeId dht -- ^ node id of /quering/ node; 29 { queringNodeId :: NodeId dht -- ^ node id of /quering/ node;
30 , queryIsReadOnly :: Bool -- ^ node is read-only as per BEP 43 30 , queryExtra :: QueryExtra dht -- , queryIsReadOnly :: Bool -- node is read-only as per BEP 43
31 , queryParams :: a -- ^ query parameters. 31 , queryParams :: a -- ^ query parameters.
32 } deriving (Typeable,Generic) 32 } deriving (Typeable,Generic)
33 33
34deriving instance (Eq (NodeId dht), Eq a ) => Eq (Query dht a) 34deriving instance (Eq (NodeId dht), Eq (QueryExtra dht), Eq a ) => Eq (Query dht a)
35deriving instance (Show (NodeId dht), Show a ) => Show (Query dht a) 35deriving instance (Show (NodeId dht), Show (QueryExtra dht), Show a ) => Show (Query dht a)
36 36
37-- | All responses have an \"id\" key and value containing the node ID 37-- | All responses have an \"id\" key and value containing the node ID
38-- of the responding node. 38-- of the responding node.
39data Response dht a = Response 39data Response dht a = Response
40 { queredNodeId :: NodeId dht -- ^ node id of /quered/ node; 40 { queredNodeId :: NodeId dht -- ^ node id of /quered/ node;
41 , responseExtra :: ResponseExtra dht
41 , responseVals :: a -- ^ query result. 42 , responseVals :: a -- ^ query result.
42 } deriving (Typeable,Generic) 43 } deriving (Typeable,Generic)
43 44
44deriving instance (Eq (NodeId dht), Eq a ) => Eq (Response dht a) 45deriving instance (Eq (NodeId dht), Eq (ResponseExtra dht), Eq a ) => Eq (Response dht a)
45deriving instance (Show (NodeId dht), Show a ) => Show (Response dht a) 46deriving instance (Show (NodeId dht), Show (ResponseExtra dht), Show a ) => Show (Response dht a)
46 47
47-- | The most basic query is a ping. Ping query is used to check if a 48-- | The most basic query is a ping. Ping query is used to check if a
48-- quered node is still alive. 49-- quered node is still alive.