summaryrefslogtreecommitdiff
path: root/DHTHandlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'DHTHandlers.hs')
-rw-r--r--DHTHandlers.hs14
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
26import Data.Ord 26import Data.Ord
27import Data.Maybe 27import Data.Maybe
28import Data.Bits 28import Data.Bits
29import System.IO
29 30
30data TransactionId = TransactionId 31data 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
95toxSpace :: R.KademliaSpace NodeId NodeInfo 96toxSpace :: R.KademliaSpace NodeId NodeInfo
96toxSpace = R.KademliaSpace 97toxSpace = 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
134wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta 136wrapAssym :: TransactionId -> NodeInfo -> NodeInfo -> (Nonce8 -> dta) -> Assym dta
135wrapAssym (TransactionId n8 n24) src dst dta = Assym 137wrapAssym (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
159ping :: Client -> NodeInfo -> IO Bool 161ping :: Client -> NodeInfo -> IO Bool
160ping client addr = do 162ping 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
164unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes)) 168unsendNodes :: Message -> Maybe (Assym (Nonce8,SendNodes))
@@ -170,12 +174,14 @@ unwrapNodes (SendNodes ns) = (ns,ns,())
170 174
171getNodes :: Client -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],())) 175getNodes :: Client -> NodeId -> NodeInfo -> IO (Maybe ([NodeInfo],[NodeInfo],()))
172getNodes client nid addr = do 176getNodes 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
176updateRouting :: Client -> Routing -> NodeInfo -> Message -> IO () 182updateRouting :: Client -> Routing -> NodeInfo -> Message -> IO ()
177updateRouting client routing naddr msg = do 183updateRouting 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)