diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-08 04:31:51 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-09-08 06:05:10 -0400 |
commit | ad20be57786ad34f80192206c480d575392b4ebb (patch) | |
tree | 722333a152705572f7437586772a9173e84a92e2 /src/Network | |
parent | e5add92a477060d9bba10de7b980c89c24012691 (diff) |
ToxManager rewrite: use aggregated netcrypto sessions.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Tox.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index c1cdb151..3ad2b11e 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -32,6 +32,7 @@ import qualified Data.ByteString as B | |||
32 | import qualified Data.ByteString.Char8 as C8 | 32 | import qualified Data.ByteString.Char8 as C8 |
33 | import Data.Data | 33 | import Data.Data |
34 | import Data.Functor.Contravariant | 34 | import Data.Functor.Contravariant |
35 | import Data.IP | ||
35 | import Data.Maybe | 36 | import Data.Maybe |
36 | import qualified Data.MinMaxPSQ as MinMaxPSQ | 37 | import qualified Data.MinMaxPSQ as MinMaxPSQ |
37 | import qualified Data.Serialize as S | 38 | import qualified Data.Serialize as S |
@@ -50,7 +51,9 @@ import Connection | |||
50 | import Crypto.Tox | 51 | import Crypto.Tox |
51 | import Data.Word64Map (fitsInInt) | 52 | import Data.Word64Map (fitsInInt) |
52 | import qualified Data.Word64Map (empty) | 53 | import qualified Data.Word64Map (empty) |
54 | import HandshakeCache | ||
53 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) | 55 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) |
56 | import Network.Kademlia.Search | ||
54 | import Network.Tox.Crypto.Transport (Handshake(..),CryptoPacket) | 57 | import Network.Tox.Crypto.Transport (Handshake(..),CryptoPacket) |
55 | import Network.Tox.Handshake | 58 | import Network.Tox.Handshake |
56 | import Network.Tox.Crypto.Handlers | 59 | import Network.Tox.Crypto.Handlers |
@@ -203,6 +206,7 @@ data Tox extra = Tox | |||
203 | , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) | 206 | , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) |
204 | , toxCrypto :: Transport String SockAddr (CryptoPacket Encrypted) | 207 | , toxCrypto :: Transport String SockAddr (CryptoPacket Encrypted) |
205 | , toxHandshakes :: Transport String SockAddr (Handshake Encrypted) | 208 | , toxHandshakes :: Transport String SockAddr (Handshake Encrypted) |
209 | , toxHandshakeCache :: HandshakeCache | ||
206 | , toxCryptoSessions :: NetCryptoSessions | 210 | , toxCryptoSessions :: NetCryptoSessions |
207 | , toxCryptoKeys :: TransportCrypto | 211 | , toxCryptoKeys :: TransportCrypto |
208 | , toxRouting :: DHT.Routing | 212 | , toxRouting :: DHT.Routing |
@@ -442,6 +446,8 @@ newToxOverTransport keydb addr mbSessionsState suppliedDHTKey udp = do | |||
442 | dhtclient <- newClient drg dhtnet0 DHT.classify (myAddr tbl4 tbl6) (DHT.handlers crypto . mkrouting) id | 446 | dhtclient <- newClient drg dhtnet0 DHT.classify (myAddr tbl4 tbl6) (DHT.handlers crypto . mkrouting) id |
443 | $ \client net -> onInbound (DHT.updateRouting client (mkrouting client) orouter) net | 447 | $ \client net -> onInbound (DHT.updateRouting client (mkrouting client) orouter) net |
444 | 448 | ||
449 | hscache <- newHandshakeCache crypto (sendMessage handshakes) | ||
450 | |||
445 | let sessionsState = sessionsState0 { sendHandshake = sendMessage handshakes | 451 | let sessionsState = sessionsState0 { sendHandshake = sendMessage handshakes |
446 | , sendSessionPacket = sendMessage cryptonet | 452 | , sendSessionPacket = sendMessage cryptonet |
447 | , transportCrypto = crypto | 453 | , transportCrypto = crypto |
@@ -479,6 +485,7 @@ newToxOverTransport keydb addr mbSessionsState suppliedDHTKey udp = do | |||
479 | , toxToRoute = onInbound (updateContactInfo roster) dtacrypt | 485 | , toxToRoute = onInbound (updateContactInfo roster) dtacrypt |
480 | , toxCrypto = addHandler (dput XMisc) (sessionPacketH sessionsState) cryptonet | 486 | , toxCrypto = addHandler (dput XMisc) (sessionPacketH sessionsState) cryptonet |
481 | , toxHandshakes = addHandler (dput XMisc) (handshakeH sessionsState) handshakes | 487 | , toxHandshakes = addHandler (dput XMisc) (handshakeH sessionsState) handshakes |
488 | , toxHandshakeCache = hscache | ||
482 | , toxCryptoSessions = sessionsState | 489 | , toxCryptoSessions = sessionsState |
483 | , toxCryptoKeys = crypto | 490 | , toxCryptoKeys = crypto |
484 | , toxRouting = mkrouting dhtclient | 491 | , toxRouting = mkrouting dhtclient |
@@ -550,3 +557,7 @@ announceToLan sock nid = do | |||
550 | let broadcast = addrAddress broadcast_info | 557 | let broadcast = addrAddress broadcast_info |
551 | bs = S.runPut $ DHT.putMessage (DHT.DHTLanDiscovery nid) | 558 | bs = S.runPut $ DHT.putMessage (DHT.DHTLanDiscovery nid) |
552 | saferSendTo sock bs broadcast | 559 | saferSendTo sock bs broadcast |
560 | |||
561 | toxQSearch :: Tox extra -> Search NodeId (IP, PortNumber) Nonce32 NodeInfo Onion.Rendezvous | ||
562 | toxQSearch tox = Onion.toxidSearch (onionTimeout tox) (toxCryptoKeys tox) (toxOnion tox) | ||
563 | |||