forked from nats-io/nats-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED] assignment copies lock value for crypto/tls.Config
Running `go vet ./...` with `go 1.7.3` would report the following: ``` server/route.go:342: assignment copies lock value to tlsConfig: crypto/tls.Config contains sync.Once contains sync.Mutex server/server.go:479: assignment copies lock value to config: crypto/tls.Config contains sync.Once contains sync.Mutex ``` Add a “clone” function while waiting for this to be addressed by the language itself (https://go-review.googlesource.com/#/c/28075/)
- Loading branch information
Showing
4 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2016 Apcera Inc. All rights reserved. | ||
|
||
package util | ||
|
||
import ( | ||
"crypto/tls" | ||
"reflect" | ||
) | ||
|
||
// CloneTLSConfig returns a copy of c. Only the exported fields are copied. | ||
// This is temporary, until this is provided by the language. | ||
// https://go-review.googlesource.com/#/c/28075/ | ||
func CloneTLSConfig(c *tls.Config) *tls.Config { | ||
newConfig := &tls.Config{ | ||
Rand: c.Rand, | ||
Time: c.Time, | ||
Certificates: c.Certificates, | ||
NameToCertificate: c.NameToCertificate, | ||
GetCertificate: c.GetCertificate, | ||
RootCAs: c.RootCAs, | ||
NextProtos: c.NextProtos, | ||
ServerName: c.ServerName, | ||
ClientAuth: c.ClientAuth, | ||
ClientCAs: c.ClientCAs, | ||
InsecureSkipVerify: c.InsecureSkipVerify, | ||
CipherSuites: c.CipherSuites, | ||
PreferServerCipherSuites: c.PreferServerCipherSuites, | ||
SessionTicketsDisabled: c.SessionTicketsDisabled, | ||
SessionTicketKey: c.SessionTicketKey, | ||
ClientSessionCache: c.ClientSessionCache, | ||
MinVersion: c.MinVersion, | ||
MaxVersion: c.MaxVersion, | ||
CurvePreferences: c.CurvePreferences, | ||
} | ||
fieldName := "DynamicRecordSizingDisabled" | ||
if cField := reflect.ValueOf(c).Elem().FieldByName(fieldName); cField.IsValid() { | ||
newField := reflect.ValueOf(newConfig).Elem().FieldByName(fieldName) | ||
newField.SetBool(cField.Bool()) | ||
|
||
fieldName = "Renegotiation" | ||
cField = reflect.ValueOf(c).Elem().FieldByName(fieldName) | ||
newField = reflect.ValueOf(newConfig).Elem().FieldByName(fieldName) | ||
newField.SetInt(cField.Int()) | ||
} | ||
return newConfig | ||
} |