summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2013-12-22 22:04:41 +0000
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-25 07:32:38 +0400
commitaf5bc8e39f3603ba8ce362f23b0f40b9a10a4ba0 (patch)
tree1c836a17e09c019a8a633c6a6087a10499e74ef9 /src
parent96098e860d20e18637764156b3a067371bd49110 (diff)
Add Monoid instance for ExtendedHandshake
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/Exchange/Message.hs18
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
677instance Default ExtendedHandshake where 677instance 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
680instance 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
680instance BEncode ExtendedHandshake where 698instance BEncode ExtendedHandshake where
681 toBEncode ExtendedHandshake {..} = toDict $ 699 toBEncode ExtendedHandshake {..} = toDict $
682 "ipv4" .=? (S.encode <$> ehsIPv4) 700 "ipv4" .=? (S.encode <$> ehsIPv4)