diff options
Diffstat (limited to 'src/Network/BitTorrent/Core/PeerId.hs')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 9 |
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 | |||
49 | import Data.Maybe (fromMaybe) | 49 | import Data.Maybe (fromMaybe) |
50 | import Data.Monoid | 50 | import Data.Monoid |
51 | import Data.Serialize as S | 51 | import Data.Serialize as S |
52 | import Data.String | ||
52 | import Data.Time.Clock (getCurrentTime) | 53 | import Data.Time.Clock (getCurrentTime) |
53 | import Data.Time.Format (formatTime) | 54 | import Data.Time.Format (formatTime) |
54 | import Data.URLEncoded | 55 | import Data.URLEncoded |
@@ -74,6 +75,14 @@ instance Serialize PeerId where | |||
74 | instance URLShow PeerId where | 75 | instance URLShow PeerId where |
75 | urlShow = BC.unpack . getPeerId | 76 | urlShow = BC.unpack . getPeerId |
76 | 77 | ||
78 | instance 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. |
78 | ppPeerId :: PeerId -> Doc | 87 | ppPeerId :: PeerId -> Doc |
79 | ppPeerId = text . BC.unpack . getPeerId | 88 | ppPeerId = text . BC.unpack . getPeerId |