diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2013-12-22 22:04:41 +0000 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-25 07:32:38 +0400 |
commit | af5bc8e39f3603ba8ce362f23b0f40b9a10a4ba0 (patch) | |
tree | 1c836a17e09c019a8a633c6a6087a10499e74ef9 /src | |
parent | 96098e860d20e18637764156b3a067371bd49110 (diff) |
Add Monoid instance for ExtendedHandshake
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Message.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index b7567e60..8d0c62f4 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs | |||
@@ -677,6 +677,24 @@ defaultQueueLength = 1 | |||
677 | instance Default ExtendedHandshake where | 677 | instance Default ExtendedHandshake where |
678 | def = ExtendedHandshake def def def def def def def def | 678 | def = ExtendedHandshake def def def def def def def def |
679 | 679 | ||
680 | instance Monoid ExtendedHandshake where | ||
681 | mempty = def { ehsCaps = mempty } | ||
682 | mappend old new = | ||
683 | ExtendedHandshake { | ||
684 | ehsCaps = ehsCaps old <> ehsCaps new, | ||
685 | ehsIPv4 = ehsIPv4 old `mergeOld` ehsIPv4 new, | ||
686 | ehsIPv6 = ehsIPv6 old `mergeOld` ehsIPv6 new, | ||
687 | ehsMetadataSize = ehsMetadataSize old `mergeNew` ehsMetadataSize new, | ||
688 | ehsPort = ehsPort old `mergeOld` ehsPort new, | ||
689 | ehsQueueLength = ehsQueueLength old `mergeNew` ehsQueueLength new, | ||
690 | ehsVersion = ehsVersion old `mergeOld` ehsVersion new, | ||
691 | ehsYourIp = ehsYourIp old `mergeOld` ehsYourIp new | ||
692 | } | ||
693 | where | ||
694 | mergeOld old new = old <|> new | ||
695 | mergeNew old new = new <|> old | ||
696 | |||
697 | |||
680 | instance BEncode ExtendedHandshake where | 698 | instance BEncode ExtendedHandshake where |
681 | toBEncode ExtendedHandshake {..} = toDict $ | 699 | toBEncode ExtendedHandshake {..} = toDict $ |
682 | "ipv4" .=? (S.encode <$> ehsIPv4) | 700 | "ipv4" .=? (S.encode <$> ehsIPv4) |