diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT/Query.hs | 21 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 6 |
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 | |||
72 | import Data.List as L | 72 | import Data.List as L |
73 | import Data.Monoid | 73 | import Data.Monoid |
74 | import Data.Text as T | 74 | import Data.Text as T |
75 | import Data.BEncode (BValue) | ||
76 | import qualified Data.Set as Set | 75 | import qualified Data.Set as Set |
77 | ;import Data.Set (Set) | 76 | ;import Data.Set (Set) |
78 | import Network | 77 | import Network |
@@ -85,13 +84,20 @@ import Network.KRPC hiding (Options, def) | |||
85 | import Network.KRPC.Message (ReflectedIP(..)) | 84 | import Network.KRPC.Message (ReflectedIP(..)) |
86 | import Network.KRPC.Manager (QueryFailure(..)) | 85 | import Network.KRPC.Manager (QueryFailure(..)) |
87 | import Data.Torrent | 86 | import Data.Torrent |
88 | import Network.BitTorrent.Address | ||
89 | import Network.BitTorrent.DHT.Message | 87 | import Network.BitTorrent.DHT.Message |
90 | import Network.BitTorrent.DHT.Routing as R | 88 | import Network.BitTorrent.DHT.Routing as R |
91 | import Network.BitTorrent.DHT.Session | 89 | import Network.BitTorrent.DHT.Session |
92 | import Control.Concurrent.STM | 90 | import Control.Concurrent.STM |
93 | import qualified Network.BitTorrent.DHT.Search as Search | 91 | import qualified Network.BitTorrent.DHT.Search as Search |
92 | #ifdef VERSION_bencoding | ||
93 | import Network.BitTorrent.Address | ||
94 | import Data.BEncode (BValue) | ||
94 | import Network.DHT.Mainline | 95 | import Network.DHT.Mainline |
96 | #else | ||
97 | import Network.BitTorrent.Address hiding (NodeId) | ||
98 | import Data.ByteString (ByteString) | ||
99 | import Data.Tox | ||
100 | #endif | ||
95 | 101 | ||
96 | {----------------------------------------------------------------------- | 102 | {----------------------------------------------------------------------- |
97 | -- Handlers | 103 | -- Handlers |
@@ -99,12 +105,23 @@ import Network.DHT.Mainline | |||
99 | 105 | ||
100 | nodeHandler :: ( Address ip | 106 | nodeHandler :: ( 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 | ||
104 | nodeHandler action = handler mainline $ \ sockAddr qry -> do | 115 | nodeHandler 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 | ||
120 | nodeHandler 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 | |||
107 | import Network.KRPC as KRPC hiding (Options, def) | 107 | import Network.KRPC as KRPC hiding (Options, def) |
108 | import qualified Network.KRPC as KRPC (def) | 108 | import qualified Network.KRPC as KRPC (def) |
109 | import Network.KRPC.Message (KMessageOf) | 109 | import Network.KRPC.Message (KMessageOf) |
110 | #ifdef VERSION_bencoding | ||
110 | import Data.BEncode (BValue) | 111 | import Data.BEncode (BValue) |
112 | #endif | ||
111 | import Network.BitTorrent.Address | 113 | import Network.BitTorrent.Address |
112 | import Network.BitTorrent.DHT.ContactInfo (PeerStore) | 114 | import Network.BitTorrent.DHT.ContactInfo (PeerStore) |
113 | import qualified Network.BitTorrent.DHT.ContactInfo as P | 115 | import 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 | ||
317 | type NodeHandler ip = Handler (DHT ip) KMessageOf BValue | 320 | type NodeHandler ip = Handler (DHT ip) KMessageOf BValue |
321 | #else | ||
322 | type 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 |