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

Fix getRegistrationByAdress (use index and handle address conflict) #517

Merged
merged 2 commits into from
Jun 7, 2018

Conversation

sbernard31
Copy link
Contributor

See #464 for more details.

@AlexITC
Copy link
Contributor

AlexITC commented May 31, 2018

Based on the question, what I see is that we are discarding registrations having the same ip address, shouldn't this cause problems with clients behind the same NAT?

@sbernard31
Copy link
Contributor Author

sbernard31 commented May 31, 2018

What do you mean "we are discarding registrations having the same ip address" ?

Registration was not discarded but the index (addr => registration) keeps the most recent registration.
(or at least this is what I tried to achieve)

@AlexITC
Copy link
Contributor

AlexITC commented May 31, 2018

From what I see this doesn't not resolve the actual question, in my opinion, the ideal scenario would be to return a list of registrations instead of a single one.

@sbernard31
Copy link
Contributor Author

Ok, let me resume that, in a leshan server context :

PskStore.getIdentity(InetSocketAddress inetAddress) is used when the server want to initiate a DTLS connection. This should return only 1 identity, this make sense as we want to talk to 1 specific device/client.

In Leshan the way to know the psk identity, is to search in RegistrationStore to find which registration is associated to this socket address.

Theoretical there is only 1 device for 1 address, but with NAT a device D1 could get an address A then go to sleep, then a new device D2 will get this free address A. So in the store 2 devices with the same address A. But in fact there is only 1 device behind the A address :D2. D1 lost this address and we don't know its new address, we will know that next time it will update its registration.

So this makes senses to me to only keep tracks to the device which use the address A lastly.

From what I see this doesn't not resolve the actual question,

I'm not sure to understand what is the question ? :)

the ideal scenario would be to return a list of registrations instead of a single one.

I do not understand what does it bring more, as pskStore must choose one of them to choose 1 identity.

@AlexITC
Copy link
Contributor

AlexITC commented Jun 1, 2018

Sounds reasonable, thanks!

byte[] regid_idx = toRegIdKey(registration.getId());
j.set(regid_idx, registration.getEndpoint().getBytes(UTF_8));
byte[] addr_idx = toRegAddrKey(registration.getSocketAddress());
j.set(addr_idx, registration.getEndpoint().getBytes(UTF_8));

if (old != null) {
Registration oldRegistration = deserializeReg(old);
// remove old secondary index
if (registration.getId() != oldRegistration.getId())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR but this string equality looks buggy...

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 will fix this in a separated commit

@sbernard31 sbernard31 merged commit 4b7a6e2 into master Jun 7, 2018
@sbernard31 sbernard31 deleted the reg_by_addr branch June 7, 2018 15:39
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.

3 participants