summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs
index 5f7b0ebe..109f6551 100644
--- a/src/Network/BitTorrent/Exchange/Wire.hs
+++ b/src/Network/BitTorrent/Exchange/Wire.hs
@@ -455,6 +455,9 @@ data Connection = Connection
455 -- map. 455 -- map.
456 , connExtCaps :: !(IORef ExtendedCaps) 456 , connExtCaps :: !(IORef ExtendedCaps)
457 457
458 -- | Current extended handshake information from the remote peer
459 , connRemoteEhs :: !(IORef ExtendedHandshake)
460
458 -- | Various stats about messages sent and received. Stats can be 461 -- | Various stats about messages sent and received. Stats can be
459 -- used to protect /this/ peer against flood attacks. 462 -- used to protect /this/ peer against flood attacks.
460 , connStats :: !(IORef ConnectionStats) 463 , connStats :: !(IORef ConnectionStats)
@@ -550,6 +553,12 @@ setExtCaps = lift . writeRef connExtCaps
550getExtCaps :: Wire ExtendedCaps 553getExtCaps :: Wire ExtendedCaps
551getExtCaps = lift $ readRef connExtCaps 554getExtCaps = lift $ readRef connExtCaps
552 555
556setRemoteEhs :: ExtendedHandshake -> Wire ()
557setRemoteEhs = lift . writeRef connRemoteEhs
558
559getRemoteEhs :: Wire ExtendedHandshake
560getRemoteEhs = lift $ readRef connRemoteEhs
561
553-- | Get current stats. Note that this value will change with the next 562-- | Get current stats. Note that this value will change with the next
554-- sent or received message. 563-- sent or received message.
555getStats :: Wire ConnectionStats 564getStats :: Wire ConnectionStats
@@ -612,8 +621,9 @@ extendedHandshake caps = do
612 sendMessage $ nullExtendedHandshake caps 621 sendMessage $ nullExtendedHandshake caps
613 msg <- recvMessage 622 msg <- recvMessage
614 case msg of 623 case msg of
615 Extended (EHandshake ExtendedHandshake {..}) -> do 624 Extended (EHandshake remoteEhs@(ExtendedHandshake {..})) -> do
616 setExtCaps $ ehsCaps <> caps 625 setExtCaps $ ehsCaps <> caps
626 setRemoteEhs remoteEhs
617 _ -> protocolError HandshakeRefused 627 _ -> protocolError HandshakeRefused
618 628
619rehandshake :: ExtendedCaps -> Wire () 629rehandshake :: ExtendedCaps -> Wire ()
@@ -651,6 +661,7 @@ connectWire hs addr extCaps wire =
651 else wire 661 else wire
652 662
653 extCapsRef <- newIORef def 663 extCapsRef <- newIORef def
664 remoteEhs <- newIORef def
654 statsRef <- newIORef ConnectionStats 665 statsRef <- newIORef ConnectionStats
655 { outcomingFlow = FlowStats 1 $ handshakeStats hs 666 { outcomingFlow = FlowStats 1 $ handshakeStats hs
656 , incomingFlow = FlowStats 1 $ handshakeStats hs' 667 , incomingFlow = FlowStats 1 $ handshakeStats hs'
@@ -664,6 +675,7 @@ connectWire hs addr extCaps wire =
664 , connThisPeerId = hsPeerId hs 675 , connThisPeerId = hsPeerId hs
665 , connOptions = def 676 , connOptions = def
666 , connExtCaps = extCapsRef 677 , connExtCaps = extCapsRef
678 , connRemoteEhs = remoteEhs
667 , connStats = statsRef 679 , connStats = statsRef
668 } 680 }
669 681