diff options
Diffstat (limited to 'dht/src/Network/Tox.hs')
-rw-r--r-- | dht/src/Network/Tox.hs | 12 |
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 | |||
73 | import Network.Tox.RelayPinger | 73 | import Network.Tox.RelayPinger |
74 | import System.Global6 | 74 | import System.Global6 |
75 | import Network.Tox.Transport | 75 | import Network.Tox.Transport |
76 | import Network.Tox.TCP (tcpClient, ViaRelay(..)) | 76 | import Network.Tox.TCP (tcpClient, ViaRelay(..), RelayClient) |
77 | import Network.Tox.Onion.Routes | 77 | import Network.Tox.Onion.Routes |
78 | import Network.Tox.ContactInfo | 78 | import Network.Tox.ContactInfo |
79 | import Text.XXD | 79 | import 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. |
217 | getContactInfo :: Tox extra -> IO DHT.DHTPublicKey | 217 | getContactInfo :: Maybe (RelayClient,PublicKey) -> Tox extra -> IO DHT.DHTPublicKey |
218 | getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do | 218 | getContactInfo 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 | ||
238 | isLocalHost :: SockAddr -> Bool | 242 | isLocalHost :: SockAddr -> Bool |