diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/ContactInfo.hs | 77 |
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 @@ | |||
1 | module Network.BitTorrent.DHT.ContactInfo () where | 1 | module Network.BitTorrent.DHT.ContactInfo |
2 | ( ) where | ||
3 | {- | ||
2 | import Data.HashMap.Strict as HM | 4 | import Data.HashMap.Strict as HM |
3 | 5 | ||
4 | import Data.Torrent.InfoHash | 6 | import 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 | |||
17 | type PeerSet a = [(PeerAddr a, NodeInfo a, Timestamp)] | ||
18 | |||
19 | -- compare PSQueue vs Ordered list | ||
20 | |||
21 | takeNewest :: PeerSet a -> [PeerAddr a] | ||
22 | takeNewest = undefined | ||
23 | |||
24 | dropOld :: Timestamp -> PeerSet a -> PeerSet a | ||
25 | dropOld = undefined | ||
26 | |||
27 | insert :: PeerAddr a -> Timestamp -> PeerSet a -> PeerSet a | ||
28 | insert = undefined | ||
29 | |||
30 | type Mask = Int | ||
31 | type Size = Int | ||
32 | type Timestamp = Int | ||
33 | |||
34 | {----------------------------------------------------------------------- | ||
35 | -- InfoHashMap | ||
36 | -----------------------------------------------------------------------} | ||
37 | |||
38 | -- compare handwritten prefix tree versus IntMap | ||
39 | |||
40 | data Tree a | ||
41 | = Nil | ||
42 | | Tip !InfoHash !(PeerSet a) | ||
43 | | Bin !InfoHash !Mask !Size !Timestamp (Tree a) (Tree a) | ||
44 | |||
45 | insertTree :: InfoHash -> a -> Tree a -> Tree a | ||
46 | insertTree = undefined | ||
47 | |||
48 | type Prio = Int | ||
49 | |||
50 | --shrink :: ContactInfo ip -> Int | ||
51 | shrink Nil = Nil | ||
52 | shrink (Tip _ _) = undefined | ||
53 | shrink (Bin _ _) = undefined | ||
54 | |||
55 | {----------------------------------------------------------------------- | ||
56 | -- InfoHashMap | ||
57 | -----------------------------------------------------------------------} | ||
58 | |||
59 | -- compare new design versus HashMap | ||
60 | |||
61 | data IntMap k p a | ||
62 | type ContactInfo = Map InfoHash Timestamp (Set (PeerAddr IP) Timestamp) | ||
63 | |||
11 | data ContactInfo ip = PeerStore | 64 | data 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 | |||
73 | size :: ContactInfo ip -> Int | ||
74 | size = undefined | ||
75 | |||
76 | prefixSize :: ContactInfo ip -> Int | ||
77 | prefixSize = undefined | ||
78 | |||
79 | lookup :: InfoHash -> ContactInfo ip -> [PeerAddr ip] | ||
80 | lookup = undefined | ||
81 | |||
82 | insert :: InfoHash -> PeerAddr ip -> ContactInfo ip -> ContactInfo ip | ||
83 | insert = undefined | ||
84 | |||
85 | -- | Limit in size. | ||
86 | prune :: NodeId -> Int -> ContactInfo ip -> ContactInfo ip | ||
87 | prune pref targetSize Nil = Nil | ||
88 | prune pref targetSize (Tip _ _) = undefined | ||
89 | |||
90 | -- | Remove expired entries. | ||
91 | splitGT :: Timestamp -> ContactInfo ip -> ContactInfo ip | ||
92 | splitGT = undefined | ||
93 | -} \ No newline at end of file | ||