亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? kelips.c

?? 該協議是經典的結構化p2p協議之一
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * Copyright (c) 2003 Robert Morris *                    Massachusetts Institute of Technology *  * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: *  * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#include "kelips.h"#include "p2psim/network.h"#include <stdio.h>#include <math.h>#include <iostream>#include <time.h>#include <map>using namespace std;// Record stabilization times.int sta[1000];int nsta;double Kelips::_rpc_bytes = 0;double Kelips::_good_latency = 0;double Kelips::_good_hops = 0;int Kelips::_good_lookups = 0;int Kelips::_ok_failures = 0;  // # legitimate lookup failuresint Kelips::_bad_failures = 0; // lookup failed, but node was liveKelips::Kelips(IPAddress i, Args a) : P2Protocol(i){  _started = false;  _live = false;  // settable parameters.  _k = a.nget<unsigned>("k", 20, 10);  _round_interval = a.nget<int>("round_interval", 2000, 10);  _group_targets = a.nget<u_int>("group_targets", 3, 10);  _contact_targets = a.nget<u_int>("contact_targets", 3, 10);  _group_ration = a.nget<u_int>("group_ration", 4, 10);  _contact_ration = a.nget<u_int>("contact_ration", 2, 10);  _n_contacts = a.nget<u_int>("n_contacts", 2, 10);  _item_rounds = a.nget<u_int>("item_rounds", 1, 10);  _timeout = a.nget<u_int>("timeout", 25000, 10);  _max_lookup_time = a.nget<uint>("maxlookuptime",4000,10);  _purge_time = a.nget<uint>("purgetime",1000,10);  _track_conncomp_timer = a.nget<uint>("track_conncomp_timer",0,10);  _to_multiplier = a.nget<uint>("timeout_multiplier",3,10);  _to_cheat = a.nget<uint>("timeout_cheat",0,10);}voidKelips::add_edge(int *matrix, int sz){  vector<IPAddress> l;  l.clear();  for(map<IPAddress, Info *>::const_iterator ii = _info.begin();      ii != _info.end();      ++ii){    if (ii->first!=ip() &&Network::Instance()->getnode(ii->first)->alive())       matrix[(ip()-1)*sz + ii->first-1] = 1;  }}stringi2s(unsigned long long x){  char buf[64];  sprintf(buf, "%llu", x);  return string(buf);}Kelips::~Kelips(){  if(ip() == 1){    printf("rpc_bytes %.0f\n", _rpc_bytes);    printf("%d good, %d ok failures, %d bad failures\n",           _good_lookups, _ok_failures, _bad_failures);    if(_good_lookups > 0)      printf("avglat %.1f avghops %.2f\n",             _good_latency / _good_lookups,             _good_hops / _good_lookups);     print_stats();  }  if(ip() == 1 && nsta > 0){    float sum = 0;    for(int i = 0; i < nsta; i++)      sum += sta[i];    printf("avg stabilization rounds %.1f %d\n",           sum / nsta, sta[nsta / 2]);  }}// assign a score to a contact, to help decide which to keep.// lower is better. pretty ad-hoc.inline intKelips::contact_score(const Info &i){  int rtt = i._rtt;  if(rtt < 1)    rtt = 200; // make a guess on the high side.  int score = rtt + (i.age() / 128);  return score;}// Find the worst contact in the given group.// Actually oldest heartbeat has some freshness advantages.// Returns 0 if there are less than _n_contacts.//// w/o rtt: p100/t100/e100 217.4 218.7 220.2// w/ evict oldest rtt: 216.8 209.2 212.2//    hmm: 237.2 231.5 232//    zzz: 223 223 223// w/ lookup via contact w/ best score: 225 229 216 222 204// fix initial _rtt bug:  219 219// record rtt after every doRPC: 206 203 207// penalize nodes after failed RPC: 189 192 192 189// lookup via closest contact, not best score: 191 197 191// direct if we know the IP address: 178 168 172IPAddressKelips::victim(int g){  Info *worst = 0;  int n_in_group = 0;  for(map<IPAddress, Info *>::const_iterator ii = _info.begin();      ii != _info.end();      ++ii){    Info *in = ii->second;    if(ip2group(in->_ip) == g){      n_in_group++;      if(worst == 0 || contact_score(*in) > contact_score(*worst))        worst = in;    }  }  if(n_in_group >= _n_contacts && worst){    return worst->_ip;  } else {    return 0;  }}// Return contact w/ lowest rtt,// or contact w/ newest hearbeat,// or zero.IPAddressKelips::closest_contact(int g){  Info *best = 0;  for(map<IPAddress, Info *>::const_iterator ii = _info.begin();      ii != _info.end();      ++ii){    Info *in = ii->second;    if(ip2group(in->_ip) == g){      if(best == 0 ||         (in->_rtt != -1 && best->_rtt != -1 && in->_rtt < best->_rtt) ||         (in->_rtt != 9999 && in->_heartbeat > best->_heartbeat)){        best = in;      }    }  }  if(best)    return best->_ip;  return 0;}voidKelips::join(Args *a){  notifyObservers(); // kick KelipsObserver so it calls all the init_state()s  assert(_live == false);  _live = true;  IPAddress wkn = a->nget<IPAddress>("wellknown");  if (0)    printf("%qd %d join known=%d\n", now(), ip(), _info.size());  assert(wkn != 0);  if(wkn != ip()){    // Remember well known node.    gotinfo(Info(wkn, now()), -1);    // Tell wkn about us, and ask it for a few random nodes.    IPAddress myip = ip();    vector<Info> ret;    xRPC(wkn, 1 + 20 * 2 * 2, &Kelips::handle_join, &myip, &ret); //originally, robert sets this to 6, but i think it's actually big    for(u_int i = 0; i < ret.size(); i++)      gotinfo(ret[i], -1);  }  if(_started == false){    _started = true;    delaycb(1000, &Kelips::gossip, (void *) 0);    delaycb(1000, &Kelips::purge, (void *) 0);  }}voidKelips::leave(Args *a){  crash(a);}//voidKelips::crash(Args *a){  if (0)    printf("%qd %d crash\n", now(), ip());  assert(_live == true);  _live = false;  // XXX: Thomer says: not necessary  // node()->crash();  _info.clear();  assert(_info.size() == 0);}// Return whether the node corresponding to a given key is alive.// This is cheating, just for diagnostics.boolKelips::node_key_alive(ID key){  if(ip2id((IPAddress) key) == key){    Node *n = Network::Instance()->getnode((IPAddress) key);    assert(n);    return n->alive();  } else {    const set<IPAddress> *ips = Network::Instance()->getallips();    for(set<IPAddress>::const_iterator i = ips->begin(); i != ips->end(); ++i){      if(ip2id(*i) == key){        return Network::Instance()->getnode(*i)->alive();      }    }  }  assert(0);  return false;}voidKelips::lookup(Args *args){  ID k = args->nget<ID>("key");  assert(k);  if (!node_key_alive(k))    return;  lookup_args *a = New lookup_args;  a->key = args->nget<ID>("key");  a->start = now();  a->retrytimes = 0;  a->history.clear();  a->total_to = 0;  a->num_to = 0;  lookup_internal(a);}// In real Kelips, the file with key K is stored in group// (K mod k), on a randomly chosen member of the group.// All nodes in the group learn that K is on that node via// gossiping filetuples. The Kelips paper doesn't talk about// replicating files. Kelips has no direction notion// of lookup(key).//// This implementation of lookup just looks for the host// with a given key. I believe this is indistinguishable from// looking for a file with a given key. It actually contacts// the target host.//// Assuming iterative lookup, though not specified in the paper.// XXX should send lookup to contact with lowest RTT.// XXX should retry in various clever ways.voidKelips::lookup_internal(lookup_args *a){  ID key = a->key;  Time t1 = now();  bool ok = lookup_loop(a);  Time t2 = now();  a->retrytimes++;  bool oops = false;  if(ok == false)    oops = node_key_alive(key);  IPAddress lasthop;  if( a->history.size() > 0 ) {    lasthop = a->history[a->history.size()-1];  } else {    lasthop = ip();  }  if (t2 - a->start >= _max_lookup_time) {    if (Node::collect_stat())       _bad_failures += 1;    record_lookup_stat(ip(), lasthop, t2-a->start, false, false, a->history.size(), a->num_to, a->total_to);  }else if (ok) {    assert( lasthop == key );    if (Node::collect_stat()) {      _good_lookups += 1;      _good_latency += t2 - t1;      _good_hops += a->history.size();    }    record_lookup_stat(ip(), lasthop, t2-a->start, true, true, a->history.size(), a->num_to, a->total_to);  }else if (oops) {    if (Node::collect_stat())       _bad_failures += 1;    delaycb(100, &Kelips::lookup_internal, a);    return;  }else {    //the destination node is dead    if (a->retrytimes >= 2)       record_lookup_stat(ip(),lasthop,t2-a->start,false,false,a->history.size(),a->num_to,a->total_to);  }  delete a;  if(0){    printf("%qd %d lat=%d lookup(%qd) ", now(), ip(), (int)(t2 - t1),           (unsigned long long) key);    for(u_int i = 0; i < a->history.size(); i++)      printf("%d ", a->history[i]);    printf("%s%s   \n", ok ? "OK" : "FAIL", (!ok && oops) ? " OOPS" : "");  }}// Keep trying to lookup.boolKelips::lookup_loop(lookup_args *a) {  // Are we looking for ourselves?  if(a->key == id())    return true;  // Try an ordinary lookup via the closest contact.  if(lookup1(a))    return true;  else if (now()-a->start>=_max_lookup_time)    return false;  // Try via each known contact.  if(_k > 1){    vector<IPAddress> cl = grouplist(id2group(a->key));    for(u_int i = 0; i < cl.size(); i++)      if(lookupvia(a,cl[i]))        return true;      else if (now()-a->start>=_max_lookup_time)	return false;  }  // Try via random nodes a few times.  for(int iter = 0; iter < 12; iter++){    if(lookup2(a))       return true;    else if (now()-a->start>=_max_lookup_time)      return false;  }  return false;}// Look up a key via closest contact.// The contact should return the IP address of// the lookup target, which we then try to talk to.// This is only suitable for the fast/ordinary// path, it doesn't try any alternate paths.boolKelips::lookup1(lookup_args *a){  IPAddress ip1 = 0;  if(id2group(a->key) == group()){    ip1 = find_by_id(a->key);    if(ip1 == 0)      return false;  } else if((ip1 = find_by_id(a->key)) != 0){    // go direct to a different group!    // not mentioned in Kelips paper, of course, but seems    // reasonable by analogy to Chord forwarding lookup to    // known node with closest ID.  } else {    IPAddress ip = closest_contact(id2group(a->key));    if(ip == 0)      return false;    bool ok = xRPC(ip, 3, &Kelips::handle_lookup1, &(a->key), &ip1, STAT_LOOKUP, &(a->total_to), &(a->num_to));    a->history.push_back(ip);    if(!ok || ip1 == 0 || (now()-a->start>=_max_lookup_time))      return false;    assert(ip1 != ip);  }  bool done = false;  bool ok = xRPC(ip1, 2, &Kelips::handle_lookup_final, &(a->key), &done, STAT_LOOKUP, &(a->total_to), &(a->num_to));  a->history.push_back(ip1);  return(ok && done && (now()-a->start < _max_lookup_time));}// Look up a key via a given contact.boolKelips::lookupvia(lookup_args *a, IPAddress via){  IPAddress ip1 = 0;  bool ok = xRPC(via, 3, &Kelips::handle_lookup1, &(a->key), &ip1, STAT_LOOKUP,&(a->total_to), &(a->num_to));  a->history.push_back(via);  if(ok == false || ip1 == 0 || (now()-a->start>=_max_lookup_time))    return false;  bool done = false;  ok = xRPC(ip1, 2, &Kelips::handle_lookup_final, &(a->key), &done, STAT_LOOKUP, &(a->total_to), &(a->num_to));  a->history.push_back(ip1);  return(ok && done && (now()-a->start<_max_lookup_time));}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久婷婷国产综合精品青草| 日韩黄色片在线观看| 国产精品系列在线| 一区二区三区蜜桃| 狠狠色狠狠色合久久伊人| 91丨porny丨国产| 日韩精品中文字幕一区| 亚洲乱码国产乱码精品精98午夜| 久久国产精品无码网站| 欧美午夜免费电影| 国产欧美中文在线| 免费在线一区观看| 欧美在线免费播放| 国产精品网站导航| 国产剧情一区二区| 欧美一二三区在线观看| 性做久久久久久| 播五月开心婷婷综合| 日韩三级免费观看| 日韩综合小视频| 在线亚洲免费视频| 国产精品久久久久影院色老大| 久久精品国产精品亚洲精品| 欧美日韩成人综合在线一区二区| 亚洲精品日产精品乱码不卡| 春色校园综合激情亚洲| 久久精品欧美日韩| 国产精品自拍一区| 久久色中文字幕| 狠狠色伊人亚洲综合成人| 日韩一区二区在线观看视频| 日韩不卡手机在线v区| 欧美美女激情18p| 丝瓜av网站精品一区二区 | 国产精品久久午夜| 国产精品一线二线三线精华| 26uuu久久综合| 韩国视频一区二区| 久久久久国产免费免费| 国产成人无遮挡在线视频| 久久嫩草精品久久久精品| 国产一区二区三区免费看 | 欧美日韩国产综合久久 | 日本特黄久久久高潮| 欧美日韩一卡二卡| 日本不卡高清视频| 久久综合狠狠综合| 成人一区二区三区在线观看| 国产精品久久久久久久久果冻传媒| 成人性视频免费网站| 18成人在线观看| 91久久精品一区二区二区| 亚洲午夜视频在线| 在线成人午夜影院| 国产一区二区三区香蕉| 国产精品国产三级国产有无不卡| 99久久99久久精品免费看蜜桃| 一区二区三区中文字幕| 欧美夫妻性生活| 国产一区二区不卡| 亚洲欧美一区二区三区极速播放| 欧美色图天堂网| 老汉av免费一区二区三区| 国产欧美日韩综合| 欧美性一二三区| 免费在线观看一区二区三区| 国产日韩欧美在线一区| 欧洲国产伦久久久久久久| 成人激情动漫在线观看| 91亚洲精品一区二区乱码| 欧美精品1区2区3区| 国产高清无密码一区二区三区| 欧美日韩一区视频| 日韩欧美在线观看一区二区三区| 激情深爱一区二区| 欧美顶级少妇做爰| 成人丝袜高跟foot| 成人黄色免费短视频| 国产成人免费在线观看不卡| 久久精品国产成人一区二区三区| 青青草原综合久久大伊人精品优势| 亚洲成av人片在线观看无码| 亚洲一级片在线观看| 亚洲在线中文字幕| 亚洲成人免费影院| 日日夜夜精品免费视频| 一本久道久久综合中文字幕| 成人av资源在线| 99国产精品视频免费观看| 91一区二区三区在线播放| 在线观看成人免费视频| 欧美日韩成人一区二区| 日韩一区国产二区欧美三区| 日韩一区二区视频| 久久精品一二三| 国产精品无遮挡| 亚洲欧美日韩综合aⅴ视频| 一区二区在线观看视频在线观看| 亚洲一区二区av在线| 琪琪久久久久日韩精品| 久久国产成人午夜av影院| 国产一区二区三区国产| www.综合网.com| 91官网在线免费观看| 欧美精品一卡两卡| 国产三级三级三级精品8ⅰ区| 国产精品美女久久久久高潮 | 欧美一区二区免费观在线| 日韩美女视频在线| 中文字幕av在线一区二区三区| 亚洲色图欧洲色图| 日本伊人午夜精品| 国产99久久精品| 欧美色爱综合网| 精品处破学生在线二十三| 国产精品毛片大码女人| 五月天视频一区| 国产主播一区二区三区| 色哟哟一区二区在线观看| 日韩美女视频一区二区在线观看| 国产精品美女久久久久久2018| 午夜精彩视频在线观看不卡| 国产高清精品久久久久| 欧美日韩五月天| 久久久久亚洲蜜桃| 亚洲一区二区偷拍精品| 国产呦萝稀缺另类资源| 欧美性视频一区二区三区| 久久婷婷国产综合精品青草 | 日本特黄久久久高潮| www.欧美亚洲| 日韩亚洲电影在线| 亚洲精品大片www| 国产一区二区三区综合| 欧美三级中文字幕| 国产精品另类一区| 久久99精品国产.久久久久久| 91偷拍与自偷拍精品| 久久美女艺术照精彩视频福利播放 | 欧美tickle裸体挠脚心vk| 亚洲人被黑人高潮完整版| 国产在线国偷精品免费看| 欧美日韩1区2区| 国产精品不卡一区| 麻豆精品一二三| 欧美日韩一区成人| 亚洲欧洲av一区二区三区久久| 另类小说色综合网站| 欧美性生活大片视频| 亚洲三级小视频| 懂色av一区二区夜夜嗨| 欧美一级在线视频| 亚洲第一搞黄网站| 在线看国产一区| 1区2区3区精品视频| 成人精品一区二区三区中文字幕| wwwwww.欧美系列| 久久精品国产精品亚洲精品| 欧美一区二区免费| 视频一区二区三区入口| 欧美亚洲高清一区| 亚洲国产成人av网| 欧美视频日韩视频在线观看| 亚洲免费观看高清| 色婷婷一区二区三区四区| 中文字幕亚洲一区二区va在线| 国产sm精品调教视频网站| 久久久久久久一区| 国产伦精品一区二区三区视频青涩| 欧美一二三在线| 久久成人羞羞网站| 2020日本不卡一区二区视频| 国产综合色视频| 欧美精品一区二区三区很污很色的| 捆绑调教一区二区三区| 精品久久久网站| 国产一区在线观看麻豆| 国产香蕉久久精品综合网| 国产激情视频一区二区三区欧美| 久久久蜜桃精品| 成人高清免费在线播放| 亚洲欧美日韩国产一区二区三区 | 亚洲国产精品麻豆| 欧美美女bb生活片| 精品一区二区三区香蕉蜜桃| 337p粉嫩大胆色噜噜噜噜亚洲 | 色综合久久久久久久久| 亚洲一线二线三线久久久| 欧美色电影在线| 免费的国产精品| 久久综合资源网| 成人性视频免费网站| 亚洲欧美一区二区三区国产精品 | 日本vs亚洲vs韩国一区三区二区| 欧美一区二区三区视频免费播放| 久久精品国产精品亚洲红杏| 中文在线一区二区 | 欧美视频在线一区二区三区 | 国产福利一区二区三区视频| 亚洲欧洲日本在线|