summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/ContactInfo.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r--src/Network/BitTorrent/DHT/ContactInfo.hs77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs
index 06d2dac0..028a4214 100644
--- a/src/Network/BitTorrent/DHT/ContactInfo.hs
+++ b/src/Network/BitTorrent/DHT/ContactInfo.hs
@@ -1,4 +1,6 @@
1module Network.BitTorrent.DHT.ContactInfo () where 1module Network.BitTorrent.DHT.ContactInfo
2 ( ) where
3{-
2import Data.HashMap.Strict as HM 4import Data.HashMap.Strict as HM
3 5
4import Data.Torrent.InfoHash 6import Data.Torrent.InfoHash
@@ -8,6 +10,57 @@ import Network.BitTorrent.Core
8-- decrease prefix when table is too small 10-- decrease prefix when table is too small
9-- filter outdated peers 11-- filter outdated peers
10 12
13{-----------------------------------------------------------------------
14-- PeerSet
15-----------------------------------------------------------------------}
16
17type PeerSet a = [(PeerAddr a, NodeInfo a, Timestamp)]
18
19-- compare PSQueue vs Ordered list
20
21takeNewest :: PeerSet a -> [PeerAddr a]
22takeNewest = undefined
23
24dropOld :: Timestamp -> PeerSet a -> PeerSet a
25dropOld = undefined
26
27insert :: PeerAddr a -> Timestamp -> PeerSet a -> PeerSet a
28insert = undefined
29
30type Mask = Int
31type Size = Int
32type Timestamp = Int
33
34{-----------------------------------------------------------------------
35-- InfoHashMap
36-----------------------------------------------------------------------}
37
38-- compare handwritten prefix tree versus IntMap
39
40data Tree a
41 = Nil
42 | Tip !InfoHash !(PeerSet a)
43 | Bin !InfoHash !Mask !Size !Timestamp (Tree a) (Tree a)
44
45insertTree :: InfoHash -> a -> Tree a -> Tree a
46insertTree = undefined
47
48type Prio = Int
49
50--shrink :: ContactInfo ip -> Int
51shrink Nil = Nil
52shrink (Tip _ _) = undefined
53shrink (Bin _ _) = undefined
54
55{-----------------------------------------------------------------------
56-- InfoHashMap
57-----------------------------------------------------------------------}
58
59-- compare new design versus HashMap
60
61data IntMap k p a
62type ContactInfo = Map InfoHash Timestamp (Set (PeerAddr IP) Timestamp)
63
11data ContactInfo ip = PeerStore 64data ContactInfo ip = PeerStore
12 { maxSize :: Int 65 { maxSize :: Int
13 , prefixSize :: Int 66 , prefixSize :: Int
@@ -16,3 +69,25 @@ data ContactInfo ip = PeerStore
16 , count :: Int -- ^ Cached size of the 'peerSet' 69 , count :: Int -- ^ Cached size of the 'peerSet'
17 , peerSet :: HashMap InfoHash [PeerAddr ip] 70 , peerSet :: HashMap InfoHash [PeerAddr ip]
18 } 71 }
72
73size :: ContactInfo ip -> Int
74size = undefined
75
76prefixSize :: ContactInfo ip -> Int
77prefixSize = undefined
78
79lookup :: InfoHash -> ContactInfo ip -> [PeerAddr ip]
80lookup = undefined
81
82insert :: InfoHash -> PeerAddr ip -> ContactInfo ip -> ContactInfo ip
83insert = undefined
84
85-- | Limit in size.
86prune :: NodeId -> Int -> ContactInfo ip -> ContactInfo ip
87prune pref targetSize Nil = Nil
88prune pref targetSize (Tip _ _) = undefined
89
90-- | Remove expired entries.
91splitGT :: Timestamp -> ContactInfo ip -> ContactInfo ip
92splitGT = undefined
93-} \ No newline at end of file