diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index d94f028f..b775e7d3 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -116,6 +116,7 @@ import Data.Text as Text | |||
116 | import Text.PrettyPrint.HughesPJClass hiding ((<>),($$)) | 116 | import Text.PrettyPrint.HughesPJClass hiding ((<>),($$)) |
117 | import Data.Serialize as S | 117 | import Data.Serialize as S |
118 | import Network.DHT.Types | 118 | import Network.DHT.Types |
119 | import Network.DatagramServer.Types | ||
119 | 120 | ||
120 | 121 | ||
121 | import Data.Torrent as Torrent | 122 | import Data.Torrent as Torrent |
@@ -343,10 +344,12 @@ locFromCS cs = case getCallStack cs of | |||
343 | -- | Run DHT session. You /must/ properly close session using | 344 | -- | Run DHT session. You /must/ properly close session using |
344 | -- 'closeNode' function, otherwise socket or other scarce resources may | 345 | -- 'closeNode' function, otherwise socket or other scarce resources may |
345 | -- leak. | 346 | -- leak. |
346 | newNode :: ( Address ip | 347 | newNode :: forall raw dht ip u. |
348 | ( Address ip | ||
347 | , FiniteBits (NodeId dht) | 349 | , FiniteBits (NodeId dht) |
348 | , Serialize (NodeId dht) | 350 | , Serialize (NodeId dht) |
349 | , Kademlia dht | 351 | , Kademlia dht |
352 | , WireFormat raw dht | ||
350 | ) | 353 | ) |
351 | => -- [NodeHandler] -- ^ handlers to run on accepted queries; | 354 | => -- [NodeHandler] -- ^ handlers to run on accepted queries; |
352 | Options -- ^ various dht options; | 355 | Options -- ^ various dht options; |
@@ -363,13 +366,18 @@ newNode opts naddr logger mbid = do | |||
363 | nodeAddr = toSockAddr naddr | 366 | nodeAddr = toSockAddr naddr |
364 | initNode = do | 367 | initNode = do |
365 | s <- getInternalState | 368 | s <- getInternalState |
366 | (_, m) <- allocate (newManager rpcOpts (logt logger) nodeAddr []) closeManager | 369 | (myId, infovar, getst) <- liftIO $ do |
370 | (i, ctx) <- initializeServerState (Proxy :: Proxy (dht raw)) mbid | ||
371 | var <- atomically (newTVar Nothing) | ||
372 | let getst dest = do | ||
373 | info <- atomically . readTVar $ var | ||
374 | return ( maybe i myNodeId info, ctx) | ||
375 | return (i, var, getst) | ||
376 | (_, m) <- allocate (newManager rpcOpts (logt logger) nodeAddr getst []) closeManager | ||
367 | liftIO $ do | 377 | liftIO $ do |
368 | dta <- initializeDHTData | 378 | dta <- initializeDHTData |
369 | myId <- maybe genNodeId return mbid | 379 | node <- Node opts myId s m infovar |
370 | node <- Node opts myId s m | 380 | <$> newTVarIO S.empty |
371 | <$> atomically (newTVar Nothing) | ||
372 | <*> newTVarIO S.empty | ||
373 | <*> pure dta | 381 | <*> pure dta |
374 | <*> pure logger | 382 | <*> pure logger |
375 | return node | 383 | return node |