diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-04-07 04:15:47 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-04-07 04:15:47 +0400 |
commit | 0b93032e3f7488681d5cb402cb5b4c9e566628b2 (patch) | |
tree | 2cfcc47075a6e59623d4e5cd8d993ca3ca437cf9 /src/Network/Torrent/THP.hs | |
parent | 1abc8ec541f74abdbd12bb91298e54d898c5de4d (diff) |
~ type synonims
Diffstat (limited to 'src/Network/Torrent/THP.hs')
-rw-r--r-- | src/Network/Torrent/THP.hs | 23 |
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 #-} |
3 | module Network.Torrent.THP | 3 | module 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 | ||
9 | import Control.Applicative | 10 | import Control.Applicative |
10 | import Data.Maybe | ||
11 | import Data.BEncode | ||
12 | import Data.Char as Char | 11 | import Data.Char as Char |
13 | import Data.Monoid | 12 | import Data.Word (Word32) |
14 | import Data.List as L | 13 | import Data.List as L |
15 | import Data.Map as M | 14 | import Data.Map as M |
15 | import Data.Monoid | ||
16 | import Data.BEncode | ||
16 | import Data.ByteString as B | 17 | import Data.ByteString as B |
17 | import qualified Data.ByteString.Lazy as Lazy | ||
18 | import Data.ByteString.Char8 as BC | 18 | import Data.ByteString.Char8 as BC |
19 | import qualified Data.ByteString.Builder as B | ||
20 | import qualified Data.ByteString.Builder.Prim as BP | ||
21 | import Data.Text as T | 19 | import Data.Text as T |
22 | import Data.Serialize.Get hiding (Result) | 20 | import Data.Serialize.Get hiding (Result) |
23 | import Data.URLEncoded as URL | 21 | import Data.URLEncoded as URL |
24 | 22 | ||
25 | import Network | 23 | import Network |
24 | import Network.Socket | ||
26 | import Network.HTTP | 25 | import Network.HTTP |
27 | import Network.URI | 26 | import Network.URI |
28 | import Network.Torrent.PeerID | 27 | import Network.Torrent.PeerID |
29 | 28 | ||
30 | import Numeric | 29 | import Numeric |
31 | 30 | ||
32 | type IP = Int | ||
33 | type Hash = ByteString | 31 | type Hash = ByteString |
34 | 32 | ||
35 | data Peer = Peer { | 33 | data 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 | |||
130 | instance URLShow PeerID where | 128 | instance URLShow PeerID where |
131 | urlShow = BC.unpack . getPeerID | 129 | urlShow = BC.unpack . getPeerID |
132 | 130 | ||
131 | instance URLShow Word32 where | ||
132 | urlShow = show | ||
133 | |||
133 | instance URLShow Event where | 134 | instance 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 | ||