diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 02:04:07 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 02:04:07 +0400 |
commit | 923abc9ee7576f2d3e1b7e2b2d5a32ed5d2f21c9 (patch) | |
tree | 4586b0d5f22eb37fd3c3b4585c5ebbb4e5b12119 /src/Network | |
parent | 8ad997f8f8725391fbaba415b0e751f42288d697 (diff) |
Add spec for client info extraction from azureus encoded peer id
Diffstat (limited to 'src/Network')
-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 |