diff options
author | joe <joe@jerkface.net> | 2018-05-27 01:40:05 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-27 01:40:05 -0400 |
commit | 735fa5c892700efb78c7a9205b719f064ce429a6 (patch) | |
tree | f51b6e7039af4c59e2bf13667ba416b3e3d09b73 /src/Network/Tox.hs | |
parent | 98000ec40f7ce9adfbc8464ec87d2230345a55d1 (diff) |
WIP: "lan" command to announce this Tox node on the lan.
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index b3c4cedc..5d791a8a 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -240,7 +240,8 @@ data Tox = Tox | |||
240 | , toxTokens :: TVar SessionTokens | 240 | , toxTokens :: TVar SessionTokens |
241 | , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys | 241 | , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys |
242 | , toxOnionRoutes :: OnionRouter | 242 | , toxOnionRoutes :: OnionRouter |
243 | , toxContactInfo :: ContactInfo | 243 | , toxContactInfo :: ContactInfo |
244 | , toxAnnounceToLan :: IO () | ||
244 | } | 245 | } |
245 | 246 | ||
246 | -- | initiate a netcrypto session, blocking | 247 | -- | initiate a netcrypto session, blocking |
@@ -315,7 +316,7 @@ newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rende | |||
315 | -> Maybe SecretKey -- ^ Optional DHT secret key to use. | 316 | -> Maybe SecretKey -- ^ Optional DHT secret key to use. |
316 | -> IO Tox | 317 | -> IO Tox |
317 | newTox keydb addr mbSessionsState suppliedDHTKey = do | 318 | newTox keydb addr mbSessionsState suppliedDHTKey = do |
318 | udp <- {- addVerbosity <$> -} udpTransport addr | 319 | (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr |
319 | (crypto0,sessionsState0) <- case mbSessionsState of | 320 | (crypto0,sessionsState0) <- case mbSessionsState of |
320 | Nothing -> do | 321 | Nothing -> do |
321 | crypto <- newCrypto | 322 | crypto <- newCrypto |
@@ -374,6 +375,7 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
374 | , toxAnnouncedKeys = keydb | 375 | , toxAnnouncedKeys = keydb |
375 | , toxOnionRoutes = orouter | 376 | , toxOnionRoutes = orouter |
376 | , toxContactInfo = roster | 377 | , toxContactInfo = roster |
378 | , toxAnnounceToLan = announceToLan sock (key2id $ transportPublic crypto) | ||
377 | } | 379 | } |
378 | 380 | ||
379 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) | 381 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) |
@@ -392,3 +394,12 @@ forkTox tox = do | |||
392 | , bootstrap (DHT.refresher6 $ toxRouting tox) | 394 | , bootstrap (DHT.refresher6 $ toxRouting tox) |
393 | ) | 395 | ) |
394 | 396 | ||
397 | -- TODO: Don't export this. | ||
398 | announceToLan :: Socket -> NodeId -> IO () | ||
399 | announceToLan sock nid = do | ||
400 | (broadcast_info:_) <- getAddrInfo (Just defaultHints { addrFlags = [AI_NUMERICHOST], addrSocketType = Datagram }) | ||
401 | (Just "192.168.1.255") -- TODO: Detect broadcast address. | ||
402 | (Just "33445") | ||
403 | let broadcast = addrAddress broadcast_info | ||
404 | bs = S.runPut $ DHT.putMessage (DHT.DHTLanDiscovery nid) | ||
405 | saferSendTo sock bs broadcast | ||