summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2013-12-25 17:04:06 +0000
committerDaniel Gröber <dxld@darkboxed.org>2013-12-25 17:04:06 +0000
commit43f068098ca6c4420ded6a1fa671436cc2b081f3 (patch)
treee89e0cd47cfbf809489a19e16fb5641b1112a6e3 /src/Network/BitTorrent/Core
parent349cd9cc63561d6e471f2be0be03fc2fae1a9371 (diff)
parent23eb8500987043a79715e01f07e2febab6adaabc (diff)
Merge branch 'master' into dev
Conflicts: src/Network/BitTorrent/Exchange/Message.hs
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/Node.hs9
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs2
2 files changed, 9 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Core/Node.hs b/src/Network/BitTorrent/Core/Node.hs
index a1a87135..0cb95dd2 100644
--- a/src/Network/BitTorrent/Core/Node.hs
+++ b/src/Network/BitTorrent/Core/Node.hs
@@ -1,6 +1,7 @@
1{-# LANGUAGE RecordWildCards #-} 1{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE TemplateHaskell #-} 2{-# LANGUAGE TemplateHaskell #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-} 3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE DeriveDataTypeable #-}
4module Network.BitTorrent.Core.Node 5module Network.BitTorrent.Core.Node
5 ( -- * Node ID 6 ( -- * Node ID
6 NodeId 7 NodeId
@@ -20,7 +21,9 @@ import Data.Aeson.TH
20import Data.Bits 21import Data.Bits
21import Data.ByteString as BS 22import Data.ByteString as BS
22import Data.BEncode as BE 23import Data.BEncode as BE
24import Data.Default
23import Data.Ord 25import Data.Ord
26import Data.Typeable
24import Data.Serialize as S 27import Data.Serialize as S
25import Data.Word 28import Data.Word
26import Network 29import Network
@@ -37,11 +40,15 @@ import Network.BitTorrent.Core.PeerAddr ()
37-- | Normally, /this/ node id should we saved between invocations of 40-- | Normally, /this/ node id should we saved between invocations of
38-- the client software. 41-- the client software.
39newtype NodeId = NodeId ByteString 42newtype NodeId = NodeId ByteString
40 deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON) 43 deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON, Typeable)
41 44
42nodeIdSize :: Int 45nodeIdSize :: Int
43nodeIdSize = 20 46nodeIdSize = 20
44 47
48-- | Meaningless node id, for testing purposes only.
49instance Default NodeId where
50 def = NodeId (BS.replicate nodeIdSize 0)
51
45instance Serialize NodeId where 52instance Serialize NodeId where
46 get = NodeId <$> getByteString nodeIdSize 53 get = NodeId <$> getByteString nodeIdSize
47 {-# INLINE get #-} 54 {-# INLINE get #-}
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index bc4a1078..86b88491 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -254,7 +254,7 @@ peerSockAddr PeerAddr {..} =
254 254
255-- | Storage used to keep track a set of known peers in client, 255-- | Storage used to keep track a set of known peers in client,
256-- tracker or DHT sessions. 256-- tracker or DHT sessions.
257newtype PeerStore a = PeerStore (HashMap InfoHash [PeerAddr a]) 257newtype PeerStore ip = PeerStore (HashMap InfoHash [PeerAddr ip])
258 258
259-- | Empty store. 259-- | Empty store.
260instance Default (PeerStore a) where 260instance Default (PeerStore a) where