mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-22 14:02:32 +00:00

* [NOD-1160] remove activeConfig from config package + update main * [NOD-1160] Update main and addrmanager * [NOD-1160] Update netAdapater * [NOD-1160] Update connmanager * [NOD-1160] Fix connmgr package * [NOD-1160] Fixed DNSSeed functions * [NOD-1160] Fixed protocol package and subpackages * [NOD-1160] Fix p2p package * [NOD-1160] Fix rpc package * [NOD-1160] Fix kaspad a final time * [NOD-1160] Make dnsseed.SeedFromDNS callable outside kaspad * [NOD-1160] Fix tests * [NOD-1160] Pass cfg to kaspad * [NOD-1160] Add comment and remove redundant object * [NOD-1160] Fix typo
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package serverutils
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/kaspanet/kaspad/config"
|
|
|
|
"github.com/kaspanet/kaspad/util"
|
|
)
|
|
|
|
// GenCertPair generates a key/cert pair to the paths provided.
|
|
func GenCertPair(certFile, keyFile string) error {
|
|
log.Infof("Generating TLS certificates...")
|
|
|
|
org := "kaspad autogenerated cert"
|
|
validUntil := time.Now().Add(10 * 365 * 24 * time.Hour)
|
|
cert, key, err := util.NewTLSCertPair(org, validUntil, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Write cert and key files.
|
|
if err = ioutil.WriteFile(certFile, cert, 0666); err != nil {
|
|
return err
|
|
}
|
|
if err = ioutil.WriteFile(keyFile, key, 0600); err != nil {
|
|
os.Remove(certFile)
|
|
return err
|
|
}
|
|
|
|
log.Infof("Done generating TLS certificates")
|
|
return nil
|
|
}
|
|
|
|
// KaspadDial connects to the address on the named network using the appropriate
|
|
// dial function depending on the address and configuration options.
|
|
func KaspadDial(cfg *config.Config, addr net.Addr) (net.Conn, error) {
|
|
return cfg.Dial(addr.Network(), addr.String(), config.DefaultConnectTimeout)
|
|
}
|