32 PeerHashMap::iterator it;
34 delete it->second.info;
66 if (bootstrapped) offset += 1<<0;
67 if (malicious) offset += 1<<1;
72 PeerHashMap::iterator it)
74 PeerInfo* peerInfo = it->second.info;
76 bool bootstrapped =
false;
77 for (AddrPerOverlayVector::iterator oit = it->second.addrVector.begin();
78 oit != it->second.addrVector.end(); oit++) {
80 bootstrapped |= oit->bootstrapped;
85 size_t offset =
calcOffset(bootstrapped, malicious);
86 size_t partitionIndex = partition*
offsetSize()+offset;
89 std::cout <<
"INSERT " << it->first <<
" partitionIndex:"
91 <<
" bootstrapped:" << bootstrapped <<
" malicious:"
92 << malicious << std::endl;
95 if (peerVector.size() < (partition + 1)*
offsetSize()) {
96 int i = peerVector.size();
97 peerVector.resize(
offsetSize()*(partition + 1));
99 while (i < (
int)(peerVector.size())) {
100 peerVector[i++].reserve(30000);
112 peerVector[partitionIndex][index] = it;
115 index = peerVector[partitionIndex].size();
116 peerVector[partitionIndex].push_back(it);
120 it->second.peerVectorIndex = index;
124 PeerHashMap::iterator it)
126 PeerInfo* peerInfo = it->second.info;
128 bool bootstrapped =
false;
129 for (AddrPerOverlayVector::iterator oit = it->second.addrVector.begin();
130 oit != it->second.addrVector.end(); oit++) {
132 bootstrapped |= oit->bootstrapped;
136 size_t partition = peerInfo->
getTypeID();
137 size_t offset =
calcOffset(bootstrapped, malicious);
138 size_t index = it->second.peerVectorIndex;
139 size_t partitionIndex = partition*
offsetSize()+offset;
141 if (peerVector[partitionIndex].
size() == (index + 1)) {
142 peerVector[partitionIndex].pop_back();
144 peerVector[partitionIndex][index] =
peerHashMap.end();
151 std::pair<const PeerHashMap::iterator, bool>
PeerStorage::insert(
const std::pair<IPvXAddress, BootstrapEntry>& element)
153 std::pair<PeerHashMap::iterator, bool> ret;
167 delete it->second.info;
175 it->second.addrVector.setAddrForOverlayId(
new NodeHandle(peer),
189 throw cRuntimeError(
"GlobalNodeList::setMalicious(): Node not found!");
193 it->second.info->setMalicious(malicious);
198 int32_t overlayId,
bool bootstrapped)
201 throw cRuntimeError(
"GlobalNodeList::setBootstrapped(): Node not found!");
208 AddrPerOverlayVector::iterator oit = it->
209 second.addrVector.getIterForOverlayId(overlayId);
211 if (oit != it->second.addrVector.end()) {
212 oit->bootstrapped = bootstrapped;
213 }
else if (bootstrapped) {
214 throw cRuntimeError(
"PeerStorage::setBootstrapped: No valid entry found!");
222 bool bootstrappedNeeded,
223 bool inoffensiveNeeded)
226 std::cout <<
"getRandomNode: empty!" << std::endl;
238 for (uint i = 0; i < peerVector.size(); i++) {
239 if (((nodeType > -1) && ((uint)nodeType != i/
offsetSize())) ||
240 (bootstrappedNeeded && !(i & 1)) ||
241 (inoffensiveNeeded && (i & 2))) {
245 sum += (peerVector[i].size() -
freeVector[i].size());
253 size_t random = intuniform(1, sum);
256 while ((i < peerVector.size())) {
257 if (((nodeType > -1) && ((uint)nodeType != i/
offsetSize())) ||
258 (bootstrappedNeeded && !(i & 1)) ||
259 (inoffensiveNeeded && (i & 2))) {
262 }
else if ((peerVector[i].
size() -
freeVector[i].size()) < random) {
263 random -= peerVector[i].size() -
freeVector[i].size();
270 random = intuniform(1, peerVector[i].
size());
271 PeerHashMap::iterator it = peerVector[i][random-1];
273 if (random == peerVector[i].
size()) {
276 it = peerVector[i][(++random)-1];