Re: [Freeciv-Dev] (PR#39492) Client not receiving/accepting data at end of turn

2007-08-05 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39492 >

On 06/08/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  This patch adds new packets PACKET_FREEZE_CLIENT and
> PACKET_THAW_CLIENT. These are used instead of PACKET_FREEZE_HINT and
> PACKET_THAW_HINT when we want client reports and agents to freeze
> instead of buffering network traffic.

 Untested S2_1 version.

 Bug is present also in S2_0. But since S2_0 has no alternating
movement mode, bug has less severe consequences there.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-08-01 19:21:39.0 +0300
+++ freeciv/client/packhand.c	2007-08-06 02:29:40.0 +0300
@@ -2806,11 +2806,19 @@
 }
 
 /**
-...
+  We have received PACKET_FREEZE_HINT. It is packet internal to network code
 **/
 void handle_freeze_hint(void)
 {
   freelog(LOG_DEBUG, "handle_freeze_hint");
+}
+
+/**
+  We have received PACKET_FREEZE_CLIENT.
+**/
+void handle_freeze_client(void)
+{
+  freelog(LOG_DEBUG, "handle_freeze_client");
 
   reports_freeze();
 
@@ -2818,11 +2826,19 @@
 }
 
 /**
-...
+  We have received PACKET_THAW_HINT. It is packet internal to network code
 **/
 void handle_thaw_hint(void)
 {
   freelog(LOG_DEBUG, "handle_thaw_hint");
+}
+
+/**
+  We have received PACKET_THAW_CLIENT
+**/
+void handle_thaw_client(void)
+{
+  freelog(LOG_DEBUG, "handle_thaw_client");
 
   reports_thaw();
 
diff -Nurd -X.diff_ignore freeciv/common/packets.c freeciv/common/packets.c
--- freeciv/common/packets.c	2007-08-01 19:21:30.0 +0300
+++ freeciv/common/packets.c	2007-08-06 02:29:40.0 +0300
@@ -119,6 +119,12 @@
   compression_level_initialized = TRUE;
 }
 
+/* TODO: PACKET_FREEZE_HINT and PACKET_THAW_HINT are meaningful
+ * only internally. They should not be sent to connection at all.
+ * Freezing could also be handled via separate functions, and
+ * not by special packets.
+ * Only problem is backward compatibility, so this cannot be
+ * changed in stable branch. */
 if (packet_type == PACKET_PROCESSING_STARTED
 	|| packet_type == PACKET_FREEZE_HINT) {
   if (pc->compression.frozen_level == 0) {
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-19 09:57:33.0 +0200
+++ freeciv/common/packets.def	2007-08-06 02:29:40.0 +0300
@@ -998,6 +998,14 @@
   TURN turn;
 end
 
+# Freeze reports and agents
+PACKET_FREEZE_CLIENT=135;sc,lsend
+end
+
+# Thaw reports and agents
+PACKET_THAW_CLIENT=136;sc,lsend
+end
+
 /** Spaceship packets **/
 
 PACKET_SPACESHIP_LAUNCH=93;cs
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-08-01 19:18:41.0 +0300
+++ freeciv/server/srv_main.c	2007-08-06 02:42:12.0 +0300
@@ -114,6 +114,8 @@
 static void announce_player(struct player *pplayer);
 static void srv_loop(void);
 
+static void freeze_clients(void);
+static void thaw_clients(void);
 
 /* this is used in strange places, and is 'extern'd where
needed (hence, it is not 'extern'd in srv_main.h) */
@@ -1625,6 +1627,30 @@
 }
 
 /**
+  Send PACKET_FREEZE_CLIENT to all clients capable of handling it.
+**/
+static void freeze_clients(void)
+{
+  conn_list_iterate(game.est_connections, pconn) {
+if (has_capability("ReportFreezeFix", pconn->capability)) {
+  send_packet_freeze_client(pconn);
+}
+  } conn_list_iterate_end;
+}
+
+/**
+  Send PACKET_THAW_CLIENT to all clients capable of handling it.
+**/
+static void thaw_clients(void)
+{
+  conn_list_iterate(game.est_connections, pconn) {
+if (has_capability("ReportFreezeFix", pconn->capability)) {
+  send_packet_thaw_client(pconn);
+}
+  } conn_list_iterate_end;
+}
+
+/**
 Play the game! Returns when server_state == GAME_OVER_STATE.
 **/
 static void main_loop(void)
@@ -1641,10 +1667,10 @@
   /* 
* This will freeze the rep

Re: [Freeciv-Dev] (PR#39492) Client not receiving/accepting data at end of turn

2007-08-05 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39492 >

On 06/08/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  It turned out that PACKET_FREEZE_HINT / PACKET_THAW_HINT pair is used
> for two different purposes (and this doesn't work, of course).
>  When delta network code notices PACKET_FREEZE_HINT, it will not send
> anything until it notices PACKET_THAW_HINT. This includes
> PACKET_FREEZE_HINT itself.
>  Client uses PACKET_FREEZE_HINT / PACKET_THAW_HINT to freeze reports
> and such. Clearly at least some of the server side code is written for
> this use, and not to block all network traffic.

 For S2_1 we need backwards compatible solution. For trunk we have
better alternatives in the future. However, now I start by writing
that S2_1 style solution. Attached patch is for trunk. Actual S2_1
version needs some additional capability checks.
 This patch adds new packets PACKET_FREEZE_CLIENT and
PACKET_THAW_CLIENT. These are used instead of PACKET_FREEZE_HINT and
PACKET_THAW_HINT when we want client reports and agents to freeze
instead of buffering network traffic.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-08-05 16:40:59.0 +0300
+++ freeciv/client/packhand.c	2007-08-06 01:58:41.0 +0300
@@ -2902,11 +2902,19 @@
 }
 
 /**
-...
+  We have received PACKET_FREEZE_HINT. It is packet internal to network code
 **/
 void handle_freeze_hint(void)
 {
   freelog(LOG_DEBUG, "handle_freeze_hint");
+}
+
+/**
+  We have received PACKET_FREEZE_CLIENT.
+**/
+void handle_freeze_client(void)
+{
+  freelog(LOG_DEBUG, "handle_freeze_client");
 
   reports_freeze();
 
@@ -2914,11 +2922,19 @@
 }
 
 /**
-...
+  We have received PACKET_THAW_HINT. It is packet internal to network code
 **/
 void handle_thaw_hint(void)
 {
   freelog(LOG_DEBUG, "handle_thaw_hint");
+}
+
+/**
+  We have received PACKET_THAW_CLIENT
+**/
+void handle_thaw_client(void)
+{
+  freelog(LOG_DEBUG, "handle_thaw_client");
 
   reports_thaw();
 
diff -Nurd -X.diff_ignore freeciv/common/packets.c freeciv/common/packets.c
--- freeciv/common/packets.c	2007-08-04 18:38:32.0 +0300
+++ freeciv/common/packets.c	2007-08-06 02:06:43.0 +0300
@@ -119,6 +119,12 @@
   compression_level_initialized = TRUE;
 }
 
+/* TODO: PACKET_FREEZE_HINT and PACKET_THAW_HINT are meaningful
+ * only internally. They should not be sent to connection at all.
+ * Freezing could also be handled via separate functions, and
+ * not by special packets.
+ * Only problem is backward compatibility, so this cannot be
+ * changed in stable branch. */
 if (packet_type == PACKET_PROCESSING_STARTED
 	|| packet_type == PACKET_FREEZE_HINT) {
   if (pc->compression.frozen_level == 0) {
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-08-04 18:38:32.0 +0300
+++ freeciv/common/packets.def	2007-08-06 01:54:37.0 +0300
@@ -1013,6 +1013,14 @@
   TURN turn;
 end
 
+# Freeze reports and agents
+PACKET_FREEZE_CLIENT=135;sc,lsend
+end
+
+# Thaw reports and agents
+PACKET_THAW_CLIENT=136;sc,lsend
+end
+
 /** Spaceship packets **/
 
 PACKET_SPACESHIP_LAUNCH=93;cs
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-08-04 18:36:24.0 +0300
+++ freeciv/server/srv_main.c	2007-08-06 01:54:06.0 +0300
@@ -1682,10 +1682,10 @@
   /* 
* This will freeze the reports and agents at the client.
* 
-   * Do this before the body so that the PACKET_THAW_HINT packet is
+   * Do this before the body so that the PACKET_THAW_CLIENT packet is
* balanced. 
*/
-  lsend_packet_freeze_hint(game.est_connections);
+  lsend_packet_freeze_client(game.est_connections);
 
   assert(server_state == RUN_GAME_STATE);
   while (server_state == RUN_GAME_STATE) {
@@ -1707,7 +1707,7 @@
   /* 
* This will thaw the reports and agents at the client.
*/
-  lsend_packet_thaw_hint(game.est_connections);
+  lsend_packet_thaw_client(game.est_connections);
 
   /* Before sniff (human player activites), report time to now: */
   freelog(LOG_VERBOSE, "End/start-turn server/ai activities: %g seconds",
@@ -1742,7 +1742,7 @@
   /* 
* This will freeze the reports and agents at the client.
*/
-  

Re: [Freeciv-Dev] (PR#39492) Client not receiving/accepting data at end of turn

2007-08-05 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39492 >

On 06/08/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  Bug is present also in S2_0. But since S2_0 has no alternating
> movement mode, bug has less severe consequences there.

 Still, backporting was simple.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-05 19:16:15.0 +0200
+++ freeciv/client/packhand.c	2007-08-06 02:57:13.0 +0300
@@ -2894,11 +2894,19 @@
 }
 
 /**
-...
+  We have received PACKET_FREEZE_HINT. It is packet internal to network code
 **/
 void handle_freeze_hint(void)
 {
   freelog(LOG_DEBUG, "handle_freeze_hint");
+}
+
+/**
+  We have received PACKET_FREEZE_CLIENT.
+**/
+void handle_freeze_client(void)
+{
+  freelog(LOG_DEBUG, "handle_freeze_client");
 
   reports_freeze();
 
@@ -2906,11 +2914,19 @@
 }
 
 /**
-...
+  We have received PACKET_THAW_HINT. It is packet internal to network code
 **/
 void handle_thaw_hint(void)
 {
   freelog(LOG_DEBUG, "handle_thaw_hint");
+}
+
+/**
+  We have received PACKET_THAW_CLIENT
+**/
+void handle_thaw_client(void)
+{
+  freelog(LOG_DEBUG, "handle_thaw_client");
 
   reports_thaw();
 
diff -Nurd -X.diff_ignore freeciv/common/capstr.c freeciv/common/capstr.c
--- freeciv/common/capstr.c	2007-03-05 19:15:59.0 +0200
+++ freeciv/common/capstr.c	2007-08-06 02:58:14.0 +0300
@@ -80,6 +80,9 @@
  *
  * "username_info" means that the username is sent in the player_info packet
  *
+ * "ReportFreezeFix" allows clients to correctly freeze reports and agents
+ *   over turn change.
+ *
  *   - No new manditory capabilities can be added to the release branch; doing
  * so would break network capability of supposedly "compatible" releases.
  *
@@ -87,7 +90,7 @@
  * as long as possible.  We want to maintain network compatibility with
  * the stable branch for as long as possible.
  */
-#define CAPABILITY "+2.0 conn_ping_info username_info new_hack"
+#define CAPABILITY "+2.0 conn_ping_info username_info new_hack ReportFreezeFix"
 
 void init_our_capability(void)
 {
diff -Nurd -X.diff_ignore freeciv/common/packets.c freeciv/common/packets.c
--- freeciv/common/packets.c	2007-08-04 04:27:37.0 +0300
+++ freeciv/common/packets.c	2007-08-06 02:57:13.0 +0300
@@ -133,6 +133,12 @@
   compression_level_initialized = TRUE;
 }
 
+/* TODO: PACKET_FREEZE_HINT and PACKET_THAW_HINT are meaningful
+ * only internally. They should not be sent to connection at all.
+ * Freezing could also be handled via separate functions, and
+ * not by special packets.
+ * Only problem is backward compatibility, so this cannot be
+ * changed in stable branch. */
 if (packet_type == PACKET_PROCESSING_STARTED
 	|| packet_type == PACKET_FREEZE_HINT) {
   if (pc->compression.frozen_level == 0) {
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-05 19:15:59.0 +0200
+++ freeciv/common/packets.def	2007-08-06 02:57:13.0 +0300
@@ -884,6 +884,14 @@
   TURN turn;
 end
 
+# Freeze reports and agents
+PACKET_FREEZE_CLIENT=135;sc,lsend
+end
+
+# Thaw reports and agents
+PACKET_THAW_CLIENT=136;sc,lsend
+end
+
 /** Spaceship packets **/
 
 PACKET_SPACESHIP_LAUNCH=93;cs
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-08-04 04:27:24.0 +0300
+++ freeciv/server/srv_main.c	2007-08-06 03:00:59.0 +0300
@@ -119,6 +119,8 @@
 static void send_select_nation(struct player *pplayer);
 static void srv_loop(void);
 
+static void freeze_clients(void);
+static void thaw_clients(void);
 
 /* this is used in strange places, and is 'extern'd where
needed (hence, it is not 'extern'd in srv_main.h) */
@@ -1506,6 +1508,30 @@
 }
 
 /**
+  Send PACKET_FREEZE_CLIENT to all clients capable of handling it.
+**/
+static void freeze_clients(void)
+{
+  conn_list_iterate(game.game_connections, pconn) {
+if (has_capability("ReportFreezeFix", pconn->capability)) {
+  send_packet_freeze_client(pconn);
+}
+  } conn_list_iterate_end;
+}
+
+/

Re: [Freeciv-Dev] (PR#39492) Client not receiving/accepting data at end of turn

2007-08-05 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39492 >

On 05/08/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  I noticed that client does not handle end_phase packet (and other
> late turn packets) until server has sent several new turn related
> packets. Even if this relates to some buffer usage, not receiving some
> of these packets in timely manner is certainly bug.
>  I'm not 100% sure that server sends the packets in time.

 Server is not sending packets.

 It turned out that PACKET_FREEZE_HINT / PACKET_THAW_HINT pair is used
for two different purposes (and this doesn't work, of course).
 When delta network code notices PACKET_FREEZE_HINT, it will not send
anything until it notices PACKET_THAW_HINT. This includes
PACKET_FREEZE_HINT itself.
 Client uses PACKET_FREEZE_HINT / PACKET_THAW_HINT to freeze reports
and such. Clearly at least some of the server side code is written for
this use, and not to block all network traffic.


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#39492) Client not receiving/accepting data at end of turn

2007-08-05 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=39492 >

 I noticed that client does not handle end_phase packet (and other
late turn packets) until server has sent several new turn related
packets. Even if this relates to some buffer usage, not receiving some
of these packets in timely manner is certainly bug.
 I'm not 100% sure that server sends the packets in time. Anyway,
flush_packets() does not help. In the clients end I know that
input_from_server() is not called.
 Same thing with both gtk and sdl clients.

 As a side note I found out that gtk_input_add_full() and friends  are
nowadays considered deprecated.

 I made server to sleep 10 secs after each turn.
Following log comes from client get_packet_from_connection().

1: Got PACKET_GAME_STATE
1: Got PACKET_FREEZE_HINT
1: Got PACKET_GAME_INFO
1: Got PACKET_PLAYER_INFO
1: Got PACKET_START_PHASE
1: Got PACKET_UNIT_INFO
1: last message repeated 2 times
1: last message repeated 2 times (total 4 repeats)
1: Got PACKET_PLAYER_INFO
1: Got PACKET_GAME_INFO
1: Got PACKET_THAW_HINT
1: Got PACKET_PROCESSING_STARTED
1: Got PACKET_PLAYER_INFO
1: Got PACKET_PROCESSING_FINISHED

* Output stops until server wakes up *

1: Got PACKET_FREEZE_HINT
1: Got PACKET_END_PHASE
1: Got PACKET_UNIT_INFO
1: last message repeated 2 times
1: last message repeated 2 times (total 4 repeats)
1: Got PACKET_PLAYER_INFO
1: Got PACKET_GAME_INFO
1: Got PACKET_NEW_YEAR
1: Got PACKET_CHAT_MSG

* Last packet server sent before sleep was above chat_msg (year) *

1: Got PACKET_GAME_INFO
1: Got PACKET_PLAYER_INFO
1: Got PACKET_START_PHASE
1: Got PACKET_UNIT_INFO
1: last message repeated 2 times
1: last message repeated 2 times (total 4 repeats)
1: Got PACKET_PLAYER_INFO
1: Got PACKET_GAME_INFO
1: Got PACKET_THAW_HINT


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev