Skip to content
Permalink
Browse files

Add support for IPv6

Two new configuration options are added:
     - "enable_ipv6" to enable/disable the overall use of IPv6
     - "ipv6_server" to enable/disable the use of IPv6 sockets when running
       a server (when "enable_ipv6" is enabled)
  • Loading branch information...
proller committed Jun 23, 2013
1 parent 309c5f3 commit f960c3be313c761fe02f9167dc1fe3fca5dc4ada
Showing with 475 additions and 209 deletions.
  1. +6 −0 minetest.conf.example
  2. +3 −2 src/client.cpp
  3. +2 −1 src/client.h
  4. +5 −2 src/connection.cpp
  5. +2 −2 src/connection.h
  6. +1 −0 src/constants.h
  7. +1 −1 src/debug.h
  8. +4 −0 src/defaultsettings.cpp
  9. +23 −8 src/game.cpp
  10. +3 −0 src/gettext.h
  11. +1 −1 src/jthread/jmutex.h
  12. +4 −1 src/porting.h
  13. +2 −1 src/server.cpp
  14. +327 −160 src/socket.cpp
  15. +43 −12 src/socket.h
  16. +48 −18 src/test.cpp
@@ -367,3 +367,9 @@

# Float islands starts from height, 0 to disable
#mgindev_float_islands = 500

# Enable/disable IPv6
#enable_ipv6 = true
# Enable/disable running an IPv6 server. An IPv6 server may be restricted
# to IPv6 clients, depending on system configuration.
#ipv6_server = false
@@ -271,7 +271,8 @@ Client::Client(
IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event
MtEventManager *event,
bool ipv6
):
m_tsrc(tsrc),
m_shsrc(shsrc),
@@ -287,7 +288,7 @@ Client::Client(
device->getSceneManager(),
tsrc, this, device
),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
m_device(device),
m_server_ser_ver(SER_FMT_VER_INVALID),
m_playeritem(0),
@@ -263,7 +263,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event
MtEventManager *event,
bool ipv6
);

~Client();
@@ -520,10 +520,12 @@ void Peer::reportRTT(float rtt)
Connection
*/

Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout):
Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout,
bool ipv6):
m_protocol_id(protocol_id),
m_max_packet_size(max_packet_size),
m_timeout(timeout),
m_socket(ipv6),
m_peer_id(0),
m_bc_peerhandler(NULL),
m_bc_receive_timeout(0),
@@ -535,10 +537,11 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout):
}

Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout,
PeerHandler *peerhandler):
bool ipv6, PeerHandler *peerhandler):
m_protocol_id(protocol_id),
m_max_packet_size(max_packet_size),
m_timeout(timeout),
m_socket(ipv6),
m_peer_id(0),
m_bc_peerhandler(peerhandler),
m_bc_receive_timeout(0),
@@ -548,8 +548,8 @@ struct ConnectionCommand
class Connection: public SimpleThread
{
public:
Connection(u32 protocol_id, u32 max_packet_size, float timeout);
Connection(u32 protocol_id, u32 max_packet_size, float timeout,
Connection(u32 protocol_id, u32 max_packet_size, float timeout, bool ipv6);
Connection(u32 protocol_id, u32 max_packet_size, float timeout, bool ipv6,
PeerHandler *peerhandler);
~Connection();
void * Thread();
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Causes the socket class to deliberately drop random packets.
// This disables unit testing of socket and connection.
#define INTERNET_SIMULATOR 0
#define INTERNET_SIMULATOR_PACKET_LOSS 10 // 10 = easy, 4 = hard

#define CONNECTION_TIMEOUT 30

@@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#ifdef _MSC_VER
@@ -251,6 +251,10 @@ void set_default_settings(Settings *settings)
settings->setDefault("mgindev_np_float_islands3", "0, 1, (256, 256, 256), 6412, 2, 0.5, 1, 0.5");
settings->setDefault("mgindev_np_biome", "0, 1, (250, 250, 250), 9130, 3, 0.50, 1, 10");
settings->setDefault("mgindev_float_islands", "500");

// IPv6
settings->setDefault("enable_ipv6", "true");
settings->setDefault("ipv6_server", "false");
}

void override_default_settings(Settings *settings, Settings *from)
@@ -1039,12 +1039,6 @@ void the_game(
infostream<<"Creating client"<<std::endl;

MapDrawControl draw_control;

Client client(device, playername.c_str(), password, draw_control,
tsrc, shsrc, itemdef, nodedef, sound, &eventmgr);

// Client acts as our GameDef
IGameDef *gamedef = &client;

{
wchar_t* text = wgettext("Resolving address...");
@@ -1054,18 +1048,39 @@ void the_game(
Address connect_address(0,0,0,0, port);
try{
if(address == "")
{
//connect_address.Resolve("localhost");
connect_address.setAddress(127,0,0,1);
if(g_settings->getBool("enable_ipv6") && g_settings->getBool("ipv6_server"))
{
IPv6AddressBytes addr_bytes;
addr_bytes.bytes[15] = 1;
connect_address.setAddress(&addr_bytes);
}
else
{
connect_address.setAddress(127,0,0,1);
}
}
else
connect_address.Resolve(address.c_str());
}
catch(ResolveError &e)
{
error_message = L"Couldn't resolve address";
error_message = L"Couldn't resolve address: " + narrow_to_wide(e.what());
errorstream<<wide_to_narrow(error_message)<<std::endl;
// Break out of client scope
break;
}

/*
Create client
*/
Client client(device, playername.c_str(), password, draw_control,
tsrc, shsrc, itemdef, nodedef, sound, &eventmgr,
connect_address.isIPv6());

// Client acts as our GameDef
IGameDef *gamedef = &client;

/*
Attempt to connect to the server
@@ -14,6 +14,9 @@

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#endif

@@ -31,7 +31,7 @@

#if (defined(WIN32) || defined(_WIN32_WCE))
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#define _WIN32_WINNT 0x0501
#endif
#ifndef _WIN32_WCE
#include <process.h>
@@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#ifdef _WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>

@@ -153,6 +153,9 @@ bool threadSetPriority(threadid_t tid, int prio);
Overflow can occur at any value higher than 10000000.
*/
#ifdef _WIN32 // Windows
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>

inline u32 getTimeS()
@@ -639,7 +639,8 @@ Server::Server(
m_simple_singleplayer_mode(simple_singleplayer_mode),
m_async_fatal_error(""),
m_env(NULL),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT,
g_settings->getBool("enable_ipv6") && g_settings->getBool("ipv6_server"), this),
m_banmanager(path_world+DIR_DELIM+"ipban.txt"),
m_rollback(NULL),
m_rollback_sink_enabled(true),
Oops, something went wrong.

0 comments on commit f960c3b

Please sign in to comment.
You can’t perform that action at this time.