← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/ignore-me__net-debug into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/ignore-me__net-debug into lp:widelands.

Commit message:
do not merge

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/ignore-me__net-debug/+merge/369105

Do not review or merge this branch, I am only proposing it for the Windows builds.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ignore-me__net-debug into lp:widelands.
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc	2019-06-14 16:50:41 +0000
+++ src/network/internet_gaming.cc	2019-06-20 16:46:28 +0000
@@ -65,6 +65,7 @@
 
 /// resets all stored variables without the chat messages for a clean new login (not relogin)
 void InternetGaming::reset() {
+	log("InternetGaming::reset\n");
 	net.reset();
 	state_ = OFFLINE;
 	authenticator_ = "";
@@ -102,14 +103,21 @@
 
 void InternetGaming::initialize_connection() {
 	// First of all try to connect to the metaserver
-	log("InternetGaming: Connecting to the metaserver.\n");
+	const time_t now = time(nullptr);
+	log("InternetGaming: Connecting to the metaserver at UTC %s",
+		asctime(gmtime(&now)));
 	NetAddress addr;
+	log("InternetGaming::initialize_connection: Trying to resolve to v6\n");
 	if (NetAddress::resolve_to_v6(&addr, meta_, port_)) {
+	log("InternetGaming::initialize_connection: Trying to connect to v6\n");
 		net = NetClient::connect(addr);
 	}
+	log("InternetGaming::initialize_connection: Trying to resolve to v4\n");
 	if ((!net || !net->is_connected()) && NetAddress::resolve_to_v4(&addr, meta_, port_)) {
+	log("InternetGaming::initialize_connection: Trying to connect to v4\n");
 		net = NetClient::connect(addr);
 	}
+	log("InternetGaming::initialize_connection: Done with trying\n");
 	if (!net || !net->is_connected()) {
 		throw WLWarning(_("Could not establish connection to host"),
 		                _("Widelands could not establish a connection to the given address.\n"
@@ -127,10 +135,12 @@
                            bool registered,
                            const std::string& meta,
                            uint32_t port) {
+	log("InternetGaming::login\n");
 
 	// Reset local state. Only resetting on logout() or error isn't enough since
 	// the game might jump to the main menu from other places, too
 	reset();
+	log("InternetGaming::resetted\n");
 
 	clientname_ = nick;
 	reg_ = registered;
@@ -149,6 +159,7 @@
 }
 
 bool InternetGaming::do_login(bool should_relogin) {
+	log("InternetGaming::do_login\n");
 
 	initialize_connection();
 
@@ -163,6 +174,7 @@
 	s.string(bool2str(reg_));
 	s.string(reg_ ? "" : authenticator_);
 	net->send(s);
+	log("send\n");
 
 	// Now let's see, whether the metaserver is answering
 	uint32_t const secs = time(nullptr);
@@ -172,7 +184,9 @@
 		// Check if we are a step further... if yes handle_packet has taken care about all the
 		// paperwork, so we put our feet up and just return. ;)
 		if (state_ != CONNECTING) {
+	log("Connected!\n");
 			if (state_ == LOBBY) {
+	log("in lobby\n");
 				if (!should_relogin) {
 					format_and_add_chat(
 					   "", "", true, _("Users marked with IRC will possibly not react to messages."));
@@ -319,12 +333,14 @@
 		while (net != nullptr) {
 			// Check if the connection is still open
 			if (!net->is_connected()) {
+	log("InternetGaming::handle_metaserver_communication: not connected\n");
 				handle_failed_read();
 				return;
 			}
 			// Process all available packets
 			std::unique_ptr<RecvPacket> packet = net->try_receive();
 			if (packet) {
+	log("InternetGaming::handle_metaserver_communication: got packet\n");
 				handle_packet(*packet, relogin_on_error);
 			} else {
 				// Nothing more to receive
@@ -337,6 +353,7 @@
 	}
 
 	if (state_ == LOBBY) {
+	// log("InternetGaming::handle_metaserver_communication: in lobby\n");
 		// client is in the lobby and therefore we want realtime information updates
 		if (clientupdateonmetaserver_) {
 			SendPacket s;
@@ -356,6 +373,7 @@
 	}
 
 	if (!waitcmd_.empty()) {
+	log("InternetGaming::handle_metaserver_communication: waiting\n");
 		// Check if timeout is reached
 		time_t now = time(nullptr);
 		if (now > waittimeout_) {
@@ -373,9 +391,11 @@
 	// Check connection to the metaserver
 	// Was a ping received in the last 4 minutes?
 	if (time(nullptr) - lastping_ > 240) {
+	log("InternetGaming::handle_metaserver_communication: ping timeout\n");
 		// Try to relogin
 		set_error();
 		if (relogin_on_error && !relogin()) {
+	log("InternetGaming::handle_metaserver_communication: ping timeout - resetting\n");
 			// Do not try to relogin again automatically.
 			reset();
 			set_error();
@@ -385,16 +405,20 @@
 
 /// Handle one packet received from the metaserver.
 void InternetGaming::handle_packet(RecvPacket& packet, bool relogin_on_error) {
+	log("InternetGaming::handle_packet\n");
 	std::string cmd = packet.string();
 
 	// First check if everything is fine or whether the metaserver broke up with the client.
 	if (cmd == IGPCMD_DISCONNECT) {
+	log("InternetGaming::handle_packet: disconnect\n");
 		std::string reason = packet.string();
 		format_and_add_chat("", "", true, InternetGamingMessages::get_message(reason));
 		if (reason == "CLIENT_TIMEOUT") {
+	log("InternetGaming::handle_packet: disconnect CLIENT_TIMEOUT\n");
 			// Try to relogin
 			set_error();
 			if (relogin_on_error && !relogin()) {
+	log("InternetGaming::handle_packet: reset\n");
 				// Do not try to relogin again automatically.
 				reset();
 				set_error();
@@ -402,6 +426,7 @@
 		}
 		return;
 	} else if (cmd == IGPCMD_PING) {
+	log("InternetGaming::handle_packet: ping\n");
 		// Client received a PING and should immediately PONG as requested
 		SendPacket s;
 		s.string(IGPCMD_PONG);
@@ -413,7 +438,9 @@
 
 	// Are we already online?
 	if (state_ == CONNECTING) {
+	log("InternetGaming::handle_packet: connecting\n");
 		if (cmd == IGPCMD_PWD_CHALLENGE) {
+	log("InternetGaming::handle_packet: pwd challenge\n");
 			const std::string nonce = packet.string();
 			SendPacket s;
 			s.string(IGPCMD_PWD_CHALLENGE);
@@ -422,6 +449,7 @@
 			return;
 
 		} else if (cmd == IGPCMD_LOGIN) {
+	log("InternetGaming::handle_packet: login\n");
 			// Clients request to login was granted
 			format_and_add_chat("", "", true, _("Welcome to the Widelands Metaserver!"));
 			const std::string assigned_name = packet.string();
@@ -453,12 +481,14 @@
 			return;
 
 		} else if (cmd == IGPCMD_PWD_OK) {
+	log("InternetGaming::handle_packet: pwd ok\n");
 			const time_t now = time(nullptr);
 			log("InternetGaming: Password check successful at UTC %s", asctime(gmtime(&now)));
 			state_ = LOBBY;
 			return;
 
 		} else if (cmd == IGPCMD_ERROR) {
+	log("InternetGaming::handle_packet: error\n");
 			std::string errortype = packet.string();
 			if (errortype != IGPCMD_LOGIN && errortype != IGPCMD_PWD_CHALLENGE) {
 				log("InternetGaming: Strange ERROR in connecting state: %s\n", errortype.c_str());
@@ -471,6 +501,7 @@
 			return;
 
 		} else {
+	log("InternetGaming::handle_packet: else\n");
 			logout();
 			set_error();
 			log("InternetGaming: Expected a LOGIN, PWD_CHALLENGE or ERROR packet from server, but "
@@ -667,9 +698,11 @@
 		}
 
 		else if (cmd == IGPCMD_ERROR) {
+	log("InternetGaming::handle_packet: IGPCMD_ERROR\n");
 			// Client received an ERROR message - seems something went wrong
 			std::string subcmd(packet.string());
 			std::string reason(packet.string());
+	log("InternetGaming::handle_packet: IGPCMD_ERROR %s %s\n", subcmd.c_str(), reason.c_str());
 			std::string message;
 
 			if (subcmd == IGPCMD_CHAT) {
@@ -1037,10 +1070,13 @@
  * Check for vaild username characters.
  */
 bool InternetGaming::valid_username(std::string username) {
+	log("InternetGaming::valid_username\n");
 	if (username.empty() ||
 	    username.find_first_not_of("abcdefghijklmnopqrstuvwxyz"
 	                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= username.size()) {
+	log("InternetGaming::valid_username no\n");
 		return false;
 	}
+	log("InternetGaming::valid_username yes\n");
 	return true;
 }

=== modified file 'src/network/internet_gaming_protocol.h'
--- src/network/internet_gaming_protocol.h	2019-06-03 17:26:33 +0000
+++ src/network/internet_gaming_protocol.h	2019-06-20 16:46:28 +0000
@@ -57,9 +57,9 @@
 /// Metaserver connection details
 static const std::string INTERNET_GAMING_METASERVER = "widelands.org";
 // Default port for connecting to the metaserver
-constexpr uint16_t kInternetGamingPort = 7395;
+constexpr uint16_t kInternetGamingPort = 80;
 // Default port for connecting to the relay
-constexpr uint16_t kInternetRelayPort = 7397;
+constexpr uint16_t kInternetRelayPort = 8080;
 // The following ones are only used between metaserver and relay
 // Port used by the metaserver to contact the relay
 // INTERNET_RELAY_RPC_PORT 7398

=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc	2018-03-05 08:11:38 +0000
+++ src/network/netclient.cc	2019-06-20 16:46:28 +0000
@@ -36,7 +36,9 @@
 }
 
 void NetClient::close() {
+   	log("NetClient::close\n");
 	if (!is_connected()) {
+   	log("NetClient::close: is closed\n");
 		return;
 	}
 	boost::system::error_code ec;
@@ -52,13 +54,16 @@
 }
 
 std::unique_ptr<RecvPacket> NetClient::try_receive() {
+   	// log("NetClient::try_receive\n");
 	if (is_connected()) {
+   	// log("NetClient::try_receive: connected\n");
 		// If we are connected, try to receive some data
 
 		uint8_t buffer[kNetworkBufferSize];
 		boost::system::error_code ec;
 		size_t length = socket_.read_some(boost::asio::buffer(buffer, kNetworkBufferSize), ec);
 		if (!ec) {
+   	log("NetClient::try_receive !ec, read %lu\n", length);
 			assert(length > 0);
 			assert(length <= kNetworkBufferSize);
 			// Has read something
@@ -67,9 +72,12 @@
 
 		if (ec && ec != boost::asio::error::would_block) {
 			// Connection closed or some error, close the socket
-			log("[NetClient] Error when trying to receive some data: %s.\n", ec.message().c_str());
+			log("[NetClient] Error when trying to receive some data: %s (%i) %s / %i.\n", ec.message().c_str(), ec.value(), ec.category().name(), ec.default_error_condition().value());
+			log("Got %lu bytes\n", length);
 			close();
 		}
+	} else {
+   	 log("NetClient::try_receive: not connected!\n");
 	}
 	// Try to get one packet from the deserializer
 	std::unique_ptr<RecvPacket> packet(new RecvPacket);
@@ -81,13 +89,16 @@
 }
 
 void NetClient::send(const SendPacket& packet) {
+   	log("NetClient::send\n");
 	if (!is_connected()) {
+   	log("NetClient::send: not connected\n");
 		return;
 	}
 
 	boost::system::error_code ec;
 	size_t written =
 	   boost::asio::write(socket_, boost::asio::buffer(packet.get_data(), packet.get_size()), ec);
+   	log("NetClient::send: wrote %lu of %lu\n", written, packet.get_size());
 
 	if (ec == boost::asio::error::would_block) {
 		throw wexception("[NetClient] Socket connected to relay would block when writing");
@@ -106,6 +117,7 @@
 
 NetClient::NetClient(const NetAddress& host)
    : io_service_(), socket_(io_service_), deserializer_() {
+   	log("NetClient::NetClient %s %u\n", host.ip.to_string().c_str(), host.port);
 
 	assert(host.is_valid());
 	const boost::asio::ip::tcp::endpoint destination(host.ip, host.port);

=== modified file 'src/network/network.cc'
--- src/network/network.cc	2019-06-19 05:42:00 +0000
+++ src/network/network.cc	2019-06-20 16:46:28 +0000
@@ -221,27 +221,33 @@
 }
 
 void Deserializer::read_data(const uint8_t* data, const int32_t len) {
-
+log("Deserializer::read_data %u\n", len);
 	queue_.insert(queue_.end(), &data[0], &data[len]);
 }
 
 bool Deserializer::write_packet(RecvPacket* packet) {
+// log("Deserializer::write_packet\n");
 	// No data at all
-	if (queue_.size() < 2)
+	if (queue_.size() < 2) {
+// log("Deserializer::write_packet: not enough for header\n");
 		return false;
+	}
 
 	uint16_t const size = queue_[0] << 8 | queue_[1];
 	assert(size >= 2);
 
 	// Not enough data for a complete packet
-	if (queue_.size() < static_cast<size_t>(size))
+	if (queue_.size() < static_cast<size_t>(size)) {
+// log("Deserializer::write_packet: not enough for packet\n");
 		return false;
+	}
 
 	packet->buffer.clear();
 	packet->buffer.insert(packet->buffer.end(), queue_.begin() + 2, queue_.begin() + size);
 	packet->index_ = 0;
 
 	queue_.erase(queue_.begin(), queue_.begin() + size);
+log("Deserializer::write_packet: wrote packet\n");
 	return true;
 }