Fix client id not showing in log on failed connections, where possible.

This commit is contained in:
Roger A. Light 2021-10-06 09:54:02 +01:00
parent 3b471c8669
commit be80a3f4d0
8 changed files with 22 additions and 12 deletions

View File

@ -9,6 +9,7 @@ Broker:
- Fix problem parsing config files with Windows line endings. Closes #2297.
- Don't send retained messages when a shared subscription is made.
- Fix log being truncated in Windows.
- Fix client id not showing in log on failed connections, where possible.
Client library:
- Initialise sockpairR/W to invalid in `mosquitto_reinitialise()` to avoid

View File

@ -17,6 +17,11 @@ struct mosquitto *context__init(mosq_sock_t sock)
return NULL;
}
void context__add_to_by_id(struct mosquitto *context)
{
UNUSED(context);
}
int db__message_store(const struct mosquitto *source, struct mosquitto_msg_store *stored, uint32_t message_expiry_interval, dbid_t store_id, enum mosquitto_msg_origin origin)
{
UNUSED(source);

View File

@ -285,7 +285,7 @@ struct mosquitto {
time_t session_expiry_time;
uint32_t session_expiry_interval;
#ifdef WITH_BROKER
bool removed_from_by_id; /* True if removed from by_id hash */
bool in_by_id;
bool is_dropping;
bool is_bridge;
struct mosquitto__bridge *bridge;

View File

@ -92,7 +92,7 @@ int bridge__new(struct mosquitto__bridge *bridge)
return MOSQ_ERR_NOMEM;
}
new_context->id = local_id;
HASH_ADD_KEYPTR(hh_id, db.contexts_by_id, new_context->id, strlen(new_context->id), new_context);
context__add_to_by_id(new_context);
}
new_context->bridge = bridge;
new_context->is_bridge = true;

View File

@ -281,16 +281,25 @@ void context__free_disused(void)
}
void context__add_to_by_id(struct mosquitto *context)
{
if(context->in_by_id == false){
context->in_by_id = true;
HASH_ADD_KEYPTR(hh_id, db.contexts_by_id, context->id, strlen(context->id), context);
}
}
void context__remove_from_by_id(struct mosquitto *context)
{
struct mosquitto *context_found;
if(context->removed_from_by_id == false && context->id){
if(context->in_by_id == true && context->id){
HASH_FIND(hh_id, db.contexts_by_id, context->id, strlen(context->id), context_found);
if(context_found){
HASH_DELETE(hh_id, db.contexts_by_id, context_found);
}
context->removed_from_by_id = true;
context->in_by_id = false;
}
}

View File

@ -253,7 +253,7 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1
connection_check_acl(context, &context->msgs_out.inflight);
connection_check_acl(context, &context->msgs_out.queued);
HASH_ADD_KEYPTR(hh_id, db.contexts_by_id, context->id, strlen(context->id), context);
context__add_to_by_id(context);
#ifdef WITH_PERSISTENCE
if(!context->clean_start){
@ -908,12 +908,6 @@ int handle__connect(struct mosquitto *context)
#endif
{
rc = mosquitto_unpwd_check(context);
if(rc != MOSQ_ERR_SUCCESS){
/* We must have context->id == NULL here so we don't later try and
* remove the client from the by_id hash table */
mosquitto__free(context->id);
context->id = NULL;
}
switch(rc){
case MOSQ_ERR_SUCCESS:
break;

View File

@ -692,6 +692,7 @@ void context__disconnect(struct mosquitto *context);
void context__add_to_disused(struct mosquitto *context);
void context__free_disused(void);
void context__send_will(struct mosquitto *context);
void context__add_to_by_id(struct mosquitto *context);
void context__remove_from_by_id(struct mosquitto *context);
int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint16_t auth_data_out_len);

View File

@ -64,7 +64,7 @@ static struct mosquitto *persist__find_or_add_context(const char *client_id, uin
context->clean_start = false;
HASH_ADD_KEYPTR(hh_id, db.contexts_by_id, context->id, strlen(context->id), context);
context__add_to_by_id(context);
}
if(last_mid){
context->last_mid = last_mid;