summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Onion/Handlers.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox/Onion/Handlers.hs')
-rw-r--r--src/Network/Tox/Onion/Handlers.hs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/Network/Tox/Onion/Handlers.hs b/src/Network/Tox/Onion/Handlers.hs
index 91dd843e..167df336 100644
--- a/src/Network/Tox/Onion/Handlers.hs
+++ b/src/Network/Tox/Onion/Handlers.hs
@@ -159,9 +159,19 @@ handlers net routing toks keydb AnnounceType
159 $ announceH routing toks keydb 159 $ announceH routing toks keydb
160handlers net _ _ keydb _ = Just $ NoReply Right $ dataToRouteH keydb net 160handlers net _ _ keydb _ = Just $ NoReply Right $ dataToRouteH keydb net
161 161
162
163data Rendezvous = Rendezvous
164 { rendezvousKey :: PublicKey
165 , rendezvousNode :: NodeInfo
166 }
167 deriving Eq
168
169instance Show Rendezvous where
170 show (Rendezvous k ni) = concat [show $ key2id k, ":", show ni]
171
162toxidSearch :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) 172toxidSearch :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int))
163 -> Client r 173 -> Client r
164 -> Search NodeId (IP, PortNumber) (Maybe Nonce32) NodeInfo PublicKey 174 -> Search NodeId (IP, PortNumber) (Maybe Nonce32) NodeInfo Rendezvous
165toxidSearch getTimeout client = Search 175toxidSearch getTimeout client = Search
166 { searchSpace = toxSpace 176 { searchSpace = toxSpace
167 , searchNodeAddress = nodeIP &&& nodePort 177 , searchNodeAddress = nodeIP &&& nodePort
@@ -194,23 +204,23 @@ announceSerializer getTimeout = MethodSerializer
194 _ -> Nothing 204 _ -> Nothing
195 } 205 }
196 206
197unwrapAnnounceResponse :: AnnounceResponse -> ([NodeInfo], [PublicKey], Maybe Nonce32) 207unwrapAnnounceResponse :: NodeInfo -> AnnounceResponse -> ([NodeInfo], [Rendezvous], Maybe Nonce32)
198unwrapAnnounceResponse (AnnounceResponse is_stored (SendNodes ns)) 208unwrapAnnounceResponse ni (AnnounceResponse is_stored (SendNodes ns))
199 = case is_stored of 209 = case is_stored of
200 NotStored n32 -> (ns, [], Just n32) 210 NotStored n32 -> (ns, [], Just n32)
201 SendBackKey k -> (ns, [k], Nothing) 211 SendBackKey k -> (ns, [Rendezvous k ni], Nothing)
202 Acknowledged n32 -> (ns, [], Just n32) 212 Acknowledged n32 -> (ns, [], Just n32)
203 213
204announce :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) 214announce :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int))
205 -> Client r 215 -> Client r
206 -> NodeId 216 -> NodeId
207 -> NodeInfo 217 -> NodeInfo
208 -> IO (Maybe ([NodeInfo],[PublicKey],Maybe Nonce32)) 218 -> IO (Maybe ([NodeInfo],[Rendezvous],Maybe Nonce32))
209announce getTimeout client nid ni = 219announce getTimeout client nid ni =
210 -- Four tries and then we tap out. 220 -- Four tries and then we tap out.
211 flip fix 4 $ \loop n -> do 221 flip fix 4 $ \loop n -> do
212 let oaddr = OnionDestination ni Nothing 222 let oaddr = OnionDestination ni Nothing
213 mb <- QR.sendQuery client (announceSerializer getTimeout) (AnnounceRequest zeros32 nid zeroID) oaddr 223 mb <- QR.sendQuery client (announceSerializer getTimeout) (AnnounceRequest zeros32 nid zeroID) oaddr
214 maybe (if n>0 then loop $! n - 1 else return Nothing) 224 maybe (if n>0 then loop $! n - 1 else return Nothing)
215 (return . Just . unwrapAnnounceResponse) 225 (return . Just . unwrapAnnounceResponse ni)
216 $ join mb 226 $ join mb