diff options
author | joe <joe@jerkface.net> | 2017-11-19 22:59:49 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-11-19 22:59:49 -0500 |
commit | eaaf761dfb6af3673d9f064a791afadbbdc60e29 (patch) | |
tree | a8b927e0dc497f91298c2d43e85bba9dff48e0b9 /src/Network/Tox.hs | |
parent | 0e10db03f6d8f60b4afa58c39765ac2d78e2f859 (diff) |
Conduit stubs to convert between Tox and XMPP messages.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 68 |
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 | |||
46 | import qualified Data.ByteString.Char8 as C8 | 46 | import qualified Data.ByteString.Char8 as C8 |
47 | import Data.ByteString.Lazy (toStrict) | 47 | import Data.ByteString.Lazy (toStrict) |
48 | import Data.Char | 48 | import Data.Char |
49 | import Data.Conduit (Source,Sink,Flush(..)) | ||
49 | import Data.Data | 50 | import Data.Data |
50 | import Data.Functor.Contravariant | 51 | import Data.Functor.Contravariant |
51 | import Data.Hashable | 52 | import Data.Hashable |
@@ -85,11 +86,12 @@ import Control.TriadCommittee | |||
85 | import Network.BitTorrent.DHT.Token as Token | 86 | import Network.BitTorrent.DHT.Token as Token |
86 | import GHC.TypeLits | 87 | import GHC.TypeLits |
87 | 88 | ||
89 | import Connection | ||
88 | import Crypto.Tox | 90 | import Crypto.Tox |
89 | import Data.Word64Map (fitsInInt) | 91 | import Data.Word64Map (fitsInInt) |
90 | import qualified Data.Word64Map (empty) | 92 | import qualified Data.Word64Map (empty) |
91 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) | 93 | import Network.Kademlia.Bootstrap (forkPollForRefresh, bootstrap) |
92 | import Network.Tox.Crypto.Transport (NetCrypto) | 94 | import Network.Tox.Crypto.Transport (NetCrypto, CryptoMessage) |
93 | import Network.Tox.Crypto.Handlers (cryptoNetHandler, newSessionsState, defaultUnRecHook, defaultCryptoDataHooks, NetCryptoSessions(..)) | 95 | import Network.Tox.Crypto.Handlers (cryptoNetHandler, newSessionsState, defaultUnRecHook, defaultCryptoDataHooks, NetCryptoSessions(..)) |
94 | import qualified Network.Tox.DHT.Handlers as DHT | 96 | import qualified Network.Tox.DHT.Handlers as DHT |
95 | import qualified Network.Tox.DHT.Transport as DHT | 97 | import 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 | ||
226 | data ConnectionKey -- TODO | ||
227 | data ConnectionStatus -- TODO | ||
228 | |||
224 | data Tox = Tox | 229 | data 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 | ||
238 | getContactInfo :: Tox -> IO DHT.DHTPublicKey | 244 | getContactInfo :: 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 | ||
292 | newTox :: TVar Onion.AnnouncedKeys -> SockAddr -> Maybe NetCryptoSessions -> Maybe SecretKey -> IO Tox | 298 | newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rendezvous for. |
293 | newTox 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 | ||
308 | newTox 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 | ||
354 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) | 376 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) |