summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/ContactInfo.hs
blob: 028a4214c974e1eab35bc0d44b441b8cca580748 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module Network.BitTorrent.DHT.ContactInfo
       (        ) where
{-
import Data.HashMap.Strict as HM

import Data.Torrent.InfoHash
import Network.BitTorrent.Core

-- increase prefix when table is too large
-- decrease prefix when table is too small
-- filter outdated peers

{-----------------------------------------------------------------------
--  PeerSet
-----------------------------------------------------------------------}

type PeerSet a = [(PeerAddr a, NodeInfo a, Timestamp)]

-- compare PSQueue vs Ordered list

takeNewest :: PeerSet a -> [PeerAddr a]
takeNewest = undefined

dropOld :: Timestamp -> PeerSet a -> PeerSet a
dropOld = undefined

insert :: PeerAddr a -> Timestamp -> PeerSet a -> PeerSet a
insert = undefined

type Mask = Int
type Size = Int
type Timestamp = Int

{-----------------------------------------------------------------------
--  InfoHashMap
-----------------------------------------------------------------------}

-- compare handwritten prefix tree versus IntMap

data Tree a
  = Nil
  | Tip !InfoHash !(PeerSet a)
  | Bin !InfoHash !Mask !Size !Timestamp (Tree a) (Tree a)

insertTree :: InfoHash -> a -> Tree a -> Tree a
insertTree = undefined

type Prio = Int

--shrink :: ContactInfo ip -> Int
shrink  Nil      = Nil
shrink (Tip _ _) = undefined
shrink (Bin _ _) = undefined

{-----------------------------------------------------------------------
-- InfoHashMap
-----------------------------------------------------------------------}

-- compare new design versus HashMap

data IntMap k p a
type ContactInfo = Map InfoHash Timestamp (Set (PeerAddr IP) Timestamp)

data ContactInfo ip = PeerStore
  { maxSize    :: Int
  , prefixSize :: Int
  , thisNodeId :: NodeId

  , count      :: Int  -- ^ Cached size of the 'peerSet'
  , peerSet    :: HashMap InfoHash [PeerAddr ip]
  }

size :: ContactInfo ip -> Int
size = undefined

prefixSize :: ContactInfo ip -> Int
prefixSize = undefined

lookup :: InfoHash -> ContactInfo ip -> [PeerAddr ip]
lookup = undefined

insert :: InfoHash -> PeerAddr ip -> ContactInfo ip -> ContactInfo ip
insert = undefined

-- | Limit in size.
prune :: NodeId -> Int -> ContactInfo ip -> ContactInfo ip
prune pref targetSize  Nil      = Nil
prune pref targetSize (Tip _ _) = undefined

-- | Remove expired entries.
splitGT :: Timestamp -> ContactInfo ip -> ContactInfo ip
splitGT = undefined
-}