diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Protocol.hs | 8 | ||||
-rw-r--r-- | src/Network/BitTorrent/Internal.hs | 12 | ||||
-rw-r--r-- | src/Network/BitTorrent/Peer.hs | 44 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker.hs | 6 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Protocol.hs | 4 |
5 files changed, 37 insertions, 37 deletions
diff --git a/src/Network/BitTorrent/Exchange/Protocol.hs b/src/Network/BitTorrent/Exchange/Protocol.hs index feccf760..073dad58 100644 --- a/src/Network/BitTorrent/Exchange/Protocol.hs +++ b/src/Network/BitTorrent/Exchange/Protocol.hs | |||
@@ -116,7 +116,7 @@ data Handshake = Handshake { | |||
116 | -- | Peer id of the initiator. This is usually the same peer id | 116 | -- | Peer id of the initiator. This is usually the same peer id |
117 | -- that is transmitted in tracker requests. | 117 | -- that is transmitted in tracker requests. |
118 | -- | 118 | -- |
119 | , hsPeerID :: PeerID | 119 | , hsPeerId :: PeerId |
120 | 120 | ||
121 | } deriving (Show, Eq) | 121 | } deriving (Show, Eq) |
122 | 122 | ||
@@ -126,7 +126,7 @@ instance Serialize Handshake where | |||
126 | S.putByteString (hsProtocol hs) | 126 | S.putByteString (hsProtocol hs) |
127 | S.putWord64be (hsReserved hs) | 127 | S.putWord64be (hsReserved hs) |
128 | S.put (hsInfoHash hs) | 128 | S.put (hsInfoHash hs) |
129 | S.put (hsPeerID hs) | 129 | S.put (hsPeerId hs) |
130 | 130 | ||
131 | get = do | 131 | get = do |
132 | len <- S.getWord8 | 132 | len <- S.getWord8 |
@@ -142,7 +142,7 @@ handshakeCaps = hsReserved | |||
142 | -- | Format handshake in human readable form. | 142 | -- | Format handshake in human readable form. |
143 | ppHandshake :: Handshake -> Doc | 143 | ppHandshake :: Handshake -> Doc |
144 | ppHandshake Handshake {..} = | 144 | ppHandshake Handshake {..} = |
145 | text (BC.unpack hsProtocol) <+> ppClientInfo (clientInfo hsPeerID) | 145 | text (BC.unpack hsProtocol) <+> ppClientInfo (clientInfo hsPeerId) |
146 | 146 | ||
147 | -- | Get handshake message size in bytes from the length of protocol | 147 | -- | Get handshake message size in bytes from the length of protocol |
148 | -- string. | 148 | -- string. |
@@ -163,7 +163,7 @@ defaultReserved = 0 | |||
163 | 163 | ||
164 | -- | Length of info hash and peer id is unchecked, so it /should/ be | 164 | -- | Length of info hash and peer id is unchecked, so it /should/ be |
165 | -- equal 20. | 165 | -- equal 20. |
166 | defaultHandshake :: InfoHash -> PeerID -> Handshake | 166 | defaultHandshake :: InfoHash -> PeerId -> Handshake |
167 | defaultHandshake = Handshake defaultBTProtocol defaultReserved | 167 | defaultHandshake = Handshake defaultBTProtocol defaultReserved |
168 | 168 | ||
169 | -- | Handshaking with a peer specified by the second argument. | 169 | -- | Handshaking with a peer specified by the second argument. |
diff --git a/src/Network/BitTorrent/Internal.hs b/src/Network/BitTorrent/Internal.hs index 5a7e493f..bd20aa16 100644 --- a/src/Network/BitTorrent/Internal.hs +++ b/src/Network/BitTorrent/Internal.hs | |||
@@ -22,7 +22,7 @@ module Network.BitTorrent.Internal | |||
22 | ( Progress(..), startProgress | 22 | ( Progress(..), startProgress |
23 | 23 | ||
24 | -- * Client | 24 | -- * Client |
25 | , ClientSession (clientPeerID, allowedExtensions) | 25 | , ClientSession (clientPeerId, allowedExtensions) |
26 | 26 | ||
27 | , ThreadCount | 27 | , ThreadCount |
28 | , defaultThreadCount | 28 | , defaultThreadCount |
@@ -206,7 +206,7 @@ it should contain the all client identification info. (e.g. DHT) -} | |||
206 | -- | 206 | -- |
207 | data ClientSession = ClientSession { | 207 | data ClientSession = ClientSession { |
208 | -- | Used in handshakes and discovery mechanism. | 208 | -- | Used in handshakes and discovery mechanism. |
209 | clientPeerID :: !PeerID | 209 | clientPeerId :: !PeerId |
210 | 210 | ||
211 | -- | Extensions we should try to use. Hovewer some particular peer | 211 | -- | Extensions we should try to use. Hovewer some particular peer |
212 | -- might not support some extension, so we keep enabledExtension in | 212 | -- might not support some extension, so we keep enabledExtension in |
@@ -232,10 +232,10 @@ data ClientSession = ClientSession { | |||
232 | -- maybe we can remove the 'currentProgress' and compute it on demand? | 232 | -- maybe we can remove the 'currentProgress' and compute it on demand? |
233 | 233 | ||
234 | instance Eq ClientSession where | 234 | instance Eq ClientSession where |
235 | (==) = (==) `on` clientPeerID | 235 | (==) = (==) `on` clientPeerId |
236 | 236 | ||
237 | instance Ord ClientSession where | 237 | instance Ord ClientSession where |
238 | compare = comparing clientPeerID | 238 | compare = comparing clientPeerId |
239 | 239 | ||
240 | -- | Get current global progress of the client. This value is usually | 240 | -- | Get current global progress of the client. This value is usually |
241 | -- shown to a user. | 241 | -- shown to a user. |
@@ -265,7 +265,7 @@ newClient n exts = do | |||
265 | _ <- forkIO $ loop mgr | 265 | _ <- forkIO $ loop mgr |
266 | 266 | ||
267 | ClientSession | 267 | ClientSession |
268 | <$> newPeerID | 268 | <$> newPeerId |
269 | <*> pure exts | 269 | <*> pure exts |
270 | <*> MSem.new n | 270 | <*> MSem.new n |
271 | <*> pure n | 271 | <*> pure n |
@@ -487,7 +487,7 @@ withPeerSession ss @ SwarmSession {..} addr | |||
487 | openSession = do | 487 | openSession = do |
488 | let caps = encodeExts $ allowedExtensions $ clientSession | 488 | let caps = encodeExts $ allowedExtensions $ clientSession |
489 | let ihash = tInfoHash torrentMeta | 489 | let ihash = tInfoHash torrentMeta |
490 | let pid = clientPeerID $ clientSession | 490 | let pid = clientPeerId $ clientSession |
491 | let chs = Handshake defaultBTProtocol caps ihash pid | 491 | let chs = Handshake defaultBTProtocol caps ihash pid |
492 | 492 | ||
493 | sock <- connectToPeer addr | 493 | sock <- connectToPeer addr |
diff --git a/src/Network/BitTorrent/Peer.hs b/src/Network/BitTorrent/Peer.hs index 80f47eac..68771052 100644 --- a/src/Network/BitTorrent/Peer.hs +++ b/src/Network/BitTorrent/Peer.hs | |||
@@ -34,16 +34,16 @@ | |||
34 | {-# OPTIONS -fno-warn-orphans #-} | 34 | {-# OPTIONS -fno-warn-orphans #-} |
35 | module Network.BitTorrent.Peer | 35 | module Network.BitTorrent.Peer |
36 | ( -- * Peer identificators | 36 | ( -- * Peer identificators |
37 | PeerID (getPeerID), ppPeerID | 37 | PeerId (getPeerId), ppPeerId |
38 | 38 | ||
39 | -- ** Encoding styles | 39 | -- ** Encoding styles |
40 | , azureusStyle, shadowStyle | 40 | , azureusStyle, shadowStyle |
41 | 41 | ||
42 | -- ** Defaults | 42 | -- ** Defaults |
43 | , defaultClientID, defaultVersionNumber | 43 | , defaultClientId, defaultVersionNumber |
44 | 44 | ||
45 | -- ** Generation | 45 | -- ** Generation |
46 | , newPeerID, timestampByteString | 46 | , newPeerId, timestampByteString |
47 | 47 | ||
48 | -- ** Extra | 48 | -- ** Extra |
49 | , byteStringPadded | 49 | , byteStringPadded |
@@ -104,19 +104,19 @@ version = Version [0, 10, 0, 0] [] | |||
104 | -----------------------------------------------------------------------} | 104 | -----------------------------------------------------------------------} |
105 | 105 | ||
106 | -- | Peer identifier is exactly 20 bytes long bytestring. | 106 | -- | Peer identifier is exactly 20 bytes long bytestring. |
107 | newtype PeerID = PeerID { getPeerID :: ByteString } | 107 | newtype PeerId = PeerId { getPeerId :: ByteString } |
108 | deriving (Show, Eq, Ord, BEncodable) | 108 | deriving (Show, Eq, Ord, BEncodable) |
109 | 109 | ||
110 | instance Serialize PeerID where | 110 | instance Serialize PeerId where |
111 | put = putByteString . getPeerID | 111 | put = putByteString . getPeerId |
112 | get = PeerID <$> getBytes 20 | 112 | get = PeerId <$> getBytes 20 |
113 | 113 | ||
114 | instance URLShow PeerID where | 114 | instance URLShow PeerId where |
115 | urlShow = BC.unpack . getPeerID | 115 | urlShow = BC.unpack . getPeerId |
116 | 116 | ||
117 | -- | Format peer id in human readable form. | 117 | -- | Format peer id in human readable form. |
118 | ppPeerID :: PeerID -> Doc | 118 | ppPeerId :: PeerId -> Doc |
119 | ppPeerID = text . BC.unpack . getPeerID | 119 | ppPeerId = text . BC.unpack . getPeerId |
120 | 120 | ||
121 | 121 | ||
122 | -- | Azureus-style encoding have the following layout: | 122 | -- | Azureus-style encoding have the following layout: |
@@ -134,8 +134,8 @@ ppPeerID = text . BC.unpack . getPeerID | |||
134 | azureusStyle :: ByteString -- ^ 2 character client ID, padded with 'H'. | 134 | azureusStyle :: ByteString -- ^ 2 character client ID, padded with 'H'. |
135 | -> ByteString -- ^ Version number, padded with 'X'. | 135 | -> ByteString -- ^ Version number, padded with 'X'. |
136 | -> ByteString -- ^ Random number, padded with '0'. | 136 | -> ByteString -- ^ Random number, padded with '0'. |
137 | -> PeerID -- ^ Azureus-style encoded peer ID. | 137 | -> PeerId -- ^ Azureus-style encoded peer ID. |
138 | azureusStyle cid ver rnd = PeerID $ BL.toStrict $ B.toLazyByteString $ | 138 | azureusStyle cid ver rnd = PeerId $ BL.toStrict $ B.toLazyByteString $ |
139 | B.char8 '-' <> | 139 | B.char8 '-' <> |
140 | byteStringPadded cid 2 'H' <> | 140 | byteStringPadded cid 2 'H' <> |
141 | byteStringPadded ver 4 'X' <> | 141 | byteStringPadded ver 4 'X' <> |
@@ -155,16 +155,16 @@ azureusStyle cid ver rnd = PeerID $ BL.toStrict $ B.toLazyByteString $ | |||
155 | shadowStyle :: Char -- ^ Client ID. | 155 | shadowStyle :: Char -- ^ Client ID. |
156 | -> ByteString -- ^ Version number. | 156 | -> ByteString -- ^ Version number. |
157 | -> ByteString -- ^ Random number. | 157 | -> ByteString -- ^ Random number. |
158 | -> PeerID -- ^ Shadow style encoded peer ID. | 158 | -> PeerId -- ^ Shadow style encoded peer ID. |
159 | shadowStyle cid ver rnd = PeerID $ BL.toStrict $ B.toLazyByteString $ | 159 | shadowStyle cid ver rnd = PeerId $ BL.toStrict $ B.toLazyByteString $ |
160 | B.char8 cid <> | 160 | B.char8 cid <> |
161 | byteStringPadded ver 4 '-' <> | 161 | byteStringPadded ver 4 '-' <> |
162 | byteStringPadded rnd 15 '0' | 162 | byteStringPadded rnd 15 '0' |
163 | 163 | ||
164 | 164 | ||
165 | -- | "HS" - 2 bytes long client identifier. | 165 | -- | "HS" - 2 bytes long client identifier. |
166 | defaultClientID :: ByteString | 166 | defaultClientId :: ByteString |
167 | defaultClientID = "HS" | 167 | defaultClientId = "HS" |
168 | 168 | ||
169 | -- | Gives exactly 4 bytes long version number for any version of the | 169 | -- | Gives exactly 4 bytes long version number for any version of the |
170 | -- package. Version is taken from .cabal. | 170 | -- package. Version is taken from .cabal. |
@@ -199,8 +199,8 @@ timestampByteString = (BC.pack . format) <$> getCurrentTime | |||
199 | -- | 199 | -- |
200 | -- * UTC time day ++ day time for the random number. | 200 | -- * UTC time day ++ day time for the random number. |
201 | -- | 201 | -- |
202 | newPeerID :: IO PeerID | 202 | newPeerId :: IO PeerId |
203 | newPeerID = azureusStyle defaultClientID defaultVersionNumber | 203 | newPeerId = azureusStyle defaultClientId defaultVersionNumber |
204 | <$> timestampByteString | 204 | <$> timestampByteString |
205 | 205 | ||
206 | -- | Pad bytestring so it's becomes exactly request length. Conversion | 206 | -- | Pad bytestring so it's becomes exactly request length. Conversion |
@@ -398,9 +398,9 @@ unknownClient = ClientInfo unknownImpl unknownVersion | |||
398 | -- peer id uses unknown coding style then client info returned is | 398 | -- peer id uses unknown coding style then client info returned is |
399 | -- 'unknownClient'. | 399 | -- 'unknownClient'. |
400 | -- | 400 | -- |
401 | clientInfo :: PeerID -> ClientInfo | 401 | clientInfo :: PeerId -> ClientInfo |
402 | clientInfo pid = either (const unknownClient) id $ | 402 | clientInfo pid = either (const unknownClient) id $ |
403 | runGet getCI (getPeerID pid) | 403 | runGet getCI (getPeerId pid) |
404 | where -- TODO other styles | 404 | where -- TODO other styles |
405 | getCI = do | 405 | getCI = do |
406 | _ <- getWord8 | 406 | _ <- getWord8 |
@@ -489,7 +489,7 @@ nameMap = | |||
489 | -- | Peer address info normally extracted from peer list or peer | 489 | -- | Peer address info normally extracted from peer list or peer |
490 | -- compact list encoding. | 490 | -- compact list encoding. |
491 | data PeerAddr = PeerAddr { | 491 | data PeerAddr = PeerAddr { |
492 | peerID :: Maybe PeerID | 492 | peerID :: Maybe PeerId |
493 | , peerIP :: HostAddress | 493 | , peerIP :: HostAddress |
494 | , peerPort :: PortNumber | 494 | , peerPort :: PortNumber |
495 | } deriving (Show, Eq, Ord) | 495 | } deriving (Show, Eq, Ord) |
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs index ed3f1d78..f7d88bd9 100644 --- a/src/Network/BitTorrent/Tracker.hs +++ b/src/Network/BitTorrent/Tracker.hs | |||
@@ -79,11 +79,11 @@ import Network.BitTorrent.Tracker.Protocol | |||
79 | data TConnection = TConnection { | 79 | data TConnection = TConnection { |
80 | tconnAnnounce :: URI -- ^ Announce URL. | 80 | tconnAnnounce :: URI -- ^ Announce URL. |
81 | , tconnInfoHash :: InfoHash -- ^ Hash of info part of current .torrent file. | 81 | , tconnInfoHash :: InfoHash -- ^ Hash of info part of current .torrent file. |
82 | , tconnPeerID :: PeerID -- ^ Client peer ID. | 82 | , tconnPeerId :: PeerId -- ^ Client peer ID. |
83 | , tconnPort :: PortNumber -- ^ The port number the client is listenning on. | 83 | , tconnPort :: PortNumber -- ^ The port number the client is listenning on. |
84 | } deriving Show | 84 | } deriving Show |
85 | 85 | ||
86 | tconnection :: Torrent -> PeerID -> PortNumber -> TConnection | 86 | tconnection :: Torrent -> PeerId -> PortNumber -> TConnection |
87 | tconnection t = TConnection (tAnnounce t) (tInfoHash t) | 87 | tconnection t = TConnection (tAnnounce t) (tInfoHash t) |
88 | 88 | ||
89 | 89 | ||
@@ -92,7 +92,7 @@ genericReq :: TConnection -> Progress -> TRequest | |||
92 | genericReq ses pr = TRequest { | 92 | genericReq ses pr = TRequest { |
93 | reqAnnounce = tconnAnnounce ses | 93 | reqAnnounce = tconnAnnounce ses |
94 | , reqInfoHash = tconnInfoHash ses | 94 | , reqInfoHash = tconnInfoHash ses |
95 | , reqPeerID = tconnPeerID ses | 95 | , reqPeerId = tconnPeerId ses |
96 | , reqPort = tconnPort ses | 96 | , reqPort = tconnPort ses |
97 | 97 | ||
98 | , reqUploaded = _uploaded pr | 98 | , reqUploaded = _uploaded pr |
diff --git a/src/Network/BitTorrent/Tracker/Protocol.hs b/src/Network/BitTorrent/Tracker/Protocol.hs index d4f3da3c..52eb6c92 100644 --- a/src/Network/BitTorrent/Tracker/Protocol.hs +++ b/src/Network/BitTorrent/Tracker/Protocol.hs | |||
@@ -74,7 +74,7 @@ data TRequest = TRequest { -- TODO peer here -- TODO detach announce | |||
74 | -- ^ Hash of info part of the torrent usually obtained from | 74 | -- ^ Hash of info part of the torrent usually obtained from |
75 | -- 'Torrent'. | 75 | -- 'Torrent'. |
76 | 76 | ||
77 | , reqPeerID :: !PeerID | 77 | , reqPeerId :: !PeerId |
78 | -- ^ ID of the peer doing request. | 78 | -- ^ ID of the peer doing request. |
79 | 79 | ||
80 | , reqPort :: !PortNumber | 80 | , reqPort :: !PortNumber |
@@ -186,7 +186,7 @@ instance URLShow Event where | |||
186 | 186 | ||
187 | instance URLEncode TRequest where | 187 | instance URLEncode TRequest where |
188 | urlEncode req = mconcat | 188 | urlEncode req = mconcat |
189 | [ s "peer_id" %= reqPeerID req | 189 | [ s "peer_id" %= reqPeerId req |
190 | , s "port" %= reqPort req | 190 | , s "port" %= reqPort req |
191 | , s "uploaded" %= reqUploaded req | 191 | , s "uploaded" %= reqUploaded req |
192 | , s "downloaded" %= reqDownloaded req | 192 | , s "downloaded" %= reqDownloaded req |