diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-04-05 01:55:37 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-04-05 01:55:37 +0400 |
commit | 9418e61f941b3654f9d1d0bb44805cc9edfad15d (patch) | |
tree | 2caa5deb11ac5a5e3fffdc6c8fee6faf146fc309 /src | |
parent | a532ae52a00c053a59540e7041a4f132cfe34f0e (diff) |
add instance for bencode
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/Torrent/PeerID.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Network/Torrent/PeerID.hs b/src/Network/Torrent/PeerID.hs index 35c70c9d..ec87b470 100644 --- a/src/Network/Torrent/PeerID.hs +++ b/src/Network/Torrent/PeerID.hs | |||
@@ -1,9 +1,9 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving #-} |
2 | -- | Recommended method for generation of the peer ID's is 'newPeerID', | 2 | -- | Recommended method for generation of the peer ID's is 'newPeerID', |
3 | -- though this module exports some other goodies for custom generation. | 3 | -- though this module exports some other goodies for custom generation. |
4 | -- | 4 | -- |
5 | module Network.Torrent.PeerID | 5 | module Network.Torrent.PeerID |
6 | ( PeerID(PeerID, getPeerID) | 6 | ( PeerID (getPeerID) |
7 | -- * Encoding styles | 7 | -- * Encoding styles |
8 | , azureusStyle, shadowStyle | 8 | , azureusStyle, shadowStyle |
9 | -- * Defaults | 9 | -- * Defaults |
@@ -15,6 +15,7 @@ module Network.Torrent.PeerID | |||
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Control.Applicative | 17 | import Control.Applicative |
18 | import Data.BEncode | ||
18 | import Data.ByteString (ByteString) | 19 | import Data.ByteString (ByteString) |
19 | import qualified Data.ByteString as B | 20 | import qualified Data.ByteString as B |
20 | import qualified Data.ByteString.Char8 as BC | 21 | import qualified Data.ByteString.Char8 as BC |
@@ -22,17 +23,19 @@ import qualified Data.ByteString.Lazy as BL | |||
22 | import qualified Data.ByteString.Builder as B | 23 | import qualified Data.ByteString.Builder as B |
23 | import Data.Foldable (foldMap) | 24 | import Data.Foldable (foldMap) |
24 | import Data.Monoid ((<>)) | 25 | import Data.Monoid ((<>)) |
25 | import Data.Version (versionBranch) | 26 | import Data.Version (Version(Version), versionBranch) |
26 | import Data.Time.Clock (getCurrentTime) | 27 | import Data.Time.Clock (getCurrentTime) |
27 | import Data.Time.Format (formatTime) | 28 | import Data.Time.Format (formatTime) |
28 | import System.Locale (defaultTimeLocale) | 29 | import System.Locale (defaultTimeLocale) |
29 | 30 | ||
30 | import Paths_network_torrent (version) | 31 | -- TODO we have linker error here, so manual hardcoded version for a while. |
31 | 32 | --import Paths_network_bittorrent (version) | |
33 | version :: Version | ||
34 | version = Version [0, 10, 0, 0] [] | ||
32 | 35 | ||
33 | -- | Peer identifier is exactly 20 bytes long bytestring. | 36 | -- | Peer identifier is exactly 20 bytes long bytestring. |
34 | newtype PeerID = PeerID { getPeerID :: ByteString } | 37 | newtype PeerID = PeerID { getPeerID :: ByteString } |
35 | deriving (Show, Eq, Ord) | 38 | deriving (Show, Eq, Ord, BEncodable) |
36 | 39 | ||
37 | -- | Azureus-style encoding: | 40 | -- | Azureus-style encoding: |
38 | -- * 1 byte : '-' | 41 | -- * 1 byte : '-' |