diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2013-12-22 22:05:17 +0000 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2013-12-22 22:05:17 +0000 |
commit | 6dd7c5a05787176cd83df9dc21fca7160611f465 (patch) | |
tree | f5d46acb402eea4810ffc234a8eaa3ee47a22892 | |
parent | ff6e18a0ff146bd84c5d68b6e0a1a73cc12af7bf (diff) |
Add connRemoteEhs field to Connection
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 14 |
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 | |||
550 | getExtCaps :: Wire ExtendedCaps | 553 | getExtCaps :: Wire ExtendedCaps |
551 | getExtCaps = lift $ readRef connExtCaps | 554 | getExtCaps = lift $ readRef connExtCaps |
552 | 555 | ||
556 | setRemoteEhs :: ExtendedHandshake -> Wire () | ||
557 | setRemoteEhs = lift . writeRef connRemoteEhs | ||
558 | |||
559 | getRemoteEhs :: Wire ExtendedHandshake | ||
560 | getRemoteEhs = 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. |
555 | getStats :: Wire ConnectionStats | 564 | getStats :: 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 | ||
619 | rehandshake :: ExtendedCaps -> Wire () | 629 | rehandshake :: 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 | ||