Updated TODO list
Added IS_HANDSHAKE macro to check if a NetworkMessage is a handshake easier Utility: All From... methods are now ToBytes replaced emplace_back to insert since it was not compiling correcly
This commit is contained in:
		
							
								
								
									
										6
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								TODO
									
									
									
									
									
								
							| @ -1,13 +1,13 @@ | |||||||
| initialization code for other operating systems - currently VoidNet only supports windows | initialization code for other operating systems - currently VoidNet only supports windows | ||||||
| initialization code for tcp client and tcp server for other operating systems | initialization code for tcp client and tcp server for other operating systems - currently windows only | ||||||
| handle SendNetworkMessage errors for windows | handle SendNetworkMessage errors for windows | ||||||
| handle ReceiveDataArray errors for windows | handle ReceiveDataArray errors for windows | ||||||
|  |  | ||||||
| revamped BitConverter class | revamped BitConverter class | ||||||
| new StringConverter class | new StringConverter class | ||||||
|  |  | ||||||
| implement ConfigReader methods |  | ||||||
|  |  | ||||||
| maybe i should implement error codes | maybe i should implement error codes | ||||||
|  |  | ||||||
| plugin system - idk how im going to implement it yet | plugin system - idk how im going to implement it yet | ||||||
|  |  | ||||||
|  | maybe i should use virtual methods for the server and client, maybe... | ||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -38,18 +38,18 @@ | |||||||
|     <ClCompile Include="..\..\src\Handshake.cpp" /> |     <ClCompile Include="..\..\src\Handshake.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\Init.cpp" /> |     <ClCompile Include="..\..\src\Init.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\InitWindows.cpp"> |     <ClCompile Include="..\..\src\InitWindows.cpp"> | ||||||
|       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> |       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="..\..\src\NetworkBuffer.cpp" /> |     <ClCompile Include="..\..\src\NetworkBuffer.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\NetworkMessage.cpp" /> |     <ClCompile Include="..\..\src\NetworkMessage.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\Serializer.cpp" /> |     <ClCompile Include="..\..\src\Serializer.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\TcpClient.cpp" /> |     <ClCompile Include="..\..\src\TcpClient.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\TcpClientWindows.cpp"> |     <ClCompile Include="..\..\src\TcpClientWindows.cpp"> | ||||||
|       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> |       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="..\..\src\TcpServer.cpp" /> |     <ClCompile Include="..\..\src\TcpServer.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\TcpServerWindows.cpp"> |     <ClCompile Include="..\..\src\TcpServerWindows.cpp"> | ||||||
|       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> |       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="..\..\src\Utility.cpp" /> |     <ClCompile Include="..\..\src\Utility.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\VoidNetClient.cpp" /> |     <ClCompile Include="..\..\src\VoidNetClient.cpp" /> | ||||||
|  | |||||||
| @ -243,4 +243,6 @@ enum InternalTags | |||||||
| 	DISCONNECT = 255, | 	DISCONNECT = 255, | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | #define IS_HANDSHAKE(name) name.subject == 1 && (name.tag == DISCONNECT || name.tag == CONNECT || name.tag == ConnectionCode::Accept || name.tag == ConnectionCode::Close || name.tag == ConnectionCode::Reject) | ||||||
|  |  | ||||||
| #endif // DEFS_HPP | #endif // DEFS_HPP | ||||||
| @ -18,28 +18,28 @@ struct Utility | |||||||
|  |  | ||||||
| 	struct BitConverter | 	struct BitConverter | ||||||
| 	{ | 	{ | ||||||
| 		static const std::vector<byte> &FromUint8(uint8 number); | 		static const std::vector<byte> &ToBytes(uint8 number); | ||||||
| 		static uint8 ToUint8(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static uint8 ToUint8(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromUint16(uint16 number); | 		static const std::vector<byte> &ToBytes(uint16 number); | ||||||
| 		static uint16 ToUint16(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static uint16 ToUint16(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromUint32(uint32 number); | 		static const std::vector<byte> &ToBytes(uint32 number); | ||||||
| 		static uint32 ToUint32(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static uint32 ToUint32(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
| 		 | 		 | ||||||
| 		static const std::vector<byte> &FromUint64(uint64 number); | 		static const std::vector<byte> &ToBytes(uint64 number); | ||||||
| 		static uint64 ToUint64(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static uint64 ToUint64(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromInt8(int8 number); | 		static const std::vector<byte> &ToBytes(int8 number); | ||||||
| 		static int8 ToInt8(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static int8 ToInt8(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromInt16(int16 number); | 		static const std::vector<byte> &ToBytes(int16 number); | ||||||
| 		static int16 ToInt16(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static int16 ToInt16(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromInt32(int32 number); | 		static const std::vector<byte> &ToBytes(int32 number); | ||||||
| 		static int32 ToInt32(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static int32 ToInt32(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromInt64(int64 number); | 		static const std::vector<byte> &ToBytes(int64 number); | ||||||
| 		static int64 ToInt64(const std::vector<byte> &bytes, uint16 start_index = 0); | 		static int64 ToInt64(const std::vector<byte> &bytes, uint16 start_index = 0); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @ -56,7 +56,7 @@ struct Utility | |||||||
| 		static const std::string &ToString(int64 value); | 		static const std::string &ToString(int64 value); | ||||||
| 		static const std::string &ToString(const std::vector<byte> &bytes); | 		static const std::string &ToString(const std::vector<byte> &bytes); | ||||||
|  |  | ||||||
| 		static const std::vector<byte> &FromString(const std::string &str); | 		static const std::vector<byte> &ToBytes(const std::string &str); | ||||||
|  |  | ||||||
| 		static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0); | 		static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0); | ||||||
|  |  | ||||||
|  | |||||||
| @ -21,12 +21,13 @@ const std::vector<byte>& Handshake::EncodeHandshake(const Handshake & handshake) | |||||||
| { | { | ||||||
| 	std::vector<byte> handshake_bytes; | 	std::vector<byte> handshake_bytes; | ||||||
|  |  | ||||||
| 	std::vector<byte> id = Utility::BitConverter::FromUint16(handshake.id); | 	std::vector<byte> id = Utility::BitConverter::ToBytes(handshake.id); | ||||||
| 	std::vector<byte> con_mode = Utility::BitConverter::FromUint8(handshake.con_code); | 	std::vector<byte> con_mode = Utility::BitConverter::ToBytes(handshake.con_code); | ||||||
|  | 	std::vector<byte> type = Utility::BitConverter::ToBytes(static_cast<uint8>(1)); | ||||||
|  |  | ||||||
| 	handshake_bytes.emplace_back(Utility::BitConverter::FromUint8(1)); | 	handshake_bytes.insert(handshake_bytes.begin(), type.begin(), type.end()); | ||||||
| 	handshake_bytes.emplace_back(id.begin(), id.end()); | 	handshake_bytes.insert(handshake_bytes.begin(), id.begin(), id.end()); | ||||||
| 	handshake_bytes.emplace_back(con_mode.begin(), con_mode.end()); | 	handshake_bytes.insert(handshake_bytes.begin(), con_mode.begin(), con_mode.end()); | ||||||
|  |  | ||||||
| 	return handshake_bytes; | 	return handshake_bytes; | ||||||
| } | } | ||||||
|  | |||||||
| @ -29,33 +29,36 @@ const NetworkBuffer &NetworkMessage::EncodeMessage(const NetworkMessage &message | |||||||
| 	{ | 	{ | ||||||
| 		NetworkBuffer net_buffer; | 		NetworkBuffer net_buffer; | ||||||
|  |  | ||||||
| 		if (message.subject != 1) | 		if (!IS_HANDSHAKE(message)) | ||||||
| 		{ | 		{ | ||||||
| 			std::vector<byte> sender = Utility::BitConverter::FromUint16(message.sender); | 			std::vector<byte> sender = Utility::BitConverter::ToBytes(message.sender); | ||||||
| 			std::vector<byte> distribution_mode = Utility::BitConverter::FromUint8(message.distribution_mode); | 			std::vector<byte> distribution_mode = Utility::BitConverter::ToBytes(message.distribution_mode); | ||||||
| 			std::vector<byte> destination_id = Utility::BitConverter::FromUint16(message.destination_id); | 			std::vector<byte> destination_id = Utility::BitConverter::ToBytes(message.destination_id); | ||||||
| 			std::vector<byte> tag = Utility::BitConverter::FromUint8(message.tag); | 			std::vector<byte> tag = Utility::BitConverter::ToBytes(message.tag); | ||||||
| 			std::vector<byte> subject = Utility::BitConverter::FromUint16(message.subject); | 			std::vector<byte> subject = Utility::BitConverter::ToBytes(message.subject); | ||||||
| 			std::vector<byte> data; | 			std::vector<byte> data; | ||||||
| 			if (message.data != nullptr) | 			if (message.data != nullptr) | ||||||
| 				data = Serializer::to_bytes(message.data); | 				data = Serializer::to_bytes(message.data); | ||||||
|  | 			std::vector<byte> type = Utility::BitConverter::ToBytes(0); | ||||||
|  |  | ||||||
| 			net_buffer.body.emplace_back(Utility::BitConverter::FromInt8(0)); | 			net_buffer.body.insert(net_buffer.body.begin(), type.begin(), type.end()); | ||||||
| 			net_buffer.body.emplace_back(sender.begin(), sender.end()); | 			net_buffer.body.insert(net_buffer.body.begin(), sender.begin(), sender.end()); | ||||||
| 			net_buffer.body.emplace_back(distribution_mode.begin(), distribution_mode.end()); | 			net_buffer.body.insert(net_buffer.body.begin(), distribution_mode.begin(), distribution_mode.end()); | ||||||
| 			net_buffer.body.emplace_back(destination_id.begin(), destination_id.end()); | 			net_buffer.body.insert(net_buffer.body.begin(), destination_id.begin(), destination_id.end()); | ||||||
| 			net_buffer.body.emplace_back(tag.begin(), tag.end()); | 			net_buffer.body.insert(net_buffer.body.begin(), tag.begin(), tag.end()); | ||||||
| 			net_buffer.body.emplace_back(subject.begin(), subject.end()); | 			net_buffer.body.insert(net_buffer.body.begin(), subject.begin(), subject.end()); | ||||||
| 			if (message.data != nullptr && data.size() > 0) | 			if (message.data != nullptr && data.size() > 0) | ||||||
| 				net_buffer.body.emplace_back(data.begin(), data.end()); | 				net_buffer.body.insert(net_buffer.body.begin(), data.begin(), data.end()); | ||||||
| 			net_buffer.header = Utility::BitConverter::FromInt32(sender.size() + distribution_mode.size() + destination_id.size() + | 			net_buffer.header = Utility::BitConverter::ToBytes(sender.size() + distribution_mode.size() + destination_id.size() + | ||||||
| 				tag.size() + subject.size() + data.size()); | 				tag.size() + subject.size() + data.size()); | ||||||
| 			net_buffer.valid = true; | 			net_buffer.valid = true; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			std::vector<byte> handshake_bytes = Handshake::EncodeHandshake(Handshake::NetworkMessageToHandshake(message)); | 			std::vector<byte> handshake_bytes = Handshake::EncodeHandshake(Handshake::NetworkMessageToHandshake(message)); | ||||||
| 			net_buffer.header = Utility::BitConverter::FromInt32(handshake_bytes.size()); | 			std::vector<byte> type = Utility::BitConverter::ToBytes(static_cast<uint8>(1)); | ||||||
|  | 			handshake_bytes.insert(handshake_bytes.begin(), type.begin(), type.end()); | ||||||
|  | 			net_buffer.header = Utility::BitConverter::ToBytes(handshake_bytes.size()); | ||||||
| 			net_buffer.body = handshake_bytes; | 			net_buffer.body = handshake_bytes; | ||||||
| 		} | 		} | ||||||
| 		return net_buffer; | 		return net_buffer; | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ void TcpClient::receive_data(TcpClient *client) | |||||||
| 		NetworkMessage message(client->ReceiveMessage()); | 		NetworkMessage message(client->ReceiveMessage()); | ||||||
| 		if (message.valid) | 		if (message.valid) | ||||||
| 		{ | 		{ | ||||||
| 			if (message.subject == 1) // its a handshake | 			if (IS_HANDSHAKE(message)) | ||||||
| 			{ | 			{ | ||||||
| 				if (message.tag == CONNECT) // some user has connected - not us, never | 				if (message.tag == CONNECT) // some user has connected - not us, never | ||||||
| 					std::async(std::launch::async, client->OnConnect, message.sender); | 					std::async(std::launch::async, client->OnConnect, message.sender); | ||||||
|  | |||||||
| @ -80,7 +80,7 @@ bool TcpClient::Connect() | |||||||
| 		return false; | 		return false; | ||||||
|  |  | ||||||
| 	NetworkMessage message(receive_data_array()); | 	NetworkMessage message(receive_data_array()); | ||||||
| 	if (message.valid && message.subject == 1) | 	if (IS_HANDSHAKE(message)) | ||||||
| 	{ | 	{ | ||||||
| 		if (message.tag == ConnectionCode::Accept) | 		if (message.tag == ConnectionCode::Accept) | ||||||
| 		{ | 		{ | ||||||
|  | |||||||
| @ -82,7 +82,7 @@ void TcpServer::accept_connections(TcpServer *server) | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		TcpClient client(client_socket); | 		TcpClient client(client_socket); | ||||||
| 		server->AddToClientsList(client); | 		server->add_to_clients_list(client); | ||||||
|  |  | ||||||
| 		std::async(std::launch::async, &process_client_messages, server, client); | 		std::async(std::launch::async, &process_client_messages, server, client); | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ std::vector<std::string> Utility::StringConverter::Split(const std::string & str | |||||||
| 	return splited; | 	return splited; | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> &Utility::BitConverter::FromUint8(uint8 number) | const std::vector<byte> &Utility::BitConverter::ToBytes(uint8 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -42,7 +42,7 @@ uint8 Utility::BitConverter::ToUint8(const std::vector<byte> &bytes, uint16 star | |||||||
| 	return uint8(); | 	return uint8(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> &Utility::BitConverter::FromUint16(uint16 number) | const std::vector<byte> &Utility::BitConverter::ToBytes(uint16 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -52,7 +52,7 @@ uint16 Utility::BitConverter::ToUint16(const std::vector<byte> &bytes, uint16 st | |||||||
| 	return uint16(); | 	return uint16(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromUint32(uint32 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(uint32 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -62,7 +62,7 @@ uint32 Utility::BitConverter::ToUint32(const std::vector<byte> & bytes, uint16 s | |||||||
| 	return uint32(); | 	return uint32(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromUint64(uint64 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(uint64 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -72,7 +72,7 @@ uint64 Utility::BitConverter::ToUint64(const std::vector<byte> & bytes, uint16 s | |||||||
| 	return uint64(); | 	return uint64(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromInt8(int8 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(int8 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -82,7 +82,7 @@ int8 Utility::BitConverter::ToInt8(const std::vector<byte> & bytes, uint16 start | |||||||
| 	return int8(); | 	return int8(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromInt16(int16 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(int16 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -92,7 +92,7 @@ int16 Utility::BitConverter::ToInt16(const std::vector<byte> & bytes, uint16 sta | |||||||
| 	return int16(); | 	return int16(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromInt32(int32 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(int32 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -102,7 +102,7 @@ int32 Utility::BitConverter::ToInt32(const std::vector<byte> & bytes, uint16 sta | |||||||
| 	return int32(); | 	return int32(); | ||||||
| } | } | ||||||
|  |  | ||||||
| const std::vector<byte> & Utility::BitConverter::FromInt64(int64 number) | const std::vector<byte> & Utility::BitConverter::ToBytes(int64 number) | ||||||
| { | { | ||||||
| 	return std::vector<byte>(); | 	return std::vector<byte>(); | ||||||
| } | } | ||||||
| @ -162,6 +162,11 @@ const std::string & Utility::StringConverter::ToString(const std::vector<byte>& | |||||||
| 	return std::string(); | 	return std::string(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | const std::vector<byte>& Utility::StringConverter::ToBytes(const std::string & str) | ||||||
|  | { | ||||||
|  | 	return std::vector<byte>(); | ||||||
|  | } | ||||||
|  |  | ||||||
| const std::string & Utility::StringConverter::ToString(const std::vector<byte> & bytes, uint16 start_index, uint16 lenght) | const std::string & Utility::StringConverter::ToString(const std::vector<byte> & bytes, uint16 start_index, uint16 lenght) | ||||||
| { | { | ||||||
| 	return std::string(); | 	return std::string(); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 xX-TheDoctor-Xx
					xX-TheDoctor-Xx