From 3b8c8d74db95fa8dc345a73101d2c1921655c70d Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 18 Oct 2017 20:55:56 -0400 Subject: WIP: Command to publish a toxid on a given node. --- src/Network/Tox/Onion/Handlers.hs | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/Network/Tox/Onion/Handlers.hs') diff --git a/src/Network/Tox/Onion/Handlers.hs b/src/Network/Tox/Onion/Handlers.hs index 439de709..9702cbb8 100644 --- a/src/Network/Tox/Onion/Handlers.hs +++ b/src/Network/Tox/Onion/Handlers.hs @@ -166,7 +166,7 @@ toxidSearch :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, toxidSearch getTimeout client = Search { searchSpace = toxSpace , searchNodeAddress = nodeIP &&& nodePort - , searchQuery = announce getTimeout client + , searchQuery = getRendezvous getTimeout client } announceSerializer :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) @@ -221,16 +221,39 @@ unwrapAnnounceResponse ni (AnnounceResponse is_stored (SendNodes ns)) -- started. -announce :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) +sendOnion :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) -> Client r - -> NodeId + -> AnnounceRequest -> NodeInfo - -> IO (Maybe ([NodeInfo],[Rendezvous],Maybe Nonce32)) -announce getTimeout client nid ni = + -> (NodeInfo -> AnnounceResponse -> t) + -> IO (Maybe t) +sendOnion getTimeout client req ni unwrap = -- Four tries and then we tap out. flip fix 4 $ \loop n -> do let oaddr = OnionDestination ni Nothing - mb <- QR.sendQuery client (announceSerializer getTimeout) (AnnounceRequest zeros32 nid zeroID) oaddr + mb <- QR.sendQuery client (announceSerializer getTimeout) req oaddr maybe (if n>0 then loop $! n - 1 else return Nothing) - (return . Just . unwrapAnnounceResponse ni) + (return . Just . unwrap ni) $ join mb + +getRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) + -> Client r + -> NodeId + -> NodeInfo + -> IO (Maybe ([NodeInfo],[Rendezvous],Maybe Nonce32)) +getRendezvous getTimeout client nid ni = + sendOnion getTimeout client (AnnounceRequest zeros32 nid zeroID) ni unwrapAnnounceResponse + +putRendezvous :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) + -> TransportCrypto + -> Client r + -> PublicKey + -> Nonce32 + -> NodeInfo + -> IO (Maybe (Rendezvous, AnnounceResponse)) +putRendezvous getTimeout crypto client pubkey nonce32 ni = do + let longTermKey = key2id pubkey + rkey = rendezvousPublic crypto + rendezvousKey = key2id rkey + sendOnion getTimeout client (AnnounceRequest nonce32 longTermKey rendezvousKey) ni + $ \ni resp -> (Rendezvous rkey ni, resp) -- cgit v1.2.3