summaryrefslogtreecommitdiff
path: root/Roster.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Roster.hs')
-rw-r--r--Roster.hs29
1 files changed, 24 insertions, 5 deletions
diff --git a/Roster.hs b/Roster.hs
index 94ab462d..ab2f9911 100644
--- a/Roster.hs
+++ b/Roster.hs
@@ -1,13 +1,15 @@
1{-# LANGUAGE NamedFieldPuns #-} 1{-# LANGUAGE NamedFieldPuns #-}
2module Roster where 2module Roster where
3 3
4import Crypto.PubKey.Curve25519 4import System.IO
5import Network.Tox.Onion.Transport as Onion 5import Control.Monad
6import Network.Tox.DHT.Transport as DHT
7import Network.Tox.NodeId
8import Control.Concurrent.STM 6import Control.Concurrent.STM
7import Crypto.PubKey.Curve25519
9import qualified Data.HashMap.Strict as HashMap 8import qualified Data.HashMap.Strict as HashMap
10import Data.HashMap.Strict (HashMap) 9 ;import Data.HashMap.Strict (HashMap)
10import Network.Tox.DHT.Transport as DHT
11import Network.Tox.NodeId
12import Network.Tox.Onion.Transport as Onion
11 13
12newtype Roster = Roster { accounts :: TVar (HashMap NodeId Account) } 14newtype Roster = Roster { accounts :: TVar (HashMap NodeId Account) }
13 15
@@ -32,6 +34,7 @@ delRoster (Roster as) pk = modifyTVar' as $ HashMap.delete (key2id pk)
32 34
33updateRoster :: Roster -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () 35updateRoster :: Roster -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO ()
34updateRoster roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do 36updateRoster roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do
37 hPutStrLn stderr "updateRoster!!!"
35 atomically $ do 38 atomically $ do
36 as <- readTVar (accounts roster) 39 as <- readTVar (accounts roster)
37 maybe (return ()) 40 maybe (return ())
@@ -53,3 +56,19 @@ updateAccount remoteUserKey (Onion.OnionDHTPublicKey dhtpk) acc = do
53updateAccount remoteUserKey (Onion.OnionFriendRequest fr) acc = do 56updateAccount remoteUserKey (Onion.OnionFriendRequest fr) acc = do
54 -- TODO 57 -- TODO
55 return () 58 return ()
59
60dnsPresentation :: Roster -> STM String
61dnsPresentation (Roster accsvar) = do
62 accs <- readTVar accsvar
63 ms <- forM accs $ \Account { userSecret = sec, contacts = cvar } -> do
64 cs <- readTVar cvar
65 return $
66 "; local key = " ++ show (key2id $ toPublic sec) ++ "\n"
67 ++ concatMap dnsPresentation1 (HashMap.toList cs)
68 return $ concat ms
69
70dnsPresentation1 :: (NodeId,DHTPublicKey) -> String
71dnsPresentation1 (nid,dk) = unlines
72 [ concat [ show nid, ".tox. IN CNAME ", show (key2id $ dhtpk dk), ".dht." ]
73 ]
74