summaryrefslogtreecommitdiff
path: root/ToxToXMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r--ToxToXMPP.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index ad5cb0dd..d6a31f1e 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -100,11 +100,13 @@ key2jid nospam key = T.pack $ show $ NoSpamId nsp key
100 nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16 100 nlo = fromIntegral (0x0FFFF .&. nospam) :: Word16
101 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16 101 nhi = fromIntegral (0x0FFFF .&. (nospam `shiftR` 16)) :: Word16
102 102
103dispatch :: Account -> PresenceState -> ContactEvent -> IO () 103dispatch :: Announcer -> Account -> PresenceState -> ContactEvent -> IO ()
104dispatch acnt st (AddrChange theirkey saddr) = return () -- todo 104dispatch acr acnt st (SessionEstablished theirKey) = return ()
105dispatch acnt st (PolicyChange theirkey policy ) = return () -- todo 105dispatch acr acnt st (SessionTerminated theirKey) = return ()
106dispatch acnt st (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo 106dispatch acr acnt st (AddrChange theirkey saddr) = return () -- todo
107dispatch acnt st (OnionRouted theirkey (OnionFriendRequest fr) ) = do 107dispatch acr acnt st (PolicyChange theirkey policy ) = return () -- todo
108dispatch acr acnt st (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo
109dispatch acr acnt st (OnionRouted theirkey (OnionFriendRequest fr) ) = do
108 k2c <- atomically $ do 110 k2c <- atomically $ do
109 refs <- readTVar (clientRefs acnt) 111 refs <- readTVar (clientRefs acnt)
110 k2c <- Map.filterWithKey (\k _ -> k `Set.member` refs) <$> readTVar (keyToChan st) 112 k2c <- Map.filterWithKey (\k _ -> k `Set.member` refs) <$> readTVar (keyToChan st)
@@ -127,6 +129,10 @@ interweave :: [a] -> [a] -> [a]
127interweave [] ys = ys 129interweave [] ys = ys
128interweave (x:xs) ys = x : interweave ys xs 130interweave (x:xs) ys = x : interweave ys xs
129 131
132akeyDHTKeyShare announcer me them = atomically $ do
133 packAnnounceKey announcer $ "dhtkey:" ++ (take 8 $ show me) ++ ":" ++ show them
134akeyConnect announcer me them = atomically $ do
135 packAnnounceKey announcer $ "connect:" ++ (take 8 $ show me) ++ ":" ++ show them
130 136
131forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadId 137forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadId
132forkAccountWatcher acc tox st announcer = forkIO $ do 138forkAccountWatcher acc tox st announcer = forkIO $ do
@@ -150,7 +156,8 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
150 wanted <- atomically $ (==Just TryingToConnect) <$> readTVar contactPolicy 156 wanted <- atomically $ (==Just TryingToConnect) <$> readTVar contactPolicy
151 when wanted $ do 157 when wanted $ do
152 let pub = toPublic $ userSecret acc 158 let pub = toPublic $ userSecret acc
153 akey <- atomically $ packAnnounceKey announcer $ "dhtkey:" ++ show them 159 me = key2id pub
160 akey <- akeyDHTKeyShare announcer me them
154 -- We send this packet every 30 seconds if there is more 161 -- We send this packet every 30 seconds if there is more
155 -- than one peer (in the 8) that says they our friend is 162 -- than one peer (in the 8) that says they our friend is
156 -- announced on them. This packet can also be sent through 163 -- announced on them. This packet can also be sent through
@@ -165,6 +172,7 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
165 -- likelihood of failure as the chances of packet loss 172 -- likelihood of failure as the chances of packet loss
166 -- happening to all (up to to 8) packets sent is low. 173 -- happening to all (up to to 8) packets sent is low.
167 -- 174 --
175 -- TODO: Reschedule this as appropriate within 'dispatch' function.
168 scheduleSearch announcer 176 scheduleSearch announcer
169 akey 177 akey
170 (SearchMethod (toxQSearch tox) 178 (SearchMethod (toxQSearch tox)
@@ -189,7 +197,7 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
189 refs <- readTVar $ clientRefs acc 197 refs <- readTVar $ clientRefs acc
190 check $ Set.null refs 198 check $ Set.null refs
191 return Nothing 199 return Nothing
192 forM_ mev $ \ev -> dispatch acc st ev >> loop 200 forM_ mev $ \ev -> dispatch announcer acc st ev >> loop
193 201
194toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous 202toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous
195toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox) 203toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox)
@@ -197,3 +205,5 @@ toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox)
197toxAnnounceInterval :: POSIXTime 205toxAnnounceInterval :: POSIXTime
198toxAnnounceInterval = 15 206toxAnnounceInterval = 15
199 207
208
209