summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-09-08 04:31:51 -0400
committerJoe Crayne <joe@jerkface.net>2018-09-08 06:05:10 -0400
commitad20be57786ad34f80192206c480d575392b4ebb (patch)
tree722333a152705572f7437586772a9173e84a92e2 /src/Network
parente5add92a477060d9bba10de7b980c89c24012691 (diff)
ToxManager rewrite: use aggregated netcrypto sessions.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox.hs11
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
32import qualified Data.ByteString.Char8 as C8 32import qualified Data.ByteString.Char8 as C8
33import Data.Data 33import Data.Data
34import Data.Functor.Contravariant 34import Data.Functor.Contravariant
35import Data.IP
35import Data.Maybe 36import Data.Maybe
36import qualified Data.MinMaxPSQ as MinMaxPSQ 37import qualified Data.MinMaxPSQ as MinMaxPSQ
37import qualified Data.Serialize as S 38import qualified Data.Serialize as S
@@ -50,7 +51,9 @@ import Connection
50import Crypto.Tox 51import Crypto.Tox
51import Data.Word64Map (fitsInInt) 52import Data.Word64Map (fitsInInt)
52import qualified Data.Word64Map (empty) 53import qualified Data.Word64Map (empty)
54import HandshakeCache
53import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) 55import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap)
56import Network.Kademlia.Search
54import Network.Tox.Crypto.Transport (Handshake(..),CryptoPacket) 57import Network.Tox.Crypto.Transport (Handshake(..),CryptoPacket)
55import Network.Tox.Handshake 58import Network.Tox.Handshake
56import Network.Tox.Crypto.Handlers 59import 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
561toxQSearch :: Tox extra -> Search NodeId (IP, PortNumber) Nonce32 NodeInfo Onion.Rendezvous
562toxQSearch tox = Onion.toxidSearch (onionTimeout tox) (toxCryptoKeys tox) (toxOnion tox)
563