diff options
Diffstat (limited to 'DHTHandlers.hs')
-rw-r--r-- | DHTHandlers.hs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/DHTHandlers.hs b/DHTHandlers.hs index 437b05f3..7ff7a3ce 100644 --- a/DHTHandlers.hs +++ b/DHTHandlers.hs | |||
@@ -26,6 +26,7 @@ import Data.IP | |||
26 | import Data.Ord | 26 | import Data.Ord |
27 | import Data.Maybe | 27 | import Data.Maybe |
28 | import Data.Bits | 28 | import Data.Bits |
29 | import System.IO | ||
29 | 30 | ||
30 | data TransactionId = TransactionId | 31 | data TransactionId = TransactionId |
31 | { transactionKey :: Nonce8 -- ^ Used to lookup pending query. | 32 | { transactionKey :: Nonce8 -- ^ Used to lookup pending query. |
@@ -95,8 +96,9 @@ prefer4or6 addr iptyp = fromMaybe (ipFamily $ nodeIP addr) iptyp | |||
95 | toxSpace :: R.KademliaSpace NodeId NodeInfo | 96 | toxSpace :: R.KademliaSpace NodeId NodeInfo |
96 | toxSpace = R.KademliaSpace | 97 | toxSpace = R.KademliaSpace |
97 | { R.kademliaLocation = nodeId | 98 | { R.kademliaLocation = nodeId |
98 | , R.kademliaTestBit = testIdBit | 99 | , R.kademliaTestBit = testNodeIdBit |
99 | , R.kademliaXor = xor | 100 | , R.kademliaXor = xorNodeId |
101 | , R.kademliaSample = sampleNodeId | ||
100 | } | 102 | } |
101 | 103 | ||
102 | 104 | ||
@@ -133,7 +135,7 @@ type Client = QR.Client String PacketKind TransactionId NodeInfo Message | |||
133 | 135 | ||
134 | wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta | 136 | wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta |
135 | wrapAssym (TransactionId n8 n24) src dst dta = Assym | 137 | wrapAssym (TransactionId n8 n24) src dst dta = Assym |
136 | { senderKey = let NodeId pubkey = nodeId src in pubkey | 138 | { senderKey = id2key $ nodeId src |
137 | , assymNonce = n24 | 139 | , assymNonce = n24 |
138 | , assymData = dta n8 | 140 | , assymData = dta n8 |
139 | } | 141 | } |
@@ -158,7 +160,9 @@ unpong _ = Nothing | |||
158 | 160 | ||
159 | ping :: Client -> NodeInfo -> IO Bool | 161 | ping :: Client -> NodeInfo -> IO Bool |
160 | ping client addr = do | 162 | ping client addr = do |
163 | hPutStrLn stderr $ show addr ++ " <-- ping" | ||
161 | reply <- QR.sendQuery client (serializer PingType DHTPing unpong) Ping addr | 164 | reply <- QR.sendQuery client (serializer PingType DHTPing unpong) Ping addr |
165 | hPutStrLn stderr $ show addr ++ " -pong-> " ++ show reply | ||
162 | maybe (return False) (\Pong -> return True) $ join reply | 166 | maybe (return False) (\Pong -> return True) $ join reply |
163 | 167 | ||
164 | unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes)) | 168 | unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes)) |
@@ -170,12 +174,14 @@ unwrapNodes (SendNodes ns) = (ns,ns,()) | |||
170 | 174 | ||
171 | getNodes :: Client -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],())) | 175 | getNodes :: Client -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],())) |
172 | getNodes client nid addr = do | 176 | getNodes client nid addr = do |
177 | hPutStrLn stderr $ show addr ++ " <-- getnodes " ++ show nid | ||
173 | reply <- QR.sendQuery client (serializer GetNodesType DHTGetNodes unsendNodes) (GetNodes nid) addr | 178 | reply <- QR.sendQuery client (serializer GetNodesType DHTGetNodes unsendNodes) (GetNodes nid) addr |
179 | hPutStrLn stderr $ show addr ++ " -sendnodes-> " ++ show reply | ||
174 | return $ fmap unwrapNodes $ join reply | 180 | return $ fmap unwrapNodes $ join reply |
175 | 181 | ||
176 | updateRouting :: Client -> Routing -> NodeInfo -> Message -> IO () | 182 | updateRouting :: Client -> Routing -> NodeInfo -> Message -> IO () |
177 | updateRouting client routing naddr msg = do | 183 | updateRouting client routing naddr msg = do |
178 | -- hPutStrLn stderr $ "updateRouting "++show typ | 184 | hPutStrLn stderr $ "updateRouting "++show (fst $ dhtMessageType $ fst $ DHTTransport.encrypt (error "updateRouting") msg naddr ) |
179 | -- TODO: check msg type | 185 | -- TODO: check msg type |
180 | case prefer4or6 naddr Nothing of | 186 | case prefer4or6 naddr Nothing of |
181 | Want_IP4 -> updateTable client naddr (routing4 routing) (committee4 routing) (sched4 routing) | 187 | Want_IP4 -> updateTable client naddr (routing4 routing) (committee4 routing) (sched4 routing) |