// \file
//
// This file is part of RakNet Copyright 2003 Jenkins Software LLC
//
// Usage of RakNet is subject to the appropriate license agreement.
#include "RakNetDefines.h"
#include "RakPeer.h"
#include "RakNetTypes.h"
#include "WSAStartupSingleton.h"
#ifdef _WIN32
#elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
#else
#define closesocket close
#include <unistd.h>
#endif
#if defined(new)
#pragma push_macro("new")
#undef new
#define RMO_NEW_UNDEF_ALLOCATING_QUEUE
#endif
#include <time.h>
#include <ctype.h> // toupper
#include <string.h>
#include "GetTime.h"
#include "MessageIdentifiers.h"
#include "DS_HuffmanEncodingTree.h"
#include "Rand.h"
#include "PluginInterface2.h"
#include "StringCompressor.h"
#include "StringTable.h"
#include "NetworkIDObject.h"
#include "RakNetTypes.h"
#include "SHA1.h"
#include "RakSleep.h"
#include "RouterInterface.h"
#include "RakAssert.h"
#include "RakNetVersion.h"
#include "NetworkIDManager.h"
#include "DataBlockEncryptor.h"
#include "gettimeofday.h"
#include "SignaledEvent.h"
#include "SuperFastHash.h"
RAK_THREAD_DECLARATION(UpdateNetworkLoop);
RAK_THREAD_DECLARATION(RecvFromLoop);
RAK_THREAD_DECLARATION(UDTConnect);
#define REMOTE_SYSTEM_LOOKUP_HASH_MULTIPLE 8
#if !defined ( __APPLE__ ) && !defined ( __APPLE_CC__ )
#include <stdlib.h> // malloc
#endif
#if defined(_XBOX) || defined(X360)
#elif defined(_WIN32)
//
#else
/*
#include <alloca.h> // Console 2
#include <stdlib.h>
extern bool _extern_Console2LoadModules(void);
extern int _extern_Console2GetConnectionStatus(void);
extern int _extern_Console2GetLobbyStatus(void);
//extern bool Console2StartupFluff(unsigned int *);
extern void Console2ShutdownFluff(void);
//extern unsigned int Console2ActivateConnection(unsigned int, void *);
//extern bool Console2BlockOnEstablished(void);
extern void Console2GetIPAndPort(unsigned int, char *, unsigned short *, unsigned int );
//extern void Console2DeactivateConnection(unsigned int, unsigned int);
*/
#endif
static const int NUM_MTU_SIZES=3;
#if defined(_XBOX) || defined(X360)
#elif __PC__
static const int mtuSizes[NUM_MTU_SIZES]={1200, 1200, 576};
#else
static const int mtuSizes[NUM_MTU_SIZES]={MAXIMUM_MTU_SIZE, 1200, 576};
#endif
#include "RakAlloca.h"
// Note to self - if I change this it might affect RECIPIENT_OFFLINE_MESSAGE_INTERVAL in Natpunchthrough.cpp
//static const int MAX_OPEN_CONNECTION_REQUESTS=8;
//static const int TIME_BETWEEN_OPEN_CONNECTION_REQUESTS=500;
#ifdef _MSC_VER
#pragma warning( push )
#endif
using namespace RakNet;
static RakNetRandom rnr;
struct RakPeerAndIndex
{
SOCKET s;
unsigned short remotePortRakNetWasStartedOn_PS3;
RakPeer *rakPeer;
};
// On a Little-endian machine the RSA key and message are mangled, but we're
// trying to be friendly to the little endians, so we do byte order
// mangling on Big-Endian machines. Note that this mangling is independent
// of the byte order used on the network (which also defaults to little-end).
#ifdef HOST_ENDIAN_IS_BIG
void __inline BSWAPCPY(unsigned char *dest, unsigned char *source, int bytesize)
{
#ifdef _DEBUG
RakAssert( (bytesize % 4 == 0)&&(bytesize)&& "Something is wrong with your exponent or modulus size.");
#endif
int i;
for (i=0; i<bytesize; i+=4)
{
dest[i] = source[i+3];
dest[i+1] = source[i+2];
dest[i+2] = source[i+1];
dest[i+3] = source[i];
}
}
void __inline BSWAPSELF(unsigned char *source, int bytesize)
{
#ifdef _DEBUG
RakAssert( (bytesize % 4 == 0)&&(bytesize)&& "Something is wrong with your exponent or modulus size.");
#endif
int i;
unsigned char a, b;
for (i=0; i<bytesize; i+=4)
{
a = source[i];
b = source[i+1];
source[i] = source[i+3];
source[i+1] = source[i+2];
source[i+2] = b;
source[i+3] = a;
}
}
#endif
static const unsigned int SYN_COOKIE_OLD_RANDOM_NUMBER_DURATION = 10000;
static const unsigned int MAX_OFFLINE_DATA_LENGTH=400; // I set this because I limit ID_CONNECTION_REQUEST to 512 bytes, and the password is appended to that packet.
// Used to distinguish between offline messages with data, and messages from the reliability layer
// Should be different than any message that could result from messages from the reliability layer
#pragma warning(disable:4309) // 'initializing' : truncation of constant value
// Make sure highest bit is 0, so isValid in DatagramHeaderFormat is false
static const char OFFLINE_MESSAGE_DATA_ID[16]={0x00,0xFF,0xFF,0x00,0xFE,0xFE,0xFE,0xFE,0xFD,0xFD,0xFD,0xFD,0x12,0x34,0x56,0x78};
//#define _DO_PRINTF
// UPDATE_THREAD_POLL_TIME is how often the update thread will poll to see
// if receive wasn't called within UPDATE_THREAD_UPDATE_TIME. If it wasn't called within that time,
// the updating thread will activate and take over network communication until Receive is called again.
//static const unsigned int UPDATE_THREAD_UPDATE_TIME=30;
//static const unsigned int UPDATE_THREAD_POLL_TIME=30;
//#define _TEST_AES
struct PacketFollowedByData
{
Packet p;
unsigned char data[1];
};
Packet *RakPeer::AllocPacket(unsigned dataSize, const char *file, unsigned int line)
{
// Crashes when dataSize is 4 bytes - not sure why
// unsigned char *data = (unsigned char *) rakMalloc_Ex(sizeof(PacketFollowedByData)+dataSize, file, line);
// Packet *p = &((PacketFollowedByData *)data)->p;
// p->data=((PacketFollowedByData *)data)->data;
// p->length=dataSize;
// p->bitSize=BYTES_TO_BITS(dataSize);
// p->deleteData=false;
// p->guid=UNASSIGNED_RAKNET_GUID;
// return p;
Packet *p;
packetAllocationPoolMutex.Lock();
p = packetAllocationPool.Allocate(file,line);
packetAllocationPoolMutex.Unlock();
p = new ((void*)p) Packet;
p->data=(unsigned char*) rakMalloc_Ex(dataSize,file,line);
p->length=dataSize;
p->bitSize=BYTES_TO_BITS(dataSize);
p->deleteData=true;
p->guid=UNASSIGNED_RAKNET_GUID;
return p;
}
Packet *RakPeer::AllocPacket(unsigned dataSize, unsigned char *data, const char *file, unsigned int line)
{
// Packet *p = (Packet *)rakMalloc_Ex(sizeof(Packet), file, line);
Packet *p;
packetAllocationPoolMutex.Lock();
p = packetAllocationPool.Allocate(file,line);
packetAllocationPoolMutex.Unlock();
p = new ((void*)p) Packet;
p->data=data;
p->length=dataSize;
p->bitSize=BYTES_TO_BITS(dataSize);
p->deleteData=true;
p->guid=UNASSIGNED_RAKNET_GUID;
return p;
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Constructor
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RakPeer::RakPeer()
{
StringCompressor::AddReference();
RakNet::StringTable::AddReference();
WSAStartupSingleton::AddRef();
#if !defined(_XBOX) && !defined(_WIN32_WCE) && !defined(X360)
usingSecurity = false;
#endif
memset( frequencyTable, 0, sizeof( unsigned int ) * 256 );
rawBytesSent = rawBytesReceived = compressedBytesSent = compressedBytesReceived = 0;
outputTree = inputTree = 0;
defaultMTUSize = mtuSizes[NUM_MTU_SIZES-1];
trackFrequencyTable = false;
maximumIncomingConnections = 0;
maximumNumberOfPeers = 0;
//remoteSystemListSize=0;
remoteSystemList = 0;
remoteSystemLookup=0;
bytesSentPerSecond = bytesReceivedPerSecond = 0;
endThreads = true;
isMainLoopThreadActive = false;
isRecvFromLoopThreadActive = false;
// isRecvfromThreadActive=false;
#if defined(GET_TIME_SPIKE_LIMIT) && GET_TIME_SPIKE_LIMIT>0
occasionalPing = true;
#else
occasionalPing = false;
#end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
毕设&课设&项目&实训-基于集群的后台日志分析系统,操作系统linux,开发语言c++。程序分为三部分,我保存的.zip (562个子文件)
libraknet.so.0.0.0 1.5MB
libxml.so.0.0.0 98KB
libraknet.a 4.63MB
libsqlapiu.a 1.69MB
libsqlapi.a 1.62MB
libxml.a 212KB
cmake_install.cmake 1KB
CMakeDirectoryInformation.cmake 613B
setting.conf 82B
controls 1.27MB
controls-new 1.24MB
RakPeer.cpp 287KB
ReliabilityLayer.cpp 133KB
rdlmalloc.cpp 130KB
ReplicaManager3.cpp 81KB
ReplicaManager2.cpp 74KB
ReplicaManager.cpp 47KB
BigInt.cpp 47KB
Router2.cpp 43KB
SocketLayer.cpp 40KB
BitStream.cpp 32KB
FileListTransfer.cpp 32KB
BitStream_NoTemplate.cpp 30KB
RakString.cpp 29KB
TCPInterface.cpp 29KB
CCRakNetUDT.cpp 27KB
DS_Table.cpp 27KB
Gen_RPC8.cpp 25KB
LightweightDatabaseServer.cpp 24KB
NatPunchthroughClient.cpp 24KB
main.cpp 23KB
AutoRPC.cpp 23KB
TeamBalancer.cpp 23KB
rijndael.cpp 22KB
ConnectionGraph.cpp 21KB
FileList.cpp 21KB
raknet_serv.cpp 21KB
UDPProxyCoordinator.cpp 18KB
NatPunchthroughServer.cpp 18KB
ReadyEvent.cpp 17KB
UDPForwarder.cpp 15KB
EmailSender.cpp 14KB
PacketLogger.cpp 14KB
FullyConnectedMesh2.cpp 13KB
RakNetCommandParser.cpp 12KB
PacketizedTCP.cpp 12KB
MessageFilter.cpp 11KB
Router.cpp 11KB
ConsoleServer.cpp 10KB
UDPProxyClient.cpp 10KB
TableSerializer.cpp 10KB
RakNetTypes.cpp 9KB
DS_HuffmanEncodingTree.cpp 9KB
TelnetTransport.cpp 9KB
Rand.cpp 9KB
pure_log.cpp 9KB
VariableDeltaSerializer.cpp 9KB
StringCompressor.cpp 9KB
NatTypeDetectionServer.cpp 8KB
AsynchronousFileIO.cpp 8KB
RakMemoryOverride.cpp 7KB
LogCommandParser.cpp 7KB
NetworkIDObject.cpp 7KB
DirectoryDeltaTransfer.cpp 7KB
testxml3.cpp 7KB
HTTPConnection.cpp 7KB
SHA1.cpp 7KB
GridSectorizer.cpp 6KB
RakNetStatistics.cpp 6KB
DataBlockEncryptor.cpp 6KB
GetTime.cpp 6KB
ServerClientTest.cpp 6KB
ServerClientTest.cpp 6KB
NetworkIDManager.cpp 5KB
UDPProxyServer.cpp 5KB
ConnectionGraph2.cpp 5KB
RakNetTransport.cpp 5KB
CommandParserInterface.cpp 5KB
testxml2.cpp 5KB
RSACrypt.cpp 5KB
NatTypeDetectionClient.cpp 5KB
VariadicSQLParser.cpp 4KB
RPCMap.cpp 4KB
_FindFirst.cpp 4KB
RakNetworkFactory.cpp 4KB
RPC4Plugin.cpp 4KB
raknet_client.cpp 4KB
LightweightDatabaseClient.cpp 4KB
testxml.cpp 4KB
FunctionThread.cpp 4KB
FileOperations.cpp 3KB
DS_ByteQueue.cpp 3KB
SignaledEvent.cpp 3KB
DS_BytePool.cpp 3KB
RakNetTransport2.cpp 3KB
StringTable.cpp 3KB
mysqlop.cpp 3KB
NatTypeDetectionCommon.cpp 3KB
SuperFastHash.cpp 3KB
SystemAddressList.cpp 3KB
共 562 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功