1 int CDHT::dht_periodic(const void *buf, size_t buflen,const struct sockaddr *fromAddr, int fromlen,time_t *tosleep,dht_callback *callback, void *closure)2 {3 gettimeofday(&nowTime, NULL);4
5 if(buflen > 0)6 {7 intmessage;8 unsigned char tid[16], id[20], info_hash[20], target[20];9 unsigned char nodes[256], nodes6[1024], token[128];10 int tid_len = 16, token_len = 128;11 int nodes_len = 256, nodes6_len = 1024;12 unsigned shortport;13 unsigned char values[2048], values6[2048];14 int values_len = 2048, values6_len = 2048;15 intwant;16 unsigned shortttid;17
18 struct sockaddr_in* tempip=(struct sockaddr_in *)fromAddr;19
20 if(is_martian(fromAddr))21 gotodontread;22
23 if(node_blacklisted(fromAddr, fromlen)) {24 _dout("Received packet from blacklisted node.\n");25 gotodontread;26 }27
28 if(((char*)buf)[buflen] != '\0') {29 _dout("Unterminated message.\n");30 errno =EINVAL;31 return -1;32 }33
34 message = parse_message((unsigned char *)buf, buflen, tid, &tid_len, id, info_hash,target, &port, token, &token_len,nodes, &nodes_len, nodes6, &nodes6_len,values, &values_len, values6, &values6_len,&want);35
36 if(token_len>0)37 {38 int a=0;39 }40 if(message < 0 || message == ERROR || id_cmp(id, zeroes) == 0)41 {42 _dout("Unparseable message:");43 debug_printable((const unsigned char *)buf, buflen);44 _dout("\n");45 gotodontread;46 }47
48 if(id_cmp(id, myid) == 0) {49 _dout("Received message from self.\n");50 gotodontread;51 }52
53 if(message >REPLY) {54 /*Rate limit requests.*/
55 if(!token_bucket()) {56 _dout("Dropping request due to rate limiting.\n");57 gotodontread;58 }59 }60
61 switch(message)62 {63 caseREPLY:64 if(tid_len != 4)65 {66 _dout("Broken node truncates transaction ids:");67 debug_printable((const unsigned char *)buf, buflen);68 _dout("\n");69 /*This is really annoying, as it means that we will70 time-out all our searches that go through this node.71 Kill it.*/
72 blacklist_node(id, fromAddr, fromlen);73 gotodont