summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox.hs')
-rw-r--r--dht/src/Network/Tox.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/dht/src/Network/Tox.hs b/dht/src/Network/Tox.hs
index 0a6cccaa..6b39d57a 100644
--- a/dht/src/Network/Tox.hs
+++ b/dht/src/Network/Tox.hs
@@ -73,7 +73,7 @@ import qualified Network.Tox.Onion.Transport as Onion
73import Network.Tox.RelayPinger 73import Network.Tox.RelayPinger
74import System.Global6 74import System.Global6
75import Network.Tox.Transport 75import Network.Tox.Transport
76import Network.Tox.TCP (tcpClient, ViaRelay(..)) 76import Network.Tox.TCP (tcpClient, ViaRelay(..), RelayClient)
77import Network.Tox.Onion.Routes 77import Network.Tox.Onion.Routes
78import Network.Tox.ContactInfo 78import Network.Tox.ContactInfo
79import Text.XXD 79import Text.XXD
@@ -214,8 +214,8 @@ data Tox extra = Tox
214 214
215 215
216-- | Create a DHTPublicKey packet to send to a remote contact. 216-- | Create a DHTPublicKey packet to send to a remote contact.
217getContactInfo :: Tox extra -> IO DHT.DHTPublicKey 217getContactInfo :: Maybe (RelayClient,PublicKey) -> Tox extra -> IO DHT.DHTPublicKey
218getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do 218getContactInfo mthem Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do
219 (rcnt,relays) <- currentRelays (tcpRelayPinger toxOnionRoutes) 219 (rcnt,relays) <- currentRelays (tcpRelayPinger toxOnionRoutes)
220 r4 <- readTVar $ DHT.routing4 toxRouting 220 r4 <- readTVar $ DHT.routing4 toxRouting
221 r6 <- readTVar $ DHT.routing6 toxRouting 221 r6 <- readTVar $ DHT.routing6 toxRouting
@@ -227,12 +227,16 @@ getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically
227 n6s = R.kclosest DHT.toxSpace 4 self r6 227 n6s = R.kclosest DHT.toxSpace 4 self r6
228 ns = filter (DHT.isGlobal . nodeIP) [n4,n6] 228 ns = filter (DHT.isGlobal . nodeIP) [n4,n6]
229 ++ concat (zipWith (\a b -> [a,b]) n4s n6s) 229 ++ concat (zipWith (\a b -> [a,b]) n4s n6s)
230 sending_ns = take 4 $ relays ++ map TCP.fromUDPNode ns
230 return $ do 231 return $ do
232 forM_ mthem $ \(tcp,theirDHTKey) ->
233 forM_ (filter (\n -> TCP.tcpPort n /= 0) sending_ns) $ \ni -> do
234 Multi.tcpConnectionRequest tcp theirDHTKey ni
231 timestamp <- round . (* 1000000) <$> getPOSIXTime 235 timestamp <- round . (* 1000000) <$> getPOSIXTime
232 return DHT.DHTPublicKey 236 return DHT.DHTPublicKey
233 { dhtpkNonce = timestamp 237 { dhtpkNonce = timestamp
234 , dhtpk = id2key self 238 , dhtpk = id2key self
235 , dhtpkNodes = DHT.SendNodes $ take 4 $ relays ++ map TCP.fromUDPNode ns 239 , dhtpkNodes = DHT.SendNodes sending_ns
236 } 240 }
237 241
238isLocalHost :: SockAddr -> Bool 242isLocalHost :: SockAddr -> Bool