|
|
@ -366,10 +366,18 @@ func mustNewNode(enableSingle bool) *Node {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func mustNewNodeEncrypted(enableSingle, httpEncrypt, nodeEncrypt bool) *Node {
|
|
|
|
func mustNewNodeEncrypted(enableSingle, httpEncrypt, nodeEncrypt bool) *Node {
|
|
|
|
return mustNodeEncrypted(mustTempDir(), enableSingle, httpEncrypt, nodeEncrypt, "")
|
|
|
|
dir := mustTempDir()
|
|
|
|
|
|
|
|
var tn *tcp.Transport
|
|
|
|
|
|
|
|
if nodeEncrypt {
|
|
|
|
|
|
|
|
tn = mustNewOpenTLSTransport(x509.CertFile(dir), x509.CertFile(dir), "")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tn = mustNewOpenTransport("")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mustNodeEncrypted(dir, enableSingle, httpEncrypt, tn, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func mustNodeEncrypted(dir string, enableSingle, httpEncrypt, nodeEncrypt bool, nodeID string) *Node {
|
|
|
|
func mustNodeEncrypted(dir string, enableSingle, httpEncrypt bool, tn store.Listener, nodeID string) *Node {
|
|
|
|
nodeCertPath := x509.CertFile(dir)
|
|
|
|
nodeCertPath := x509.CertFile(dir)
|
|
|
|
nodeKeyPath := x509.KeyFile(dir)
|
|
|
|
nodeKeyPath := x509.KeyFile(dir)
|
|
|
|
httpCertPath := nodeCertPath
|
|
|
|
httpCertPath := nodeCertPath
|
|
|
@ -385,17 +393,6 @@ func mustNodeEncrypted(dir string, enableSingle, httpEncrypt, nodeEncrypt bool,
|
|
|
|
|
|
|
|
|
|
|
|
dbConf := store.NewDBConfig("", false)
|
|
|
|
dbConf := store.NewDBConfig("", false)
|
|
|
|
|
|
|
|
|
|
|
|
var tn *tcp.Transport
|
|
|
|
|
|
|
|
if nodeEncrypt {
|
|
|
|
|
|
|
|
tn = tcp.NewTLSTransport(node.NodeCertPath, node.NodeCertPath, true)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tn = tcp.NewTransport()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := tn.Open("localhost:0"); err != nil {
|
|
|
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id := nodeID
|
|
|
|
id := nodeID
|
|
|
|
if id == "" {
|
|
|
|
if id == "" {
|
|
|
|
id = tn.Addr().String()
|
|
|
|
id = tn.Addr().String()
|
|
|
@ -449,6 +446,30 @@ func mustTempDir() string {
|
|
|
|
return path
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func mustNewOpenTransport(addr string) *tcp.Transport {
|
|
|
|
|
|
|
|
if addr == "" {
|
|
|
|
|
|
|
|
addr = "localhost:0"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tn := tcp.NewTransport()
|
|
|
|
|
|
|
|
if err := tn.Open(addr); err != nil {
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("failed to open transport: %s", err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tn
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func mustNewOpenTLSTransport(certFile, keyPath, addr string) *tcp.Transport {
|
|
|
|
|
|
|
|
if addr == "" {
|
|
|
|
|
|
|
|
addr = "localhost:0"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tn := tcp.NewTLSTransport(certFile, keyPath, true)
|
|
|
|
|
|
|
|
if err := tn.Open(addr); err != nil {
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("failed to open transport: %s", err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tn
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func mustParseDuration(d string) time.Duration {
|
|
|
|
func mustParseDuration(d string) time.Duration {
|
|
|
|
if dur, err := time.ParseDuration(d); err != nil {
|
|
|
|
if dur, err := time.ParseDuration(d); err != nil {
|
|
|
|
panic("failed to parse duration")
|
|
|
|
panic("failed to parse duration")
|
|
|
|