summaryrefslogtreecommitdiff
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
parent1abc8ec541f74abdbd12bb91298e54d898c5de4d (diff)
~ type synonims
-rw-r--r--network-bittorrent.cabal10
-rw-r--r--src/Network/Torrent/PeerID.hs1
-rw-r--r--src/Network/Torrent/THP.hs23
3 files changed, 22 insertions, 12 deletions
diff --git a/network-bittorrent.cabal b/network-bittorrent.cabal
index b99a6ebd..c8bcb955 100644
--- a/network-bittorrent.cabal
+++ b/network-bittorrent.cabal
@@ -18,11 +18,13 @@ source-repository head
18 18
19library 19library
20 exposed-modules: Data.Torrent 20 exposed-modules: Data.Torrent
21 , Network.Torrent
21 , Network.Torrent.THP 22 , Network.Torrent.THP
22 , Network.Torrent.PWP 23 , Network.Torrent.PWP
23 , Network.Torrent.PeerID 24 , Network.Torrent.PeerID
25 , Network.Torrent.Handshake
24 other-modules: 26 other-modules:
25 Network.Torrent.Handshake 27
26 28
27 build-depends: base == 4.5.* 29 build-depends: base == 4.5.*
28 30
@@ -55,9 +57,15 @@ executable client
55 main-is: client.hs 57 main-is: client.hs
56 build-depends: base == 4.5.* 58 build-depends: base == 4.5.*
57 , bytestring >= 0.10.2.0 59 , bytestring >= 0.10.2.0
60 , network >= 2.4.1.2
61 , text
62 , cereal
63 , mtl
64
58 , bencoding >= 0.1.0.0 65 , bencoding >= 0.1.0.0
59 , network-bittorrent >= 0.1.0.0 66 , network-bittorrent >= 0.1.0.0
60 67
68
61 hs-source-dirs: tests 69 hs-source-dirs: tests
62 ghc-options: -Wall -O2 70 ghc-options: -Wall -O2
63 71
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