summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 02:04:07 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 02:04:07 +0400
commit923abc9ee7576f2d3e1b7e2b2d5a32ed5d2f21c9 (patch)
tree4586b0d5f22eb37fd3c3b4585c5ebbb4e5b12119 /src/Network
parent8ad997f8f8725391fbaba415b0e751f42288d697 (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.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