summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs21
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs6
2 files changed, 25 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs
index a1934014..e1104cb9 100644
--- a/src/Network/BitTorrent/DHT/Query.hs
+++ b/src/Network/BitTorrent/DHT/Query.hs
@@ -72,7 +72,6 @@ import Data.Either
72import Data.List as L 72import Data.List as L
73import Data.Monoid 73import Data.Monoid
74import Data.Text as T 74import Data.Text as T
75import Data.BEncode (BValue)
76import qualified Data.Set as Set 75import qualified Data.Set as Set
77 ;import Data.Set (Set) 76 ;import Data.Set (Set)
78import Network 77import Network
@@ -85,13 +84,20 @@ import Network.KRPC hiding (Options, def)
85import Network.KRPC.Message (ReflectedIP(..)) 84import Network.KRPC.Message (ReflectedIP(..))
86import Network.KRPC.Manager (QueryFailure(..)) 85import Network.KRPC.Manager (QueryFailure(..))
87import Data.Torrent 86import Data.Torrent
88import Network.BitTorrent.Address
89import Network.BitTorrent.DHT.Message 87import Network.BitTorrent.DHT.Message
90import Network.BitTorrent.DHT.Routing as R 88import Network.BitTorrent.DHT.Routing as R
91import Network.BitTorrent.DHT.Session 89import Network.BitTorrent.DHT.Session
92import Control.Concurrent.STM 90import Control.Concurrent.STM
93import qualified Network.BitTorrent.DHT.Search as Search 91import qualified Network.BitTorrent.DHT.Search as Search
92#ifdef VERSION_bencoding
93import Network.BitTorrent.Address
94import Data.BEncode (BValue)
94import Network.DHT.Mainline 95import Network.DHT.Mainline
96#else
97import Network.BitTorrent.Address hiding (NodeId)
98import Data.ByteString (ByteString)
99import Data.Tox
100#endif
95 101
96{----------------------------------------------------------------------- 102{-----------------------------------------------------------------------
97-- Handlers 103-- Handlers
@@ -99,12 +105,23 @@ import Network.DHT.Mainline
99 105
100nodeHandler :: ( Address ip 106nodeHandler :: ( Address ip
101 , KRPC (Query a) (Response b) 107 , KRPC (Query a) (Response b)
108#ifdef VERSION_bencoding
102 , Envelope (Query a) (Response b) ~ BValue ) 109 , Envelope (Query a) (Response b) ~ BValue )
110#else
111 , Envelope (Query a) (Response b) ~ ByteString )
112#endif
103 => (NodeAddr ip -> a -> DHT ip b) -> NodeHandler ip 113 => (NodeAddr ip -> a -> DHT ip b) -> NodeHandler ip
114#ifdef VERSION_bencoding
104nodeHandler action = handler mainline $ \ sockAddr qry -> do 115nodeHandler action = handler mainline $ \ sockAddr qry -> do
105 let remoteId = queringNodeId qry 116 let remoteId = queringNodeId qry
106 read_only = queryIsReadOnly qry 117 read_only = queryIsReadOnly qry
107 q = queryParams qry 118 q = queryParams qry
119#else
120nodeHandler action = handler (error "TODO TOX Messaging") $ \ sockAddr qry -> do
121 let remoteId = msgClient qry
122 read_only = False
123 q = msgPayload qry
124#endif
108 case fromSockAddr sockAddr of 125 case fromSockAddr sockAddr of
109 Nothing -> throwIO BadAddress 126 Nothing -> throwIO BadAddress
110 Just naddr -> do 127 Just naddr -> do
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index db8e7cff..20dba595 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -107,7 +107,9 @@ import Data.Torrent as Torrent
107import Network.KRPC as KRPC hiding (Options, def) 107import Network.KRPC as KRPC hiding (Options, def)
108import qualified Network.KRPC as KRPC (def) 108import qualified Network.KRPC as KRPC (def)
109import Network.KRPC.Message (KMessageOf) 109import Network.KRPC.Message (KMessageOf)
110#ifdef VERSION_bencoding
110import Data.BEncode (BValue) 111import Data.BEncode (BValue)
112#endif
111import Network.BitTorrent.Address 113import Network.BitTorrent.Address
112import Network.BitTorrent.DHT.ContactInfo (PeerStore) 114import Network.BitTorrent.DHT.ContactInfo (PeerStore)
113import qualified Network.BitTorrent.DHT.ContactInfo as P 115import qualified Network.BitTorrent.DHT.ContactInfo as P
@@ -314,7 +316,11 @@ instance MonadLogger (DHT ip) where
314 logger <- asks loggerFun 316 logger <- asks loggerFun
315 liftIO $ logger loc src lvl (toLogStr msg) 317 liftIO $ logger loc src lvl (toLogStr msg)
316 318
319#ifdef VERSION_bencoding
317type NodeHandler ip = Handler (DHT ip) KMessageOf BValue 320type NodeHandler ip = Handler (DHT ip) KMessageOf BValue
321#else
322type NodeHandler ip = Handler (DHT ip) KMessageOf ByteString
323#endif
318 324
319-- | Run DHT session. You /must/ properly close session using 325-- | Run DHT session. You /must/ properly close session using
320-- 'closeNode' function, otherwise socket or other scarce resources may 326-- 'closeNode' function, otherwise socket or other scarce resources may