summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Onion/Transport.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox/Onion/Transport.hs')
-rw-r--r--dht/src/Network/Tox/Onion/Transport.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/dht/src/Network/Tox/Onion/Transport.hs b/dht/src/Network/Tox/Onion/Transport.hs
index e746c414..407cd387 100644
--- a/dht/src/Network/Tox/Onion/Transport.hs
+++ b/dht/src/Network/Tox/Onion/Transport.hs
@@ -38,15 +38,19 @@ module Network.Tox.Onion.Transport
38 , wrapSymmetric 38 , wrapSymmetric
39 , wrapOnion 39 , wrapOnion
40 , wrapOnionPure 40 , wrapOnionPure
41 , unwrapAnnounceResponse
41 ) where 42 ) where
42 43
43import Data.ByteString (ByteString) 44import Data.ByteString (ByteString)
45import Data.Maybe
44import Data.Serialize 46import Data.Serialize
45import Network.Socket 47import Network.Socket
46 48
47import Crypto.Tox hiding (encrypt,decrypt) 49import Crypto.Tox hiding (encrypt,decrypt)
50import Network.Tox.TCP.NodeId (udpNodeInfo)
48import qualified Data.Tox.Relay as TCP 51import qualified Data.Tox.Relay as TCP
49import Data.Tox.Onion 52import Data.Tox.Onion
53import Network.Tox.DHT.Transport (SendNodes(..))
50import Network.Tox.NodeId 54import Network.Tox.NodeId
51 55
52{- 56{-
@@ -117,3 +121,10 @@ wrapForRoute crypto msg ni r@OnionRoute{routeRelayPort = Just tcpport} = do
117 (nodeAddr ni) 121 (nodeAddr ni)
118 (NotForwarded msg) 122 (NotForwarded msg)
119 return $ Left $ TCP.OnionPacket nonce $ Addressed (nodeAddr $ routeNodeB r) fwd 123 return $ Left $ TCP.OnionPacket nonce $ Addressed (nodeAddr $ routeNodeB r) fwd
124
125unwrapAnnounceResponse :: Maybe NodeId -> NodeInfo -> AnnounceResponse -> ([NodeInfo], [Rendezvous], Maybe Nonce32)
126unwrapAnnounceResponse alias ni (AnnounceResponse is_stored (SendNodes ns0)) | let ns = map udpNodeInfo ns0
127 = case is_stored of
128 NotStored n32 -> ( ns , [] , Just n32)
129 SendBackKey k -> ( ns , [Rendezvous k ni] , Nothing )
130 Acknowledged n32 -> ( ns , maybeToList $ fmap (\k -> Rendezvous (id2key k) ni) alias , Just n32)