diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/Tox.hs | 22 | ||||
-rw-r--r-- | src/Network/Tox/Avahi.hs | 13 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 3c3bce49..170a07e8 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE ViewPatterns #-} | ||
1 | {-# LANGUAGE CPP #-} | 2 | {-# LANGUAGE CPP #-} |
2 | {-# LANGUAGE DeriveDataTypeable #-} | 3 | {-# LANGUAGE DeriveDataTypeable #-} |
3 | {-# LANGUAGE DeriveFoldable #-} | 4 | {-# LANGUAGE DeriveFoldable #-} |
@@ -19,7 +20,11 @@ import Debug.Trace | |||
19 | import Control.Exception hiding (Handler) | 20 | import Control.Exception hiding (Handler) |
20 | import Control.Applicative | 21 | import Control.Applicative |
21 | import Control.Arrow | 22 | import Control.Arrow |
22 | import Control.Concurrent (MVar,killThread) | 23 | #ifdef THREAD_DEBUG |
24 | import Control.Concurrent.Lifted.Instrument | ||
25 | #else | ||
26 | import Control.Concurrent.Lifted | ||
27 | #endif | ||
23 | import Control.Concurrent.STM | 28 | import Control.Concurrent.STM |
24 | import Control.Monad | 29 | import Control.Monad |
25 | import Control.Monad.Fix | 30 | import Control.Monad.Fix |
@@ -113,7 +118,7 @@ import Data.HashMap.Strict (HashMap) | |||
113 | import qualified Data.Map.Strict as Map | 118 | import qualified Data.Map.Strict as Map |
114 | import Control.Concurrent (threadDelay) | 119 | import Control.Concurrent (threadDelay) |
115 | import DPut | 120 | import DPut |
116 | 121 | import Network.Tox.Avahi | |
117 | 122 | ||
118 | newCrypto :: IO TransportCrypto | 123 | newCrypto :: IO TransportCrypto |
119 | newCrypto = do | 124 | newCrypto = do |
@@ -476,6 +481,17 @@ newTox keydb addr mbSessionsState suppliedDHTKey = do | |||
476 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) | 481 | onionTimeout :: Tox -> DHT.TransactionId -> Onion.OnionDestination RouteId -> STM (Onion.OnionDestination RouteId, Int) |
477 | onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od | 482 | onionTimeout Tox { toxOnionRoutes = or } (DHT.TransactionId n8 _) od = lookupTimeout or n8 od |
478 | 483 | ||
484 | routing4nodeInfo :: DHT.Routing -> IO NodeInfo | ||
485 | routing4nodeInfo (DHT.routing4 -> tv) = R.thisNode <$> readTVarIO tv | ||
486 | |||
487 | dnssdAnnounce :: Tox -> IO () | ||
488 | dnssdAnnounce (toxRouting -> r) = do | ||
489 | ni <- routing4nodeInfo r | ||
490 | announceToxService (nodePort ni) (nodeId ni) | ||
491 | |||
492 | dnssdDiscover :: Tox -> NodeInfo -> IO () | ||
493 | dnssdDiscover (toxDHT -> client) ni = void $ DHT.ping client ni | ||
494 | |||
479 | forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) | 495 | forkTox :: Tox -> IO (IO (), [NodeInfo] -> [NodeInfo] -> IO (), [NodeInfo] -> [NodeInfo] -> IO ()) |
480 | forkTox tox = do | 496 | forkTox tox = do |
481 | _ <- forkListener "toxHandshakes" (toxHandshakes tox) | 497 | _ <- forkListener "toxHandshakes" (toxHandshakes tox) |
@@ -485,6 +501,8 @@ forkTox tox = do | |||
485 | quit <- forkListener "toxCrypto" (toxCrypto tox) | 501 | quit <- forkListener "toxCrypto" (toxCrypto tox) |
486 | forkPollForRefresh (DHT.refresher4 $ toxRouting tox) | 502 | forkPollForRefresh (DHT.refresher4 $ toxRouting tox) |
487 | forkPollForRefresh (DHT.refresher6 $ toxRouting tox) | 503 | forkPollForRefresh (DHT.refresher6 $ toxRouting tox) |
504 | dnssdIn <- forkIO $ queryToxService (dnssdDiscover tox) | ||
505 | dnssdOut <- forkIO $ dnssdAnnounce tox | ||
488 | keygc <- Onion.forkAnnouncedKeysGC (toxAnnouncedKeys tox) | 506 | keygc <- Onion.forkAnnouncedKeysGC (toxAnnouncedKeys tox) |
489 | return ( killThread keygc >> quit | 507 | return ( killThread keygc >> quit |
490 | , bootstrap (DHT.refresher4 $ toxRouting tox) | 508 | , bootstrap (DHT.refresher4 $ toxRouting tox) |
diff --git a/src/Network/Tox/Avahi.hs b/src/Network/Tox/Avahi.hs index ba5138bc..ed52de74 100644 --- a/src/Network/Tox/Avahi.hs +++ b/src/Network/Tox/Avahi.hs | |||
@@ -5,12 +5,11 @@ module Network.Tox.Avahi | |||
5 | , NodeInfo(..) | 5 | , NodeInfo(..) |
6 | , NodeId(..) | 6 | , NodeId(..) |
7 | ) where | 7 | ) where |
8 | |||
8 | import Data.Foldable | 9 | import Data.Foldable |
9 | import GHC.Conc.Sync | ||
10 | import GHC.Word (Word16) | 10 | import GHC.Word (Word16) |
11 | import Network.Address | 11 | import Network.Address |
12 | import Network.Avahi | 12 | import Network.Avahi |
13 | import Network.Avahi | ||
14 | import Network.Socket | 13 | import Network.Socket |
15 | import Network.Tox.NodeId | 14 | import Network.Tox.NodeId |
16 | import Text.Read | 15 | import Text.Read |
@@ -37,12 +36,14 @@ toxService hostname (fromIntegral -> port) (show -> extra) = | |||
37 | serviceText = extra | 36 | serviceText = extra |
38 | } | 37 | } |
39 | 38 | ||
40 | announceToxService :: String -> PortNumber -> NodeId -> IO ThreadId | 39 | announceToxServiceWithHostname :: String -> PortNumber -> NodeId -> IO () |
41 | announceToxService = ((.).(.).(.)) (forkIO . announce) toxService | 40 | announceToxServiceWithHostname = ((.).(.).(.)) announce toxService |
41 | |||
42 | announceToxService :: PortNumber -> NodeId -> IO () | ||
43 | announceToxService = announceToxServiceWithHostname "" | ||
42 | 44 | ||
43 | queryToxService :: (NodeInfo -> IO ()) -> IO ThreadId | 45 | queryToxService :: (NodeInfo -> IO ()) -> IO () |
44 | queryToxService cb = | 46 | queryToxService cb = |
45 | forkIO $ | ||
46 | browse $ | 47 | browse $ |
47 | BrowseQuery | 48 | BrowseQuery |
48 | { lookupProtocol = PROTO_UNSPEC | 49 | { lookupProtocol = PROTO_UNSPEC |