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

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

?? mbus.c

?? jpeg and mpeg 編解碼技術源代碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
 * FILE:     mbus.c
 * AUTHOR:   Colin Perkins
 * MODIFIED: Orion Hodson
 *           Markus Germeier
 * 
 * Copyright (c) 1997-2000 University College London
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, is permitted provided that the following conditions 
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the Computer Science
 *      Department at University College London
 * 4. Neither the name of the University nor of the Department may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include "config_unix.h"
#include "config_win32.h"
#include "debug.h"
#include "memory.h"
#include "net_udp.h"
#include "hmac.h"
#include "qfDES.h"
#include "base64.h"
#include "gettimeofday.h"
#include "vsnprintf.h"
#include "mbus.h"
#include "mbus_config.h"
#include "mbus_parser.h"
#include "mbus_addr.h"

#define MBUS_BUF_SIZE	  1500
#define MBUS_ACK_BUF_SIZE 1500
#define MBUS_MAX_ADDR	    10
#define MBUS_MAX_QLEN	    50 /* Number of messages we can queue with mbus_qmsg() */

#define MBUS_MAGIC	0x87654321
#define MBUS_MSG_MAGIC	0x12345678

struct mbus_msg {
	struct mbus_msg	*next;
	struct timeval	 send_time;	/* Time the message was sent, to trigger a retransmit */
	struct timeval	 comp_time;	/* Time the message was composed, the timestamp in the packet header */
	char		*dest;
	int		 reliable;
	int		 complete;	/* Indicates that we've finished adding cmds to this message */
	int		 seqnum;
	int		 retransmit_count;
	int		 message_size;
	int		 num_cmds;
	char		*cmd_list[MBUS_MAX_QLEN];
	char		*arg_list[MBUS_MAX_QLEN];
	uint32_t	 idx_list[MBUS_MAX_QLEN];
	uint32_t	 magic;		/* For debugging... */
};

struct mbus {
	socket_udp	 	 *s;
	char		 	 *addr;				/* Addresses we respond to. 					*/
	int		 	  max_other_addr;
	int		 	  num_other_addr;
	char			**other_addr;			/* Addresses of other entities on the mbus. 			*/
        struct timeval          **other_hello;                  /* Time of last mbus.hello we received from other entities      */
	int		 	  seqnum;
	struct mbus_msg	 	 *cmd_queue;			/* Queue of messages waiting to be sent */
	struct mbus_msg	 	 *waiting_ack;			/* The last reliable message sent, if we have not yet got the ACK */
	char		 	 *hashkey;
	int		 	  hashkeylen;
	char		 	 *encrkey;
	int		 	  encrkeylen;
	struct timeval	 	  last_heartbeat;		/* Last time we sent a heartbeat message */
	struct mbus_config	 *cfg;
	void (*cmd_handler)(char *src, char *cmd, char *arg, void *dat);
	void (*err_handler)(int seqnum, int reason);
	uint32_t		  magic;			/* For debugging...                                             */
	uint32_t		  index;
	uint32_t		  index_sent;
};

static void mbus_validate(struct mbus *m)
{
#ifdef DEBUG
	int	i;

	ASSERT(m->num_other_addr <= m->max_other_addr);
	ASSERT(m->num_other_addr >= 0);
	for (i = 0; i < m->num_other_addr; i++) {
		ASSERT(m->other_addr[i]  != NULL);
		ASSERT(m->other_hello[i] != NULL);
	}
	for (i = m->num_other_addr + 1; i < m->max_other_addr; i++) {
		ASSERT(m->other_addr[i]  == NULL);
		ASSERT(m->other_hello[i] == NULL);
	}
#endif
	ASSERT(m->magic == MBUS_MAGIC);
	xmemchk();
}

static void mbus_msg_validate(struct mbus_msg *m)
{
#ifdef DEBUG
	int	i;

	ASSERT((m->num_cmds < MBUS_MAX_QLEN) && (m->num_cmds >= 0));
	for (i = 0; i < m->num_cmds; i++) {
		ASSERT(m->cmd_list[i] != NULL);
		ASSERT(m->arg_list[i] != NULL);
		if (i > 0) {
			ASSERT(m->idx_list[i] > m->idx_list[i-1]);
		}
	}
	for (i = m->num_cmds + 1; i < MBUS_MAX_QLEN; i++) {
		ASSERT(m->cmd_list[i] == NULL);
		ASSERT(m->arg_list[i] == NULL);
	}	
	ASSERT(m->dest != NULL);
#endif
	ASSERT(m->magic == MBUS_MSG_MAGIC);
}

static void store_other_addr(struct mbus *m, char *a)
{
	/* This takes the address a and ensures it is stored in the   */
	/* m->other_addr field of the mbus structure. The other_addr  */
	/* field should probably be a hash table, but for now we hope */
	/* that there are not too many entities on the mbus, so the   */
	/* list is small.                                             */
	int	i;

	mbus_validate(m);

	for (i = 0; i < m->num_other_addr; i++) {
		if (mbus_addr_match(m->other_addr[i], a)) {
			/* Already in the list... */
			gettimeofday(m->other_hello[i],NULL);
			return;
		}
	}

	if (m->num_other_addr == m->max_other_addr) {
		/* Expand the list... */
		m->max_other_addr *= 2;
		m->other_addr = (char **) xrealloc(m->other_addr, m->max_other_addr * sizeof(char *));
		m->other_hello = (struct timeval **) xrealloc(m->other_hello, m->max_other_addr * sizeof(struct timeval *));
	}
	m->other_hello[m->num_other_addr]=(struct timeval *)xmalloc(sizeof(struct timeval));
	gettimeofday(m->other_hello[m->num_other_addr],NULL);
	m->other_addr[m->num_other_addr++] = xstrdup(a);
}

static void remove_other_addr(struct mbus *m, char *a)
{
	/* Removes the address a from the m->other_addr field of the */
	/* mbus structure.                                           */
	int	i, j;

	mbus_validate(m);

	for (i = 0; i < m->num_other_addr; i++) {
		if (mbus_addr_match(m->other_addr[i], a)) {
			xfree(m->other_addr[i]);
			xfree(m->other_hello[i]);
			for (j = i+1; j < m->num_other_addr; j++) {
				m->other_addr[j-1] = m->other_addr[j];
				m->other_hello[j-1] = m->other_hello[j];
			}
			m->other_addr[m->num_other_addr  - 1] = NULL;
			m->other_hello[m->num_other_addr - 1] = NULL;
			m->num_other_addr--;
		}
	}
}

static void remove_inactiv_other_addr(struct mbus *m, struct timeval t, int interval){
	/* Remove addresses we haven't heard from for about 5 * interval */
	/* Count backwards so it is safe to remove entries               */
	int i;
    
	mbus_validate(m);

	for (i=m->num_other_addr-1; i>=0; i--){
		if ((t.tv_sec-(m->other_hello[i]->tv_sec)) > 5 * interval) {
			debug_msg("remove dead entity (%s)\n", m->other_addr[i]);
			remove_other_addr(m, m->other_addr[i]);
		}
	}
}

int mbus_addr_valid(struct mbus *m, char *addr)
{
	int	i;

	mbus_validate(m);

	for (i = 0; i < m->num_other_addr; i++) {
		if (mbus_addr_match(m->other_addr[i], addr)) {
			return TRUE;
		}
	}
	return FALSE;
}

static int mbus_addr_unique(struct mbus *m, char *addr)
{
	int     i, n = 0;

	mbus_validate(m);

	for (i = 0; i < m->num_other_addr; i++) {
		if (mbus_addr_match(m->other_addr[i], addr)) {
			n++;
		}
	}
	return n==1;
}

/* The mb_* functions are used to build an mbus message up in the */
/* mb_buffer, and to add authentication and encryption before the */
/* message is sent.                                               */
char	 mb_cryptbuf[MBUS_BUF_SIZE];
char	*mb_buffer;
char	*mb_bufpos;

#define MBUS_AUTH_LEN 16

static void mb_header(int seqnum, int ts, char reliable, const char *src, const char *dst, int ackseq)
{
	xmemchk();
	mb_buffer   = (char *) xmalloc(MBUS_BUF_SIZE + 1);
	memset(mb_buffer,   0, MBUS_BUF_SIZE);
	memset(mb_buffer, ' ', MBUS_AUTH_LEN);
	mb_bufpos = mb_buffer + MBUS_AUTH_LEN;
	sprintf(mb_bufpos, "\nmbus/1.0 %6d %9d %c (%s) %s ", seqnum, ts, reliable, src, dst);
	mb_bufpos += 33 + strlen(src) + strlen(dst);
	if (ackseq == -1) {
		sprintf(mb_bufpos, "()\n");
		mb_bufpos += 3;
	} else {
		sprintf(mb_bufpos, "(%6d)\n", ackseq);
		mb_bufpos += 9;
	}
}

static void mb_add_command(const char *cmnd, const char *args)
{
	int offset = strlen(cmnd) + strlen(args) + 5;

	ASSERT((mb_bufpos + offset - mb_buffer) < MBUS_BUF_SIZE);

	sprintf(mb_bufpos, "%s (%s)\n", cmnd, args);
	mb_bufpos += offset - 1; /* The -1 in offset means we're not NUL terminated - fix in mb_send */
}

static void mb_send(struct mbus *m)
{
	char		digest[16];
	int		len;
	unsigned char	initVec[8] = {0,0,0,0,0,0,0,0};
 
	mbus_validate(m);

	*(mb_bufpos++) = '\0';
	ASSERT((mb_bufpos - mb_buffer) < MBUS_BUF_SIZE);
	ASSERT(strlen(mb_buffer) < MBUS_BUF_SIZE);

	/* Pad to a multiple of 8 bytes, so the encryption can work... */
	while (((mb_bufpos - mb_buffer) % 8) != 0) {
		*(mb_bufpos++) = '\0';
	}
	len = mb_bufpos - mb_buffer;
	ASSERT(len < MBUS_BUF_SIZE);
	ASSERT(strlen(mb_buffer) < MBUS_BUF_SIZE);

	xmemchk();
	if (m->hashkey != NULL) {
		/* Authenticate... */
		hmac_md5(mb_buffer + MBUS_AUTH_LEN+1, strlen(mb_buffer) - (MBUS_AUTH_LEN+1), m->hashkey, m->hashkeylen, digest);
		base64encode(digest, 12, mb_buffer, MBUS_AUTH_LEN);
	}
	xmemchk();
	if (m->encrkey != NULL) {
		/* Encrypt... */
		memset(mb_cryptbuf, 0, MBUS_BUF_SIZE);
		memcpy(mb_cryptbuf, mb_buffer, len);
		ASSERT((len % 8) == 0);
		ASSERT(len < MBUS_BUF_SIZE);
		ASSERT(m->encrkeylen == 8);
		xmemchk();
		qfDES_CBC_e(m->encrkey, mb_cryptbuf, len, initVec);
		xmemchk();
		memcpy(mb_buffer, mb_cryptbuf, len);
	}
	xmemchk();
	udp_send(m->s, mb_buffer, len);
	xfree(mb_buffer);
}

static void resend(struct mbus *m, struct mbus_msg *curr) 
{
	/* Don't need to check for buffer overflows: this was done in mbus_send() when */
	/* this message was first transmitted. If it was okay then, it's okay now.     */
	int	 i;

	mbus_validate(m);

	mb_header(curr->seqnum, curr->comp_time.tv_sec, (char)(curr->reliable?'R':'U'), m->addr, curr->dest, -1);
	for (i = 0; i < curr->num_cmds; i++) {
		mb_add_command(curr->cmd_list[i], curr->arg_list[i]);
	}
	mb_send(m);
	curr->retransmit_count++;
}

void mbus_retransmit(struct mbus *m)
{
	struct mbus_msg	*curr = m->waiting_ack;
	struct timeval	time;
	long		diff;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产乱码精品一区二区三区五月婷| 国产精品国产三级国产有无不卡 | 91精品国产综合久久久久久漫画| 777欧美精品| 国产日产欧产精品推荐色| 亚洲欧美在线另类| 日本中文一区二区三区| 国产丶欧美丶日本不卡视频| 91亚洲午夜精品久久久久久| 欧美一区二区视频观看视频| 国产欧美日韩综合| 午夜av一区二区| 成人综合在线网站| 7777精品伊人久久久大香线蕉| 国产午夜精品一区二区三区嫩草| 中文字幕中文字幕一区| 青青草伊人久久| 99re66热这里只有精品3直播| 91精品国产综合久久小美女| 国产区在线观看成人精品| 亚洲国产人成综合网站| 成人黄色小视频| 精品成人a区在线观看| 一区二区三区不卡在线观看| 国产精品夜夜嗨| 欧美精品vⅰdeose4hd| 中文字幕一区在线观看视频| 激情综合网最新| 欧美精品 日韩| 亚洲免费高清视频在线| 国产麻豆午夜三级精品| 日韩三级高清在线| 亚洲成人777| 一本色道综合亚洲| 国产欧美精品日韩区二区麻豆天美| 亚洲成人久久影院| 91看片淫黄大片一级在线观看| 欧美精品一区视频| 激情成人午夜视频| 日韩手机在线导航| 天堂蜜桃一区二区三区| 在线观看不卡一区| 一区二区三区四区在线免费观看| av在线综合网| 久久精品人人做人人综合 | 成人一二三区视频| 久久九九国产精品| 国产一区二三区好的| 精品欧美黑人一区二区三区| 天堂精品中文字幕在线| 欧美性大战久久久久久久蜜臀 | 欧美大片在线观看一区| 亚洲aaa精品| 制服丝袜亚洲精品中文字幕| 亚洲成人一区二区在线观看| 精品视频全国免费看| 亚洲制服丝袜在线| 欧美精三区欧美精三区| 婷婷综合五月天| 日韩一区二区三区观看| 奇米色一区二区三区四区| 日韩欧美成人一区二区| 麻豆精品在线看| 26uuu国产电影一区二区| 国产专区欧美精品| 国产欧美视频一区二区三区| 成人av电影在线播放| 亚洲欧美色图小说| 欧美日韩免费电影| 乱中年女人伦av一区二区| 亚洲视频一区在线| 色女孩综合影院| 亚洲电影一级片| 日韩免费看的电影| 高清在线观看日韩| 亚洲精品五月天| 91精品国产综合久久精品| 久久99国内精品| 国产精品乱人伦一区二区| 日本精品一级二级| 蜜臀av亚洲一区中文字幕| 国产嫩草影院久久久久| 色爱区综合激月婷婷| 青青青伊人色综合久久| 日韩一级成人av| av成人免费在线观看| 一区二区三区精密机械公司| 欧美一级在线免费| 91影视在线播放| 久久成人久久爱| 亚洲私人影院在线观看| 337p亚洲精品色噜噜| 成人污污视频在线观看| 图片区小说区区亚洲影院| 国产性色一区二区| 欧美日韩国产a| 丁香一区二区三区| 手机精品视频在线观看| 中文字幕一区日韩精品欧美| 欧美日韩成人一区| www.亚洲国产| 国产一区在线不卡| 午夜精品视频一区| 亚洲欧洲一区二区在线播放| 777色狠狠一区二区三区| 成人动漫一区二区三区| 另类中文字幕网| 亚洲6080在线| 亚洲色图欧洲色图| 亚洲黄色录像片| 国产亚洲一二三区| 亚洲精品一区二区三区福利| 欧美伊人久久久久久午夜久久久久| 国产一区二区三区四区五区美女| 丝袜美腿亚洲综合| 亚洲综合精品自拍| 亚洲欧美色综合| 国产精品久久毛片a| 久久嫩草精品久久久精品一| 欧美日韩一区在线| 色婷婷综合久久久久中文一区二区 | 一区二区成人在线| 国产精品嫩草影院com| 亚洲精品一区二区三区福利| 91精品国产福利| 欧美久久久久久蜜桃| 欧美性色欧美a在线播放| 一本大道久久a久久综合| 成人高清在线视频| 成人午夜av在线| 国产高清亚洲一区| 一区二区不卡在线视频 午夜欧美不卡在 | 色综合天天综合| 成人精品小蝌蚪| av电影在线观看一区| 成人av在线资源网| 92精品国产成人观看免费| 91视频一区二区| 欧美亚洲动漫另类| 欧美人与性动xxxx| 91精品国产综合久久精品麻豆| 欧美久久婷婷综合色| 91精品黄色片免费大全| 日韩欧美色电影| 精品国产91乱码一区二区三区 | 欧美一级视频精品观看| 欧美日韩免费高清一区色橹橹| 欧美在线观看视频一区二区| 91麻豆国产自产在线观看| 成人福利视频网站| 91农村精品一区二区在线| 一本色道久久综合狠狠躁的推荐 | 中文字幕亚洲欧美在线不卡| 亚洲美女少妇撒尿| 亚洲mv在线观看| 午夜视频在线观看一区| 麻豆精品久久精品色综合| 国产一区二区伦理片| 99久久综合精品| 欧美日韩高清在线| 久久久另类综合| 亚洲免费在线电影| 蜜臀av国产精品久久久久| 国产激情视频一区二区三区欧美| 99久久99久久精品免费看蜜桃| 91精品91久久久中77777| 在线观看区一区二| 欧美一级xxx| 国产精品久久久久国产精品日日 | 欧美日韩国产a| 日本一区二区高清| 成人免费在线视频| 亚洲制服丝袜一区| 成人av动漫在线| 欧美一级理论片| 欧美国产一区二区在线观看| 一区二区三区免费网站| 狠狠狠色丁香婷婷综合激情 | 一区二区三区在线观看欧美| 日本欧美加勒比视频| 成人v精品蜜桃久久一区| 9191久久久久久久久久久| 国产清纯在线一区二区www| 一区二区三区国产精品| 久久成人麻豆午夜电影| 91丨九色丨尤物| 国产欧美日韩麻豆91| 午夜精品久久久| 9i看片成人免费高清| 欧美电视剧免费观看| 一区二区激情视频| 成人精品国产福利| 精品日韩99亚洲| 婷婷成人综合网| 色呦呦国产精品| 国产精品狼人久久影院观看方式| 丝袜美腿高跟呻吟高潮一区| 97久久超碰国产精品电影| 久久精品视频在线看| 日韩国产一二三区|