diff options
Diffstat (limited to 'src/Network/BitTorrent/Tracker')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Protocol.hs | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/src/Network/BitTorrent/Tracker/Protocol.hs b/src/Network/BitTorrent/Tracker/Protocol.hs index c0e84c24..a6c1c8b6 100644 --- a/src/Network/BitTorrent/Tracker/Protocol.hs +++ b/src/Network/BitTorrent/Tracker/Protocol.hs | |||
@@ -53,7 +53,6 @@ import Network.HTTP | |||
53 | import Network.URI | 53 | import Network.URI |
54 | 54 | ||
55 | import Network.BitTorrent.Peer | 55 | import Network.BitTorrent.Peer |
56 | import Network.BitTorrent.PeerID | ||
57 | import Network.BitTorrent.Tracker.Scrape | 56 | import Network.BitTorrent.Tracker.Scrape |
58 | 57 | ||
59 | 58 | ||
@@ -84,27 +83,9 @@ data TResponse = | |||
84 | , respMinInterval :: Maybe Int -- ^ Minimal amount of time between requests. | 83 | , respMinInterval :: Maybe Int -- ^ Minimal amount of time between requests. |
85 | , respComplete :: Maybe Int -- ^ Number of peers completed the torrent. (seeders) | 84 | , respComplete :: Maybe Int -- ^ Number of peers completed the torrent. (seeders) |
86 | , respIncomplete :: Maybe Int -- ^ Number of peers downloading the torrent. | 85 | , respIncomplete :: Maybe Int -- ^ Number of peers downloading the torrent. |
87 | , respPeers :: [Peer] -- ^ Peers that must be contacted. | 86 | , respPeers :: [PeerAddr] -- ^ Peers that must be contacted. |
88 | } deriving Show | 87 | } deriving Show |
89 | 88 | ||
90 | instance BEncodable PortNumber where | ||
91 | toBEncode = toBEncode . fromEnum | ||
92 | fromBEncode b = toEnum <$> fromBEncode b | ||
93 | |||
94 | instance BEncodable Peer where | ||
95 | toBEncode (Peer pid pip pport) = fromAssocs | ||
96 | [ "peer id" -->? pid | ||
97 | , "ip" --> pip | ||
98 | , "port" --> pport | ||
99 | ] | ||
100 | |||
101 | fromBEncode (BDict d) = | ||
102 | Peer <$> d >--? "peer id" | ||
103 | <*> d >-- "ip" | ||
104 | <*> d >-- "port" | ||
105 | |||
106 | fromBEncode _ = decodingError "Peer" | ||
107 | |||
108 | instance BEncodable TResponse where | 89 | instance BEncodable TResponse where |
109 | toBEncode (Failure t) = fromAssocs ["failure reason" --> t] | 90 | toBEncode (Failure t) = fromAssocs ["failure reason" --> t] |
110 | toBEncode resp@(OK {}) = fromAssocs | 91 | toBEncode resp@(OK {}) = fromAssocs |
@@ -125,7 +106,7 @@ instance BEncodable TResponse where | |||
125 | <*> getPeers (M.lookup "peers" d) | 106 | <*> getPeers (M.lookup "peers" d) |
126 | 107 | ||
127 | where | 108 | where |
128 | getPeers :: Maybe BEncode -> Result [Peer] | 109 | getPeers :: Maybe BEncode -> Result [PeerAddr] |
129 | getPeers (Just (BList l)) = fromBEncode (BList l) | 110 | getPeers (Just (BList l)) = fromBEncode (BList l) |
130 | getPeers (Just (BString s)) | 111 | getPeers (Just (BString s)) |
131 | | B.length s `mod` 6 == 0 = | 112 | | B.length s `mod` 6 == 0 = |
@@ -136,7 +117,7 @@ instance BEncodable TResponse where | |||
136 | peerG = do | 117 | peerG = do |
137 | pip <- getWord32be | 118 | pip <- getWord32be |
138 | pport <- getWord16be | 119 | pport <- getWord16be |
139 | return (Peer Nothing (fromIntegral pip) (fromIntegral pport)) | 120 | return (PeerAddr Nothing (fromIntegral pip) (fromIntegral pport)) |
140 | 121 | ||
141 | getPeers _ = decodingError "Peers" | 122 | getPeers _ = decodingError "Peers" |
142 | 123 | ||