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 method to be able to hook in SNIMatchers that exists since java8 #247

Closed
wants to merge 1 commit into from

Conversation

normanmaurer
Copy link
Member

Motivation:

Java8 supports the concept of SNIMatcher, we should allow to hook these into tcnative.

Modifications:

Add new method and interface to allow using SNIMatcher in netty when using java8+

Result:

More inline with features provided by java8+

TCN_ASSERT(ctx != 0);

if (matcher == NULL) {
SSL_CTX_set_tlsext_servername_callback(c->ctx, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but maybe we should just always do this first? ... and then check if (matcher != NULL) for the rest? That way if method == null below, these will already have been properly cleared.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

@nmittler so you say we should always just set to NULL first and then maybe set to something not null if needed later in the method ?

Copy link
Member

Choose a reason for hiding this comment

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

@normanmaurer yeah that was the thought ... WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure this is really needed. I think I would prefer to keep it like it is...

@Scottmitch WDYT ?

Copy link
Member

@Scottmitch Scottmitch Mar 28, 2017

Choose a reason for hiding this comment

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

I'm fine with setting the value only when necessary.

However shouldn't we always check if we need to free memory?

if (c->sni_hostname_matcher != NULL) {
  (*e)->DeleteGlobalRef(e, c->sni_hostname_matcher);
  c->sni_hostname_matcher = NULL;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 let me fix this

if (c->sni_hostname_matcher != NULL) {
(*e)->DeleteLocalRef(e, c->sni_hostname_matcher);
}
c->sni_hostname_matcher = (*e)->NewGlobalRef(e, matcher);
Copy link
Member

Choose a reason for hiding this comment

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

Don't know if it's applicable but maybe NewWeakGlobalRef() instead of NewGlobalRef?

c->sni_hostname_matcher = (*e)->NewWeakGlobalRef(e, matcher);
jobject matcher = (*e)->NewLocalRef(e, (jweak)c->sni_hostname_matcher);
if (!(*e)->IsSameObject(e, matcher, NULL)) {
  // Do something with the SNIMatcher
} else {
  // It appears the SNIMatcher got GC'd in Java land
}
(*e)->DeleteLocalRef(e, matcher);

Copy link
Member Author

Choose a reason for hiding this comment

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

I think a a GlobalRef is ok

}
// Delete the reference to the previous specified matcher if needed.
if (c->sni_hostname_matcher != NULL) {
(*e)->DeleteLocalRef(e, c->sni_hostname_matcher);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bug, shouldn't it be DeleteGlobalRef?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right... doh!

@normanmaurer
Copy link
Member Author

@Scottmitch PTAL

@normanmaurer
Copy link
Member Author

@trustin PTAL as well

TCN_ASSERT(ctx != 0);

if (matcher == NULL) {
SSL_CTX_set_tlsext_servername_callback(c->ctx, NULL);
Copy link
Member

@Scottmitch Scottmitch Mar 28, 2017

Choose a reason for hiding this comment

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

I'm fine with setting the value only when necessary.

However shouldn't we always check if we need to free memory?

if (c->sni_hostname_matcher != NULL) {
  (*e)->DeleteGlobalRef(e, c->sni_hostname_matcher);
  c->sni_hostname_matcher = NULL;
}

Motivation:

Java8 supports the concept of SNIMatcher, we should allow to hook these into tcnative.

Modifications:

Add new method and interface to allow using SNIMatcher in netty when using java8+

Result:

More inline with features provided by java8+
@normanmaurer
Copy link
Member Author

Cherry-picked into master (563307a)

@normanmaurer normanmaurer deleted the sni_matcher branch March 31, 2017 05:44
@Scottmitch
Copy link
Member

See PR #262 for followup

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

Successfully merging this pull request may close these issues.

4 participants