From 6b822e47e4995e4aaf4cb1cc034c34314bd51da2 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 20 Sep 2017 20:47:10 -0400 Subject: Added outbound initiation addresses to the Onion transport. --- src/Network/Tox/Onion/Handlers.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 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 9dc6177c..72398735 100644 --- a/src/Network/Tox/Onion/Handlers.hs +++ b/src/Network/Tox/Onion/Handlers.hs @@ -35,7 +35,7 @@ import Data.Bits import Data.Ord import Data.Functor.Identity -type Client = QR.Client String PacketKind TransactionId OnionToOwner Message +type Client = QR.Client String PacketKind TransactionId OnionDestination Message type Message = OnionMessage Identity classify :: Message -> MessageClass String PacketKind TransactionId @@ -59,7 +59,7 @@ classify msg = go msg -- The reason for this 20 second timeout in toxcore is that it gives a reasonable -- time (20 to 40 seconds) for a peer to announce himself while taking in count -- all the possible delays with some extra seconds. -announceH :: Routing -> TVar SessionTokens -> TVar AnnouncedKeys -> OnionToOwner -> AnnounceRequest -> IO AnnounceResponse +announceH :: Routing -> TVar SessionTokens -> TVar AnnouncedKeys -> OnionDestination -> AnnounceRequest -> IO AnnounceResponse announceH routing toks keydb (OnionToOwner naddr retpath) req = do case () of _ | announcePingId req == zeros32 @@ -89,16 +89,16 @@ announceH routing toks keydb (OnionToOwner naddr retpath) req = do then Nonce32 . toPaddedByteString 32 <$> grantToken toks naddr else return $ zeros32 let k = case record of - Nothing -> NotStored newtok - Just (OnionToOwner {}) | storing -> Acknowledged newtok - Just (OnionToOwner ni _) -> SendBackKey $ id2key (nodeId ni) + Nothing -> NotStored newtok + Just (OnionDestination {}) | storing -> Acknowledged newtok + Just (OnionToOwner ni _) -> SendBackKey $ id2key (nodeId ni) let response = AnnounceResponse k ns hPutStrLn stderr $ unwords ["Announce:", show req, "-reply->", show response] return response dataToRouteH :: TVar AnnouncedKeys - -> Transport err OnionToOwner (OnionMessage f) + -> Transport err OnionDestination (OnionMessage f) -> addr -> OnionMessage f -> IO () @@ -118,11 +118,11 @@ type NodeDistance = NodeId data AnnouncedKeys = AnnouncedKeys { keyByAge :: !(PSQ NodeId (Down POSIXTime)) -- timeout of 300 seconds - , keyAssoc :: !(MinMaxPSQ' NodeId NodeDistance (Int,OnionToOwner)) + , keyAssoc :: !(MinMaxPSQ' NodeId NodeDistance (Int,OnionDestination)) } -insertKey :: POSIXTime -> NodeId -> OnionToOwner -> NodeDistance -> AnnouncedKeys -> AnnouncedKeys +insertKey :: POSIXTime -> NodeId -> OnionDestination -> NodeDistance -> AnnouncedKeys -> AnnouncedKeys insertKey tm pub toxpath d keydb = AnnouncedKeys { keyByAge = PSQ.insert pub (Down tm) (keyByAge keydb) , keyAssoc = case MinMaxPSQ.lookup' pub (keyAssoc keydb) of @@ -134,12 +134,12 @@ areq :: Message -> Either String AnnounceRequest areq (OnionAnnounce assym) = Right $ fst $ runIdentity $ assymData assym areq _ = Left "Unexpected non-announce OnionMessage" -handlers :: Transport err OnionToOwner Message +handlers :: Transport err OnionDestination Message -> Routing -> TVar SessionTokens -> TVar AnnouncedKeys -> PacketKind - -> Maybe (MethodHandler String TransactionId OnionToOwner Message) + -> Maybe (MethodHandler String TransactionId OnionDestination Message) handlers net routing toks keydb AnnounceType = Just $ MethodHandler areq (\(TransactionId n8 n24) src dst -> OnionAnnounceResponse n8 n24 . Identity) -- cgit v1.2.3