diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-21 02:18:16 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-21 02:18:16 +0400 |
commit | e3f7c822a3e6f57260881fa3245ad2b89087ecce (patch) | |
tree | eac74591d19f38d710994264c2549c28ce4a9b56 /src/Network/BitTorrent/Core/Node.hs | |
parent | 4693ed53ec5cdbf0b2fa993d169c96e45f2dce91 (diff) |
Add DHT messages
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 #-} |