Giter Site home page Giter Site logo

facebookarchive / raknet Goto Github PK

View Code? Open in Web Editor NEW
3.3K 456.0 1.0K 40.72 MB

RakNet is a cross platform, open source, C++ networking engine for game programmers.

License: Other

C++ 21.55% C 33.51% Shell 2.77% C# 2.76% Makefile 0.08% XSLT 0.04% CSS 0.07% Perl 0.02% HTML 38.87% Assembly 0.16% Python 0.06% SAS 0.04% Smalltalk 0.01% Java 0.03% JavaScript 0.01% Objective-C 0.01% Objective-C++ 0.01%

raknet's Introduction

RakNet 4.081

Copyright (c) 2014, Oculus VR, Inc.

Package notes

The Help directory contains index.html, which is full help documentation in HTML format The Source directory contain all files required for the core of Raknet and is used if you want to use the source in your program or create your own dll The Samples directory contains code samples and one game using an older version of Raknet. The code samples each demonstrate one feature of Raknet. The game samples cover several features. The lib directory contains libs for debug and release versions of RakNet and RakVoice There is a make file for linux users in the root directory. Windows users can use projects under Samples\Project Samples

C# support

See Help\swigtutorial.html

Upgrading from version 3

See 3.x_to_4.x_upgrade.txt

Windows users (Visual Studio 2008 and 2010)

Load RakNet_VS2008.sln and convert if necessary.

After the project conversion, if you encounter error MSB4006, follow the steps below to fix it:

  1. Open project properties
  2. Click on "Common Properties"
  3. Click on "Framework and References"
  4. Look under "Build Properties"
  5. Change the "Copy Local" flag from "True" to "False"

For other compiler issues, please see Help/compilersetup.html

Windows users (VC6)

Not supported, but you can get by if you directly include the source.

CYGWIN users

Copy Include, Source, and whatever you want to run in the home directory. Then type g++ ../../lib/w32api/libws2_32.a *.cpp You can run a.exe. You might have to copy *.dll from cygwin\bin as well.

Linux users

Use cmake, or g++ -lpthread -g *.cpp in the /Source directory. With libcat, use g++ -pthread -g -I./../DependentExtensions *.cpp in the /Source directory.

64 bit use -m64 command line Sometimes you need -pthread instead of -lpthread

Command to build 64 bit chat example server from the /Source directory:

g++ -m64 -g -lpthread -I./ "../Samples/Chat Example/Chat Example Server.cpp" *.cpp

Command to build NATCompleteServer from the Samples/NATCompleteServer directory:

g++ -g -lpthread -I./ -I./../../Source main.cpp -I./../CloudServer ./../../Source/*.cpp ./../CloudServer/CloudServerHelper.cpp

Command to build autopatcher server from /Source directory:

g++ -lpthread -lpq -lssl -lbz2 -lssl -lcrypto -L/opt/PostgreSQL/9.0/lib -L../DependentExtensions/bzip2-1.0.6 -I/opt/PostgreSQL/9.0/include -I../DependentExtensions/bzip2-1.0.6 -I./ -I../DependentExtensions/Autopatcher -I../DependentExtensions/Autopatcher/AutopatcherPostgreRepository -I../DependentExtensions/PostgreSQLInterface -g *.cpp ../DependentExtensions/Autopatcher/AutopatcherServer.cpp ../DependentExtensions/Autopatcher/CreatePatch.cpp ../DependentExtensions/Autopatcher/MemoryCompressor.cpp ../DependentExtensions/Autopatcher/AutopatcherPostgreRepository/AutopatcherPostgreRepository.cpp ../DependentExtensions/PostgreSQLInterface/PostgreSQLInterface.cpp ../Samples/AutopatcherServer/AutopatcherServerTest.cpp

Command to build NATCompleteServer from /Source directory:

g++ -lpthread -I./ -I../Samples/CloudServer ../Samples/CloudServer/CloudServerHelper.cpp ../Samples/NATCompleteServer/main.cpp *.cpp

Command to build BigPacketTest from /Source directory:

g++ -lpthread -I./ ../Samples/BigPacketTest/BigPacketTest.cpp *.cpp

Or with debugging info on:

g++ -g -lpthread -I./ ../Samples/BigPacketTest/BigPacketTest.cpp *.cpp

If you get /usr/local/lib/libraknet.so: undefined reference to `__sync_fetch_and_add_4 then build with -march=i686

To debug: http://www.unknownroad.com/rtfm/gdbtut/gdbstack.html http://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html http://linux.bytesex.org/gdb.html http://www.delorie.com/gnu/docs/gdb/gdb_29.html

gdb ./a.out

Set breakpoint:

b file:line

Disable a breakpoint:

disable <breakpointNumber>

Delete a breakpoint:

delete <breakpointNumber>

Get a list of breakpoints:

info breakpoints

St breakpoint to be ignored that number of times

ignore <breakpointNumber> <count>
run

Other useful commands:

info stack
info locals
delete (Clears all breakpoints)
step (step into)
next (step over)
finish (step out)
continue to keep going after step or next
p <variableName>
For example: p users.orderedList.listArray[0].guid

Command to install g++

sudo apt-get install gcc-c++
sudo apt-get install build-essential

Or:

yum install gcc-c++

Or:

sudo apt-get update
sudo apt-get install g++

Command to install gdb

sudo apt-get install gdb

Command to install wget, used to download files from webpages sudo apt-get install wget

Series of commands for a new server: sudo apt-get install wget sudo apt-get update sudo apt-get install --fix-missing g++ sudo apt-get install gdb cd RakNet_Install_Directory\Source g++ -m64 -g -pthread -I./ "../Samples/Chat Example/Chat Example Server.cpp" *.cpp ./a.out

Mac Users

Open a Terminal window and type:

cd ~/Desktop/RakNet/Source
g++ -c -DNDEBUG -I -isysroot /Developer/SDKs/MacOSX10.5u.sdk/ -arch i386 *.cpp

Use whichever SDK you have. However, the 10.4 SDK is bugged and will not compile unless you use GCC 4.0 from inside XCODE

The sources should build cleanly. This gives you a bunch of PowerPC binaries, compiled against the 10.3.9 SDK which is a good thing.

Give the following command:

libtool -static -o raknetppc.a *.o

This will stitch together a static library for the PowerPC architecture. There may be warnings that some .o files do not have any symbols. If you want to be prudent, remove the named files (the .o files, not the .cpp files!) and re-run the libtool command.

Now, we build the source files for Intel:

gcc -c -I ../Include -isysroot /Developer/SDKs/MacOSX10.4u.sdk/ -arch i386 *.cpp

..and stitch it into a i386 library:

libtool -static -o rakneti386.a *.o

Now, type:

ls *.a

which should list the two .a files. Now, we make them into a universal binary:

lipo -create *.a -o libraknet.a

You now have a file named libraknet.a. This is the RakNet library, built to run on both PowerPC and Intel Macs. Enjoy! ;-)

IPod

Depending on what version you target, you may have to change two defines to not use 64 bit integers and floats or doubles.

Android

You will need the latest CYWGIN and the android SDK to build native code on the android. Under CYWGIN, you will need to run ndk-build on a directory for RakNet.

  1. Under cygwin, create the RakNet directory somewhere, such as under samples. For example, if you create the path \cygwin\home\Kevin\android-ndk-r4b\samples\RakNet

  2. I copied the Android.Manifest.xml and other files from another sample

  3. Under jni, you will need the following Android.mk

    LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := RakNet MY_PREFIX := $(LOCAL_PATH)/RakNetSources/ MY_SOURCES := $(wildcard $(MY_PREFIX)*.cpp) LOCAL_SRC_FILES += $(MY_SOURCES:$(MY_PREFIX)%=RakNetSources/%) include $(BUILD_SHARED_LIBRARY)

This version of Android.mk assumes there is a directory called RakNetSources, for example cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources

Under RakNetSources should be the /Source directory to RakNet. Rather than copy the files I used junction.exe http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

The command I used to create the junction was:

D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/junction.exe -s D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources D:/RakNet4/Source

To unjunction I used:

D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/junction.exe -d D:/cygwin/home/Kevin/android-ndk-r4b/samples/RakNet/jni/RakNetSources

From within the CYWGIN enviroment, navigate to home/Kevin/android-ndk-r4b/samples/RakNet. Then type

../../ndk-build

Everything should build and you should end up with a .so file.

You should then be able to create a project in eclipse, and import cygwin/home/Kevin/android-ndk-r4b/samples/RakNet

Native client

Solution: RakNet_NativeClient_VS2010. See Samples\nacl_sdk\RakNet_NativeClient_VS2010\HowToSetup.txt for detailed instructions on setup.

Windows Phone 8

Example solution: RakNet_WinPhone8_VS2012. Add to your project DependentExtensions\WinPhone8\ThreadEmulation.cpp Add DependentExtensions\WinPhone8\ to your include paths Define _CRT_SECURE_NO_WARNINGS and WINDOWS_PHONE_8

Windows Store 8

Example solution: RakNet_WindowsStore8_VS2012.sln Add to your project DependentExtensions\WinPhone8\ThreadEmulation.cpp Add DependentExtensions\WinPhone8\ and DependentExtensions\WinRT to your include paths TCP is not supported, only UDP (RakPeer). IPV4 only (not hard to also add IPV6 upon request). Define: _CRT_SECURE_NO_WARNINGS WINDOWS_STORE_RT _RAKNET_SUPPORT_TCPInterface=0 _RAKNET_SUPPORT_PacketizedTCP=0 _RAKNET_SUPPORT_EmailSender=0 _RAKNET_SUPPORT_HTTPConnection=0 _RAKNET_SUPPORT_HTTPConnection2=0 _RAKNET_SUPPORT_TelnetTransport=0 _RAKNET_SUPPORT_NatTypeDetectionServer=0 _RAKNET_SUPPORT_UDPProxyServer=0 _RAKNET_SUPPORT_UDPProxyCoordinator=0 _RAKNET_SUPPORT_UDPForwarder=0

Unreal engine

See https://udn.epicgames.com/lists/showpost.php?list=unprog3&id=37697&lessthan=&show=20

raknet's People

Contributors

alliekins avatar echelon9 avatar jpratliffvr avatar png85 avatar ralith avatar rovanion avatar trotter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raknet's Issues

Corrupt packets trought mobile network

Hello. As far as I know, there is no cancer is RUDP. but do not know whether it guarantees the safety of the package?
In general sent Xml

   rak_peer-> Send (ptr, size, HIGH_PRIORITY, RELIABLE_ORDERED, 0, to_guid, false);
And sometimes it comes distorted, and always the same

Here - the most interesting thing in the end, as if a piece of torn out and crooked inserted ago

Normal - http://www.everfall.com/paste/id.php?8g41jw03yyf2
Damaged - http://www.everfall.com/paste/id.php?ivmdr8fa0cc8

This crap happens rarely, but it happens only when the server Win64 client communication via Android 2G 3G or 4G ...

RakNetDOS (!)

RakNet DoS attack.

The problem lays in ACKs and NAKs system in function:
ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer

commit e97c4bb didn't fix it

Specially crafted packet can hang RakNet thread for quite a while or freeze it for good.

ReliabilityLayer.cpp

Line 736:
for (i=0; i<incomingAcks.ranges.Size();i++)
{
...
...
Line 746:
for (datagramNumber=incomingAcks.ranges[i].minIndex; datagramNumber >= incomingAcks.ranges[i].minIndex && datagramNumber <= incomingAcks.ranges[i].maxIndex; datagramNumber++)
}

and

Line 818:
for (i=0; i<incomingNAKs.ranges.Size();i++)
{
...
...
Line 831:
for (messageNumber=incomingNAKs.ranges[i].minIndex; messageNumber >= incomingNAKs.ranges[i].minIndex && messageNumber <= incomingNAKs.ranges[i].maxIndex; messageNumber++)
}

When ranges[i].minIndex = 0 and ranges[i].maxIndex = 0xFFFFFFFE then loop will be executed 4294967294 times. Which is a lot. What is more, a single packet can contain
even 200 "ranges" or more. So loop at line 746 and 818 going to be executed 200 * 4294967294 = 858993458800 times, because ranges.Size() = 200;
This can hang RakNet thread for a while, so no new incoming connections are going to be accepted and all peers already connected will timeout.

Special case:
incomingNAKs.ranges[i].minIndex = 0 and incomingNAKs.ranges[i].maxIndex = 0xFFFFFFFF then loop at line 818 will never end.

In this case RakNet thread will be trapped in an endless loop.

CMake quoting "fix" breaks future versions of MSVC

At Lib/LibStatic/CMakeLists.txt#L20 there is a hotfix to work around windows quoting issues, which conditional checks "some" vs compilers, which is a bit too restrictive.
IF( MSVC10 OR MSVC11 OR MSVC12 )

For VS2015 preview, which is build chain MSVC14, and any future MSVC's this will require additions to fix this. This causes the build to fail on the incorrect quote escaping.

The majority of the build system is already assuming MSVC chain on windows for definitions and arguments, the same should be assumed for these quoting mechanisms

IF(WIN32 AND NOT UNIX)

instead.

ComprhansivePCGame demo: "Error Parsing Json" on Win7

Atfer Building the source Code via VS2015
I run the NatCompleteServer Then Run the ComprhansivePCGame.
And The ComprhansivePCGame shows error like this:

Demonstrates networking elements for a P2P game on the PC, self-released,
with player hosted game servers
Difficulty: Advanced

Our guid is 612489550940309598
Started on 127.0.0.1|49154
Enter address of server running the NATCompleteServer project.
Enter for default: 192.168.1.103
Enter server port, or enter for default: 61111
ID_CONNECTION_REQUEST_ACCEPTED from 192.168.1.103|61111,guid=540431956319473136
Discovering UPNP...
List of UPNP devices found on the network :
desc: http://192.168.1.1:1900/igd.xml
st: urn:schemas-upnp-org:device:InternetGatewayDevice:1

Downloading rooms...
Error parsing JSON

Thx in advance.

Missing FindRakNet.cmake module

There is no provided cmake module for client project using CMake to find RakNet easily. All custom FindRakNet.cmake modules I have found online so far does not manage windows/visual studio case, they only work on linux.

Send custom packet before kick (CloseConnection)

I'd like to send a custom packet to a client before kicking them with CloseConnection.
So I put a IMMEDIATE_PRIORITY in my Send function right before CloseConnection but the packet never reaches the client..
So I wonder if there's a way to send some data to the client before kicking them?

uint24_t does not work on Big-Endian systems

This code in a Big-Endian system:
RakNet::uint24_t test(0);
test++;
printf("%u\n", test.val);
will print 0 and not the expected 1.

I will try to solve it and post a solution in a comment.

Build fails for Android: Enabling LIBCAT_SECURITY for Android builds fail - no pthread_cancel()

I'm wanting to enable libCat security on Android but it fails to compile due to cat/src/threads/Threads.cpp calling pthread_cancel(..) in Threads::AbortThread().

My research suggests that Android/NDK does not support pthread_cancel(..)

Threads.cpp is included in RakNet/SecureHandshake.cpp

Is there a workaround for this?

I'm building using android-ndk-r10d-linux specifying android-9 as the platform target.

Solved: In case anyone else is having this issue, it's very simple to fix.

You just need to define CAT_NO_ENTROPY_THREAD in cat/Config.hpp.

This removed the thread call completely and building is successful!

Windows Firewall complaining

Whenever I start a compiled client program with raknet, Windows Firewall opens and asks to whitelist the program. Why is that? It is just client program connect to a server. It even happens when using the example code.

Packet Corruption on 64bit

I've been having issues where packets are apparently corrupted. This seems to only affect about 1 in 50 people, who it seems to happen to quite regularly. I've added CRCs to both datagrams and packet content, the CRC on the datagrams always pass. The CRC on the packet content itself fails very occasionally.

This apparently happens when packet size > MTU. Could there be an issue when sending lots of data to 100+ connected clients where the client would reconstruct packets wrong?

OculusVR / RakNet FileOperations: WriteFileWithDirectories() Array Overflow/Remote Code Execution Vulnerability

Overview:
There are two .cpp files namely 'FileOperations.cpp' and 'FileList.cpp"

FileOperations.cpp contains a function called 'WriteFileWithDirectories()' which accepts 3 parameters one of which is a pointer to the physical path that the data will be written onto disk.

FileList.cpp contains a function called 'WriteDataToDisk()" which also accepts a parameter as a pointer to the application directory.

The idea is that 'WriteDataToDisk' in FileList.cpp will receive a list of filenames along with corresponding directories (eg; C:\UnrealEngine\Mods\guns.dat) with which 'WriteFileWithDirectories' in FileOperations.cpp will write/update data to.

Vulnerability Details:
Now the root cause of the vulnerability exists in 'WriteFileWithDirectories' of FileOperations.cpp that the directory structure+filename is only limited to 260 maximum. However 'WriteDataToDisk' function can pass structure+filename up to 512. So when Strcpy() in WriteFileWithDirectories copy path+filename provided by WriteDataToDisk. The overflow is triggered. Refer to the link for more info.

https://drive.google.com/file/d/0B8MQckpnz0TaOTd6NkJXenV5M0E/view?usp=sharing

More Info:
There are features that DIRECTLY call 'WriteFileWithDirectories()' function. The result is it effectively eliminates/extend the limitation for max structure+filename size that can be passed to 'WriteFileWithDirectories() since no WriteDataToDisk() function is called before. So there is a window of opportunity in terms of control over buffer.
One such example is DirectoryDeltaTransfer and AutoPatcher feature. Please refer to page 2 and 3 of attached pdf.

(http://www.jenkinssoftware.com/raknet/manual/directorydeltatransfer.html

(http://www.raknet.net/raknet/manual/autopatcher.html)

Attack Vector:
As it has been highlighted. The FileOperations can be implemented both on server side (eg; DirectoryDeltaTransfer) and client side(eg;AutoPatcher ). It means to say that the attack can simply be a malicious user uploading crafted content to the server ( thus exploiting both server itself and users who download the payload).

Where to get RakNet Support ?

As the forum looks dead , and massages here are barely get answered ,
Where are the community of RakNet are Usually?
Tישמלד

Android compilation fail

Hello, when I try to build RakNet for Android with cygwin, I get this error :

jni/RakNetSources/FileList.cpp:18:20: fatal error: asm/io.h: No such file or directory
 #include <asm/io.h>

[C#] System.TypeInitializationException whenever creating BitStream

Hey guys,

I am mostly a Java guy doing a lot of Minecraft: Pocket Edition Server development. MCPE uses RakNet as it's networking library, so with the Oculus purchase I thought that maybe I could use RakNet with C# as C# is similar to Java. I had some trouble compiling, but I finally got the C# code generated somehow, and I used VS2013 Community to compile it into a DLL. I added it into my project, and once I start receiving packets, the program crashes as I try to create a BitStream for each packet. A System.TypeInitalizationException is thrown. I have searched google for this, and turned up with nothing.

private void handlePacket(byte[] buffer)
        {
            BitStream bs = new BitStream(buffer, (uint)buffer.Length, false);

            byte packetID;
            bs.Read(out packetID);
            switch (packetID)
            {
                default:
                    logger.Info("Got a packet: " + packetID);
                    break;
            }
        }

Compiling DLL under VS2015 Preview

I've noticed that there is an issue in CCRakNetSlidingWindow.cpp where math.h is included rather than cmath which causes an ambiguous call to abs() and fails to compile. Just thought I would point this out.

Templated BitStream::operator << should take a reference to a const value

The BitStream has a << operator which simply takes any argument and redirects it to BitStream::Write(...):

template <class templateType>
BitStream& operator<<(BitStream& out, templateType& c)
{
    out.Write(c);
    return out;
}

c (or the value referenced) however will never be changed, so that c should be const. Then the following code becomes valid:

RakString some_str()
{
    ...
}

BitStream bs;
bs << MessageID(0);
bs << some_str();

split packet out-of-order issue

When udp packet greater than mtusize ,between times split packet send out-of-order

fixed:
// Insert the packet into the SplitPacketChannel
// find ReliabilityLayer.cpp file search
// splitPacketChannelList[index]->splitPacketList.Insert(internalPacket, FILE, LINE );
// change to
splitPacketChannelList[index]->splitPacketList.Replace(internalPacket, 0, internalPacket->splitPacketIndex, FILE, LINE);

找到ReliabilityLayer.cpp 文件中的
// splitPacketChannelList[index]->splitPacketList.Insert(internalPacket, FILE, LINE ); 行

//替换为
splitPacketChannelList[index]->splitPacketList.Replace(internalPacket, 0, internalPacket->splitPacketIndex, FILE, LINE);

Android secure connection crash.

Hi I use raknet secure connections in my game but it crash in android here is logcat log.

F/libc (18590): Fatal signal 7 (SIGBUS), code 1, fault addr 0x96d62c87 in tid 18665 (Thread-5992)
W/libc (18590): Security Level: (1), Debug inforamtion is controlled by the DUMPABLE flag.
I/DEBUG ( 446): *** *** *** *** *** *** *** *** *** *** *** *** *** *** * ***
I/DEBUG ( 446): Build fingerprint: 'htc/htc_asia_tw/htc_eyetuhl:5.0.2/LRX22G/653658.2:user/release-keys'
I/DEBUG ( 446): Revision: '0'
I/DEBUG ( 446): ABI: 'arm'
I/DEBUG ( 446): pid: 18590, tid: 18665, name: Thread-5992 >>> com.plangtongs.skyheroes <<<
I/DEBUG ( 446): signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x96d62c87
I/DEBUG ( 446): r0 95213588 r1 96d62c87 r2 00000008 r3 00000000
I/DEBUG ( 446): r4 00000000 r5 00000000 r6 995ef788 r7 95213588
I/DEBUG ( 446): r8 96d62c87 r9 952136c0 sl 96d62c7f fp 00000001
I/DEBUG ( 446): ip 95213580 sp 95213514 lr 9ac016b3 pc 9abff36e cpsr 800f0030
I/DEBUG ( 446):
I/DEBUG ( 446): backtrace:
I/DEBUG ( 446): #00 pc 0144336e /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (cat::SecureEqual(void const_, void const_, int)+27)
I/DEBUG ( 446): #1 pc 014456af /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (cat::AuthenticatedEncryption::Decrypt(unsigned char_, unsigned int&)+282)
I/DEBUG ( 446): #2 pc 0143e461 /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (RakNet::ReliabilityLayer::HandleSocketReceiveFromConnectedPlayer(char const_, unsigned int, RakNet::SystemAddress&, DataStructures::ListRakNet::PluginInterface2
&, int, RakNet::RakNetSocket2_, RakNet::RakNetRandom_, unsigned long long, RakNet::BitStream&)+184)
I/DEBUG ( 446): #3 pc 01434237 /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (RakNet::ProcessNetworkPacket(RakNet::SystemAddress, char const_, int, RakNet::RakPeer_, RakNet::RakNetSocket2_, unsigned long long, RakNet::BitStream&)+150)
I/DEBUG ( 446): #4 pc 0143648f /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (RakNet::RakPeer::RunUpdateCycle(RakNet::BitStream&)+98)
I/DEBUG ( 446): #5 pc 0142edb3 /data/app/com.plangtongs.skyheroes-1/lib/arm/libUE4.so (RakNet::UpdateNetworkLoop(void_)+62)
I/DEBUG ( 446): #6 pc 00012f93 /system/lib/libc.so (__pthread_start(void
)+30)
I/DEBUG ( 446): #7 pc 00011057 /system/lib/libc.so (__start_thread+6)

Startup creates more than one thread to handle recv data

In RakPeer.cpp at line 417 - 423

if !defined(native_client) && !defined(WINDOWS_STORE_RT)

for( i = 0; i < socketDescriptorCount; i++ )
{
    if( socketList[i]->IsBerkleySocket() )
        ( (RNS2_Berkley*) socketList[i] )->CreateRecvPollingThread(threadPriority);
}

endif

if the number of bound sockets are greater than 1, mroe than one thread will be created to handle recv data. However, as the document says, raknet only support one-thread-send and one-thread-recv.

Memory Leak Issue !!!

I found memory leak issue everytime I assign a new queue to an old queue by using operator=. After debuging the source codes line by line in raknet, i found there is a bug in the impl of operator= function in line of 303 - 307 in DS_Queue.h file:
template
bool Queue<queue_type>::operator= ( const Queue& original_copy )
{
if ( ( &original_copy ) == this ) return false;
Clear(FILE_AND_LINE);
// Allocate memory for copy
if ( original_copy.Size() == 0 ) ///line 303
{
allocation_size = 0; /
} ///line 307
........
As you see, when original queue has size of 0, raknet just simply updates allocation_size to 0.

template
void Queue<queue_type>::Push( const queue_type& input, const char *file, unsigned int line )
{
if ( allocation_size == 0 )
{
array = RakNet::OP_NEW_ARRAY<queue_type>(16, file, line );
head = 0;
tail = 1;
array[ 0 ] = input;
allocation_size = 16;
return ;
}
......
So, When you then push a new element to this queue, you will get memory leak withput deleting the old array.

An posssible security issue in RakNet connect()

Raknet uses Diffie-Hellman key agreement protocol to do key exchange with a precondition that the long-term server public key is given to clients in some secured way(possibly hard-coded in executive).
PS. the public key i refer to has nothing to do with RSA. Some possible bugs in connect() function makes it very vulnerable to the MITM attacks, the explanations are shown below:

  1. Client keeps secret of its private key c but send its public key C to server in challenge
  2. Server answers the challenge
  3. the client side public key and private key is generated based on the server side public key

in function KeyAgreementInitiator::GenerateChallenge()
// A = client public key,a = client private key
GenerateKey(math, csprng, a);

However math is initialised based on server side public key in function KeyAgreementInitiator::Initialize()
// Unpack the responder's public key
if (!math->LoadVerifyAffineXY(responder_public_key, responder_public_key + KeyBytes, B))
return false;

So, as we see, in the whole sage, the most important variable is server side public key that is pre-given to client. However, Raknet send it to client in the id_connection_request_replay_1 message in clear text !

Someone has done research on this part and we can talk about it. This problem really has been bothering me a long time.

[C#, XP] Application crashes during RakPeerInterface::connect

I ported the project via SWIG to C#. The provided sample runs fine on machines like win7, win10 but crashes on XP as soon as i try to connect the client to a running server (for simplicity both running on the same system!). The sample has not been modified.
It's working if the client cannot find the sever (e.g. due to not firing up the server...). I tried to catch all possible exception which can be catched in C#, but no luck here. Just the typical XP prompt (xyz has encountered a problem and needs to close. Send Error Report, Don't Send)

The port was done via visual studio 2015 with the toolset vs140_xp (otherwise it won't even start the application due to missing XP support).

Can't accept connections in WinRT

Is accepting incoming connections supported in WinRT? I've added both Internet (Client & Server) and Private Networks to the capabilities of my app, and have modified the WinRT sample code accept connections and it never connects.

RakPeerInterface *rakPeer = RakPeerInterface::GetInstance();

RakNet::SocketDescriptor socketDescriptor;
socketDescriptor.port = DEFAULT_SERVER_PORT;
socketDescriptor.socketFamily = AF_INET; // IPV4

// Startup the peer interface with the given socket settings.  Will fail if we already have a peer interface for this host
RakNet::StartupResult startupResult = rakPeer->Startup(MAX_CONNECTIONS, &socketDescriptor, 1);
assert(startupResult == RAKNET_STARTED);

// Calling this function starts the peer listening for incoming connections
rakPeer->SetMaximumIncomingConnections(MAX_CONNECTIONS);


Packet *packet;
do 
{
    packet = rakPeer->Receive();
    Sleep(1);
} 
while (!packet || packet->data[0] != ID_NEW_INCOMING_CONNECTION);

RakAssert(packet->data[0] == ID_NEW_INCOMING_CONNECTION);

in TCPInterface::Connect, there may access array overflow

    int newRemoteClientIndex=-1;
    for (newRemoteClientIndex=0; newRemoteClientIndex < remoteClientsLength; newRemoteClientIndex++)
    {
        remoteClients[newRemoteClientIndex].isActiveMutex.Lock();
        if (remoteClients[newRemoteClientIndex].isActive==false)
        {
            remoteClients[newRemoteClientIndex].SetActive(true);
            remoteClients[newRemoteClientIndex].isActiveMutex.Unlock();
            break;
        }
        remoteClients[newRemoteClientIndex].isActiveMutex.Unlock();
    }
    if (newRemoteClientIndex==-1)
        return UNASSIGNED_SYSTEM_ADDRESS;

if all removeClients is inactive then newRemoteClientIndex==remoteClientsLength. But the code doesn't check for that. And use newRemoteClientIndex as usual.

LibCat security

Need any update for secure connection or depricated?
I see some parts is very old.

!X.Empty() should be used instead of X.Size()

As an example, the DS_WeightedGraph.h implementation of GetShortestPath() and GetSpanningTree() use the following template:

for (col=0; X.Size(); col++)
    path.Insert(X.Pop(), _FILE_AND_LINE_);

It was probably intended to use !X.Empty() instead.

Note, there is a potential performance impact here (unquantified) given this is designed to be a performant algorithm.

Lobby2 Steam on Linux?

Is it possible to make the Lobby2 Steam plugin work under linux? Right now it uses Windows-dependent headers and sockets. What will be necessary to port it to linux?

So many buffer overflows. Can't count.

Did a quick:

grep -rn "sprintf(" .

and got 215 results. Some of these seem pretty serious, too. Like:

https://github.com/OculusVR/RakNet/blob/master/Source/EmailSender.cpp#L153

Which has a good chance of being remote.

I may try to make a pull request later, but this is going to need a big change and I thought you ought to know soon. "Swiss cheese" comes to mind. I'd recommend taking care of the low hanging fruit first, replace all unsafe string functions with their safe counterparts. IE: snprintf() instead of sprintf(). I'd also not recommend running this on any important systems until then.

Other things to grep for which will give you loads of dangerous overflows in the RakNet code:

"strcat", "strcpy", and "memcpy"

Thanks

How to send udp massage from RakNet Client to Boos::asio server

I try to send simple udp massage to simple boost::asio server
for this example i used the boost::asio echo server
and the raknet tutorial .
The server accept the client massage but i have problem translate in boost::asio concepts the use of RakNet.
How do i use the RakNet::BitStream inside the Boost::Asio server
to the raknet client could understand it , or even can i do that ?

In short what i need to change in this simple example so it could work .

    class server
    {
    public:
        server(boost::asio::io_service& io_service, short port)
            : socket_(io_service, udp::endpoint(udp::v4(), port))
        {
            socket_.async_receive_from(
                boost::asio::buffer(data_, max_length), sender_endpoint_,
                boost::bind(&server::handle_receive_from, this,
                boost::asio::placeholders::error,
                boost::asio::placeholders::bytes_transferred));
        }

        void handle_receive_from(const boost::system::error_code& error,
            size_t bytes_recvd)
        {
            if (!error && bytes_recvd > 0)
            {
                socket_.async_send_to(
                    boost::asio::buffer(data_, bytes_recvd), sender_endpoint_,
                    boost::bind(&server::handle_send_to, this,
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred));
            }
            else
            {
                socket_.async_receive_from(
                    boost::asio::buffer(data_, max_length), sender_endpoint_,
                    boost::bind(&server::handle_receive_from, this,
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred));
            }
        }

        void handle_send_to(const boost::system::error_code& /*error*/,
            size_t /*bytes_sent*/)
        {
            socket_.async_receive_from(
                boost::asio::buffer(data_, max_length), sender_endpoint_,
                boost::bind(&server::handle_receive_from, this,
                boost::asio::placeholders::error,
                boost::asio::placeholders::bytes_transferred));
        }

    private:
        udp::socket socket_;
        udp::endpoint sender_endpoint_;
        enum { max_length = 1024 };
        char data_[max_length];
    };

    int main(int argc, char* argv[])
    {
        try
        {


            boost::asio::io_service io_service;

            using namespace std; // For atoi.
            server s(io_service, 9991);
            std::cout << "Starting server on 9991" <<std::endl;
            io_service.run();
        }
        catch (std::exception& e)
        {
            std::cerr << "Exception: " << e.what() << "\n";
        }

        return 0;
    }



And the RakNet Client 

    void RakNetWrapper::Init()
    {
        char str[512];
        strcpy(str, "127.0.0.1");
        RakNet::SocketDescriptor sd;
        RakNet::StartupResult startupResult = peer->Startup(1, &sd, 1);
        RakNet::ConnectionAttemptResult connectionAttemptResult = peer->Connect(str, SERVER_PORT, 0, 0);
        StartReciveLoop();
    }

    void RakNetWrapper::StartReciveLoop()
    {
        while (1)
        {
            for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
            {
                switch (packet->data[0])
                {
                case ID_REMOTE_DISCONNECTION_NOTIFICATION:
                    log("Another client has disconnected.\n");
                    break;
                case ID_REMOTE_CONNECTION_LOST:
                    log("Another client has lost the connection.\n");
                    break;
                case ID_REMOTE_NEW_INCOMING_CONNECTION:
                    log("Another client has connected.\n");
                    break;
                case ID_CONNECTION_REQUEST_ACCEPTED:
                {
                    log("Our connection request has been accepted.\n");

                    // Use a BitStream to write a custom user message
                    // Bitstreams are easier to use than sending casted structures, and handle endian swapping automatically
                    RakNet::BitStream bsOut;
                    bsOut.Write((RakNet::MessageID)ID_GAME_MESSAGE_1);
                    bsOut.Write("Hello world");
                    peer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
                }
                break;
                case ID_NEW_INCOMING_CONNECTION:
                    log("A connection is incoming.\n");
                    break;
                case ID_NO_FREE_INCOMING_CONNECTIONS:
                    log("The server is full.\n");
                    break;
                case ID_DISCONNECTION_NOTIFICATION:
                    {
                        log("We have been disconnected.\n");
                    }
                    break;
                case ID_CONNECTION_LOST:
                    {
                        log("Connection lost.\n");

                    }
                    break;

                case ID_GAME_MESSAGE_1:
                {
                    RakNet::RakString rs;
                    RakNet::BitStream bsIn(packet->data, packet->length, false);
                    bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
                    bsIn.Read(rs);
                    log("%s\n", rs.C_String());
                }
                break;

                default:
                    log("Message with identifier %i has arrived.\n", packet->data[0]);
                    break;
                }
            }
        }
    }

SQL Injection in dependencies

It's all over. Here is just one example:

https://github.com/OculusVR/RakNet/blob/master/DependentExtensions/Autopatcher/AutopatcherMySQLRepository/AutopatcherMySQLRepository.cpp#L170

(which is funny because it buffer overflows AND SQL injects on the same line)

I'm not sure what the current state of those dependencies are, and if there's newer patched versions. Definitely not safe to use in the meantime.

I just did a quick grep for:

grep -rn "SELECT " .

Try doing the same and you'll see loads of hits.

Incorrect/duplicated test in CrossConnectionTest.cpp

CrossConnectionTest.cpp tests connecting two peers at the same time with the internet simulator running.

One of the test conditionals is a duplicate, whilst the accompanying text output indicates the intention was to test something different ("ID_NEW_INCOMING_CONNECTION is false for both instances")

This may have been caused by an errant copy-paste.

int main()
{
    printf("An internal test to test two peers connecting to each other\n");
    printf("at the same time.  This causes bugs so I fix them here\n");
...
else if (gotConnectionRequestAccepted[0]==0 && gotConnectionRequestAccepted[1]==0)
{
    printf("Test failed, ID_CONNECTION_REQUEST_ACCEPTED is false for both instances\n");
}
else if (gotNewIncomingConnection[0]==1 && gotNewIncomingConnection[1]==1)
{
    printf("Test failed, ID_NEW_INCOMING_CONNECTION is true for both instances\n");
}
else if (gotConnectionRequestAccepted[0]==0 && gotConnectionRequestAccepted[1]==0)
{
    // ** ISSUE HERE, DUPLICATES ABOVE CONDITIONAL **
    printf("Test failed, ID_NEW_INCOMING_CONNECTION is false for both instances\n");
}
...

sendto return -1 and errno is EPERM on ios10.2

Before iphone upgrade to ios10.2, all going well, after upgrade can not connect.
sendto returns -1 and errno is 1(EPERM).
When I connect a NAT64 wifi, all going well again, why?
Please help me!

RakString bug with long strings on Linux

Function RakString::Assign doesn't handle long string well on Linux version.

There are 2 calls to function _vsnprintf.
First one is followed by ... #ifndef _WIN32, but second one isn't.

I believe this will cause RakString::Assign to produce wrong result on long strings in Linux version (strings longer than 512 chars).

compilatione error

using this following command in Source directory
g++ -pthread -g -I./../DependentExtensions *.cpp

i have this error:

/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib/crt1.o: nella funzione "_start":
(.text+0x20): riferimento non definito a "main"
collect2: error: ld returned 1 exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.