kaspad/network/rpc/utils.go
stasatdaglabs 8a4ece1101
[NOD-1223] Reorganize project (#868)
* [NOD-1223] Move all network stuff into a new network package.

* [NOD-1223] Delete the unused package testutil.

* [NOD-1223] Move infrastructure stuff into a new instrastructure package.

* [NOD-1223] Move domain stuff into a new domain package.
2020-08-13 17:27:25 +03:00

43 lines
1.0 KiB
Go

package rpc
import (
"io/ioutil"
"net"
"os"
"time"
"github.com/kaspanet/kaspad/infrastructure/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)
}