summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Onion/Routes.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-11 03:23:55 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:25:07 -0500
commit44290a1b44f4b206a1eda866766d4aa11e1ae7b2 (patch)
treeb56cc635c7334d7e6055059a73caa13d1db4c7d5 /dht/src/Network/Tox/Onion/Routes.hs
parent6326b4f674b4093c28a8760e53f5a81ad5747a50 (diff)
Maintain special relay links for connectivity purposes.
Diffstat (limited to 'dht/src/Network/Tox/Onion/Routes.hs')
-rw-r--r--dht/src/Network/Tox/Onion/Routes.hs28
1 files changed, 19 insertions, 9 deletions
diff --git a/dht/src/Network/Tox/Onion/Routes.hs b/dht/src/Network/Tox/Onion/Routes.hs
index c054b99e..d61c721e 100644
--- a/dht/src/Network/Tox/Onion/Routes.hs
+++ b/dht/src/Network/Tox/Onion/Routes.hs
@@ -14,6 +14,7 @@ import Network.QueryResponse
14import Network.QueryResponse.TCP 14import Network.QueryResponse.TCP
15import Network.Tox.NodeId 15import Network.Tox.NodeId
16import Network.Tox.Onion.Transport as Onion 16import Network.Tox.Onion.Transport as Onion
17import Network.Tox.RelayPinger
17import qualified Data.Tox.Relay as TCP 18import qualified Data.Tox.Relay as TCP
18import qualified Network.Tox.TCP as TCP 19import qualified Network.Tox.TCP as TCP
19import qualified TCPProber as TCP 20import qualified TCPProber as TCP
@@ -88,6 +89,7 @@ data OnionRouter = OnionRouter
88 , tcpProberThread :: ThreadId 89 , tcpProberThread :: ThreadId
89 -- | Kademlia table of TCP relays. 90 -- | Kademlia table of TCP relays.
90 , tcpBucketRefresher :: BucketRefresher NodeId TCP.NodeInfo 91 , tcpBucketRefresher :: BucketRefresher NodeId TCP.NodeInfo
92 , tcpRelayPinger :: RelayPinger
91 -- | Debug prints are written to this channel which is then flushed to 93 -- | Debug prints are written to this channel which is then flushed to
92 -- 'routeLogger'. 94 -- 'routeLogger'.
93 , routeLog :: TChan String 95 , routeLog :: TChan String
@@ -207,7 +209,8 @@ newOnionRouter crypto perror tcp_enabled = do
207 writeTChan rlog $ unwords ["Selected TCP Gateway:",show ni,"via",show gw] 209 writeTChan rlog $ unwords ["Selected TCP Gateway:",show ni,"via",show gw]
208 return gw 210 return gw
209 } 211 }
210 or <- atomically $ do 212
213 or0 <- atomically $ do
211 -- chan <- newTChan 214 -- chan <- newTChan
212 drg <- newTVar drg0 215 drg <- newTVar drg0
213 -- forM_ [0..11] $ \n -> writeTChan chan $ BuildRoute (RouteId n) 216 -- forM_ [0..11] $ \n -> writeTChan chan $ BuildRoute (RouteId n)
@@ -243,12 +246,7 @@ newOnionRouter crypto perror tcp_enabled = do
243 } 246 }
244 , tcpMode = tcpmode 247 , tcpMode = tcpmode
245 , tcpKademliaClient = tcp 248 , tcpKademliaClient = tcp
246 { TCP.tcpClient = 249 , tcpRelayPinger = error "forkRouteBuilder: no RelayPinger specified"
247 let c = TCP.tcpClient tcp
248 in c { clientNet = addHandler perror (handleMessage c)
249 $ onInbound (updateTCP o)
250 $ clientNet c }
251 }
252 , tcpBucketRefresher = refresher 250 , tcpBucketRefresher = refresher
253 , routeLog = rlog 251 , routeLog = rlog
254 , routeThread = error "forkRouteBuilder not invoked (missing onion route builder thread)." 252 , routeThread = error "forkRouteBuilder not invoked (missing onion route builder thread)."
@@ -259,10 +257,21 @@ newOnionRouter crypto perror tcp_enabled = do
259 , routeLogger = perror 257 , routeLogger = perror
260 } 258 }
261 return o 259 return o
260 pinger <- forkRelayPinger (kademSpace $ refreshKademlia $ tcpBucketRefresher or0)
261 (TCP.tcpClient tcp)
262 let or = or0 { tcpRelayPinger = pinger
263 , tcpKademliaClient = tcp
264 { TCP.tcpClient =
265 let c = TCP.tcpClient tcp
266 in c { clientNet = addHandler perror (handleMessage c)
267 $ onInbound (updateTCP or)
268 $ clientNet c }
269 }
270 }
262 return (or,tcptbl) 271 return (or,tcptbl)
263 272
264updateTCP :: OnionRouter -> TCP.NodeInfo -> p -> IO () 273updateTCP :: OnionRouter -> TCP.NodeInfo -> p -> IO ()
265updateTCP or addr x = 274updateTCP or addr x = do
266 let refresher = tcpBucketRefresher or 275 let refresher = tcpBucketRefresher or
267 kademlia0 = refreshKademlia refresher 276 kademlia0 = refreshKademlia refresher
268 kademlia = kademlia0 { kademIO = (kademIO kademlia0) 277 kademlia = kademlia0 { kademIO = (kademIO kademlia0)
@@ -275,7 +284,8 @@ updateTCP or addr x =
275 tblTransition (kademIO kademlia0) tr 284 tblTransition (kademIO kademlia0) tr
276 } 285 }
277 } 286 }
278 in insertNode kademlia addr 287 atomically $ bumpRelay (tcpRelayPinger or) addr
288 insertNode kademlia addr
279 289
280selectGateway :: TVar (R.BucketList TCP.NodeInfo) -> NodeInfo -> STM (Maybe TCP.NodeInfo) 290selectGateway :: TVar (R.BucketList TCP.NodeInfo) -> NodeInfo -> STM (Maybe TCP.NodeInfo)
281selectGateway tbl ni = do 291selectGateway tbl ni = do