diff options
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index eb4c6027..c0e1dee0 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -196,7 +196,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do | |||
196 | mkclient (tbl,var) handlers = | 196 | mkclient (tbl,var) handlers = |
197 | let client = Client | 197 | let client = Client |
198 | { clientNet = addHandler eprinter (handleMessage client) $ modifynet client net | 198 | { clientNet = addHandler eprinter (handleMessage client) $ modifynet client net |
199 | , clientDispatcher = dispatch tbl var handlers -- (fmap (contramapAddr (\(ToxPath ni _) -> ni)) . handlers) | 199 | , clientDispatcher = dispatch tbl var handlers |
200 | , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } | 200 | , clientErrorReporter = eprinter { reportTimeout = reportTimeout ignoreErrors } |
201 | , clientPending = var | 201 | , clientPending = var |
202 | , clientAddress = selfAddr | 202 | , clientAddress = selfAddr |
@@ -208,7 +208,7 @@ newClient drg net classify selfAddr handlers modifytbl modifynet = do | |||
208 | data Tox = Tox | 208 | data Tox = Tox |
209 | { toxDHT :: DHT.Client | 209 | { toxDHT :: DHT.Client |
210 | , toxOnion :: Onion.Client RouteId | 210 | , toxOnion :: Onion.Client RouteId |
211 | , toxToRoute :: Transport String Onion.Rendezvous Onion.DataToRoute | 211 | , toxToRoute :: Transport String Onion.AnnouncedRendezvous (PublicKey,Onion.OnionData) |
212 | , toxCrypto :: Transport String SockAddr NetCrypto | 212 | , toxCrypto :: Transport String SockAddr NetCrypto |
213 | , toxCryptoKeys :: TransportCrypto | 213 | , toxCryptoKeys :: TransportCrypto |
214 | , toxRouting :: DHT.Routing | 214 | , toxRouting :: DHT.Routing |
@@ -217,6 +217,26 @@ data Tox = Tox | |||
217 | , toxOnionRoutes :: OnionRouter | 217 | , toxOnionRoutes :: OnionRouter |
218 | } | 218 | } |
219 | 219 | ||
220 | getContactInfo :: Tox -> IO DHT.DHTPublicKey | ||
221 | getContactInfo Tox{toxCryptoKeys,toxRouting} = join $ atomically $ do | ||
222 | r4 <- readTVar $ DHT.routing4 toxRouting | ||
223 | r6 <- readTVar $ DHT.routing6 toxRouting | ||
224 | nonce <- transportNewNonce toxCryptoKeys | ||
225 | let self = nodeId n4 | ||
226 | n4 = R.thisNode r4 | ||
227 | n6 = R.thisNode r6 | ||
228 | n4s = R.kclosest DHT.toxSpace 4 self r4 | ||
229 | n6s = R.kclosest DHT.toxSpace 4 self r6 | ||
230 | ns = filter (DHT.isGlobal . nodeIP) [n4,n6] | ||
231 | ++ concat (zipWith (\a b -> [a,b]) n4s n6s) | ||
232 | return $ do | ||
233 | timestamp <- round . (* 1000000) <$> getPOSIXTime | ||
234 | return DHT.DHTPublicKey | ||
235 | { dhtpkNonce = timestamp | ||
236 | , dhtpk = id2key self | ||
237 | , dhtpkNodes = DHT.SendNodes $ take 4 ns | ||
238 | } | ||
239 | |||
220 | isLocalHost :: SockAddr -> Bool | 240 | isLocalHost :: SockAddr -> Bool |
221 | isLocalHost (SockAddrInet _ host32) = (fromBE32 host32 == 0x7f000001) | 241 | isLocalHost (SockAddrInet _ host32) = (fromBE32 host32 == 0x7f000001) |
222 | isLocalHost _ = False | 242 | isLocalHost _ = False |