summaryrefslogtreecommitdiff
path: root/src/Network/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Torrent')
-rw-r--r--src/Network/Torrent/PeerID.hs1
-rw-r--r--src/Network/Torrent/THP.hs23
2 files changed, 13 insertions, 11 deletions
diff --git a/src/Network/Torrent/PeerID.hs b/src/Network/Torrent/PeerID.hs
index 5ca3ea42..551b0dcc 100644
--- a/src/Network/Torrent/PeerID.hs
+++ b/src/Network/Torrent/PeerID.hs
@@ -1,4 +1,5 @@
1{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-} 1{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-}
2-- TODO: tests
2-- | Recommended method for generation of the peer ID's is 'newPeerID', 3-- | Recommended method for generation of the peer ID's is 'newPeerID',
3-- though this module exports some other goodies for custom generation. 4-- though this module exports some other goodies for custom generation.
4-- 5--
diff --git a/src/Network/Torrent/THP.hs b/src/Network/Torrent/THP.hs
index e440d0f2..e584ead1 100644
--- a/src/Network/Torrent/THP.hs
+++ b/src/Network/Torrent/THP.hs
@@ -2,39 +2,37 @@
2{-# LANGUAGE OverloadedStrings #-} 2{-# LANGUAGE OverloadedStrings #-}
3module Network.Torrent.THP 3module Network.Torrent.THP
4 ( Peer(..), Event(..), TRequest(..), TResponse(..) 4 ( Peer(..), Event(..), TRequest(..), TResponse(..)
5 , sendRequest, defaultRequest 5 , defaultRequest, defaultPorts
6 , sendRequest
6 ) 7 )
7 where 8 where
8 9
9import Control.Applicative 10import Control.Applicative
10import Data.Maybe
11import Data.BEncode
12import Data.Char as Char 11import Data.Char as Char
13import Data.Monoid 12import Data.Word (Word32)
14import Data.List as L 13import Data.List as L
15import Data.Map as M 14import Data.Map as M
15import Data.Monoid
16import Data.BEncode
16import Data.ByteString as B 17import Data.ByteString as B
17import qualified Data.ByteString.Lazy as Lazy
18import Data.ByteString.Char8 as BC 18import Data.ByteString.Char8 as BC
19import qualified Data.ByteString.Builder as B
20import qualified Data.ByteString.Builder.Prim as BP
21import Data.Text as T 19import Data.Text as T
22import Data.Serialize.Get hiding (Result) 20import Data.Serialize.Get hiding (Result)
23import Data.URLEncoded as URL 21import Data.URLEncoded as URL
24 22
25import Network 23import Network
24import Network.Socket
26import Network.HTTP 25import Network.HTTP
27import Network.URI 26import Network.URI
28import Network.Torrent.PeerID 27import Network.Torrent.PeerID
29 28
30import Numeric 29import Numeric
31 30
32type IP = Int
33type Hash = ByteString 31type Hash = ByteString
34 32
35data Peer = Peer { 33data Peer = Peer {
36 peerID :: Maybe PeerID 34 peerID :: Maybe PeerID
37 , peerIP :: IP 35 , peerIP :: HostAddress
38 , peerPort :: PortNumber 36 , peerPort :: PortNumber
39 } deriving Show 37 } deriving Show
40 38
@@ -51,7 +49,7 @@ data TRequest = TRequest { -- TODO peer here -- TODO detach announce
51 , reqUploaded :: Int -- ^ # of bytes that the peer has uploaded in the swarm. 49 , reqUploaded :: Int -- ^ # of bytes that the peer has uploaded in the swarm.
52 , reqDownloaded :: Int -- ^ # of bytes downloaded in the swarm by the peer. 50 , reqDownloaded :: Int -- ^ # of bytes downloaded in the swarm by the peer.
53 , reqLeft :: Int -- ^ # of bytes needed in order to complete download. 51 , reqLeft :: Int -- ^ # of bytes needed in order to complete download.
54 , reqIP :: Maybe IP -- ^ The peer IP. 52 , reqIP :: Maybe HostAddress -- ^ The peer IP.
55 , reqNumWant :: Maybe Int -- ^ Number of peers that the peers wants to receive from. 53 , reqNumWant :: Maybe Int -- ^ Number of peers that the peers wants to receive from.
56 , reqEvent :: Maybe Event -- ^ If not specified, 54 , reqEvent :: Maybe Event -- ^ If not specified,
57 -- the request is regular periodic request. 55 -- the request is regular periodic request.
@@ -130,6 +128,9 @@ instance URLShow PortNumber where
130instance URLShow PeerID where 128instance URLShow PeerID where
131 urlShow = BC.unpack . getPeerID 129 urlShow = BC.unpack . getPeerID
132 130
131instance URLShow Word32 where
132 urlShow = show
133
133instance URLShow Event where 134instance URLShow Event where
134 urlShow e = urlShow (Char.toLower x : xs) 135 urlShow e = urlShow (Char.toLower x : xs)
135 where 136 where
@@ -183,7 +184,7 @@ defaultRequest announce hash pid =
183 , reqDownloaded = 0 184 , reqDownloaded = 0
184 , reqLeft = 0 185 , reqLeft = 0
185 , reqIP = Nothing 186 , reqIP = Nothing
186 , reqNumWant = Just 50 187 , reqNumWant = Just 25
187 , reqEvent = Just Started 188 , reqEvent = Just Started
188 } 189 }
189 190