Do key generation try before connection create
@@ -79,6 +79,12 @@ _conn_get(void)
{
struct conn *conn;
+ // Generate a new key for each connection
+ unsigned char *aes_key = generate_aes_key();
+ if (aes_key == NULL) {
+ return NULL;
+ }
+
if (!TAILQ_EMPTY(&free_connq)) {
ASSERT(nfree_connq > 0);
@@ -97,6 +103,9 @@ _conn_get(void)
conn->owner = NULL;
conn->conn_pool = NULL;
+ // Save a key generated earlier within the connection
+ memcpy(conn->aes_key, aes_key, AES_KEYLEN);
+
conn->sd = -1;
string_init(&conn->pname);
/* {family, addrlen, addr} are initialized in enqueue handler */
@@ -143,14 +152,6 @@ _conn_get(void)
conn_set_write_consistency(conn, g_write_consistency);
conn->type = CONN_UNSPECIFIED;
- // Generate a new key for each connection
- unsigned char *aes_key = generate_aes_key();
- if (aes_key == NULL) {
- dn_free(conn);
- return NULL;
- }
- memcpy(conn->aes_key, aes_key, AES_KEYLEN);
-
return conn;
}
