summaryrefslogtreecommitdiff
path: root/src/Network/Torrent
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-05 01:55:37 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-05 01:55:37 +0400
commit9418e61f941b3654f9d1d0bb44805cc9edfad15d (patch)
tree2caa5deb11ac5a5e3fffdc6c8fee6faf146fc309 /src/Network/Torrent
parenta532ae52a00c053a59540e7041a4f132cfe34f0e (diff)
add instance for bencode
Diffstat (limited to 'src/Network/Torrent')
-rw-r--r--src/Network/Torrent/PeerID.hs15
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--
5module Network.Torrent.PeerID 5module 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
17import Control.Applicative 17import Control.Applicative
18import Data.BEncode
18import Data.ByteString (ByteString) 19import Data.ByteString (ByteString)
19import qualified Data.ByteString as B 20import qualified Data.ByteString as B
20import qualified Data.ByteString.Char8 as BC 21import qualified Data.ByteString.Char8 as BC
@@ -22,17 +23,19 @@ import qualified Data.ByteString.Lazy as BL
22import qualified Data.ByteString.Builder as B 23import qualified Data.ByteString.Builder as B
23import Data.Foldable (foldMap) 24import Data.Foldable (foldMap)
24import Data.Monoid ((<>)) 25import Data.Monoid ((<>))
25import Data.Version (versionBranch) 26import Data.Version (Version(Version), versionBranch)
26import Data.Time.Clock (getCurrentTime) 27import Data.Time.Clock (getCurrentTime)
27import Data.Time.Format (formatTime) 28import Data.Time.Format (formatTime)
28import System.Locale (defaultTimeLocale) 29import System.Locale (defaultTimeLocale)
29 30
30import 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)
33version :: Version
34version = 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.
34newtype PeerID = PeerID { getPeerID :: ByteString } 37newtype 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 : '-'