summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core/PeerId.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Core/PeerId.hs')
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index 1ae55913..8883656b 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -49,6 +49,7 @@ import Data.List as L
49import Data.Maybe (fromMaybe) 49import Data.Maybe (fromMaybe)
50import Data.Monoid 50import Data.Monoid
51import Data.Serialize as S 51import Data.Serialize as S
52import Data.String
52import Data.Time.Clock (getCurrentTime) 53import Data.Time.Clock (getCurrentTime)
53import Data.Time.Format (formatTime) 54import Data.Time.Format (formatTime)
54import Data.URLEncoded 55import Data.URLEncoded
@@ -74,6 +75,14 @@ instance Serialize PeerId where
74instance URLShow PeerId where 75instance URLShow PeerId where
75 urlShow = BC.unpack . getPeerId 76 urlShow = BC.unpack . getPeerId
76 77
78instance IsString PeerId where
79 fromString str
80 | BS.length bs == 20 = PeerId bs
81 | otherwise = error $ "Peer id should be 20 bytes long: "
82 ++ show str
83 where
84 bs = fromString str
85
77-- | Format peer id in human readable form. 86-- | Format peer id in human readable form.
78ppPeerId :: PeerId -> Doc 87ppPeerId :: PeerId -> Doc
79ppPeerId = text . BC.unpack . getPeerId 88ppPeerId = text . BC.unpack . getPeerId