Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make upnp lease duration configurable #868

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lcruz99
Copy link
Contributor

@lcruz99 lcruz99 commented Oct 11, 2024

Problem

User is not able to set a custom UPnP lease duration.

Solution

This PR adds a UPnP telio feature with lease duration field.

☑️ Definition of Done checklist

  • Commit history is clean (requirements)
  • README.md is updated
  • Functionality is covered by unit or integration tests

@lcruz99 lcruz99 requested a review from a team as a code owner October 11, 2024 15:26
@lcruz99 lcruz99 force-pushed the LLT-5299_upnp_configurable_lease_duration branch 2 times, most recently from 366199d to 0bb3037 Compare October 11, 2024 15:39
@@ -36,7 +36,7 @@ const GET_INTERFACE_TIMEOUT_S: Duration = Duration::from_secs(2);

const EPHEMERAL_PORT_RANGE: std::ops::RangeInclusive<u16> = 49152..=65535;

const DEFAULT_LEASE_DURATION_S: u32 = 600;
const LEASE_RENEWAL_LIMIT_S: u32 = 600;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this const controll, we have what we set as wanted, but i don't entirely get there this comes from.
At what poin we should update lease ?

Copy link
Contributor Author

@lcruz99 lcruz99 Oct 16, 2024

Choose a reason for hiding this comment

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

We have FeaturesUPnP::lease_duration_s which sets the actual lease duration for the UPnP port mappings. This LEASE_RENEWAL_LIMIT_S is the value which when the lease duration falls below it, we should renew the mappings by sending a new mapping request to the UPnP device.

E.g: We set the mappings lease duration to 3600s, when we check the lease duration left - every upnp_interval tick time - and there's less than 600s left for them to expire, we simple renew the lease for another FeaturesUPnP::lease_duration_s which is 3600s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking this better, maybe this const can be correlated with the FeaturesUPnP::lease_duration_s, something like 1/5 of FeaturesUPnP::lease_duration_s

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeh, that was what i was thinking also, maybe min(1/10, 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has to be higher than the tick time (upnp_interval) though, otherwise it will get expired. I'll try to come up with something.

Comment on lines 530 to 532
telio_log_info!("Error validating endpoint: {}", e);

telio_log_info!("Deleting an old Upnp endpoint");
let detete = self.igd_gw.delete_endpoint_routes(
telio_log_info!("Dropping Upnp endpoint");
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. seems to me this should be telio_log_error!
  2. is there a reason not to merge those two logs into one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. It was already telio_log_info and I've questioned myself the same, but when there's an error validating the endpoint I consider not critical enough to be an error regarding the library runtime, and it can be easily recovered from.
  2. I think we can, it will just result in a somewhat long log. But I can merge it, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. in that case this sounds like it should be telio_log_warn!.
  2. imo, lets merge it

)
.await
{
telio_log_info!("Error dropping Upnp endpoint: {}", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it should be an error log, not info.

Copy link
Contributor Author

@lcruz99 lcruz99 Oct 16, 2024

Choose a reason for hiding this comment

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

This error could be simply the mappings that were already dropped by the UPnP device, as the comment above, I don't consider it worth to be logged as a error, as the runtime is not affected and the mappings won't exist anyway.

Let me know if you disagree, this is something I've also questined myself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, in that case it sounds like a telio_log_warn!.

src/device.rs Outdated
@@ -1352,6 +1352,7 @@ impl Runtime {

// Create Upnp Endpoint Provider
let upnp_endpoint_provider = if has_provider(Upnp) {
let direct_features = self.features.direct.clone().unwrap_or_default();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is no need for direct_features since direct variable is already in scope here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, I missed that

@tomaszklak
Copy link
Contributor

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

@lcruz99
Copy link
Contributor Author

lcruz99 commented Oct 16, 2024

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

You're right, the commits prefixed with review: will be squashed before merging the PR. I've been doing that to avoid messing up the git history for the reviewers and segregate what's been changed during the review.

@tomaszklak
Copy link
Contributor

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

You're right, the commits prefixed with review: will be squashed before merging the PR. I've been doing that to avoid messing up the git history for the reviewers and segregate what's been changed during the review.

In that case, when is the good time to review the commit history?

@lcruz99
Copy link
Contributor Author

lcruz99 commented Oct 16, 2024

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

You're right, the commits prefixed with review: will be squashed before merging the PR. I've been doing that to avoid messing up the git history for the reviewers and segregate what's been changed during the review.

In that case, when is the good time to review the commit history?

I'd say after every issue is resolved and +2 acquired. Then commit history is cleaned and approval by the reviewers unlocked.

@tomaszklak
Copy link
Contributor

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

You're right, the commits prefixed with review: will be squashed before merging the PR. I've been doing that to avoid messing up the git history for the reviewers and segregate what's been changed during the review.

In that case, when is the good time to review the commit history?

I'd say after every issue is resolved and +2 acquired. Then commit history is cleaned and approval by the reviewers unlocked.

I don't think we agreed to this way of working - I would like to see a clean git history (in the state you intend to merge it) before I add any points.

@lcruz99
Copy link
Contributor Author

lcruz99 commented Oct 17, 2024

I think that 4bb57eb shouldn't be a separate commit but a part of b5caf1c

You're right, the commits prefixed with review: will be squashed before merging the PR. I've been doing that to avoid messing up the git history for the reviewers and segregate what's been changed during the review.

In that case, when is the good time to review the commit history?

I'd say after every issue is resolved and +2 acquired. Then commit history is cleaned and approval by the reviewers unlocked.

I don't think we agreed to this way of working - I would like to see a clean git history (in the state you intend to merge it) before I add any points.

I understand your POV. I propose once the review is done I would clean git history and then get the eventual reviewer points.

@lcruz99 lcruz99 force-pushed the LLT-5299_upnp_configurable_lease_duration branch 5 times, most recently from 19047e2 to f8e2b04 Compare October 18, 2024 11:09
tomaszklak
tomaszklak previously approved these changes Oct 18, 2024
Copy link
Contributor

@tomaszklak tomaszklak left a comment

Choose a reason for hiding this comment

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

+1

@lcruz99
Copy link
Contributor Author

lcruz99 commented Oct 18, 2024

it looks like the test is flaky, I have to investigate it and probably make some changes

@lcruz99
Copy link
Contributor Author

lcruz99 commented Oct 18, 2024

it looks like the test is flaky, I have to investigate it and probably make some changes

test is fixed, I've had to adjust endpoint time variables on the test itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants