summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-11-19 22:59:49 -0500
committerjoe <joe@jerkface.net>2017-11-19 22:59:49 -0500
commiteaaf761dfb6af3673d9f064a791afadbbdc60e29 (patch)
treea8b927e0dc497f91298c2d43e85bba9dff48e0b9 /src/Network
parent0e10db03f6d8f60b4afa58c39765ac2d78e2f859 (diff)
Conduit stubs to convert between Tox and XMPP messages.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox.hs68
1 files changed, 45 insertions, 23 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs
index 37802e3c..5b30a7e6 100644
--- a/src/Network/Tox.hs
+++ b/src/Network/Tox.hs
@@ -46,6 +46,7 @@ import qualified Data.ByteString.Base16 as Base16
46import qualified Data.ByteString.Char8 as C8 46import qualified Data.ByteString.Char8 as C8
47import Data.ByteString.Lazy (toStrict) 47import Data.ByteString.Lazy (toStrict)
48import Data.Char 48import Data.Char
49import Data.Conduit (Source,Sink,Flush(..))
49import Data.Data 50import Data.Data
50import Data.Functor.Contravariant 51import Data.Functor.Contravariant
51import Data.Hashable 52import Data.Hashable
@@ -85,11 +86,12 @@ import Control.TriadCommittee
85import Network.BitTorrent.DHT.Token as Token 86import Network.BitTorrent.DHT.Token as Token
86import GHC.TypeLits 87import GHC.TypeLits
87 88
89import Connection
88import Crypto.Tox 90import Crypto.Tox
89import Data.Word64Map (fitsInInt) 91import Data.Word64Map (fitsInInt)
90import qualified Data.Word64Map (empty) 92import qualified Data.Word64Map (empty)
91import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) 93import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap)
92import Network.Tox.Crypto.Transport (NetCrypto) 94import Network.Tox.Crypto.Transport (NetCrypto, CryptoMessage)
93import Network.Tox.Crypto.Handlers (cryptoNetHandler, newSessionsState, defaultUnRecHook, defaultCryptoDataHooks, NetCryptoSessions(..)) 95import Network.Tox.Crypto.Handlers (cryptoNetHandler, newSessionsState, defaultUnRecHook, defaultCryptoDataHooks, NetCryptoSessions(..))
94import qualified Network.Tox.DHT.Handlers as DHT 96import qualified Network.Tox.DHT.Handlers as DHT
95import qualified Network.Tox.DHT.Transport as DHT 97import qualified Network.Tox.DHT.Transport as DHT
@@ -221,18 +223,22 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do
221 in client 223 in client
222 return $ either mkclient mkclient tblvar handlers 224 return $ either mkclient mkclient tblvar handlers
223 225
226data ConnectionKey -- TODO
227data ConnectionStatus -- TODO
228
224data Tox = Tox 229data Tox = Tox
225 { toxDHT :: DHT.Client 230 { toxDHT :: DHT.Client
226 , toxOnion :: Onion.Client RouteId 231 , toxOnion :: Onion.Client RouteId
227 , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) 232 , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData)
228 , toxCrypto :: Transport String SockAddr NetCrypto 233 , toxCrypto :: Transport String SockAddr NetCrypto
229 , toxCryptoSessions :: NetCryptoSessions 234 , toxCryptoSessions :: NetCryptoSessions
230 , toxCryptoKeys :: TransportCrypto 235 , toxCryptoKeys :: TransportCrypto
231 , toxRouting :: DHT.Routing 236 , toxRouting :: DHT.Routing
232 , toxTokens :: TVar SessionTokens 237 , toxTokens :: TVar SessionTokens
233 , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys 238 , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys
234 , toxOnionRoutes :: OnionRouter 239 , toxOnionRoutes :: OnionRouter
235 , toxRoster :: Roster 240 , toxRoster :: Roster
241 , toxManager :: Connection.Manager ConnectionStatus ConnectionKey
236 } 242 }
237 243
238getContactInfo :: Tox -> IO DHT.DHTPublicKey 244getContactInfo :: Tox -> IO DHT.DHTPublicKey
@@ -289,8 +295,17 @@ getOnionAlias crypto dhtself remoteNode = atomically $ do
289 return $ Onion.OnionDestination Onion.SearchingAlias alias Nothing 295 return $ Onion.OnionDestination Onion.SearchingAlias alias Nothing
290 296
291 297
292newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> Maybe NetCryptoSessions -> Maybe SecretKey -> IO Tox 298newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for.
293newTox keydb addr mbSessionsState suppliedDHTKey = do 299 -> SockAddr -- ^ Bind-address to listen on.
300 -> Maybe NetCryptoSessions -- ^ State of all one-on-one Tox links.
301 -> Maybe SecretKey -- ^ Optional DHT secret key to use.
302 -> ( SockAddr -- ^ Address of remote peer.
303 -> STM Bool -- ^ True if connection requires a ping.
304 -> Source IO CryptoMessage -- ^ Inbound packets.
305 -> Sink (Flush CryptoMessage) IO () -- ^ Outbound packets.
306 -> IO () ) -- ^ Action to invoke on new connections.
307 -> IO Tox
308newTox keydb addr mbSessionsState suppliedDHTKey announceConnection = do
294 udp <- {- addVerbosity <$> -} udpTransport addr 309 udp <- {- addVerbosity <$> -} udpTransport addr
295 (crypto0,sessionsState) <- case mbSessionsState of 310 (crypto0,sessionsState) <- case mbSessionsState of
296 Nothing -> do 311 Nothing -> do
@@ -338,17 +353,24 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do
338 353
339 roster <- newRoster 354 roster <- newRoster
340 return Tox 355 return Tox
341 { toxDHT = dhtclient 356 { toxDHT = dhtclient
342 , toxOnion = onionclient 357 , toxOnion = onionclient
343 , toxToRoute = onInbound (updateRoster roster) dtacrypt 358 , toxToRoute = onInbound (updateRoster roster) dtacrypt
344 , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) cryptonet 359 , toxCrypto = addHandler (hPutStrLn stderr) (cryptoNetHandler sessionsState) cryptonet
345 , toxCryptoSessions = sessionsState 360 , toxCryptoSessions = sessionsState
346 , toxCryptoKeys = crypto 361 , toxCryptoKeys = crypto
347 , toxRouting = mkrouting dhtclient 362 , toxRouting = mkrouting dhtclient
348 , toxTokens = toks 363 , toxTokens = toks
349 , toxAnnouncedKeys = keydb 364 , toxAnnouncedKeys = keydb
350 , toxOnionRoutes = orouter 365 , toxOnionRoutes = orouter
351 , toxRoster = roster 366 , toxRoster = roster
367 , toxManager = Connection.Manager
368 { setPolicy = _todo -- k -> Policy -> IO ()
369 , connections = _todo -- STM (Map k (Connection status))
370 , stringToKey = _todo -- String -> Maybe k
371 , showProgress = _todo -- status -> String
372 , showKey = _todo -- k -> String
373 }
352 } 374 }
353 375
354onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) 376onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int)