diff options
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r-- | ToxToXMPP.hs | 24 |
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 | ||
103 | dispatch :: Account -> PresenceState -> ContactEvent -> IO () | 103 | dispatch :: Announcer -> Account -> PresenceState -> ContactEvent -> IO () |
104 | dispatch acnt st (AddrChange theirkey saddr) = return () -- todo | 104 | dispatch acr acnt st (SessionEstablished theirKey) = return () |
105 | dispatch acnt st (PolicyChange theirkey policy ) = return () -- todo | 105 | dispatch acr acnt st (SessionTerminated theirKey) = return () |
106 | dispatch acnt st (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo | 106 | dispatch acr acnt st (AddrChange theirkey saddr) = return () -- todo |
107 | dispatch acnt st (OnionRouted theirkey (OnionFriendRequest fr) ) = do | 107 | dispatch acr acnt st (PolicyChange theirkey policy ) = return () -- todo |
108 | dispatch acr acnt st (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo | ||
109 | dispatch 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] | |||
127 | interweave [] ys = ys | 129 | interweave [] ys = ys |
128 | interweave (x:xs) ys = x : interweave ys xs | 130 | interweave (x:xs) ys = x : interweave ys xs |
129 | 131 | ||
132 | akeyDHTKeyShare announcer me them = atomically $ do | ||
133 | packAnnounceKey announcer $ "dhtkey:" ++ (take 8 $ show me) ++ ":" ++ show them | ||
134 | akeyConnect announcer me them = atomically $ do | ||
135 | packAnnounceKey announcer $ "connect:" ++ (take 8 $ show me) ++ ":" ++ show them | ||
130 | 136 | ||
131 | forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadId | 137 | forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadId |
132 | forkAccountWatcher acc tox st announcer = forkIO $ do | 138 | forkAccountWatcher 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 | ||
194 | toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous | 202 | toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous |
195 | toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox) | 203 | toxQSearch 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) | |||
197 | toxAnnounceInterval :: POSIXTime | 205 | toxAnnounceInterval :: POSIXTime |
198 | toxAnnounceInterval = 15 | 206 | toxAnnounceInterval = 15 |
199 | 207 | ||
208 | |||
209 | |||