diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 23:26:21 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 23:26:21 +0400 |
commit | 254a407eafe53d7d98b55a694b840f1af6fe5e75 (patch) | |
tree | 9464626052e0f05ce7e9d8b6fba147ce033d4498 /src/Network/BitTorrent/Exchange | |
parent | c7d84e12184430062305d1d4677a90df558484ea (diff) | |
parent | 8e4419d5bf7880ac862675dc4105cf6503c488bc (diff) |
Merge branch 'dev' of https://github.com/DanielG/bittorrent
Diffstat (limited to 'src/Network/BitTorrent/Exchange')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Assembler.hs | 9 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Message.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 6 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/Exchange/Assembler.hs b/src/Network/BitTorrent/Exchange/Assembler.hs index 5dc7c5ca..aa009f49 100644 --- a/src/Network/BitTorrent/Exchange/Assembler.hs +++ b/src/Network/BitTorrent/Exchange/Assembler.hs | |||
@@ -65,6 +65,7 @@ import Data.IntMap.Strict as IM | |||
65 | import Data.List as L | 65 | import Data.List as L |
66 | import Data.Map as M | 66 | import Data.Map as M |
67 | import Data.Maybe | 67 | import Data.Maybe |
68 | import Data.IP | ||
68 | 69 | ||
69 | import Data.Torrent.Piece | 70 | import Data.Torrent.Piece |
70 | import Network.BitTorrent.Core | 71 | import Network.BitTorrent.Core |
@@ -79,7 +80,7 @@ type PieceMap = IntMap | |||
79 | 80 | ||
80 | data Assembler = Assembler | 81 | data Assembler = Assembler |
81 | { -- | A set of blocks that have been 'Request'ed but not yet acked. | 82 | { -- | A set of blocks that have been 'Request'ed but not yet acked. |
82 | _inflight :: Map PeerAddr (PieceMap [BlockRange]) | 83 | _inflight :: Map (PeerAddr IP) (PieceMap [BlockRange]) |
83 | 84 | ||
84 | -- | A set of blocks that but not yet assembled. | 85 | -- | A set of blocks that but not yet assembled. |
85 | , _pending :: PieceMap Bucket | 86 | , _pending :: PieceMap Bucket |
@@ -114,7 +115,7 @@ allowPiece pix a @ Assembler {..} = over pending (IM.insert pix bkt) a | |||
114 | where | 115 | where |
115 | bkt = B.empty (piPieceLength info) | 116 | bkt = B.empty (piPieceLength info) |
116 | 117 | ||
117 | allowedSet :: PeerAddr -> Assembler -> [BlockIx] | 118 | allowedSet :: (PeerAddr IP) -> Assembler -> [BlockIx] |
118 | allowedSet = undefined | 119 | allowedSet = undefined |
119 | 120 | ||
120 | --inflight :: PeerAddr -> BlockIx -> Assembler -> Assembler | 121 | --inflight :: PeerAddr -> BlockIx -> Assembler -> Assembler |
@@ -123,7 +124,7 @@ allowedSet = undefined | |||
123 | -- You should check if a returned by peer block is actually have | 124 | -- You should check if a returned by peer block is actually have |
124 | -- been requested and in-flight. This is needed to avoid "I send | 125 | -- been requested and in-flight. This is needed to avoid "I send |
125 | -- random corrupted block" attacks. | 126 | -- random corrupted block" attacks. |
126 | insert :: PeerAddr -> Block a -> Assembler -> Assembler | 127 | insert :: (PeerAddr IP) -> Block a -> Assembler -> Assembler |
127 | insert = undefined | 128 | insert = undefined |
128 | 129 | ||
129 | {- | 130 | {- |
@@ -156,4 +157,4 @@ inserta :: Block a | |||
156 | -> (PieceMap [Block a], Maybe (Piece a)) | 157 | -> (PieceMap [Block a], Maybe (Piece a)) |
157 | inserta = undefined | 158 | inserta = undefined |
158 | 159 | ||
159 | -} \ No newline at end of file | 160 | -} |
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index 0adb8299..fb3a5c82 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs | |||
@@ -678,8 +678,8 @@ instance Default ExtendedHandshake where | |||
678 | 678 | ||
679 | instance BEncode ExtendedHandshake where | 679 | instance BEncode ExtendedHandshake where |
680 | toBEncode ExtendedHandshake {..} = toDict $ | 680 | toBEncode ExtendedHandshake {..} = toDict $ |
681 | "ipv4" .=? ehsIPv4 -- FIXME invalid encoding | 681 | "ipv4" .=? (S.encode <$> ehsIPv4) |
682 | .: "ipv6" .=? ehsIPv6 -- FIXME invalid encoding | 682 | .: "ipv6" .=? (S.encode <$> ehsIPv6) |
683 | .: "m" .=! ehsCaps | 683 | .: "m" .=! ehsCaps |
684 | .: "metadata_size" .=? ehsMetadataSize | 684 | .: "metadata_size" .=? ehsMetadataSize |
685 | .: "p" .=? ehsPort | 685 | .: "p" .=? ehsPort |
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index ae9babb3..27b4be12 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs | |||
@@ -505,7 +505,7 @@ initiateHandshake sock hs = do | |||
505 | recvHandshake sock | 505 | recvHandshake sock |
506 | 506 | ||
507 | -- | Tries to connect to peer using reasonable default parameters. | 507 | -- | Tries to connect to peer using reasonable default parameters. |
508 | connectToPeer :: PeerAddr -> IO Socket | 508 | connectToPeer :: (IPAddress i) => PeerAddr i -> IO Socket |
509 | connectToPeer p = do | 509 | connectToPeer p = do |
510 | sock <- socket AF_INET Stream Network.Socket.defaultProtocol | 510 | sock <- socket AF_INET Stream Network.Socket.defaultProtocol |
511 | connect sock (peerSockAddr p) | 511 | connect sock (peerSockAddr p) |
@@ -628,7 +628,7 @@ reconnect = undefined | |||
628 | -- | 628 | -- |
629 | -- This function can throw 'WireFailure' exception. | 629 | -- This function can throw 'WireFailure' exception. |
630 | -- | 630 | -- |
631 | connectWire :: Handshake -> PeerAddr -> ExtendedCaps -> Wire () -> IO () | 631 | connectWire :: (IPAddress i) => Handshake -> PeerAddr i -> ExtendedCaps -> Wire () -> IO () |
632 | connectWire hs addr extCaps wire = | 632 | connectWire hs addr extCaps wire = |
633 | bracket (connectToPeer addr) close $ \ sock -> do | 633 | bracket (connectToPeer addr) close $ \ sock -> do |
634 | hs' <- initiateHandshake sock hs | 634 | hs' <- initiateHandshake sock hs |
@@ -673,7 +673,7 @@ connectWire hs addr extCaps wire = | |||
673 | -- | 673 | -- |
674 | -- This function can throw 'WireFailure' exception. | 674 | -- This function can throw 'WireFailure' exception. |
675 | -- | 675 | -- |
676 | acceptWire :: Socket -> PeerAddr -> Wire () -> IO () | 676 | acceptWire :: (IPAddress i) => Socket -> PeerAddr i -> Wire () -> IO () |
677 | acceptWire sock peerAddr wire = do | 677 | acceptWire sock peerAddr wire = do |
678 | bracket (return sock) close $ \ _ -> do | 678 | bracket (return sock) close $ \ _ -> do |
679 | error "acceptWire: not implemented" | 679 | error "acceptWire: not implemented" |