diff options
Diffstat (limited to 'src/Network/BitTorrent/Address.hs')
-rw-r--r-- | src/Network/BitTorrent/Address.hs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Address.hs b/src/Network/BitTorrent/Address.hs index b4ce96b0..381ff50b 100644 --- a/src/Network/BitTorrent/Address.hs +++ b/src/Network/BitTorrent/Address.hs | |||
@@ -58,7 +58,8 @@ module Network.BitTorrent.Address | |||
58 | 58 | ||
59 | -- * Node | 59 | -- * Node |
60 | -- ** Id | 60 | -- ** Id |
61 | , NodeId(..) | 61 | , NodeId |
62 | , asNodeId | ||
62 | , nodeIdSize | 63 | , nodeIdSize |
63 | , testIdBit | 64 | , testIdBit |
64 | , NodeDistance | 65 | , NodeDistance |
@@ -646,6 +647,9 @@ newtype NodeId = NodeId ByteString | |||
646 | nodeIdSize :: Int | 647 | nodeIdSize :: Int |
647 | nodeIdSize = 20 | 648 | nodeIdSize = 20 |
648 | 649 | ||
650 | asNodeId :: ByteString -> NodeId | ||
651 | asNodeId bs = NodeId $ BS.take nodeIdSize bs | ||
652 | |||
649 | -- | Meaningless node id, for testing purposes only. | 653 | -- | Meaningless node id, for testing purposes only. |
650 | instance Default NodeId where | 654 | instance Default NodeId where |
651 | def = NodeId (BS.replicate nodeIdSize 0) | 655 | def = NodeId (BS.replicate nodeIdSize 0) |
@@ -801,6 +805,7 @@ data NodeInfo a = NodeInfo | |||
801 | , nodeAddr :: !(NodeAddr a) | 805 | , nodeAddr :: !(NodeAddr a) |
802 | } deriving (Show, Eq, Functor, Foldable, Traversable) | 806 | } deriving (Show, Eq, Functor, Foldable, Traversable) |
803 | 807 | ||
808 | |||
804 | instance Eq a => Ord (NodeInfo a) where | 809 | instance Eq a => Ord (NodeInfo a) where |
805 | compare = comparing nodeId | 810 | compare = comparing nodeId |
806 | 811 | ||