Skip to content

Commit

Permalink
Add support for IPv6
Browse files Browse the repository at this point in the history
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 f960c3b
Show file tree
Hide file tree
Showing 16 changed files with 475 additions and 209 deletions.
6 changes: 6 additions & 0 deletions minetest.conf.example
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/client.cpp
Expand Up @@ -271,7 +271,8 @@ Client::Client(
IWritableItemDefManager *itemdef,
IWritableNodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event
MtEventManager *event,
bool ipv6
):
m_tsrc(tsrc),
m_shsrc(shsrc),
Expand All @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/client.h
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/connection.cpp
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/connection.h
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/constants.h
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/debug.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/defaultsettings.cpp
Expand Up @@ -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)
Expand Down
31 changes: 23 additions & 8 deletions src/game.cpp
Expand Up @@ -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...");
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/gettext.h
Expand Up @@ -14,6 +14,9 @@

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

Expand Down
2 changes: 1 addition & 1 deletion src/jthread/jmutex.h
Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion src/porting.h
Expand Up @@ -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>

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/server.cpp
Expand Up @@ -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),
Expand Down

0 comments on commit f960c3b

Please sign in to comment.