diff options
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Wire.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index 4ddade66..53c9afb2 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs | |||
@@ -50,9 +50,9 @@ module Network.BitTorrent.Exchange.Wire | |||
50 | , connStats | 50 | , connStats |
51 | 51 | ||
52 | -- * Setup | 52 | -- * Setup |
53 | , ConnectionPrefs (..) | 53 | , ConnectionPrefs (..) |
54 | , ConnectionSession (..) | 54 | , SessionLink (..) |
55 | , ConnectionConfig (..) | 55 | , ConnectionConfig (..) |
56 | 56 | ||
57 | -- ** Initiate | 57 | -- ** Initiate |
58 | , connectWire | 58 | , connectWire |
@@ -753,17 +753,18 @@ instance Default ConnectionPrefs where | |||
753 | normalize :: ConnectionPrefs -> ConnectionPrefs | 753 | normalize :: ConnectionPrefs -> ConnectionPrefs |
754 | normalize = undefined | 754 | normalize = undefined |
755 | 755 | ||
756 | data ConnectionSession s = ConnectionSession | 756 | -- | Bridge between 'Connection' and 'Network.BitTorrent.Exchange.Session'. |
757 | { sessionTopic :: !(InfoHash) | 757 | data SessionLink s = SessionLink |
758 | , sessionPeerId :: !(PeerId) | 758 | { linkTopic :: !(InfoHash) |
759 | , metadataSize :: !(Maybe Int) | 759 | , linkPeerId :: !(PeerId) |
760 | , outputChan :: !(Maybe (Chan Message)) | 760 | , linkMetadataSize :: !(Maybe Int) |
761 | , connectionSession :: !(s) | 761 | , linkOutputChan :: !(Maybe (Chan Message)) |
762 | , linkSession :: !(s) | ||
762 | } | 763 | } |
763 | 764 | ||
764 | data ConnectionConfig s = ConnectionConfig | 765 | data ConnectionConfig s = ConnectionConfig |
765 | { cfgPrefs :: !(ConnectionPrefs) | 766 | { cfgPrefs :: !(ConnectionPrefs) |
766 | , cfgSession :: !(ConnectionSession s) | 767 | , cfgSession :: !(SessionLink s) |
767 | , cfgWire :: !(Wire s ()) | 768 | , cfgWire :: !(Wire s ()) |
768 | } | 769 | } |
769 | 770 | ||
@@ -771,8 +772,8 @@ configHandshake :: ConnectionConfig s -> Handshake | |||
771 | configHandshake ConnectionConfig {..} = Handshake | 772 | configHandshake ConnectionConfig {..} = Handshake |
772 | { hsProtocol = prefProtocol cfgPrefs | 773 | { hsProtocol = prefProtocol cfgPrefs |
773 | , hsReserved = prefCaps cfgPrefs | 774 | , hsReserved = prefCaps cfgPrefs |
774 | , hsInfoHash = sessionTopic cfgSession | 775 | , hsInfoHash = linkTopic cfgSession |
775 | , hsPeerId = sessionPeerId cfgSession | 776 | , hsPeerId = linkPeerId cfgSession |
776 | } | 777 | } |
777 | 778 | ||
778 | {----------------------------------------------------------------------- | 779 | {----------------------------------------------------------------------- |
@@ -841,13 +842,13 @@ afterHandshaking :: ChannelSide -> PeerAddr IP -> Socket -> HandshakePair | |||
841 | afterHandshaking initiator addr sock | 842 | afterHandshaking initiator addr sock |
842 | hpair @ (HandshakePair hs hs') | 843 | hpair @ (HandshakePair hs hs') |
843 | (ConnectionConfig | 844 | (ConnectionConfig |
844 | { cfgPrefs = ConnectionPrefs {..} | 845 | { cfgPrefs = ConnectionPrefs {..} |
845 | , cfgSession = ConnectionSession {..} | 846 | , cfgSession = SessionLink {..} |
846 | , cfgWire = wire | 847 | , cfgWire = wire |
847 | }) = do | 848 | }) = do |
848 | let caps = hsReserved hs <> hsReserved hs' | 849 | let caps = hsReserved hs <> hsReserved hs' |
849 | cstate <- newIORef def { _connStats = establishedStats hpair } | 850 | cstate <- newIORef def { _connStats = establishedStats hpair } |
850 | chan <- maybe newChan return outputChan | 851 | chan <- maybe newChan return linkOutputChan |
851 | let conn = Connection { | 852 | let conn = Connection { |
852 | connInitiatedBy = initiator | 853 | connInitiatedBy = initiator |
853 | , connRemoteAddr = addr | 854 | , connRemoteAddr = addr |
@@ -858,7 +859,7 @@ afterHandshaking initiator addr sock | |||
858 | , connThisPeerId = hsPeerId hs | 859 | , connThisPeerId = hsPeerId hs |
859 | , connOptions = def | 860 | , connOptions = def |
860 | , connState = cstate | 861 | , connState = cstate |
861 | , connSession = connectionSession | 862 | , connSession = linkSession |
862 | , connChan = chan | 863 | , connChan = chan |
863 | } | 864 | } |
864 | 865 | ||
@@ -897,7 +898,7 @@ connectWire addr cfg = do | |||
897 | acceptWire :: PendingConnection -> ConnectionConfig s -> IO () | 898 | acceptWire :: PendingConnection -> ConnectionConfig s -> IO () |
898 | acceptWire pc @ PendingConnection {..} cfg = do | 899 | acceptWire pc @ PendingConnection {..} cfg = do |
899 | bracket (return pendingSock) close $ \ _ -> do | 900 | bracket (return pendingSock) close $ \ _ -> do |
900 | unless (sessionTopic (cfgSession cfg) == pendingTopic) $ do | 901 | unless (linkTopic (cfgSession cfg) == pendingTopic) $ do |
901 | throwIO (ProtocolError (UnexpectedTopic pendingTopic)) | 902 | throwIO (ProtocolError (UnexpectedTopic pendingTopic)) |
902 | 903 | ||
903 | let hs = configHandshake cfg | 904 | let hs = configHandshake cfg |