From adb285e2d875314355bb055fb208e789bbd87fc6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 4 Sep 2022 07:40:26 +0300 Subject: [PATCH 24/24] Fix ping packet problems - Handle high number of connections correctly - Reduce accuracy of the ping time, and support bigger values instead See osdn #45499 and osdn #45501 Signed-off-by: Marko Lindqvist --- client/packhand.c | 32 ++++++++++++++++++++++++-------- common/networking/packets.def | 10 +++++++--- fc_version | 2 +- server/sernet.c | 13 +++++++++---- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index 4426acd2bb..f2fdcd24ba 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -2790,20 +2790,36 @@ void handle_conn_info(const struct packet_conn_info *pinfo) Handles a conn_ping_info packet from the server. This packet contains ping times for each connection. **************************************************************************/ -void handle_conn_ping_info(int connections, const int *conn_id, - const float *ping_time) +void handle_conn_ping_info(const struct packet_conn_ping_info *packet) { int i; + bool pingfix = has_capability("pingfix", client.conn.capability); + int connections = (pingfix ? packet->connections_16 : packet->connections_8); - for (i = 0; i < connections; i++) { - struct connection *pconn = conn_by_number(conn_id[i]); + if (pingfix) { + for (i = 0; i < connections; i++) { + struct connection *pconn = conn_by_number(packet->conn_id_new[i]); - if (!pconn) { - continue; + if (!pconn) { + continue; + } + + pconn->ping_time = packet->ping_time_6[i]; + + log_debug("conn-id=%d, ping=%fs", pconn->id, pconn->ping_time); } + } else { + for (i = 0; i < connections; i++) { + struct connection *pconn = conn_by_number(packet->conn_id_old[i]); - pconn->ping_time = ping_time[i]; - log_debug("conn-id=%d, ping=%fs", pconn->id, pconn->ping_time); + if (!pconn) { + continue; + } + + pconn->ping_time = packet->ping_time_7[i]; + + log_debug("conn-id=%d, ping=%fs", pconn->id, pconn->ping_time); + } } /* The old_ping_time data is ignored. */ diff --git a/common/networking/packets.def b/common/networking/packets.def index 5600f0b571..c1795e40ab 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -184,6 +184,7 @@ Syntax: # typedefs for numbers type BOOL = bool8(bool) type SFLOAT10x3 = sfloat100(float) +type SFLOAT10x6 = sfloat100000(float) type SFLOAT10x7 = sfloat1000000(float) type SINT8 = sint8(int) type SINT16 = sint16(int) @@ -1228,9 +1229,12 @@ end # Information about the ping times of the connections. PACKET_CONN_PING_INFO = 116; sc, lsend - UINT8 connections; - CONNECTION conn_id[MAX_NUM_CONNECTIONS:connections]; - SFLOAT10x7 ping_time[MAX_NUM_CONNECTIONS:connections]; + UINT8 connections_8; remove-cap(pingfix) + UINT16 connections_16; add-cap(pingfix) + CONNECTION conn_id_old[MAX_NUM_CONNECTIONS:connections_8]; remove-cap(pingfix) + CONNECTION conn_id_new[MAX_NUM_CONNECTIONS:connections_16]; add-cap(pingfix) + SFLOAT10x7 ping_time_7[MAX_NUM_CONNECTIONS:connections_8]; remove-cap(pingfix) + SFLOAT10x6 ping_time_6[MAX_NUM_CONNECTIONS:connections_16]; add-cap(pingfix) end # For compatibility with older versions, this number cannot be changed. diff --git a/fc_version b/fc_version index 590f09d830..400f509557 100755 --- a/fc_version +++ b/fc_version @@ -60,7 +60,7 @@ DEFAULT_FOLLOW_TAG=stable # as long as possible. We want to maintain network compatibility with # the stable branch for as long as possible. NETWORK_CAPSTRING_MANDATORY="+Freeciv-3.0-network" -NETWORK_CAPSTRING_OPTIONAL="year32 plrculture32" +NETWORK_CAPSTRING_OPTIONAL="year32 plrculture32 pingfix" FREECIV_DISTRIBUTOR="" diff --git a/server/sernet.c b/server/sernet.c index 915e6bce91..9c6ac5cd15 100644 --- a/server/sernet.c +++ b/server/sernet.c @@ -1467,12 +1467,17 @@ static void send_ping_times_to_all(void) if (!pconn->used) { continue; } - fc_assert(i < ARRAY_SIZE(packet.conn_id)); - packet.conn_id[i] = pconn->id; - packet.ping_time[i] = pconn->ping_time; + fc_assert(i < ARRAY_SIZE(packet.conn_id_new)); + packet.conn_id_new[i] = pconn->id; + packet.ping_time_6[i] = pconn->ping_time; + if (i < 256) { + packet.conn_id_old[i] = pconn->id; + packet.ping_time_7[i] = pconn->ping_time; /* _7 really is the OLD protocol */ + } i++; } conn_list_iterate_end; - packet.connections = i; + packet.connections_8 = (i < 256) ? i : 255; + packet.connections_16 = i; lsend_packet_conn_ping_info(game.est_connections, &packet); } -- 2.35.1