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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? kelips.c

?? 該協(xié)議是經(jīng)典的結(jié)構(gòu)化p2p協(xié)議之一
?? 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));}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
男男视频亚洲欧美| 99久久综合99久久综合网站| 亚洲福中文字幕伊人影院| 亚洲三级理论片| 亚洲男人电影天堂| 亚洲另类一区二区| 一区二区三区四区视频精品免费 | 欧美群妇大交群的观看方式| aaa国产一区| 成人av在线观| 97精品久久久久中文字幕| 成人高清视频在线观看| 国产91丝袜在线18| 丰满放荡岳乱妇91ww| 成人精品在线视频观看| 成人av免费在线| 91色乱码一区二区三区| 91高清在线观看| 欧美日韩一卡二卡| 51精品国自产在线| 久久久噜噜噜久久人人看 | 欧美一区二区黄| 日韩欧美精品三级| 久久色成人在线| 最新日韩av在线| 三级精品在线观看| 欧美激情在线一区二区三区| 亚洲国产精华液网站w| 国产精品成人网| 亚洲自拍偷拍图区| 蜜桃传媒麻豆第一区在线观看| 韩国成人在线视频| 成人网页在线观看| 欧美三级视频在线观看| www久久精品| 自拍偷拍国产精品| 午夜久久电影网| 国产麻豆成人传媒免费观看| 91丨九色porny丨蝌蚪| 欧美日韩国产欧美日美国产精品| 精品人在线二区三区| 亚洲视频在线一区观看| 偷拍日韩校园综合在线| 国产精品羞羞答答xxdd| 欧亚洲嫩模精品一区三区| 日韩欧美国产综合一区| 国产精品成人免费在线| 日韩激情视频在线观看| 不卡一区中文字幕| 欧美一区二区三区婷婷月色| 欧美国产乱子伦| 日韩黄色小视频| 福利一区福利二区| 亚洲国产精品欧美一二99| 日本女优在线视频一区二区 | 在线观看日韩国产| 欧美一区二区在线视频| 国产精品女主播av| 日韩国产高清影视| 99国产精品一区| 日韩欧美一区二区久久婷婷| 亚洲欧美日韩在线| 国产综合色产在线精品| 欧美区一区二区三区| 国产精品午夜在线观看| 奇米777欧美一区二区| 99国产欧美另类久久久精品| 26uuu色噜噜精品一区| 亚洲制服欧美中文字幕中文字幕| 国产成人免费视频网站| 91精品免费观看| 亚洲综合色噜噜狠狠| 成人午夜私人影院| 久久综合狠狠综合久久激情| 香蕉影视欧美成人| 91浏览器在线视频| 久久久美女毛片| 麻豆久久一区二区| 欧美日韩国产免费一区二区| 亚洲欧美日韩人成在线播放| 午夜私人影院久久久久| 国产成人午夜视频| 日韩欧美的一区二区| 亚洲午夜在线观看视频在线| av电影一区二区| 国产日韩欧美精品电影三级在线| 精品一区二区三区免费毛片爱| 在线一区二区三区四区五区| 成人欧美一区二区三区视频网页 | 国产成人av一区二区三区在线观看| 欧美一区二区播放| 亚洲h在线观看| 欧美日韩久久久久久| 亚洲自拍偷拍麻豆| 色屁屁一区二区| 亚洲欧美电影院| 91玉足脚交白嫩脚丫在线播放| 日本一区二区三区四区在线视频| 激情久久五月天| 欧美xfplay| 精品中文av资源站在线观看| 日韩一区二区不卡| 久久精品免费观看| 日韩欧美卡一卡二| 激情都市一区二区| 亚洲精品在线观看视频| 国产精品白丝在线| 国产欧美日韩麻豆91| 韩国中文字幕2020精品| 精品少妇一区二区三区日产乱码 | 亚洲黄色免费电影| 91免费版pro下载短视频| 一区二区三区中文字幕在线观看| 日本韩国精品在线| 亚洲成人av在线电影| 欧美精品视频www在线观看| 丝袜美腿一区二区三区| 91精选在线观看| 精品一区免费av| 国产亚洲成年网址在线观看| 国产福利电影一区二区三区| 国产精品网站在线观看| 99riav久久精品riav| 亚洲一二三级电影| 91精品国产综合久久精品性色| 奇米影视一区二区三区小说| 久久综合色一综合色88| 成人综合在线观看| 亚洲伦在线观看| 4438x亚洲最大成人网| 另类小说图片综合网| 国产欧美日韩综合精品一区二区| jlzzjlzz亚洲女人18| 亚洲图片欧美一区| 欧美大胆人体bbbb| 成人免费看视频| 午夜视黄欧洲亚洲| 精品国产a毛片| 色悠悠亚洲一区二区| 日韩在线播放一区二区| 国产亚洲va综合人人澡精品 | 久久精品人人做人人综合 | 91浏览器在线视频| 蜜桃91丨九色丨蝌蚪91桃色| 国产精品免费视频一区| 欧美日韩一区二区在线观看| 经典三级在线一区| 亚洲激情网站免费观看| 欧美成人官网二区| 一本一道综合狠狠老| 美脚の诱脚舐め脚责91 | ww亚洲ww在线观看国产| 91浏览器入口在线观看| 日本三级亚洲精品| 国产精品天美传媒| 91麻豆精品国产91久久久资源速度| 国产成人自拍高清视频在线免费播放| 亚洲伦在线观看| 久久久精品国产免费观看同学| 在线观看欧美日本| 国产黄色精品网站| 日韩不卡一区二区| 亚洲人123区| 久久久久久久久久久久久夜| 欧美视频在线不卡| 成人免费观看av| 久久 天天综合| 性欧美疯狂xxxxbbbb| 亚洲色图都市小说| 国产欧美日韩中文久久| 欧美一区二区三区视频免费| 色呦呦国产精品| 成人黄色a**站在线观看| 韩国女主播一区二区三区| 亚洲国产另类精品专区| √…a在线天堂一区| 国产亚洲欧美日韩俺去了| 欧美大片在线观看一区二区| 欧美日本国产一区| 在线精品视频一区二区三四| 不卡视频在线观看| 国产一区二区三区美女| 日本 国产 欧美色综合| 亚洲国产人成综合网站| 日韩一区在线免费观看| 国产精品私人自拍| 久久久久久久久久久黄色| 日韩欧美国产电影| 欧美精选在线播放| 欧美日韩国产综合视频在线观看| 91小视频在线| 99这里都是精品| 不卡的电影网站| 成人激情视频网站| 国产成人午夜视频| 国产精品一区二区久激情瑜伽 | 日韩一区中文字幕| 国产精品欧美一级免费| 国产色综合一区| 欧美精品一区二区在线播放|