summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-14 23:26:21 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-14 23:26:21 +0400
commit254a407eafe53d7d98b55a694b840f1af6fe5e75 (patch)
tree9464626052e0f05ce7e9d8b6fba147ce033d4498 /src/Network/BitTorrent/Exchange
parentc7d84e12184430062305d1d4677a90df558484ea (diff)
parent8e4419d5bf7880ac862675dc4105cf6503c488bc (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.hs9
-rw-r--r--src/Network/BitTorrent/Exchange/Message.hs4
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs6
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
65import Data.List as L 65import Data.List as L
66import Data.Map as M 66import Data.Map as M
67import Data.Maybe 67import Data.Maybe
68import Data.IP
68 69
69import Data.Torrent.Piece 70import Data.Torrent.Piece
70import Network.BitTorrent.Core 71import Network.BitTorrent.Core
@@ -79,7 +80,7 @@ type PieceMap = IntMap
79 80
80data Assembler = Assembler 81data 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
117allowedSet :: PeerAddr -> Assembler -> [BlockIx] 118allowedSet :: (PeerAddr IP) -> Assembler -> [BlockIx]
118allowedSet = undefined 119allowedSet = 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.
126insert :: PeerAddr -> Block a -> Assembler -> Assembler 127insert :: (PeerAddr IP) -> Block a -> Assembler -> Assembler
127insert = undefined 128insert = 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))
157inserta = undefined 158inserta = 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
679instance BEncode ExtendedHandshake where 679instance 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.
508connectToPeer :: PeerAddr -> IO Socket 508connectToPeer :: (IPAddress i) => PeerAddr i -> IO Socket
509connectToPeer p = do 509connectToPeer 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--
631connectWire :: Handshake -> PeerAddr -> ExtendedCaps -> Wire () -> IO () 631connectWire :: (IPAddress i) => Handshake -> PeerAddr i -> ExtendedCaps -> Wire () -> IO ()
632connectWire hs addr extCaps wire = 632connectWire 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--
676acceptWire :: Socket -> PeerAddr -> Wire () -> IO () 676acceptWire :: (IPAddress i) => Socket -> PeerAddr i -> Wire () -> IO ()
677acceptWire sock peerAddr wire = do 677acceptWire 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"