|
|
@@ -16,11 +16,13 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
"sync/atomic"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
+ tlsConfigLock sync.RWMutex
|
|
|
tlsConfigRegister map[string]*tls.Config // Register for custom tls.Configs
|
|
|
)
|
|
|
|
|
|
@@ -54,19 +56,32 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
|
|
|
return fmt.Errorf("key '%s' is reserved", key)
|
|
|
}
|
|
|
|
|
|
+ tlsConfigLock.Lock()
|
|
|
if tlsConfigRegister == nil {
|
|
|
tlsConfigRegister = make(map[string]*tls.Config)
|
|
|
}
|
|
|
|
|
|
tlsConfigRegister[key] = config
|
|
|
+ tlsConfigLock.Unlock()
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// DeregisterTLSConfig removes the tls.Config associated with key.
|
|
|
func DeregisterTLSConfig(key string) {
|
|
|
+ tlsConfigLock.Lock()
|
|
|
if tlsConfigRegister != nil {
|
|
|
delete(tlsConfigRegister, key)
|
|
|
}
|
|
|
+ tlsConfigLock.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+func getTLSConfigClone(key string) (config *tls.Config) {
|
|
|
+ tlsConfigLock.RLock()
|
|
|
+ if v, ok := tlsConfigRegister[key]; ok {
|
|
|
+ config = cloneTLSConfig(v)
|
|
|
+ }
|
|
|
+ tlsConfigLock.RUnlock()
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// Returns the bool value of the input.
|
|
|
@@ -745,6 +760,7 @@ func escapeStringQuotes(buf []byte, v string) []byte {
|
|
|
/******************************************************************************
|
|
|
* Sync utils *
|
|
|
******************************************************************************/
|
|
|
+
|
|
|
// noCopy may be embedded into structs which must not be copied
|
|
|
// after the first use.
|
|
|
//
|