⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netcomm.h

📁 自己开发基于P2P通讯的网络服务器
💻 H
字号:
/*********************************************************************
 * 模块名称:netcomm
 * 说明:网络通讯模块,监听网络事件,接收请求数据包
 * 其它说明: 
 * 作者: 刘青山 
 * 时间 : 2004-09-23 21:13:30 
*********************************************************************/
#ifndef	_NETCOMM_H
#define	_NETCOMM_H

#include <pthread.h>
#include "natpacket.h"
#include "list.h"

struct rtt_info 
{
  float		rtt_rtt;	/* most recent measured RTT, seconds */
  float		rtt_srtt;	/* smoothed RTT estimator, seconds */
  float		rtt_rttvar;	/* smoothed mean deviation, seconds */
  float		rtt_rto;	/* current RTO to use, seconds */
  int		rtt_nrexmt;	/* #times retransmitted: 0, 1, 2, ... */
  uint32	rtt_base;	/* #sec since 1/1/1970 at start */
  uint32	rtt_lastchk;	// the last check time,seconds
  uint32	rtt_timestamp;	// timestamp,Milliseconds
} ;


typedef struct tagP2P_USER
{
	struct  list_head ipport;	// hash by ip and port
	struct  list_head uin;		// hash by kkid
	struct  list_head listItem;	// Keep alive item
	struct  list_head listAns ;	// answer queue,it record that had not send successful packet
	DWORD	dwID ;			// KK ID
	DWORD	dwLocalIP ;		// 本地IP
	DWORD	dwNatIP ;		// NAT IP
	WORD	wLocalPort ;	// 本地 PORT
	WORD	wNatPort ;		// NAT PORT

	BYTE	Window[1 << 13];

	DWORD	dwRttBase ;		// Rtt及计算基准
	DWORD	dwRto ;			// 用户数据报往返时间,(毫秒)
	DWORD	dwExpire;
	int		iRefCount;		// 使用计数
	WORD	wRefCRC;		// CRC使用计数
	pthread_mutex_t		mtUser;	// 内存互斥锁
	BYTE	byStatus;		// status:alive or dead
	struct tagP2P_USER  *next;
}P2P_USER,*LPP2P_USER;

#pragma pack(1)
typedef struct tagREQ_PACKET
{
	struct  list_head   listItem ;
	LPP2P_USER		pUser ;				// 用户数据指针
	LPP2P_HDR		pHeader;
	BYTE			*pData;				// 包头后包身数据
	BYTE			buf[P2P_DATA_LEN];	// 数据缓冲区
}REQ_PACKET,*LPREQ_PACKET;

typedef struct tagANS_PACKET
{
	struct  list_head   listUser ;		// 用户链表接点
	struct  list_head   listGlobal ;	// 全局链表接点
	LPP2P_USER		pUser ;				// 用户数据指针
	LPP2P_HDR		pHeader;
	BYTE			*pData;				// 包头后包身数据
	BYTE			buf[P2P_DATA_LEN];  // 数据缓冲区
	bool			bSended;			// 是否已经发送

	DWORD			dwExpire;			// 超时
	BYTE			byTry;				// 发送次数
}ANS_PACKET,*LPANS_PACKET;
#pragma pack()

extern short TXN_TIME[];

extern void InitNetQueue();
extern int	NetRuning( );
extern LPREQ_PACKET GetReqPacket();
extern int	SendPacket(LPANS_PACKET pAns) ;
extern unsigned char* PacketEncode(LPP2P_HDR pHdr);

extern int g_iSocksvr ;

#endif	// _NETCOMM_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -