diff options
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 35eaebb5..15b00780 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -167,11 +167,15 @@ w64Key (DHT.TransactionId (Nonce8 w) _) = w | |||
167 | nonceKey :: DHT.TransactionId -> Nonce8 | 167 | nonceKey :: DHT.TransactionId -> Nonce8 |
168 | nonceKey (DHT.TransactionId n _) = n | 168 | nonceKey (DHT.TransactionId n _) = n |
169 | 169 | ||
170 | myAddr :: DHT.Routing -> Maybe NodeInfo -> IO NodeInfo | 170 | -- | Return my own address. |
171 | myAddr routing maddr = atomically $ do | 171 | myAddr :: TVar (R.BucketList NodeInfo) -- ^ IPv4 buckets |
172 | -> TVar (R.BucketList NodeInfo) -- ^ IPv6 buckets | ||
173 | -> Maybe NodeInfo -- ^ Interested remote address | ||
174 | -> IO NodeInfo | ||
175 | myAddr routing4 routing6 maddr = atomically $ do | ||
172 | let var = case flip DHT.prefer4or6 Nothing <$> maddr of | 176 | let var = case flip DHT.prefer4or6 Nothing <$> maddr of |
173 | Just Want_IP6 -> DHT.routing6 routing | 177 | Just Want_IP6 -> routing4 |
174 | _ -> DHT.routing4 routing | 178 | _ -> routing6 |
175 | a <- readTVar var | 179 | a <- readTVar var |
176 | return $ R.thisNode a | 180 | return $ R.thisNode a |
177 | 181 | ||
@@ -179,7 +183,7 @@ newClient :: (DRG g, Show addr, Show meth) => | |||
179 | g -> Transport String addr x | 183 | g -> Transport String addr x |
180 | -> (Client String meth DHT.TransactionId addr x -> x -> MessageClass String meth DHT.TransactionId addr x) | 184 | -> (Client String meth DHT.TransactionId addr x -> x -> MessageClass String meth DHT.TransactionId addr x) |
181 | -> (Maybe addr -> IO addr) | 185 | -> (Maybe addr -> IO addr) |
182 | -> (meth -> Maybe (MethodHandler String DHT.TransactionId addr x)) | 186 | -> (Client String meth DHT.TransactionId addr x -> meth -> Maybe (MethodHandler String DHT.TransactionId addr x)) |
183 | -> (forall d. TransactionMethods d DHT.TransactionId addr x -> TransactionMethods d DHT.TransactionId addr x) | 187 | -> (forall d. TransactionMethods d DHT.TransactionId addr x -> TransactionMethods d DHT.TransactionId addr x) |
184 | -> (Client String meth DHT.TransactionId addr x -> Transport String addr x -> Transport String addr x) | 188 | -> (Client String meth DHT.TransactionId addr x -> Transport String addr x -> Transport String addr x) |
185 | -> IO (Client String meth DHT.TransactionId addr x) | 189 | -> IO (Client String meth DHT.TransactionId addr x) |
@@ -207,7 +211,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do | |||
207 | mkclient (tbl,var) handlers = | 211 | mkclient (tbl,var) handlers = |
208 | let client = Client | 212 | let client = Client |
209 | { clientNet = addHandler (reportParseError eprinter) (handleMessage client) $ modifynet client net | 213 | { clientNet = addHandler (reportParseError eprinter) (handleMessage client) $ modifynet client net |
210 | , clientDispatcher = dispatch tbl var handlers client | 214 | , clientDispatcher = dispatch tbl var (handlers client) client |
211 | , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } | 215 | , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } |
212 | , clientPending = var | 216 | , clientPending = var |
213 | , clientAddress = selfAddr | 217 | , clientAddress = selfAddr |
@@ -308,13 +312,15 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
308 | drg <- drgNew | 312 | drg <- drgNew |
309 | let lookupClose _ = return Nothing | 313 | let lookupClose _ = return Nothing |
310 | 314 | ||
311 | routing <- DHT.newRouting addr crypto updateIP updateIP | 315 | mkrouting <- DHT.newRouting addr crypto updateIP updateIP |
312 | let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. | 316 | let ignoreErrors _ = return () -- Set this to (hPutStrLn stderr) to debug onion route building. |
313 | orouter <- newOnionRouter ignoreErrors | 317 | orouter <- newOnionRouter ignoreErrors |
314 | (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp | 318 | (dhtcrypt,onioncrypt,dtacrypt,cryptonet) <- toxTransport crypto orouter lookupClose udp |
315 | let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt | 319 | let dhtnet0 = layerTransportM (DHT.decrypt crypto) (DHT.encrypt crypto) dhtcrypt |
316 | dhtclient <- newClient drg dhtnet0 DHT.classify (myAddr routing) (DHT.handlers crypto routing) id | 320 | tbl4 = DHT.routing4 $ mkrouting (error "missing client") |
317 | $ \client net -> onInbound (DHT.updateRouting client routing orouter) net | 321 | tbl6 = DHT.routing6 $ mkrouting (error "missing client") |
322 | dhtclient <- newClient drg dhtnet0 DHT.classify (myAddr tbl4 tbl6) (DHT.handlers crypto . mkrouting) id | ||
323 | $ \client net -> onInbound (DHT.updateRouting client (mkrouting client) orouter) net | ||
318 | 324 | ||
319 | orouter <- forkRouteBuilder orouter $ \nid ni -> fmap (\(_,ns,_)->ns) <$> DHT.getNodes dhtclient nid ni | 325 | orouter <- forkRouteBuilder orouter $ \nid ni -> fmap (\(_,ns,_)->ns) <$> DHT.getNodes dhtclient nid ni |
320 | 326 | ||
@@ -324,8 +330,8 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
324 | oniondrg <- drgNew | 330 | oniondrg <- drgNew |
325 | let onionnet = layerTransportM (Onion.decrypt crypto) (Onion.encrypt crypto) onioncrypt | 331 | let onionnet = layerTransportM (Onion.decrypt crypto) (Onion.encrypt crypto) onioncrypt |
326 | onionclient <- newClient oniondrg onionnet (const Onion.classify) | 332 | onionclient <- newClient oniondrg onionnet (const Onion.classify) |
327 | (getOnionAlias crypto $ R.thisNode <$> readTVar (DHT.routing4 routing)) | 333 | (getOnionAlias crypto $ R.thisNode <$> readTVar (DHT.routing4 $ mkrouting dhtclient)) |
328 | (Onion.handlers onionnet routing toks keydb) | 334 | (const $ Onion.handlers onionnet (mkrouting dhtclient) toks keydb) |
329 | (hookQueries orouter DHT.transactionKey) | 335 | (hookQueries orouter DHT.transactionKey) |
330 | (const id) | 336 | (const id) |
331 | 337 | ||
@@ -337,7 +343,7 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
337 | , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) cryptonet | 343 | , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) cryptonet |
338 | , toxCryptoSessions = sessionsState | 344 | , toxCryptoSessions = sessionsState |
339 | , toxCryptoKeys = crypto | 345 | , toxCryptoKeys = crypto |
340 | , toxRouting = routing | 346 | , toxRouting = mkrouting dhtclient |
341 | , toxTokens = toks | 347 | , toxTokens = toks |
342 | , toxAnnouncedKeys = keydb | 348 | , toxAnnouncedKeys = keydb |
343 | , toxOnionRoutes = orouter | 349 | , toxOnionRoutes = orouter |