Skip to content

Commit

Permalink
Add AuthenticationFailureWithPreexistingSharedKey and a few log state…
Browse files Browse the repository at this point in the history
…ments (#4568)
  • Loading branch information
octol committed May 3, 2024
1 parent 36e1e73 commit 7bbe153
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/client-libs/gateway-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<C, St> GatewayClient<C, St> {
}

debug_assert!(self.connection.is_available());
log::trace!("Registering gateway");
log::debug!("Registering gateway");

// it's fine to instantiate it here as it's only used once (during authentication or registration)
// and putting it into the GatewayClient struct would be a hassle
Expand Down Expand Up @@ -494,6 +494,7 @@ impl<C, St> GatewayClient<C, St> {
if !self.connection.is_established() {
return Err(GatewayClientError::ConnectionNotEstablished);
}
log::debug!("Authenticating with gateway");

// it's fine to instantiate it here as it's only used once (during authentication or registration)
// and putting it into the GatewayClient struct would be a hassle
Expand Down Expand Up @@ -529,6 +530,7 @@ impl<C, St> GatewayClient<C, St> {
self.authenticated = status;
self.bandwidth_remaining = bandwidth_remaining;
self.negotiated_protocol = protocol_version;
log::debug!("authenticated: {status}, bandwidth remaining: {bandwidth_remaining}");
Ok(())
}
ServerResponse::Error { message } => Err(GatewayClientError::GatewayError(message)),
Expand All @@ -541,10 +543,11 @@ impl<C, St> GatewayClient<C, St> {
&mut self,
) -> Result<Arc<SharedKeys>, GatewayClientError> {
if self.authenticated {
debug!("Already authenticated");
return if let Some(shared_key) = &self.shared_key {
Ok(Arc::clone(shared_key))
} else {
Err(GatewayClientError::AuthenticationFailure)
Err(GatewayClientError::AuthenticationFailureWithPreexistingSharedKey)
};
}

Expand Down
3 changes: 3 additions & 0 deletions common/client-libs/gateway-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub enum GatewayClientError {
#[error("Authentication failure")]
AuthenticationFailure,

#[error("Authentication failure with preexisting shared key")]
AuthenticationFailureWithPreexistingSharedKey,

#[error("Timed out")]
Timeout,

Expand Down

0 comments on commit 7bbe153

Please sign in to comment.