diff options
Diffstat (limited to 'Connection/Tox.hs')
-rw-r--r-- | Connection/Tox.hs | 57 |
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 @@ | |||
1 | module Connection.Tox where | ||
2 | |||
3 | import qualified Connection as G | ||
4 | ;import Connection (Manager (..), Policy (..)) | ||
5 | import Control.Concurrent.STM | ||
6 | import Crypto.Tox | ||
7 | import Network.Tox | ||
8 | import qualified Data.Map as Map | ||
9 | import Network.Tox.NodeId | ||
10 | import PingMachine | ||
11 | import Text.Read | ||
12 | |||
13 | |||
14 | data ToxProgress = ToxInProgress -- TODO | ||
15 | deriving Show | ||
16 | |||
17 | data 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. | ||
30 | setToxPolicy :: Parameters | ||
31 | -> TVar (Map.Map NodeId (G.Connection ToxProgress)) | ||
32 | -> NodeId {- their public userkey -} | ||
33 | -> Policy | ||
34 | -> IO () | ||
35 | setToxPolicy 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 | |||
48 | toxManager :: Parameters -> IO (Manager ToxProgress NodeId{- their public userkey -}) | ||
49 | toxManager 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 | } | ||