summaryrefslogtreecommitdiff
path: root/Connection/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Connection/Tox.hs')
-rw-r--r--Connection/Tox.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Connection/Tox.hs b/Connection/Tox.hs
new file mode 100644
index 00000000..58e1cb42
--- /dev/null
+++ b/Connection/Tox.hs
@@ -0,0 +1,57 @@
1module Connection.Tox where
2
3import qualified Connection as G
4 ;import Connection (Manager (..), Policy (..))
5import Control.Concurrent.STM
6import Crypto.Tox
7import Network.Tox
8import qualified Data.Map as Map
9import Network.Tox.NodeId
10import PingMachine
11import Text.Read
12
13
14data ToxProgress = ToxInProgress -- TODO
15 deriving Show
16
17data Parameters = Parameters
18 { -- | Various Tox transports and clients. XXX: This includes a lot of
19 -- irrelevant secret keys.
20 toxTransports :: Tox
21 -- | This node's public user key. The relevant secret key will be obtained
22 -- from 'toxTransports'.
23 , myToxIdentity :: NodeId
24 -- | Thread to be forked when a connection is established.
25 -- TODO: this function should accept relevant parameters.
26 , onToxSession :: IO ()
27 }
28
29-- | This function will fork threads as necessary.
30setToxPolicy :: Parameters
31 -> TVar (Map.Map NodeId (G.Connection ToxProgress))
32 -> NodeId {- their public userkey -}
33 -> Policy
34 -> IO ()
35setToxPolicy params conmap k policy = case policy of
36 TryingToConnect -> do
37 -- TODO initiate connecting if we haven't already
38 -- When established, invoke 'onToxSession'.
39 return ()
40 RefusingToConnect -> do
41 -- TODO disconnect or cancel any pending connection
42 return ()
43 OpenToConnect -> do
44 -- TODO passively accept connections if they initiate.
45 return ()
46
47
48toxManager :: Parameters -> IO (Manager ToxProgress NodeId{- their public userkey -})
49toxManager params = do
50 conmap <- newTVarIO Map.empty
51 return Manager
52 { setPolicy = setToxPolicy params conmap -- k -> Policy -> IO ()
53 , connections = readTVar conmap -- STM (Map k (Connection status))
54 , stringToKey = readMaybe -- String -> Maybe k
55 , showProgress = show -- status -> String
56 , showKey = show -- k -> String
57 }