Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/headers/lnurl_auth_jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ impl LnurlAuthToJwtProvider {
}

async fn fetch_jwt_token(&self) -> Result<JwtToken, VssHeaderProviderError> {
let client = bitreq::Client::new(1);
// Fetch the LNURL.
let lnurl_request = bitreq::get(&self.url)
.with_headers(self.default_headers.clone())
.with_timeout(DEFAULT_TIMEOUT_SECS)
.with_max_body_size(Some(MAX_RESPONSE_BODY_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we consider it that latency critical, we probably want to enable piplining for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitate mostly because the server might only want to issue a single JWT token over the course of say 24 hours for a particular public key. Is that reasonable ? So in the second round, the server might refuse to return the JWT on the second try.

There is also the fact that we could get different k1's back from the first call, so not quite idempotent, but this may be ok here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't matter because we have to wait for the first response before we can send the second request, so either way its serial.

let lnurl_response =
lnurl_request.send_async().await.map_err(VssHeaderProviderError::from)?;
client.send_async(lnurl_request).await.map_err(VssHeaderProviderError::from)?;
let lnurl_str = String::from_utf8(lnurl_response.into_bytes()).map_err(|e| {
VssHeaderProviderError::InvalidData {
error: format!("LNURL response is not valid UTF-8: {}", e),
Expand All @@ -106,7 +107,7 @@ impl LnurlAuthToJwtProvider {
.with_timeout(DEFAULT_TIMEOUT_SECS)
.with_max_body_size(Some(MAX_RESPONSE_BODY_SIZE));
let auth_response =
auth_request.send_async().await.map_err(VssHeaderProviderError::from)?;
client.send_async(auth_request).await.map_err(VssHeaderProviderError::from)?;
let lnurl_auth_response: LnurlAuthResponse =
serde_json::from_slice(&auth_response.into_bytes()).map_err(|e| {
VssHeaderProviderError::InvalidData {
Expand Down