diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2013-12-25 17:04:06 +0000 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2013-12-25 17:04:06 +0000 |
commit | 43f068098ca6c4420ded6a1fa671436cc2b081f3 (patch) | |
tree | e89e0cd47cfbf809489a19e16fb5641b1112a6e3 /src/Network/BitTorrent/Core/Node.hs | |
parent | 349cd9cc63561d6e471f2be0be03fc2fae1a9371 (diff) | |
parent | 23eb8500987043a79715e01f07e2febab6adaabc (diff) |
Merge branch 'master' into dev
Conflicts:
src/Network/BitTorrent/Exchange/Message.hs
Diffstat (limited to 'src/Network/BitTorrent/Core/Node.hs')
-rw-r--r-- | src/Network/BitTorrent/Core/Node.hs | 9 |
1 files changed, 8 insertions, 1 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 #-} | ||
4 | module Network.BitTorrent.Core.Node | 5 | module Network.BitTorrent.Core.Node |
5 | ( -- * Node ID | 6 | ( -- * Node ID |
6 | NodeId | 7 | NodeId |
@@ -20,7 +21,9 @@ import Data.Aeson.TH | |||
20 | import Data.Bits | 21 | import Data.Bits |
21 | import Data.ByteString as BS | 22 | import Data.ByteString as BS |
22 | import Data.BEncode as BE | 23 | import Data.BEncode as BE |
24 | import Data.Default | ||
23 | import Data.Ord | 25 | import Data.Ord |
26 | import Data.Typeable | ||
24 | import Data.Serialize as S | 27 | import Data.Serialize as S |
25 | import Data.Word | 28 | import Data.Word |
26 | import Network | 29 | import 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. |
39 | newtype NodeId = NodeId ByteString | 42 | newtype NodeId = NodeId ByteString |
40 | deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON) | 43 | deriving (Show, Eq, Ord, BEncode, FromJSON, ToJSON, Typeable) |
41 | 44 | ||
42 | nodeIdSize :: Int | 45 | nodeIdSize :: Int |
43 | nodeIdSize = 20 | 46 | nodeIdSize = 20 |
44 | 47 | ||
48 | -- | Meaningless node id, for testing purposes only. | ||
49 | instance Default NodeId where | ||
50 | def = NodeId (BS.replicate nodeIdSize 0) | ||
51 | |||
45 | instance Serialize NodeId where | 52 | instance Serialize NodeId where |
46 | get = NodeId <$> getByteString nodeIdSize | 53 | get = NodeId <$> getByteString nodeIdSize |
47 | {-# INLINE get #-} | 54 | {-# INLINE get #-} |