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

credentials.TLSInfo: export State #328

Merged
merged 1 commit into from
Sep 8, 2015
Merged

credentials.TLSInfo: export State #328

merged 1 commit into from
Sep 8, 2015

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Sep 6, 2015

See #111.

@@ -126,6 +126,10 @@ func (t TLSInfo) AuthType() string {
return "tls"
}

func (t TLSInfo) ConnState() tls.ConnectionState {
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this in my previous PR. I actually tend to make state exported directly.

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 think a getter makes more sense here; you don't want to allow mutation of this state.

Copy link
Contributor

Choose a reason for hiding this comment

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

The getter does not prohibit mutation. It is the same thing compared to making it exported.

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'm pretty sure it does prohibit mutation; it returns a copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

On Tue, Sep 8, 2015 at 10:50 AM, Tamir Duberstein notifications@github.com
wrote:

In credentials/credentials.go
#328 (comment):

@@ -126,6 +126,10 @@ func (t TLSInfo) AuthType() string {
return "tls"
}

+func (t TLSInfo) ConnState() tls.ConnectionState {

I'm pretty sure it does prohibit mutation; it returns a copy.

Making it exported also makes a copy when users work on it (notice
tls.ConnectionState is a object not a pointer). Plus, making a copy does
NOT prohibit mutation because tls.ConnectionState contains a number of
pointer fields.


Reply to this email directly or view it on GitHub
https://github.com/grpc/grpc-go/pull/328/files#r38957015.

Copy link
Contributor

Choose a reason for hiding this comment

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

On Tue, Sep 8, 2015 at 10:55 AM, Qi Zhao toqizhao@gmail.com wrote:

On Tue, Sep 8, 2015 at 10:50 AM, Tamir Duberstein <
notifications@github.com> wrote:

In credentials/credentials.go
#328 (comment):

@@ -126,6 +126,10 @@ func (t TLSInfo) AuthType() string {
return "tls"
}

+func (t TLSInfo) ConnState() tls.ConnectionState {

I'm pretty sure it does prohibit mutation; it returns a copy.

Making it exported also makes a copy when users work on it (notice
tls.ConnectionState is a object not a pointer). Plus, making a copy does
NOT prohibit mutation because tls.ConnectionState contains a number of
pointer fields.

Actually adding a getter might make the 2nd copy (depends on how the
compiler optimizes it) which is not needed.

Reply to this email directly or view it on GitHub
https://github.com/grpc/grpc-go/pull/328/files#r38957015.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making it exported also makes a copy when users work on it (notice
tls.ConnectionState is a object not a pointer).

Doesn't matter that it's not a pointer. If it's exported I can overwrite it entirely: tlsInfo.State = myOtherTlsState.

Plus, making a copy does
NOT prohibit mutation because tls.ConnectionState contains a number of
pointer fields.

Yes, you could mess with some of the slices in tls.ConnectionState but it's still better than exporting this.

Actually adding a getter might make the 2nd copy (depends on how the
compiler optimizes it) which is not needed.

This doesn't matter - those copies are on the stack and the Go compiler does RVO.

Copy link
Contributor

Choose a reason for hiding this comment

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

On Tue, Sep 8, 2015 at 11:00 AM, Tamir Duberstein notifications@github.com
wrote:

In credentials/credentials.go
#328 (comment):

@@ -126,6 +126,10 @@ func (t TLSInfo) AuthType() string {
return "tls"
}

+func (t TLSInfo) ConnState() tls.ConnectionState {

Making it exported also makes a copy when users work on it (notice
tls.ConnectionState is a object not a pointer).

Doesn't matter that it's not a pointer. If it's exported I can overwrite
it entirely: tlsInfo.State = myOtherTlsState.

I would say overwriting does not matter because you only overwrite your own
copy which is not the ConnectionState of the real tls connection (because
tls.ConnectionState returns a copy). I think that is the whole point why
tls.ConnectionState returns an object instead of a pointer. Keep in mind
that you are the service provider. I do not see any malicious operations
could happen here.

Plus, making a copy does
NOT prohibit mutation because tls.ConnectionState contains a number of
pointer fields.

Yes, you could mess with some of the slices in tls.ConnectionState
http://golang.org/pkg/crypto/tls/#ConnectionState but it's still better
than exporting this.

Slice elements are pointers.

Actually adding a getter might make the 2nd copy (depends on how the
compiler optimizes it) which is not needed.

This doesn't matter - those copies are on the stack and the Go compiler
does RVO.


Reply to this email directly or view it on GitHub
https://github.com/grpc/grpc-go/pull/328/files#r38958528.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've exported it.

@tamird tamird changed the title credentials.TLSInfo: add ConnectionState getter credentials.TLSInfo: export State Sep 8, 2015
@iamqizhao
Copy link
Contributor

LGTM, thanks for the fix.

iamqizhao added a commit that referenced this pull request Sep 8, 2015
credentials.TLSInfo: export State
@iamqizhao iamqizhao merged commit e3df691 into grpc:master Sep 8, 2015
@tamird tamird deleted the tls-auth-info-conn branch September 8, 2015 18:51
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants