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 f136ab96..fca0f9e0 100644
--- a/dht/src/Network/Tox.hs
+++ b/dht/src/Network/Tox.hs
@@ -72,7 +72,7 @@ import qualified Network.Tox.Onion.Transport as Onion
72import Network.Tox.RelayPinger 72import Network.Tox.RelayPinger
73import System.Global6 73import System.Global6
74import Network.Tox.Transport 74import Network.Tox.Transport
75import Network.Tox.TCP (tcpClient) 75import Network.Tox.TCP (tcpClient, RelayClient)
76import Network.Tox.Onion.Routes 76import Network.Tox.Onion.Routes
77import Network.Tox.ContactInfo 77import Network.Tox.ContactInfo
78import Text.XXD 78import Text.XXD
@@ -199,8 +199,8 @@ data Tox extra = Tox
199 199
200 200
201-- | Create a DHTPublicKey packet to send to a remote contact. 201-- | Create a DHTPublicKey packet to send to a remote contact.
202getContactInfo :: Tox extra -> IO DHT.DHTPublicKey 202getContactInfo :: Maybe (RelayClient,PublicKey) -> Tox extra -> IO DHT.DHTPublicKey
203getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do 203getContactInfo mthem Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do
204 (rcnt,relays) <- currentRelays (tcpRelayPinger toxOnionRoutes) 204 (rcnt,relays) <- currentRelays (tcpRelayPinger toxOnionRoutes)
205 r4 <- readTVar $ DHT.routing4 toxRouting 205 r4 <- readTVar $ DHT.routing4 toxRouting
206 r6 <- readTVar $ DHT.routing6 toxRouting 206 r6 <- readTVar $ DHT.routing6 toxRouting
@@ -212,12 +212,16 @@ getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically
212 n6s = R.kclosest DHT.toxSpace 4 self r6 212 n6s = R.kclosest DHT.toxSpace 4 self r6
213 ns = filter (DHT.isGlobal . nodeIP) [n4,n6] 213 ns = filter (DHT.isGlobal . nodeIP) [n4,n6]
214 ++ concat (zipWith (\a b -> [a,b]) n4s n6s) 214 ++ concat (zipWith (\a b -> [a,b]) n4s n6s)
215 sending_ns = take 4 $ relays ++ map TCP.fromUDPNode ns
215 return $ do 216 return $ do
217 forM_ mthem $ \(tcp,them) ->
218 forM_ (filter (\n -> TCP.tcpPort n /= 0) sending_ns) $ \ni -> do
219 Multi.tcpConnectionRequest tcp them ni
216 timestamp <- round . (* 1000000) <$> getPOSIXTime 220 timestamp <- round . (* 1000000) <$> getPOSIXTime
217 return DHT.DHTPublicKey 221 return DHT.DHTPublicKey
218 { dhtpkNonce = timestamp 222 { dhtpkNonce = timestamp
219 , dhtpk = id2key self 223 , dhtpk = id2key self
220 , dhtpkNodes = DHT.SendNodes $ take 4 $ relays ++ map TCP.fromUDPNode ns 224 , dhtpkNodes = DHT.SendNodes sending_ns
221 } 225 }
222 226
223isLocalHost :: SockAddr -> Bool 227isLocalHost :: SockAddr -> Bool