diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-20 04:11:04 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-20 04:11:04 +0400 |
commit | 2eade3a3dc198e602ffd834fdd95ac53ee172e7a (patch) | |
tree | ac0754c8ae339365d200446e374df332e5209157 /src/Network/BitTorrent/Peer.hs | |
parent | 6253cd5c8e1b482d78881282f3d2a271b63d1a33 (diff) |
~ Move compact peer list decoding to Peer.
Diffstat (limited to 'src/Network/BitTorrent/Peer.hs')
-rw-r--r-- | src/Network/BitTorrent/Peer.hs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Peer.hs b/src/Network/BitTorrent/Peer.hs index 7bac336b..7e4a1b5d 100644 --- a/src/Network/BitTorrent/Peer.hs +++ b/src/Network/BitTorrent/Peer.hs | |||
@@ -51,6 +51,7 @@ module Network.BitTorrent.Peer | |||
51 | 51 | ||
52 | -- * Peer address | 52 | -- * Peer address |
53 | , PeerAddr(..) | 53 | , PeerAddr(..) |
54 | , getCompactPeerList | ||
54 | , peerSockAddr | 55 | , peerSockAddr |
55 | , connectToPeer | 56 | , connectToPeer |
56 | , ppPeer | 57 | , ppPeer |
@@ -496,8 +497,8 @@ nameMap = | |||
496 | -- compact list encoding. | 497 | -- compact list encoding. |
497 | data PeerAddr = PeerAddr { | 498 | data PeerAddr = PeerAddr { |
498 | peerID :: Maybe PeerId | 499 | peerID :: Maybe PeerId |
499 | , peerIP :: HostAddress | 500 | , peerIP :: {-# UNPACK #-} !HostAddress |
500 | , peerPort :: PortNumber | 501 | , peerPort :: {-# UNPACK #-} !PortNumber |
501 | } deriving (Show, Eq, Ord) | 502 | } deriving (Show, Eq, Ord) |
502 | 503 | ||
503 | -- TODO check semantic of ord and eq instances | 504 | -- TODO check semantic of ord and eq instances |
@@ -520,6 +521,20 @@ instance BEncodable PeerAddr where | |||
520 | 521 | ||
521 | fromBEncode _ = decodingError "PeerAddr" | 522 | fromBEncode _ = decodingError "PeerAddr" |
522 | 523 | ||
524 | instance Serialize PortNumber where | ||
525 | get = fromIntegral <$> getWord16be | ||
526 | {-# INLINE get #-} | ||
527 | put = putWord16be . fromIntegral | ||
528 | {-# INLINE put #-} | ||
529 | |||
530 | instance Serialize PeerAddr where | ||
531 | put PeerAddr {..} = put peerID >> put peerPort | ||
532 | {-# INLINE put #-} | ||
533 | get = PeerAddr Nothing <$> get <*> get | ||
534 | {-# INLINE get #-} | ||
535 | |||
536 | getCompactPeerList :: Get [PeerAddr] | ||
537 | getCompactPeerList = many get | ||
523 | 538 | ||
524 | -- TODO make platform independent, clarify htonl | 539 | -- TODO make platform independent, clarify htonl |
525 | 540 | ||