summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange.hs
blob: 425ed2a3d76d620df34376c5141fdfb88aec4e6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- |
--   Copyright   :  (c) Sam T. 2013
--   License     :  MIT
--   Maintainer  :  pxqr.sta@gmail.com
--   Stability   :  experimental
--   Portability :  portable
--
{-# LANGUAGE DoAndIfThenElse #-}
module Network.BitTorrent.Exchange
       (
         -- * Session
         PeerSession, newLeacher, newSeeder
       ) where

import Control.Applicative
import Control.Concurrent
import Control.Concurrent.STM
import Data.IORef
import Data.Function
import Data.Ord
import Data.Set as S

import Data.Conduit
import Data.Conduit.Cereal
import Data.Conduit.Network
import Data.Serialize

import Network.BitTorrent.Exchange.Selection as PW
import Network.BitTorrent.Exchange.Protocol as PW

import Network.BitTorrent.Internal
import Network.BitTorrent.Extension
import Network.BitTorrent.Peer
import Data.Bitfield as BF
import Data.Torrent

{-----------------------------------------------------------------------
    P2P monad
-----------------------------------------------------------------------}

{-
type P2P = Reader PeerSession (ConduitM Message Message IO)

conduit :: Socket -> P2P a -> IO a
conduit sock p2p =
  sourceSocket sock   $=
    conduitGet get    $=
      messageLoop p2p $=
    conduitPut put    $$
  sinkSocket sock

messageLoop :: P2P () -> P2P ()
messageLoop = undefined

runP2P :: SSession -> PeerAddr -> P2P a -> IO a
runP2P se addr p2p = withPeer se addr $ conduit messageLoop

data Event = Available
           | Want
           | Block

{-
waitForEvent :: P2P Event
signalEvent  :: Event -> P2P ()
-}
-}