summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Address.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-02 00:34:47 -0500
committerjoe <joe@jerkface.net>2017-01-02 00:37:07 -0500
commit5c2140807ceaa97a90c947437ecf5ef225f27c8d (patch)
tree650b6021af1b4c7a6c00ab4e5567424db959ece0 /src/Network/BitTorrent/Address.hs
parent80c860df8c29f99e0a82b454c1c0f0c6902764ef (diff)
Parse IPv4 addresses even when using variadic IP type.
Diffstat (limited to 'src/Network/BitTorrent/Address.hs')
-rw-r--r--src/Network/BitTorrent/Address.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Address.hs b/src/Network/BitTorrent/Address.hs
index 8dbe1583..c0c0a3f8 100644
--- a/src/Network/BitTorrent/Address.hs
+++ b/src/Network/BitTorrent/Address.hs
@@ -18,6 +18,8 @@
18{-# LANGUAGE MultiParamTypeClasses #-} 18{-# LANGUAGE MultiParamTypeClasses #-}
19{-# LANGUAGE DeriveDataTypeable #-} 19{-# LANGUAGE DeriveDataTypeable #-}
20{-# LANGUAGE DeriveFunctor #-} 20{-# LANGUAGE DeriveFunctor #-}
21{-# LANGUAGE DeriveFoldable #-}
22{-# LANGUAGE DeriveTraversable #-}
21{-# LANGUAGE TemplateHaskell #-} 23{-# LANGUAGE TemplateHaskell #-}
22{-# OPTIONS -fno-warn-orphans #-} 24{-# OPTIONS -fno-warn-orphans #-}
23module Network.BitTorrent.Address 25module Network.BitTorrent.Address
@@ -443,7 +445,7 @@ instance Serialize IP where
443 case n of 445 case n of
444 4 -> IPv4 <$> get 446 4 -> IPv4 <$> get
445 16 -> IPv6 <$> get 447 16 -> IPv6 <$> get
446 _ -> fail "Wrong number of bytes remaining to parse IP" 448 _ -> fail (show n ++ " is the wrong number of remaining bytes to parse IP")
447 449
448instance Serialize IPv4 where 450instance Serialize IPv4 where
449 put = putWord32host . toHostAddress 451 put = putWord32host . toHostAddress
@@ -693,7 +695,7 @@ distance (NodeId a) (NodeId b) = NodeDistance (BS.pack (BS.zipWith xor a b))
693data NodeAddr a = NodeAddr 695data NodeAddr a = NodeAddr
694 { nodeHost :: !a 696 { nodeHost :: !a
695 , nodePort :: {-# UNPACK #-} !PortNumber 697 , nodePort :: {-# UNPACK #-} !PortNumber
696 } deriving (Eq, Typeable, Functor) 698 } deriving (Eq, Typeable, Functor, Foldable, Traversable)
697 699
698instance Show a => Show (NodeAddr a) where 700instance Show a => Show (NodeAddr a) where
699 showsPrec i NodeAddr {..} 701 showsPrec i NodeAddr {..}
@@ -745,7 +747,7 @@ fromPeerAddr PeerAddr {..} = NodeAddr
745data NodeInfo a = NodeInfo 747data NodeInfo a = NodeInfo
746 { nodeId :: !NodeId 748 { nodeId :: !NodeId
747 , nodeAddr :: !(NodeAddr a) 749 , nodeAddr :: !(NodeAddr a)
748 } deriving (Show, Eq, Functor) 750 } deriving (Show, Eq, Functor, Foldable, Traversable)
749 751
750instance Eq a => Ord (NodeInfo a) where 752instance Eq a => Ord (NodeInfo a) where
751 compare = comparing nodeId 753 compare = comparing nodeId