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

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

?? namecachemain.c

?? p2p類源代碼 kadc協議官方源代碼
?? C
?? 第 1 頁 / 共 4 頁
字號:
/****************************************************************\Copyright 2004 Enzo MichelangeliThis file is part of the KadC library.KadC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.KadC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with KadC; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAIn addition, closed-source licenses for this software may be grantedby the copyright owner on commercial basis, with conditions negotiatedcase by case. Interested parties may contact Enzo Michelangeli at oneof the following e-mail addresses (replace "(at)" with "@"): em(at)em.no-ip.com em(at)i-t-vision.com\****************************************************************/#define DEBUG 1#define arraysize(a) (sizeof(a)/sizeof(a[0]))#include <pthread.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <time.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <stdlib.h>#include <signal.h>#include <assert.h>#ifdef __WIN32__#include <winsock.h>#define socklen_t int#else /* __WIN32__ */#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#define min(a,b) (((a)<(b))?(a):(b))#include <errno.h>#endif /* __WIN32__ */#include <Debug_pthreads.h>#include <int128.h>#include <rbt.h>#include <queue.h>#include <KadCalloc.h>#include <KadClog.h>#include <millisleep.h>#include <net.h>	/* for htoa() */#include <KadCapi.h>#include <dns.h>#include <droppriv.h>#include <config.h>#define DNS_PORT 53typedef struct _DNSIO {	int fd;	unsigned long int ip;	unsigned long int port;	unsigned long int upstream[4];	/* upstream DNS servers array */	int nupstream;					/* number of upstream DNS servers */	pthread_mutex_t mutex;	queue *fifo;	int err;	int shutdown_flag;		/* set by signal handler, protected by mutex */#if !defined(__WIN32__) && !defined(__CYGWIN__)	int uid;				/* uid to fall back to in order to drop root privileges after bind() under UNIX */	int gid;				/* gid to fall back to in order to drop root privileges after bind() under UNIX */#endif} DNSIO;typedef struct _processing_thread_params {	KadCcontext *pkcc;	DNSIO *pdnsio;	char *tlpd[100];	int ntlpd;	char *my_pseudo[100];	int nmy_pseudo;	void *pending_q_rbt;	/* table of raw_qa structs for pending questions  by question */	void *cache_q_rbt;		/* table indexing raw_qa (question/answer pairs) by question */	int cache_maxentries;	/* typically 4096 */	pthread_mutex_t mutex;} processing_thread_params;/* a structure holding DNS client's address/port, a pointer to a buffer   containing the raw DNS message as it is in the UDP payload, and   the number of bytes in that buffer.  For packets exchanged over TCP,   fd contains the fd of the TCP connection, otherwise it's -1. */typedef struct _DNSpacket {	unsigned long int remoteip;	unsigned short int remoteport;	int fd;	int bufsize;	unsigned char *buf;	int qsize;	/* length of questions area inside buf */} DNSpacket;/* a structure containing one "query" and one "response" DNSpackets,   and an expiration timestamp */typedef struct _raw_qa {	DNSpacket *q;	DNSpacket *a;	time_t expiry;	time_t last_accessed;	int being_refreshed;	/* the fields below are used only by detached queries (which call the P2P backend) */	int isdetached;	pthread_t thread;				/* the thread servicing the P2P query */	pthread_mutex_t mutex;			/* protects critical areas in thread routine code */	processing_thread_params *pptp;	/* useful to access e.g. the fifo in the DNSIO block */	int done;	/* set by thread routine just before terminating: tells that pthread_join won't block for long */} raw_qa;/* header is 12 byte long, and the question(s) come next */#define HS 12/* compare DNSpacket structures by raw_question area (1st question only) *//* if the sizes are the same, compare the content; else return false */static int DNSpacket_q_eq(DNSpacket *pdnp1, DNSpacket *pdnp2) {	if(pdnp1->qsize != pdnp2->qsize)		return 0;	else		return (memcmp(pdnp1->buf + HS, pdnp2->buf + HS, pdnp1->qsize) == 0);}/* if the sizes are the same, compare the content; else compare question sizes */static int DNSpacket_q_lt(DNSpacket *pdnp1, DNSpacket *pdnp2) {	if(pdnp1->qsize != pdnp2->qsize)		return pdnp1->qsize < pdnp2->qsize;	else		return (memcmp(pdnp1->buf + HS, pdnp2->buf + HS, pdnp1->qsize) < 0);}/* compare raw_qa structures by raw_question AND by ID (important for pending queries table!) *//* if the sizes are the same, compare the content; else return false */static int DNSpacket_qi_eq(DNSpacket *pdnp1, DNSpacket *pdnp2) {	if(pdnp1->qsize != pdnp2->qsize)		return 0;	else		return (memcmp(pdnp1->buf + HS, pdnp2->buf + HS, pdnp1->qsize) == 0 &&				memcmp(pdnp1->buf, pdnp2->buf, 2) == 0);}/* if the sizes are the same, compare the content (incl. ID); else compare question sizes */static int DNSpacket_qi_lt(DNSpacket *pdnp1, DNSpacket *pdnp2) {	if(pdnp1->qsize != pdnp2->qsize)		return pdnp1->qsize < pdnp2->qsize;	else {		int compare_id = memcmp(pdnp1->buf, pdnp2->buf, 2);		if(compare_id != 0)			return compare_id;		else			return (memcmp(pdnp1->buf + HS, pdnp2->buf + HS, pdnp1->qsize) < 0);	}}static int qa_rbt_destroy(void *rbt, int destroy_data_too) {	void *iter;	raw_qa *prqa;	rbt_StatusEnum rbt_status;	for(;;) {		iter = rbt_begin(rbt);		if(iter == NULL)			break;		prqa = rbt_value(iter);		rbt_erase(rbt, iter);		if(destroy_data_too && (prqa != NULL)) {			if(prqa->q != NULL) {				if(prqa->q->buf != NULL)					free(prqa->q->buf);				free(prqa->q);			}			if(prqa->a != NULL) {				if(prqa->a->buf != NULL)					free(prqa->a->buf);				free(prqa->a);			free(prqa);			}		}	}	rbt_status = rbt_destroy(rbt);	if(rbt_status == RBT_STATUS_OK)		return 0;	else		return 1;}/* conversion routines between DNSpacket (which contains a packed buffer   together with peer information which is not retained) and the   parsed dns_msg defined in dns.h */static dns_msg *DNSpacket2msg(DNSpacket *pdnp) {	return dns_parse((char *)pdnp->buf, pdnp->bufsize);}static DNSpacket *DNSmsg2packet(dns_msg *pdm, unsigned long int ip, unsigned short int port, int fd) {	DNSpacket *pdnp;	int status;	pdnp = malloc(sizeof(DNSpacket));	assert(pdnp != NULL);	pdnp->bufsize = 4096;	/* preliminary, vastly oversized */	pdnp->buf = malloc(pdnp->bufsize);	assert(pdnp->buf != NULL);	status = dns_pack((char *)pdnp->buf, pdnp->bufsize, pdm);	assert(status > 0);/* we should also check if status > 512, and, if so, limit to 512 and set   the truncation bit:  */#if 1	if(status > 512) {#ifdef DEBUG		KadC_log("Truncation occurred: %d bytes reduced to 512\n", status);#endif		status = 512;		pdnp->buf[2] |= (1 << 1);	}#endif	pdnp->bufsize = status;	pdnp->buf = realloc(pdnp->buf, pdnp->bufsize);	/* trim down to what it's necessary */	pdnp->remoteip = ip;	pdnp->remoteport = port;	pdnp->fd = fd;	return pdnp;}static void DNSpacket_destroy(DNSpacket *pdnp) {	if(pdnp != NULL) {		if(pdnp->buf != NULL)			free(pdnp->buf);		free(pdnp);	}}/* for detached P2P queries, it also reaps the thread used in the search */static void raw_qa_destroy(raw_qa *pqa) {	if(pqa != NULL) {		if(pqa->isdetached) {			pthread_join(pqa->thread, NULL);		}		pthread_mutex_destroy(&pqa->mutex);		if(pqa->q != NULL)			DNSpacket_destroy(pqa->q);		if(pqa->a != NULL)			DNSpacket_destroy(pqa->a);		free(pqa);	}}static int trim_qa_rbt(void *rbt, int maxentries) {	int removed_entries = 0;	rbt_StatusEnum rbt_status;	while(rbt_size(rbt) > maxentries) {		/* cache full: let's expire the oldest record */		void *iter = NULL;		raw_qa *soonest_to_expire_qa = NULL;		for(iter=rbt_begin(rbt); iter != NULL; iter = rbt_next(rbt, iter)) {			raw_qa *pqa = rbt_value(iter);			if(soonest_to_expire_qa == NULL || pqa->expiry < soonest_to_expire_qa->expiry)				soonest_to_expire_qa = pqa;		}		if(soonest_to_expire_qa != NULL) {			rbt_status = rbt_eraseKey(rbt, soonest_to_expire_qa->q);			assert(rbt_status == RBT_STATUS_OK);#ifdef DEBUG			KadC_log("Expunging the soonest_to_expire cached record; %d remain in cache\n", rbt_size(rbt));#endif			raw_qa_destroy(soonest_to_expire_qa);			removed_entries++;		} else {			break;	/* should only be executed if maxentries <= 0... */		}	}	return removed_entries;}static int purge_expired(void *qarbt) {	void *iter;	int removed_entries = 0;	rbt_StatusEnum rbt_status;	int rbt_is_cache = 0;	do {		for(iter = rbt_begin(qarbt); iter != NULL; iter = rbt_next(qarbt, iter)) {			raw_qa *pqa = rbt_value(iter);			/* only for cache rbt (where pqa->a != NULL) implement "predictive caching":			   if the entry is going to expire soon (e.g., 1 minute), and it has been accessed recently,			   (e.g., less than 5 minutes ago) then perform a refresh so that			   the next access will find the data already in cache. This is implemented			   posting to the DNSIO fifo queue a dummy DNSpacket obtained by cloning			   the ->q member in the cached qa. The clone's remoteip will be set to 0, so to			   suppress the DNS reply otherwise issued by the processing thread. */			if(pqa->a != NULL && 						/* i.e., it's a cached qa, not a pending one... */			   pqa->expiry < time(NULL) + 60 &&			/* ...expiring within 60 seconds */			   pqa->last_accessed > time(NULL) - 300 &&	/* ...and accessed less that 300 seconds ago... */			   pqa->being_refreshed == 0) {				/* ...and we haven't yet taken care of it... */				DNSIO *pdnsio = pqa->pptp->pdnsio;				/* allocate a DNSpacket */				DNSpacket *dp = malloc(sizeof(DNSpacket));				assert(dp != NULL);				pqa->being_refreshed = 1;				*dp = *(pqa->q);	/* shallow clone of cached question packet */				dp->remoteip = 0;	/* identify it as a locally-generated psudo-packet */				dp->remoteport = 0;	/* same */				dp->fd = -1;		/* means "packet not arrived over TCP" */				/* allocate a copy of buffer referenced by DNSpacket */				dp->buf = malloc(dp->bufsize);				assert(dp->buf != NULL);				/* copy there the question's buf: this makes the cloning deep */				memcpy(dp->buf, pqa->q->buf, dp->bufsize);#ifdef VERBOSE_DEBUG /* DEBUG ONLY */				{					int i;					KadC_log("Predictive caching: enqueuing pseudo-packet from %s:%d %d bytes:",							htoa(dp->remoteip), dp->remoteport, dp->bufsize);					for(i=0; i < dp->bufsize /* && i < 48 */; i++) {						if((i % 16) == 0)							KadC_log("\n");						KadC_log("%02x ", dp->buf[i]);					}				}				KadC_log("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");#endif				/* enqueue the cloned DNSpacket */				if(pdnsio->fifo->enq(pdnsio->fifo, dp) != 0) {					/* if FIFO full, drop the packet? */					free(dp->buf);					free(dp);				}			}			if(pqa->expiry < time(NULL)) {				if(pqa->a != NULL)				    rbt_is_cache = 1;	/* only qa's in cache have a non-NULL a */				if(pqa->isdetached == 0 || pqa->done != 0) {	/* if detached and not done, skip it */					rbt_status = rbt_erase(qarbt, iter);					removed_entries++;					assert(rbt_status == RBT_STATUS_OK);					raw_qa_destroy(pqa);					break;	/* restart scan after erase because iter becomes invalid */				}			}		}	} while(iter != NULL);	/* until end of table is reached without deletions during a scan */#ifdef DEBUG	if(removed_entries > 0)		KadC_log("Expunging from %s %d expired record; %d remain in table\n",			(rbt_is_cache ? "cache" : "pending requests"), removed_entries, rbt_size(qarbt));#endif	return removed_entries;}/* static global variables and prototypes */static pthread_mutex_t mutex_initializer = PTHREAD_MUTEX_INITIALIZER;static void *processing_thread(void *p);static void *publishing_thread(void *p);static int udp_dns_init(DNSIO *pdnsio);void *dns_udp_recv_thread(void *p);static void ConsoleLoop(processing_thread_params *pptp);static int DNSquery(DNSIO *pd, DNSpacket *pdnp, unsigned long int ip);static int DNSreply(DNSIO *pd, DNSpacket *pdnpreply);void usage(char *prog) {#if !defined(__WIN32__) && !defined(__CYGWIN__)	KadC_log("usage: %s [-k inifile.ini] [-i ip_to_bind_to] [-p port_to_bind_to] [-s DNSserver]* -c cache_maxentries [-d my_pseudodomain[=dotted.quad.ip.addr]]* [-t toplevelpseudodomain]* [-u UID] [-g GID]\n", prog);#else	KadC_log("usage: %s [-k inifile.ini] [-i ip_to_bind_to] [-p port_to_bind_to] [-s DNSserver]* -c cache_maxentries [-d my_pseudodomain[=dotted.quad.ip.addr]]* [-t toplevelpseudodomain]*\n", prog);#endif}static DNSIO *glob_pdnsio;	/* used by sighandler */#ifdef OLD_STYLE_SIGNALvoid sighandler(int sig) {	DNSIO *pdnsio = glob_pdnsio;	pthread_mutex_lock(&pdnsio->mutex);#ifdef DEBUG	KadC_log("Signal %d caught, shutdown_flag set to 1\n", sig);#endif	pdnsio->shutdown_flag = 1;	pthread_mutex_unlock(&pdnsio->mutex);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美亚洲动漫另类| 国产精品无圣光一区二区| 精品国产一区二区三区不卡| 日韩理论片中文av| 国产精品一区二区x88av| 欧美夫妻性生活| 亚洲男人的天堂av| 丁香桃色午夜亚洲一区二区三区| 欧美日本一区二区三区| 亚洲日本在线视频观看| 国产在线播放一区二区三区| 欧美日韩国产片| 亚洲一区二区影院| 91首页免费视频| 国产精品你懂的在线欣赏| 国产精品一二三在| 日韩一级片网站| 日韩av一区二区三区四区| 在线观看日韩电影| 一区二区三区在线视频观看| 99久久精品国产一区二区三区| 国产三级精品在线| 国产91清纯白嫩初高中在线观看| 精品理论电影在线| 国产在线播精品第三| 亚洲精品一区二区三区福利| 免费成人结看片| 欧美一级欧美三级在线观看| 午夜精品aaa| 欧美电影影音先锋| 蜜桃av一区二区三区电影| 欧美一区二区三区四区五区| 肉丝袜脚交视频一区二区| 欧美福利一区二区| 蜜桃视频第一区免费观看| 精品99久久久久久| 豆国产96在线|亚洲| 久久综合国产精品| 成人一区二区三区视频在线观看| 国产人成一区二区三区影院| 国产91在线观看| 综合av第一页| 色综合久久天天| 亚洲va天堂va国产va久| 91麻豆精品国产自产在线观看一区| 日韩成人免费电影| 久久美女艺术照精彩视频福利播放| 国产麻豆一精品一av一免费| 中文字幕免费不卡在线| 91毛片在线观看| 亚洲成a天堂v人片| 欧美精品一区男女天堂| 不卡视频一二三四| 亚洲电影视频在线| 久久久久久久国产精品影院| 99精品1区2区| 亚洲国产成人av网| 精品久久久三级丝袜| eeuss影院一区二区三区| 亚洲第一福利视频在线| 久久久无码精品亚洲日韩按摩| 成人黄页毛片网站| 午夜精品久久久久久久99樱桃| 亚洲精品在线网站| 色婷婷综合久久久中文字幕| 久久精品国产亚洲a| 亚洲欧洲日韩女同| 777欧美精品| 99久久精品99国产精品| 日本亚洲一区二区| **网站欧美大片在线观看| 正在播放一区二区| 成人91在线观看| 久久99精品久久久久| 一区二区三区**美女毛片| 精品免费视频一区二区| 欧美日韩综合色| 岛国一区二区三区| 麻豆成人av在线| 亚洲综合视频在线观看| 国产亚洲综合在线| 91精品欧美一区二区三区综合在| heyzo一本久久综合| 精东粉嫩av免费一区二区三区| 亚洲一二三区在线观看| 国产精品视频一二三| 日韩欧美色综合| 欧美三级韩国三级日本一级| 国产91精品一区二区麻豆网站 | 91啦中文在线观看| 国产最新精品精品你懂的| 亚洲一二三区视频在线观看| 国产欧美久久久精品影院| 欧美不卡视频一区| 正在播放亚洲一区| 欧美日韩一区三区四区| proumb性欧美在线观看| 粉嫩嫩av羞羞动漫久久久| 国产一区二区调教| 久久99久久精品| 日韩成人av影视| 日韩精品高清不卡| 午夜国产不卡在线观看视频| 亚洲国产欧美一区二区三区丁香婷| 国产精品你懂的在线欣赏| 欧美韩日一区二区三区四区| 欧美精品一区二区久久婷婷| 日韩一卡二卡三卡国产欧美| 欧美福利一区二区| 欧美肥妇毛茸茸| 欧美一级在线视频| 欧美日韩第一区日日骚| 欧美日韩性生活| 欧美日韩三级在线| 欧美日韩一区三区| 欧美高清视频在线高清观看mv色露露十八| 91在线免费视频观看| 色先锋久久av资源部| 91蝌蚪porny成人天涯| 91在线云播放| 欧美图区在线视频| 制服视频三区第一页精品| 7878成人国产在线观看| 日韩精品一区二区三区四区| 精品剧情v国产在线观看在线| 欧美一区二区三区在线观看 | 色94色欧美sute亚洲13| 91亚洲国产成人精品一区二三 | 精品国内二区三区| 欧美不卡123| 国产欧美一区二区三区鸳鸯浴 | 国产午夜精品一区二区三区嫩草 | 91视频.com| 欧美日韩亚洲国产综合| 欧美一区二区三区在线观看 | 丁香六月久久综合狠狠色| 91在线porny国产在线看| 在线欧美小视频| 91精品国产综合久久久久久| 精品国产人成亚洲区| 欧美激情一区在线观看| 亚洲一区在线视频| 精品在线播放午夜| 91浏览器打开| 欧美成人猛片aaaaaaa| 国产精品成人一区二区艾草| 亚洲国产精品影院| 国产真实精品久久二三区| 91在线你懂得| 精品国产一区二区亚洲人成毛片 | 中文av一区二区| 亚洲成a人片综合在线| 国产成人精品aa毛片| 欧美视频一区二区三区在线观看| 精品乱码亚洲一区二区不卡| 亚洲精品免费播放| 免费成人性网站| 在线免费一区三区| 久久久综合精品| 午夜精品久久久久久久久久久 | 国产欧美精品一区二区三区四区| 亚洲九九爱视频| 国产精品一区二区果冻传媒| 亚洲午夜成aⅴ人片| 高清视频一区二区| 狠狠色狠狠色合久久伊人| caoporen国产精品视频| 91精品国产免费| 艳妇臀荡乳欲伦亚洲一区| 国产黄色精品视频| 欧美一级高清片在线观看| 亚洲激情一二三区| 成人精品视频一区二区三区尤物| 91精品国产一区二区三区香蕉| 国产精品灌醉下药二区| 国产伦精品一区二区三区免费迷| 欧美视频在线观看一区二区| 亚洲特黄一级片| 成人一区在线观看| 国产日韩av一区| 国产美女久久久久| 精品日韩99亚洲| 日本美女一区二区三区视频| 日本乱码高清不卡字幕| 自拍偷在线精品自拍偷无码专区| 国产99一区视频免费 | 日本高清视频一区二区| 国产精品天美传媒| 粉嫩av亚洲一区二区图片| 久久人人爽爽爽人久久久| 精品一区二区三区欧美| 91精品午夜视频| 麻豆精品视频在线| 日韩美女视频在线| 另类中文字幕网| 精品国产乱码久久久久久牛牛 | 色呦呦国产精品| 亚洲乱码日产精品bd| 一本大道综合伊人精品热热| 亚洲素人一区二区|