summaryrefslogtreecommitdiff
path: root/src/Network/Torrent/THP.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-07 04:15:47 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-07 04:15:47 +0400
commit0b93032e3f7488681d5cb402cb5b4c9e566628b2 (patch)
tree2cfcc47075a6e59623d4e5cd8d993ca3ca437cf9 /src/Network/Torrent/THP.hs
parent1abc8ec541f74abdbd12bb91298e54d898c5de4d (diff)
~ type synonims
Diffstat (limited to 'src/Network/Torrent/THP.hs')
-rw-r--r--src/Network/Torrent/THP.hs23
1 files changed, 12 insertions, 11 deletions
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