diff options
author | joe <joe@jerkface.net> | 2018-06-18 19:50:27 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-18 19:50:27 -0400 |
commit | 772f6547a40eb6a3a1dd76befb691f9160ed2d7a (patch) | |
tree | 777730a8f3ed0b5054287f4e8b99421055b1151a | |
parent | baa989943d301b5edf7dfd01389ae5a584566642 (diff) |
WIP: connection-related scheduled announce items.
-rw-r--r-- | ToxToXMPP.hs | 24 | ||||
-rw-r--r-- | conn-notes.txt | 4 |
2 files changed, 19 insertions, 9 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 | |||
diff --git a/conn-notes.txt b/conn-notes.txt index c1bbed00..257987d1 100644 --- a/conn-notes.txt +++ b/conn-notes.txt | |||
@@ -51,14 +51,14 @@ will be scheduled: | |||
51 | This task searches for our own user key, and publishes itself | 51 | This task searches for our own user key, and publishes itself |
52 | at rendezvous nodes. | 52 | at rendezvous nodes. |
53 | 53 | ||
54 | dhtkey:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN | 54 | dhtkey:OrjBG.Gy:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN |
55 | 55 | ||
56 | This task searches for our contact's user key and uses the | 56 | This task searches for our contact's user key and uses the |
57 | rendezvous nodes that it finds in order to share our dhtkey | 57 | rendezvous nodes that it finds in order to share our dhtkey |
58 | with our contact. | 58 | with our contact. |
59 | 59 | ||
60 | 60 | ||
61 | connect:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN | 61 | connect:OrjBG.Gy:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN |
62 | 62 | ||
63 | Depending on whether or not the ip/port is "fresh", this task | 63 | Depending on whether or not the ip/port is "fresh", this task |
64 | has two modes only one of which is active at a time: | 64 | has two modes only one of which is active at a time: |