]> git.rkrishnan.org Git - functorrent.git/blob - src/FuncTorrent/Tracker/Types.hs
refactoring: return type of tracker
[functorrent.git] / src / FuncTorrent / Tracker / Types.hs
1 {-
2  - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
3  -
4  - This file is part of FuncTorrent.
5  -
6  - FuncTorrent is free software; you can redistribute it and/or modify
7  - it under the terms of the GNU General Public License as published by
8  - the Free Software Foundation; either version 3 of the License, or
9  - (at your option) any later version.
10  -
11  - FuncTorrent is distributed in the hope that it will be useful,
12  - but WITHOUT ANY WARRANTY; without even the implied warranty of
13  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  - GNU General Public License for more details.
15  -
16  - You should have received a copy of the GNU General Public License
17  - along with FuncTorrent; if not,  see <http://www.gnu.org/licenses/>
18  -}
19
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE DuplicateRecordFields #-}
22 module FuncTorrent.Tracker.Types
23        ( TrackerProtocol(..)
24        , HttpTrackerResponse(..)
25        , UdpTrackerResponse(..)
26        , TrackerEventState(..)
27        , TState(..)
28        , TrackerMsg(..)
29        ) where
30
31 import Data.ByteString (ByteString)
32 import Data.Word (Word32)
33 import Control.Concurrent.MVar (MVar)
34
35 import FuncTorrent.PeerMsgs (Peer)
36
37 data TrackerProtocol = Http
38                      | Udp
39                      | UnknownProtocol
40                      deriving (Show)
41
42 data TrackerEventState = None
43                        | Started
44                        | Completed
45                        | Stopped
46                        deriving (Show, Eq)
47
48 data TrackerMsg = GetStatusMsg TrackerEventState
49                 | GetConnectedPeersMsg (MVar [Peer])
50
51 data TState = TState { left :: Integer
52                      , currentState :: TrackerEventState
53                      , connectedPeers :: MVar [Peer]
54                      }
55
56 -- | Tracker response
57 data HttpTrackerResponse = HttpTrackerResponse {
58   interval :: Integer
59   , peers :: [Peer]
60   , complete :: Maybe Integer
61   , incomplete :: Maybe Integer
62   } deriving (Show, Eq)
63
64 data UdpTrackerResponse = UdpTrackerResponse {
65   leechers :: Word32
66   , seeders :: Word32
67   , interval :: Word32
68   , peers :: [Peer]
69   } deriving (Show)