diff options
Diffstat (limited to 'Roster.hs')
-rw-r--r-- | Roster.hs | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -1,13 +1,15 @@ | |||
1 | {-# LANGUAGE NamedFieldPuns #-} | 1 | {-# LANGUAGE NamedFieldPuns #-} |
2 | module Roster where | 2 | module Roster where |
3 | 3 | ||
4 | import Crypto.PubKey.Curve25519 | 4 | import System.IO |
5 | import Network.Tox.Onion.Transport as Onion | 5 | import Control.Monad |
6 | import Network.Tox.DHT.Transport as DHT | ||
7 | import Network.Tox.NodeId | ||
8 | import Control.Concurrent.STM | 6 | import Control.Concurrent.STM |
7 | import Crypto.PubKey.Curve25519 | ||
9 | import qualified Data.HashMap.Strict as HashMap | 8 | import qualified Data.HashMap.Strict as HashMap |
10 | import Data.HashMap.Strict (HashMap) | 9 | ;import Data.HashMap.Strict (HashMap) |
10 | import Network.Tox.DHT.Transport as DHT | ||
11 | import Network.Tox.NodeId | ||
12 | import Network.Tox.Onion.Transport as Onion | ||
11 | 13 | ||
12 | newtype Roster = Roster { accounts :: TVar (HashMap NodeId Account) } | 14 | newtype 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 | ||
33 | updateRoster :: Roster -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () | 35 | updateRoster :: Roster -> Onion.AnnouncedRendezvous -> (PublicKey,Onion.OnionData) -> IO () |
34 | updateRoster roster Onion.AnnouncedRendezvous{remoteUserKey} (localUserKey,omsg) = do | 36 | updateRoster 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 | |||
53 | updateAccount remoteUserKey (Onion.OnionFriendRequest fr) acc = do | 56 | updateAccount remoteUserKey (Onion.OnionFriendRequest fr) acc = do |
54 | -- TODO | 57 | -- TODO |
55 | return () | 58 | return () |
59 | |||
60 | dnsPresentation :: Roster -> STM String | ||
61 | dnsPresentation (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 | |||
70 | dnsPresentation1 :: (NodeId,DHTPublicKey) -> String | ||
71 | dnsPresentation1 (nid,dk) = unlines | ||
72 | [ concat [ show nid, ".tox. IN CNAME ", show (key2id $ dhtpk dk), ".dht." ] | ||
73 | ] | ||
74 | |||