3 * Tree keeping track of the availability of each bin in a swarm
5 * Created by Riccardo Petrocco
6 * Copyright 2009-2012 Delft University of Technology. All rights reserved.
14 #ifndef AVAILABILITY_H
15 #define AVAILABILITY_H
19 typedef std::vector< std::pair<uint32_t, binmap_t*> > WaitingPeers;
28 Availability(void) { size_ = 0; }
34 explicit Availability(int size)
38 avail_ = new uint8_t[size];
47 /** return the availability array */
48 uint8_t* get() { return avail_; }
50 /** returns the availability of a single bin */
51 uint8_t get(const bin_t bin);
53 /** set/update the availability */
54 void set(uint32_t channel_id, binmap_t& binmap, bin_t target);
56 /** removes the binmap of leaving peers */
57 void remove(uint32_t channel_id, binmap_t& binmap);
59 /** returns the size of the availability tree */
60 int size() { return size_; }
62 /** sets the size of the availability tree once we know the size of the file */
63 void setSize(uint64_t size);
66 void setBinmap(binmap_t *binmap);
68 /** get rarest bin, of specified width, within a range */
69 bin_t getRarest(const bin_t range, int width);
71 /** Echo the availability status to stdout */
77 // a list of incoming have msgs, those are saved only it the file size is still unknown
78 // TODO fix... set it depending on the # of channels * something
79 WaitingPeers waiting_peers_;
80 //binmap_t *waiting_[20];
84 /** removes the binmap */
85 void removeBinmap(binmap_t& binmap);
87 /** removes the bin */
88 void removeBin(bin_t bin);
91 void setBin(bin_t bin);