From 0b93032e3f7488681d5cb402cb5b4c9e566628b2 Mon Sep 17 00:00:00 2001 From: Sam T Date: Sun, 7 Apr 2013 04:15:47 +0400 Subject: ~ type synonims --- network-bittorrent.cabal | 10 +++++++++- src/Network/Torrent/PeerID.hs | 1 + src/Network/Torrent/THP.hs | 23 ++++++++++++----------- 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 library exposed-modules: Data.Torrent + , Network.Torrent , Network.Torrent.THP , Network.Torrent.PWP , Network.Torrent.PeerID + , Network.Torrent.Handshake other-modules: - Network.Torrent.Handshake + build-depends: base == 4.5.* @@ -55,9 +57,15 @@ executable client main-is: client.hs build-depends: base == 4.5.* , bytestring >= 0.10.2.0 + , network >= 2.4.1.2 + , text + , cereal + , mtl + , bencoding >= 0.1.0.0 , network-bittorrent >= 0.1.0.0 + hs-source-dirs: tests ghc-options: -Wall -O2 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 @@ {-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-} +-- TODO: tests -- | Recommended method for generation of the peer ID's is 'newPeerID', -- though this module exports some other goodies for custom generation. -- 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 @@ {-# LANGUAGE OverloadedStrings #-} module Network.Torrent.THP ( Peer(..), Event(..), TRequest(..), TResponse(..) - , sendRequest, defaultRequest + , defaultRequest, defaultPorts + , sendRequest ) where import Control.Applicative -import Data.Maybe -import Data.BEncode import Data.Char as Char -import Data.Monoid +import Data.Word (Word32) import Data.List as L import Data.Map as M +import Data.Monoid +import Data.BEncode import Data.ByteString as B -import qualified Data.ByteString.Lazy as Lazy import Data.ByteString.Char8 as BC -import qualified Data.ByteString.Builder as B -import qualified Data.ByteString.Builder.Prim as BP import Data.Text as T import Data.Serialize.Get hiding (Result) import Data.URLEncoded as URL import Network +import Network.Socket import Network.HTTP import Network.URI import Network.Torrent.PeerID import Numeric -type IP = Int type Hash = ByteString data Peer = Peer { peerID :: Maybe PeerID - , peerIP :: IP + , peerIP :: HostAddress , peerPort :: PortNumber } deriving Show @@ -51,7 +49,7 @@ data TRequest = TRequest { -- TODO peer here -- TODO detach announce , reqUploaded :: Int -- ^ # of bytes that the peer has uploaded in the swarm. , reqDownloaded :: Int -- ^ # of bytes downloaded in the swarm by the peer. , reqLeft :: Int -- ^ # of bytes needed in order to complete download. - , reqIP :: Maybe IP -- ^ The peer IP. + , reqIP :: Maybe HostAddress -- ^ The peer IP. , reqNumWant :: Maybe Int -- ^ Number of peers that the peers wants to receive from. , reqEvent :: Maybe Event -- ^ If not specified, -- the request is regular periodic request. @@ -130,6 +128,9 @@ instance URLShow PortNumber where instance URLShow PeerID where urlShow = BC.unpack . getPeerID +instance URLShow Word32 where + urlShow = show + instance URLShow Event where urlShow e = urlShow (Char.toLower x : xs) where @@ -183,7 +184,7 @@ defaultRequest announce hash pid = , reqDownloaded = 0 , reqLeft = 0 , reqIP = Nothing - , reqNumWant = Just 50 + , reqNumWant = Just 25 , reqEvent = Just Started } -- cgit v1.2.3