summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Core/NodeInfo.hs9
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs8
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs4
-rw-r--r--src/Network/BitTorrent/Exchange/Block.hs4
-rw-r--r--src/Network/BitTorrent/Exchange/Connection/Status.hs4
-rw-r--r--src/Network/BitTorrent/Internal/Cache.hs25
-rw-r--r--src/Network/BitTorrent/Tracker/Message.hs8
-rw-r--r--src/Network/BitTorrent/Tracker/Session.hs12
8 files changed, 2 insertions, 72 deletions
diff --git a/src/Network/BitTorrent/Core/NodeInfo.hs b/src/Network/BitTorrent/Core/NodeInfo.hs
index fa20caf5..fe17c097 100644
--- a/src/Network/BitTorrent/Core/NodeInfo.hs
+++ b/src/Network/BitTorrent/Core/NodeInfo.hs
@@ -39,8 +39,6 @@ module Network.BitTorrent.Core.NodeInfo
39 ) where 39 ) where
40 40
41import Control.Applicative 41import Control.Applicative
42import Data.Aeson (ToJSON, FromJSON)
43import Data.Aeson.TH
44import Data.Bits 42import Data.Bits
45import Data.ByteString as BS 43import Data.ByteString as BS
46import Data.ByteString.Char8 as BC 44import Data.ByteString.Char8 as BC
@@ -62,7 +60,6 @@ import System.Entropy
62import Text.PrettyPrint as PP hiding ((<>)) 60import Text.PrettyPrint as PP hiding ((<>))
63import Text.PrettyPrint.Class 61import Text.PrettyPrint.Class
64 62
65import Data.Torrent.JSON
66import Network.BitTorrent.Core.PeerAddr (PeerAddr (..)) 63import Network.BitTorrent.Core.PeerAddr (PeerAddr (..))
67 64
68{----------------------------------------------------------------------- 65{-----------------------------------------------------------------------
@@ -76,7 +73,7 @@ import Network.BitTorrent.Core.PeerAddr (PeerAddr (..))
76-- Normally, /this/ node id should be saved between invocations 73-- Normally, /this/ node id should be saved between invocations
77-- of the client software. 74-- of the client software.
78newtype NodeId = NodeId ByteString 75newtype NodeId = NodeId ByteString
79 deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON, Typeable) 76 deriving (Show, Eq, Ord, BEncode, Typeable)
80 77
81nodeIdSize :: Int 78nodeIdSize :: Int
82nodeIdSize = 20 79nodeIdSize = 20
@@ -146,8 +143,6 @@ data NodeAddr a = NodeAddr
146 , nodePort :: {-# UNPACK #-} !PortNumber 143 , nodePort :: {-# UNPACK #-} !PortNumber
147 } deriving (Eq, Typeable, Functor) 144 } deriving (Eq, Typeable, Functor)
148 145
149$(deriveJSON omitRecordPrefix ''NodeAddr)
150
151instance Show a => Show (NodeAddr a) where 146instance Show a => Show (NodeAddr a) where
152 showsPrec i NodeAddr {..} 147 showsPrec i NodeAddr {..}
153 = showsPrec i nodeHost <> showString ":" <> showsPrec i nodePort 148 = showsPrec i nodeHost <> showString ":" <> showsPrec i nodePort
@@ -202,8 +197,6 @@ data NodeInfo a = NodeInfo
202 , nodeAddr :: !(NodeAddr a) 197 , nodeAddr :: !(NodeAddr a)
203 } deriving (Show, Eq, Functor) 198 } deriving (Show, Eq, Functor)
204 199
205$(deriveJSON omitRecordPrefix ''NodeInfo)
206
207instance Eq a => Ord (NodeInfo a) where 200instance Eq a => Ord (NodeInfo a) where
208 compare = comparing nodeId 201 compare = comparing nodeId
209 202
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index adf64c7f..92fb83a7 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -33,8 +33,6 @@ module Network.BitTorrent.Core.PeerAddr
33 33
34import Control.Applicative 34import Control.Applicative
35import Control.Monad 35import Control.Monad
36import Data.Aeson (ToJSON, FromJSON)
37import Data.Aeson.TH
38import Data.BEncode as BS 36import Data.BEncode as BS
39import Data.BEncode.BDict (BKey) 37import Data.BEncode.BDict (BKey)
40import Data.ByteString.Char8 as BS8 38import Data.ByteString.Char8 as BS8
@@ -58,7 +56,6 @@ import Text.Read (readMaybe)
58import qualified Text.ParserCombinators.ReadP as RP 56import qualified Text.ParserCombinators.ReadP as RP
59 57
60import Data.Torrent.InfoHash 58import Data.Torrent.InfoHash
61import Data.Torrent.JSON
62import Network.BitTorrent.Core.PeerId 59import Network.BitTorrent.Core.PeerId
63 60
64 61
@@ -66,9 +63,6 @@ import Network.BitTorrent.Core.PeerId
66-- Port number 63-- Port number
67-----------------------------------------------------------------------} 64-----------------------------------------------------------------------}
68 65
69deriving instance ToJSON PortNumber
70deriving instance FromJSON PortNumber
71
72instance BEncode PortNumber where 66instance BEncode PortNumber where
73 toBEncode = toBEncode . fromEnum 67 toBEncode = toBEncode . fromEnum
74 fromBEncode = fromBEncode >=> portNumber 68 fromBEncode = fromBEncode >=> portNumber
@@ -208,8 +202,6 @@ data PeerAddr a = PeerAddr
208 , peerPort :: {-# UNPACK #-} !PortNumber 202 , peerPort :: {-# UNPACK #-} !PortNumber
209 } deriving (Show, Eq, Ord, Typeable, Functor) 203 } deriving (Show, Eq, Ord, Typeable, Functor)
210 204
211$(deriveJSON omitRecordPrefix ''PeerAddr)
212
213peer_ip_key, peer_id_key, peer_port_key :: BKey 205peer_ip_key, peer_id_key, peer_port_key :: BKey
214peer_ip_key = "ip" 206peer_ip_key = "ip"
215peer_id_key = "peer id" 207peer_id_key = "peer id"
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index f8d69e8b..a180ff30 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -34,7 +34,6 @@ module Network.BitTorrent.Core.PeerId
34 ) where 34 ) where
35 35
36import Control.Applicative 36import Control.Applicative
37import Data.Aeson
38import Data.BEncode as BE 37import Data.BEncode as BE
39import Data.ByteString as BS 38import Data.ByteString as BS
40import Data.ByteString.Internal as BS 39import Data.ByteString.Internal as BS
@@ -62,14 +61,13 @@ import Text.PrettyPrint hiding ((<>))
62import Text.PrettyPrint.Class 61import Text.PrettyPrint.Class
63import Text.Read (readMaybe) 62import Text.Read (readMaybe)
64 63
65import Data.Torrent.JSON ()
66import Network.BitTorrent.Core.Fingerprint 64import Network.BitTorrent.Core.Fingerprint
67 65
68-- TODO use unpacked Word160 form (length is known statically) 66-- TODO use unpacked Word160 form (length is known statically)
69 67
70-- | Peer identifier is exactly 20 bytes long bytestring. 68-- | Peer identifier is exactly 20 bytes long bytestring.
71newtype PeerId = PeerId { getPeerId :: ByteString } 69newtype PeerId = PeerId { getPeerId :: ByteString }
72 deriving (Show, Eq, Ord, BEncode, ToJSON, FromJSON, Typeable) 70 deriving (Show, Eq, Ord, BEncode, Typeable)
73 71
74peerIdLen :: Int 72peerIdLen :: Int
75peerIdLen = 20 73peerIdLen = 20
diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs
index 6e5b960a..16c124e9 100644
--- a/src/Network/BitTorrent/Exchange/Block.hs
+++ b/src/Network/BitTorrent/Exchange/Block.hs
@@ -57,7 +57,6 @@ module Network.BitTorrent.Exchange.Block
57 57
58import Prelude hiding (span) 58import Prelude hiding (span)
59import Control.Applicative 59import Control.Applicative
60import Data.Aeson.TH
61import Data.ByteString as BS hiding (span) 60import Data.ByteString as BS hiding (span)
62import Data.ByteString.Lazy as BL hiding (span) 61import Data.ByteString.Lazy as BL hiding (span)
63import Data.ByteString.Lazy.Builder as BS 62import Data.ByteString.Lazy.Builder as BS
@@ -70,7 +69,6 @@ import Numeric
70import Text.PrettyPrint as PP hiding ((<>)) 69import Text.PrettyPrint as PP hiding ((<>))
71import Text.PrettyPrint.Class 70import Text.PrettyPrint.Class
72 71
73import Data.Torrent.JSON
74import Data.Torrent.Piece 72import Data.Torrent.Piece
75 73
76{----------------------------------------------------------------------- 74{-----------------------------------------------------------------------
@@ -114,8 +112,6 @@ data BlockIx = BlockIx {
114 , ixLength :: {-# UNPACK #-} !BlockSize 112 , ixLength :: {-# UNPACK #-} !BlockSize
115 } deriving (Show, Eq, Typeable) 113 } deriving (Show, Eq, Typeable)
116 114
117$(deriveJSON omitRecordPrefix ''BlockIx)
118
119-- | First block in torrent. Useful for debugging. 115-- | First block in torrent. Useful for debugging.
120instance Default BlockIx where 116instance Default BlockIx where
121 def = BlockIx 0 0 defaultTransferSize 117 def = BlockIx 0 0 defaultTransferSize
diff --git a/src/Network/BitTorrent/Exchange/Connection/Status.hs b/src/Network/BitTorrent/Exchange/Connection/Status.hs
index b4b10371..f6abc580 100644
--- a/src/Network/BitTorrent/Exchange/Connection/Status.hs
+++ b/src/Network/BitTorrent/Exchange/Connection/Status.hs
@@ -34,14 +34,12 @@ module Network.BitTorrent.Exchange.Connection.Status
34 ) where 34 ) where
35 35
36import Control.Lens 36import Control.Lens
37import Data.Aeson.TH
38import Data.Default 37import Data.Default
39import Data.Maybe 38import Data.Maybe
40import Data.Monoid 39import Data.Monoid
41import Text.PrettyPrint as PP hiding ((<>)) 40import Text.PrettyPrint as PP hiding ((<>))
42import Text.PrettyPrint.Class 41import Text.PrettyPrint.Class
43 42
44import Data.Torrent.JSON
45import Network.BitTorrent.Exchange.Message 43import Network.BitTorrent.Exchange.Message
46 44
47 45
@@ -61,7 +59,6 @@ data PeerStatus = PeerStatus
61 } deriving (Show, Eq, Ord) 59 } deriving (Show, Eq, Ord)
62 60
63$(makeLenses ''PeerStatus) 61$(makeLenses ''PeerStatus)
64$(deriveJSON omitLensPrefix ''PeerStatus)
65 62
66instance Pretty PeerStatus where 63instance Pretty PeerStatus where
67 pretty PeerStatus {..} = 64 pretty PeerStatus {..} =
@@ -104,7 +101,6 @@ data ConnectionStatus = ConnectionStatus
104 } deriving (Show, Eq) 101 } deriving (Show, Eq)
105 102
106$(makeLenses ''ConnectionStatus) 103$(makeLenses ''ConnectionStatus)
107$(deriveJSON omitRecordPrefix ''ConnectionStatus)
108 104
109instance Pretty ConnectionStatus where 105instance Pretty ConnectionStatus where
110 pretty ConnectionStatus {..} = 106 pretty ConnectionStatus {..} =
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs
index 5c3f379b..8c74467a 100644
--- a/src/Network/BitTorrent/Internal/Cache.hs
+++ b/src/Network/BitTorrent/Internal/Cache.hs
@@ -32,7 +32,6 @@ module Network.BitTorrent.Internal.Cache
32 ) where 32 ) where
33 33
34import Control.Applicative 34import Control.Applicative
35import Data.Aeson
36import Data.Monoid 35import Data.Monoid
37import Data.Default 36import Data.Default
38import Data.Time 37import Data.Time
@@ -56,30 +55,6 @@ data Cached a = Cached
56 55
57-- INVARIANT: minUpdateInterval <= updateInterval 56-- INVARIANT: minUpdateInterval <= updateInterval
58 57
59-- | Examples:
60--
61-- { data: "some string",
62-- observed: "2014-03-20T19:49:39.505Z",
63-- expires: "2014-03-20T19:50:10.881Z" }
64--
65-- or:
66--
67-- { expired: "2014-03-20T19:50:10.881Z" }
68--
69instance ToJSON a => ToJSON (Cached a) where
70 toJSON Cached {..}
71 | currentTime < expireTime = object
72 [ "observed" .= posixSecondsToUTCTime lastUpdated
73 , "expires" .= posixSecondsToUTCTime expireTime
74 , "data" .= cachedData
75 ]
76 | otherwise = object
77 [ "expired" .= posixSecondsToUTCTime expireTime
78 ]
79 where
80 expireTime = currentTime + updateInterval
81 currentTime = unsafePerformIO getPOSIXTime
82
83instance Default (Cached a) where 58instance Default (Cached a) where
84 def = mempty 59 def = mempty
85 60
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs
index ffe36c82..cdc07af8 100644
--- a/src/Network/BitTorrent/Tracker/Message.hs
+++ b/src/Network/BitTorrent/Tracker/Message.hs
@@ -97,7 +97,6 @@ module Network.BitTorrent.Tracker.Message
97 97
98import Control.Applicative 98import Control.Applicative
99import Control.Monad 99import Control.Monad
100import Data.Aeson.TH
101import Data.BEncode as BE hiding (Result) 100import Data.BEncode as BE hiding (Result)
102import Data.BEncode.BDict as BE 101import Data.BEncode.BDict as BE
103import Data.ByteString as BS 102import Data.ByteString as BS
@@ -126,7 +125,6 @@ import System.Entropy
126import Text.Read (readMaybe) 125import Text.Read (readMaybe)
127 126
128import Data.Torrent.InfoHash 127import Data.Torrent.InfoHash
129import Data.Torrent.JSON
130import Data.Torrent.Progress 128import Data.Torrent.Progress
131import Network.BitTorrent.Core 129import Network.BitTorrent.Core
132 130
@@ -150,8 +148,6 @@ data AnnounceEvent
150 | Completed 148 | Completed
151 deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) 149 deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable)
152 150
153$(deriveJSON omitRecordPrefix ''AnnounceEvent)
154
155-- | HTTP tracker protocol compatible encoding. 151-- | HTTP tracker protocol compatible encoding.
156instance QueryValueLike AnnounceEvent where 152instance QueryValueLike AnnounceEvent where
157 toQueryValue e = toQueryValue (Char.toLower x : xs) 153 toQueryValue e = toQueryValue (Char.toLower x : xs)
@@ -224,8 +220,6 @@ data AnnounceQuery = AnnounceQuery
224 , reqEvent :: Maybe AnnounceEvent 220 , reqEvent :: Maybe AnnounceEvent
225 } deriving (Show, Eq, Typeable) 221 } deriving (Show, Eq, Typeable)
226 222
227$(deriveJSON omitRecordPrefix ''AnnounceQuery)
228
229-- | UDP tracker protocol compatible encoding. 223-- | UDP tracker protocol compatible encoding.
230instance Serialize AnnounceQuery where 224instance Serialize AnnounceQuery where
231 put AnnounceQuery {..} = do 225 put AnnounceQuery {..} = do
@@ -636,8 +630,6 @@ data ScrapeEntry = ScrapeEntry {
636 , siName :: !(Maybe Text) 630 , siName :: !(Maybe Text)
637 } deriving (Show, Eq, Typeable) 631 } deriving (Show, Eq, Typeable)
638 632
639$(deriveJSON omitRecordPrefix ''ScrapeEntry)
640
641-- | HTTP tracker protocol compatible encoding. 633-- | HTTP tracker protocol compatible encoding.
642instance BEncode ScrapeEntry where 634instance BEncode ScrapeEntry where
643 toBEncode ScrapeEntry {..} = toDict $ 635 toBEncode ScrapeEntry {..} = toDict $
diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs
index 5aa9c0eb..560acf84 100644
--- a/src/Network/BitTorrent/Tracker/Session.hs
+++ b/src/Network/BitTorrent/Tracker/Session.hs
@@ -47,8 +47,6 @@ import Control.Exception
47import Control.Concurrent 47import Control.Concurrent
48import Control.Concurrent.Chan.Split as CS 48import Control.Concurrent.Chan.Split as CS
49import Control.Monad 49import Control.Monad
50import Data.Aeson
51import Data.Aeson.TH
52import Data.Default 50import Data.Default
53import Data.Fixed 51import Data.Fixed
54import Data.Foldable as F 52import Data.Foldable as F
@@ -60,7 +58,6 @@ import Data.Traversable
60import Network.URI 58import Network.URI
61 59
62import Data.Torrent.InfoHash 60import Data.Torrent.InfoHash
63import Data.Torrent.JSON
64import Network.BitTorrent.Core 61import Network.BitTorrent.Core
65import Network.BitTorrent.Internal.Cache 62import Network.BitTorrent.Internal.Cache
66import Network.BitTorrent.Internal.Types 63import Network.BitTorrent.Internal.Types
@@ -95,8 +92,6 @@ data LastScrape = LastScrape
95 , scrapeSeeders :: Maybe Int 92 , scrapeSeeders :: Maybe Int
96 } deriving (Show, Eq) 93 } deriving (Show, Eq)
97 94
98$(deriveJSON omitRecordPrefix ''LastScrape)
99
100-- | Single tracker session. 95-- | Single tracker session.
101data TrackerSession = TrackerSession 96data TrackerSession = TrackerSession
102 { -- | Used to notify 'Stopped' and 'Completed' events. 97 { -- | Used to notify 'Stopped' and 'Completed' events.
@@ -109,13 +104,6 @@ data TrackerSession = TrackerSession
109 , trackerScrape :: Cached LastScrape 104 , trackerScrape :: Cached LastScrape
110 } 105 }
111 106
112instance ToJSON (TierEntry TrackerSession) where
113 toJSON (uri, TrackerSession {..}) = object
114 [ "uri" .= uri
115 , "peers" .= trackerPeers
116 , "scrape" .= trackerScrape
117 ]
118
119-- | Not contacted. 107-- | Not contacted.
120instance Default TrackerSession where 108instance Default TrackerSession where
121 def = TrackerSession Nothing def def 109 def = TrackerSession Nothing def def