diff options
Diffstat (limited to 'src/Network/Tox/Onion/Handlers.hs')
-rw-r--r-- | src/Network/Tox/Onion/Handlers.hs | 22 |
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 |
160 | handlers net _ _ keydb _ = Just $ NoReply Right $ dataToRouteH keydb net | 160 | handlers net _ _ keydb _ = Just $ NoReply Right $ dataToRouteH keydb net |
161 | 161 | ||
162 | |||
163 | data Rendezvous = Rendezvous | ||
164 | { rendezvousKey :: PublicKey | ||
165 | , rendezvousNode :: NodeInfo | ||
166 | } | ||
167 | deriving Eq | ||
168 | |||
169 | instance Show Rendezvous where | ||
170 | show (Rendezvous k ni) = concat [show $ key2id k, ":", show ni] | ||
171 | |||
162 | toxidSearch :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) | 172 | toxidSearch :: (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 |
165 | toxidSearch getTimeout client = Search | 175 | toxidSearch 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 | ||
197 | unwrapAnnounceResponse :: AnnounceResponse -> ([NodeInfo], [PublicKey], Maybe Nonce32) | 207 | unwrapAnnounceResponse :: NodeInfo -> AnnounceResponse -> ([NodeInfo], [Rendezvous], Maybe Nonce32) |
198 | unwrapAnnounceResponse (AnnounceResponse is_stored (SendNodes ns)) | 208 | unwrapAnnounceResponse 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 | ||
204 | announce :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) | 214 | announce :: (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)) |
209 | announce getTimeout client nid ni = | 219 | announce 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 |