diff src/director/director-connection.c @ 16621:5ef62caea61b

director: Update existing users' timestamps during handshake.
author Timo Sirainen <tss@iki.fi>
date Mon, 29 Jul 2013 22:49:17 +0300
parents 9b8b5ce6ecb0
children a6736e42301e
line wrap: on
line diff
--- a/src/director/director-connection.c	Mon Jul 29 22:19:03 2013 +0300
+++ b/src/director/director-connection.c	Mon Jul 29 22:49:17 2013 +0300
@@ -119,6 +119,7 @@
 	unsigned int synced:1;
 	unsigned int wrong_host:1;
 	unsigned int verifying_left:1;
+	unsigned int users_unsorted:1;
 };
 
 static void director_connection_disconnected(struct director_connection **conn);
@@ -578,6 +579,10 @@
 
 	(void)director_user_refresh(conn, username_hash, host,
 				    timestamp, weak, &user);
+	if (user->timestamp < timestamp) {
+		conn->users_unsorted = TRUE;
+		user->timestamp = timestamp;
+	}
 	return TRUE;
 }
 
@@ -975,6 +980,12 @@
 	unsigned int handshake_secs = time(NULL) - conn->created;
 	string_t *str;
 
+	if (conn->users_unsorted && conn->user_iter == NULL) {
+		/* we sent our user list before receiving remote's */
+		conn->users_unsorted = FALSE;
+		user_directory_sort(conn->dir->users);
+	}
+
 	if (handshake_secs >= DIRECTOR_HANDSHAKE_WARN_SECS || director_debug) {
 		str = t_str_new(128);
 		str_printfa(str, "director(%s): Handshake took %u secs, "
@@ -1437,6 +1448,12 @@
 	user_directory_iter_deinit(&conn->user_iter);
 	director_connection_send(conn, "DONE\n");
 
+	if (conn->users_unsorted && conn->handshake_received) {
+		/* we received remote's list of users before sending ours */
+		conn->users_unsorted = FALSE;
+		user_directory_sort(conn->dir->users);
+	}
+
 	ret = o_stream_flush(conn->output);
 	timeout_reset(conn->to_ping);
 	return ret;