diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-08 02:47:02 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-08 02:47:02 +0400 |
commit | 784aead759a47eea59317e51edfaddc55bb4ddbd (patch) | |
tree | d1e37a4115336947f415c708b40934aa4e59f047 /src/Network/BitTorrent/Address.hs | |
parent | 75711985512c8578e913a1b464816968b4aef5dd (diff) |
s/ClientImpl/Software
Diffstat (limited to 'src/Network/BitTorrent/Address.hs')
-rw-r--r-- | src/Network/BitTorrent/Address.hs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Network/BitTorrent/Address.hs b/src/Network/BitTorrent/Address.hs index 8723433d..57cdf55e 100644 --- a/src/Network/BitTorrent/Address.hs +++ b/src/Network/BitTorrent/Address.hs | |||
@@ -66,7 +66,7 @@ module Network.BitTorrent.Address | |||
66 | 66 | ||
67 | -- * Fingerprint | 67 | -- * Fingerprint |
68 | -- $fingerprint | 68 | -- $fingerprint |
69 | , ClientImpl (..) | 69 | , Software (..) |
70 | , Fingerprint (..) | 70 | , Fingerprint (..) |
71 | , libFingerprint | 71 | , libFingerprint |
72 | , fingerprint | 72 | , fingerprint |
@@ -296,7 +296,9 @@ defaultClientId = "HS" | |||
296 | -- package. Version is taken from .cabal file. | 296 | -- package. Version is taken from .cabal file. |
297 | defaultVersionNumber :: ByteString | 297 | defaultVersionNumber :: ByteString |
298 | defaultVersionNumber = BS.take 4 $ BC.pack $ foldMap show $ | 298 | defaultVersionNumber = BS.take 4 $ BC.pack $ foldMap show $ |
299 | versionBranch $ ciVersion libFingerprint | 299 | versionBranch myVersion |
300 | where | ||
301 | Fingerprint _ myVersion = libFingerprint | ||
300 | 302 | ||
301 | ------------------------------------------------------------------------ | 303 | ------------------------------------------------------------------------ |
302 | 304 | ||
@@ -792,7 +794,7 @@ version = Version [0, 0, 0, 3] [] | |||
792 | -- prefixed by \"I\" because some of them starts from lowercase letter | 794 | -- prefixed by \"I\" because some of them starts from lowercase letter |
793 | -- but that is not a valid Haskell constructor name. | 795 | -- but that is not a valid Haskell constructor name. |
794 | -- | 796 | -- |
795 | data ClientImpl = | 797 | data Software = |
796 | IUnknown | 798 | IUnknown |
797 | 799 | ||
798 | | IMainline | 800 | | IMainline |
@@ -870,8 +872,8 @@ data ClientImpl = | |||
870 | | IZipTorrent | 872 | | IZipTorrent |
871 | deriving (Show, Eq, Ord, Enum, Bounded) | 873 | deriving (Show, Eq, Ord, Enum, Bounded) |
872 | 874 | ||
873 | parseImpl :: ByteString -> ClientImpl | 875 | parseSoftware :: ByteString -> Software |
874 | parseImpl = f . BC.unpack | 876 | parseSoftware = f . BC.unpack |
875 | where | 877 | where |
876 | f "AG" = IAres | 878 | f "AG" = IAres |
877 | f "A~" = IAres | 879 | f "A~" = IAres |
@@ -937,12 +939,12 @@ parseImpl = f . BC.unpack | |||
937 | f _ = IUnknown | 939 | f _ = IUnknown |
938 | 940 | ||
939 | -- | Used to represent a not recognized implementation | 941 | -- | Used to represent a not recognized implementation |
940 | instance Default ClientImpl where | 942 | instance Default Software where |
941 | def = IUnknown | 943 | def = IUnknown |
942 | {-# INLINE def #-} | 944 | {-# INLINE def #-} |
943 | 945 | ||
944 | -- | Example: @\"BitLet\" == 'IBitLet'@ | 946 | -- | Example: @\"BitLet\" == 'IBitLet'@ |
945 | instance IsString ClientImpl where | 947 | instance IsString Software where |
946 | fromString str | 948 | fromString str |
947 | | Just impl <- L.lookup str alist = impl | 949 | | Just impl <- L.lookup str alist = impl |
948 | | otherwise = error $ "fromString: not recognized " ++ str | 950 | | otherwise = error $ "fromString: not recognized " ++ str |
@@ -951,7 +953,7 @@ instance IsString ClientImpl where | |||
951 | mk x = (L.tail $ show x, x) | 953 | mk x = (L.tail $ show x, x) |
952 | 954 | ||
953 | -- | Example: @pretty 'IBitLet' == \"IBitLet\"@ | 955 | -- | Example: @pretty 'IBitLet' == \"IBitLet\"@ |
954 | instance Pretty ClientImpl where | 956 | instance Pretty Software where |
955 | pretty = text . L.tail . show | 957 | pretty = text . L.tail . show |
956 | 958 | ||
957 | -- | Just the '0' version. | 959 | -- | Just the '0' version. |
@@ -974,10 +976,8 @@ instance Pretty Version where | |||
974 | 976 | ||
975 | -- | The all sensible infomation that can be obtained from a peer | 977 | -- | The all sensible infomation that can be obtained from a peer |
976 | -- identifier or torrent /createdBy/ field. | 978 | -- identifier or torrent /createdBy/ field. |
977 | data Fingerprint = Fingerprint | 979 | data Fingerprint = Fingerprint Software Version |
978 | { ciImpl :: ClientImpl | 980 | deriving (Show, Eq, Ord) |
979 | , ciVersion :: Version | ||
980 | } deriving (Show, Eq, Ord) | ||
981 | 981 | ||
982 | -- | Unrecognized client implementation. | 982 | -- | Unrecognized client implementation. |
983 | instance Default Fingerprint where | 983 | instance Default Fingerprint where |
@@ -993,7 +993,7 @@ instance IsString Fingerprint where | |||
993 | (impl, _ver) = L.span ((/=) '-') str | 993 | (impl, _ver) = L.span ((/=) '-') str |
994 | 994 | ||
995 | instance Pretty Fingerprint where | 995 | instance Pretty Fingerprint where |
996 | pretty Fingerprint {..} = pretty ciImpl <+> "version" <+> pretty ciVersion | 996 | pretty (Fingerprint s v) = pretty s <+> "version" <+> pretty v |
997 | 997 | ||
998 | -- | Fingerprint of this (the bittorrent library) package. Normally, | 998 | -- | Fingerprint of this (the bittorrent library) package. Normally, |
999 | -- applications should introduce its own fingerprints, otherwise they | 999 | -- applications should introduce its own fingerprints, otherwise they |
@@ -1128,8 +1128,8 @@ fingerprint pid = either (const def) id $ runGet getCI (getPeerId pid) | |||
1128 | let mnums = L.filter (not . L.null) $ L.linesBy ('-' ==) str | 1128 | let mnums = L.filter (not . L.null) $ L.linesBy ('-' ==) str |
1129 | return $ Version (fromMaybe [] $ sequence $ L.map readMaybe mnums) [] | 1129 | return $ Version (fromMaybe [] $ sequence $ L.map readMaybe mnums) [] |
1130 | 1130 | ||
1131 | getAzureusImpl = parseImpl <$> getByteString 2 | 1131 | getAzureusImpl = parseSoftware <$> getByteString 2 |
1132 | getAzureusVersion = mkVer <$> getByteString 4 | 1132 | getAzureusVersion = mkVer <$> getByteString 4 |
1133 | where | 1133 | where |
1134 | mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] | 1134 | mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] |
1135 | 1135 | ||