From 735fa5c892700efb78c7a9205b719f064ce429a6 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 27 May 2018 01:40:05 -0400 Subject: WIP: "lan" command to announce this Tox node on the lan. --- src/Network/Tox.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Network/Tox.hs') 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 , toxTokens :: TVar SessionTokens , toxAnnouncedKeys :: TVar Onion.AnnouncedKeys , toxOnionRoutes :: OnionRouter - , toxContactInfo :: ContactInfo + , toxContactInfo :: ContactInfo + , toxAnnounceToLan :: IO () } -- | initiate a netcrypto session, blocking @@ -315,7 +316,7 @@ newTox :: TVar Onion.AnnouncedKeys -- ^ Store of announced keys we are a rende -> Maybe SecretKey -- ^ Optional DHT secret key to use. -> IO Tox newTox keydb addr mbSessionsState suppliedDHTKey = do - udp <- {- addVerbosity <$> -} udpTransport addr + (udp,sock) <- {- addVerbosity <$> -} udpTransport' addr (crypto0,sessionsState0) <- case mbSessionsState of Nothing -> do crypto <- newCrypto @@ -374,6 +375,7 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do , toxAnnouncedKeys = keydb , toxOnionRoutes = orouter , toxContactInfo = roster + , toxAnnounceToLan = announceToLan sock (key2id $ transportPublic crypto) } onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) @@ -392,3 +394,12 @@ forkTox tox = do , bootstrap (DHT.refresher6 $ toxRouting tox) ) +-- TODO: Don't export this. +announceToLan :: Socket -> NodeId -> IO () +announceToLan sock nid = do + (broadcast_info:_) <- getAddrInfo (Just defaultHints { addrFlags = [AI_NUMERICHOST], addrSocketType = Datagram }) + (Just "192.168.1.255") -- TODO: Detect broadcast address. + (Just "33445") + let broadcast = addrAddress broadcast_info + bs = S.runPut $ DHT.putMessage (DHT.DHTLanDiscovery nid) + saferSendTo sock bs broadcast -- cgit v1.2.3