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

Add endpoint identifier. #322

Closed
wants to merge 2 commits into from
Closed

Add endpoint identifier. #322

wants to merge 2 commits into from

Conversation

sbernard31
Copy link
Contributor

Here is a try to define an identifier for foreign endpoint.
The PR was largely inspired by this long discussion.

This is a work in progress and should not be merged now.
This first step introduces the concept of endpoint identifier and uses it to identify observation.

Next step : Adding Principal to CorrelationContext to be able to define PrincipalEndpointIdentifier to be able to test that in Leshan.

While this first step, I had the feeling that maybe CorrelationContext could be not necessary at CoAP side anymore (only at Connector side). This is a track I would explore. This could simplify the code and also solve some questions like #311.

Another point will be to change TokenProvider (replace reserve/release by random generation) to solve issue raised by Achim in #173.

Even, if this is a work in progress, I strongly advice to try to review this PR each time I add new commits. This is the only way to make this review digestible.

@boaks
Copy link
Contributor

boaks commented Jun 15, 2017

To be frank:
Though the discussion about RFC7252, section 9.1.2 has started again, I would not change the API too much until that discussion seems to get a direction "with future".

So in my view, providing the "intended credentials or parts of the credential as identity" ahead when sending a Message, should overcome the callbacks with that information at all. The calback are only required, if you bind the matching to the "created session".
Therefore I would not add the callbacks for the "destination endpoint". To use these credentials as identity, these credential could not be reused (e.g. groups of devices with same credentials), but until someone came up with that, I would not care too much about that.

For notifies received from changed addresses, the credential are also available on receive and could be used to find the proper exchange (and adjust the ip-address for future communication to that device). Again, this requires unique credentials for all devices.

@boaks
Copy link
Contributor

boaks commented Jun 15, 2017

Not to change the API to much, my intention was to put that "identity" into the correlation context and add a optional correlation context also for sending a request.

@sbernard31
Copy link
Contributor Author

I would not change the API too much until that discussion seems to get a direction "with future".

I'm not so confident. I don't think a final solution will be proposed soon :/

The calback are only required, if you bind the matching to the "created session".

Callback is necessary for use case where peer don't use authentication, or where the identifier chosen could not be know by the user before (e.g. session ID)

Therefore I would not add the callbacks for the "destination endpoint"

At short term, I need it for backward compatibility. For reason exposed above, I'm not sure we will be able to remove it. But If we can I agree to remove it. (Less code we have better, it is)

To use these credentials as identity, these credential could not be reused (e.g. groups of devices with same credentials),

That's why having a EndpoinIdentifierFactory is a good way to let users choose what they want to use as "identifier"

Not to change the API to much, my intention was to put that "identity" into the correlation context and add a optional correlation context also for sending a request.

I rather prefer to remove the CorrelationContext to CoapStack and just let CorrelationContext at element-connector level.

Unless you have strong opinion against my first step, I will continue in that way more in a POC spirit. We have this "identifier" issue for a long time ago and I would like to move forward. I'm sure I will face issue I don't think about for now.

@boaks
Copy link
Contributor

boaks commented Jun 15, 2017

I'm not so confident. I don't think a final solution will be proposed soon :/

I agree, that it will not be proposed soon.

Callback is necessary for use case where peer don't use authentication, or where the identifier chosen could not be know by the user before (e.g. session ID)

That's exactly the NONE use case for me. But if you want to solve that, try it.
I just don't understand, why additional values in the correlation context will not do it.

@sbernard31
Copy link
Contributor Author

I just don't understand, why additional values in the correlation context will not do it.

You mean instead of using endpoint identifier ?

@boaks
Copy link
Contributor

boaks commented Jun 16, 2017

Yes.
Add the "stringified credential identity" into it and add a optional correlation context to the send(request).

@sbernard31
Copy link
Contributor Author

And we could use a partial/incomplete correlation context on send() ?
Is this context will be used as identifier for observe ? (correlationContext+token)

@boaks
Copy link
Contributor

boaks commented Jun 16, 2017

And we could use a partial/incomplete correlation context on send() ?

Therefore the exchangeable correlation context matcher was introduced. My idea was to make a matcher, which uses the identity.

Is this context will be used as identifier for observe ? (correlationContext+token)

My idea was to use the "identity" to adjust the "address".

@sbernard31
Copy link
Contributor Author

My idea was to use the "identity" to adjust the "address".

That's mean you identify observation by (address+token) ?

@boaks
Copy link
Contributor

boaks commented Jun 16, 2017

The UdpMatcher.receiveResponse() currently uses address + token to lookup for the exchange.

So my idea (not detailed right now) was, that a correlation context may also be used for adjust addresses before this lookup.

@sbernard31
Copy link
Contributor Author

sbernard31 commented Jun 16, 2017

So you should have a kind of index {identity => keys (address+token) }?
Then update keys with the new address. Hopping that news address was not already used.
Does it simpler to just use identity+token as key instead ?

@boaks
Copy link
Contributor

boaks commented Jun 19, 2017

My basic idea is to add a "identifier" (say the psk identity) to the correlation context and pass it in with the request. The connector the decided, if the "identifier" matches using the correlation context matcher. On receiving a message, the connector adds the identity to the correlation context.
The Exchange-Matcher tries to match the incoming message as it does now (so normal request/response mapping will not work with address changes). If no exchange is found, but the message is identified as notify, the ObservationStore is considered. To possibly used the identity there (and to solve issue #173), the ObservationStore API must be extended. Though its no detailed design, sure there may occur some follow-up issues. But for now this seems to me to be the smallest change with the required effect. It depends then on the ObservationStore implementation, how to match, if no identity is used. If someone would like to us the token only approach, it would be his decision.

@sbernard31 sbernard31 mentioned this pull request Jul 5, 2017
@@ -158,7 +163,8 @@ protected final Exchange matchNotifyResponse(final Response response, final Corr
final Exchange.KeyToken idByToken = Exchange.KeyToken.fromInboundMessage(response);
Exchange exchange = null;

final Observation obs = observationStore.get(response.getToken());
final EndpointIdentifier sourceEndpoint = response.getSourceEndpoint();
Copy link
Contributor

Choose a reason for hiding this comment

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

But, where is that "reponse source endpoint" set during receiving a response?
That's the core of my question, on what "protocol artifact" your are going to build the identity.

Copy link
Contributor Author

@sbernard31 sbernard31 Jul 6, 2017

Choose a reason for hiding this comment

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

This is set in coapEndpoint.

And the IdentifierFactory is responsible to define what should be used as Identifier.

(For Leshan I want to use Principal)

Copy link
Contributor Author

@sbernard31 sbernard31 Jul 6, 2017

Choose a reason for hiding this comment

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

The IdentifierFactory is responsible to translate Identifier in context and context in Identifier.
(translation is centralized in this class)

I have in mind that context could be a connector concept and Identifier a CoAP stack one.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK.

So the main difference seems to be, that I would just pass the CorrelationContext into the ObserveStore, and you would prefer to have a "IdentifierFactory" to convert that CorrelationContext ahead into a EndpointIdentifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep.


public void onDestinationEndpointDefined(EndpointIdentifier destination) {
LOG.log(Level.FINER, "registering observe request {0}", request);
observationStore.add(destination, new Observation(request, exchange.getCorrelationContext()));
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 delay the add until onDestinationEndpointDefined, I'm not sure if we require the remove in failed()

Copy link
Contributor Author

@sbernard31 sbernard31 Jul 7, 2017

Choose a reason for hiding this comment

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

I'm not sure. The destination endpoint is defined just after an handshake success, but the APPLICATION _DATA sending can fail. In that case we want to remove observation from store.

@sbernard31
Copy link
Contributor Author

This will never be merged.
I hope the idea to have a better identifier for observations will be not dropped too :)

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.

2 participants