summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Onion/Routes.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-18 18:06:12 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:27:11 -0500
commitb6676d7c3339e46752cadfc1198886062f5c666d (patch)
tree25d8630d8d2fa6b2f5d3234a07445d61c02194df /dht/src/Network/Tox/Onion/Routes.hs
parent4e8aa82d56129aae9e5ef22e5e0aa9287b993a92 (diff)
Used partitionTransform to simplify the onion client.
Diffstat (limited to 'dht/src/Network/Tox/Onion/Routes.hs')
-rw-r--r--dht/src/Network/Tox/Onion/Routes.hs33
1 files changed, 9 insertions, 24 deletions
diff --git a/dht/src/Network/Tox/Onion/Routes.hs b/dht/src/Network/Tox/Onion/Routes.hs
index baca693b..b20ad7dd 100644
--- a/dht/src/Network/Tox/Onion/Routes.hs
+++ b/dht/src/Network/Tox/Onion/Routes.hs
@@ -159,9 +159,8 @@ newOnionRouter :: TransportCrypto
159 -> Bool -- is tcp enabled? 159 -> Bool -- is tcp enabled?
160 -> IO ( OnionRouter 160 -> IO ( OnionRouter
161 , Transport String TCP.ViaRelay B.ByteString 161 , Transport String TCP.ViaRelay B.ByteString
162 , TVar ( ChaChaDRG 162 , Transport String (OnionDestination RouteId) (OnionMessage Encrypted)
163 , Word64Map (Either (Maybe (Bool,TCP.RelayPacket) -> IO ()) 163 )
164 (Maybe (OnionMessage Identity) -> IO ()))))
165newOnionRouter crypto perror tcp_enabled = do 164newOnionRouter crypto perror tcp_enabled = do
166 drg0 <- drgNew 165 drg0 <- drgNew
167 (rlog,pq,rm) <- atomically $ do 166 (rlog,pq,rm) <- atomically $ do
@@ -169,26 +168,12 @@ newOnionRouter crypto perror tcp_enabled = do
169 pq <- newTVar W64.empty 168 pq <- newTVar W64.empty
170 rm <- newArray (0,11) Nothing 169 rm <- newArray (0,11) Nothing
171 return (rlog,pq,rm) 170 return (rlog,pq,rm)
172 ((tbl,(tcptbl,tcpcons,relaynet)),tcp) <- do 171 ((tbl,(tcptbl,tcpcons,relaynet,onionnet)),tcp) <- do
173 (tcptbl, client) <- TCP.newClient crypto Left $ \case 172 (tcptbl, client) <- TCP.newClient crypto
174 Left v -> void . v . Just . (,) False 173 id
175 Right v -> \case 174 (. (Just . (,) False))
176 TCP.OnionPacketResponse x@(OnionAnnounceResponse n8 n24 _) -> do 175 (lookupSender' pq rlog)
177 mod <- lookupSender' pq rlog localhost4 n8 176 (\_ (RouteId rid) -> atomically $ fmap storedRoute <$> readArray rm rid)
178 perror $ "TCP announce response from " ++ show mod
179 forM_ mod $ \od -> do
180 Onion.decrypt crypto x od >>= \case
181 Right (y,_) -> do perror $ "decrypted announce response, sending " ++ show y
182 let
183 RouteId rid = fromMaybe (routeId (nodeId (onionNodeInfo od)))
184 $ onionRouteSpec od
185 Nonce8 w8 = n8
186 atomically $ do
187 modifyTVar' pq (W64.delete w8)
188 modifyArray rm (fmap gotResponse) rid
189 void $ v $ Just y
190 _ -> return ()
191 x -> perror $ "Unexpected TCP query result: " ++ show x
192 177
193 let addr = SockAddrInet 0 0 178 let addr = SockAddrInet 0 0
194 tentative_udp = NodeInfo 179 tentative_udp = NodeInfo
@@ -269,7 +254,7 @@ newOnionRouter crypto perror tcp_enabled = do
269 $ clientNet c } 254 $ clientNet c }
270 } 255 }
271 } 256 }
272 return (or,relaynet,tcptbl) 257 return (or,relaynet,onionnet)
273 258
274updateTCP :: OnionRouter -> TCP.NodeInfo -> p -> IO () 259updateTCP :: OnionRouter -> TCP.NodeInfo -> p -> IO ()
275updateTCP or addr x = do 260updateTCP or addr x = do