Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package privval
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/cometbft/cometbft/crypto"
|
|
cmtnet "github.com/cometbft/cometbft/libs/net"
|
|
p2pconn "github.com/cometbft/cometbft/p2p/conn"
|
|
)
|
|
|
|
// Socket errors.
|
|
var (
|
|
ErrDialRetryMax = errors.New("dialed maximum retries")
|
|
)
|
|
|
|
// SocketDialer dials a remote address and returns a net.Conn or an error.
|
|
type SocketDialer func() (net.Conn, error)
|
|
|
|
// DialTCPFn dials the given tcp addr, using the given timeoutReadWrite and
|
|
// privKey for the authenticated encryption handshake.
|
|
func DialTCPFn(addr string, timeoutReadWrite time.Duration, privKey crypto.PrivKey) SocketDialer {
|
|
return func() (net.Conn, error) {
|
|
conn, err := cmtnet.Connect(addr)
|
|
if err == nil {
|
|
deadline := time.Now().Add(timeoutReadWrite)
|
|
err = conn.SetDeadline(deadline)
|
|
}
|
|
if err == nil {
|
|
conn, err = p2pconn.MakeSecretConnection(conn, privKey)
|
|
}
|
|
return conn, err
|
|
}
|
|
}
|
|
|
|
// DialUnixFn dials the given unix socket.
|
|
func DialUnixFn(addr string) SocketDialer {
|
|
return func() (net.Conn, error) {
|
|
unixAddr := &net.UnixAddr{Name: addr, Net: "unix"}
|
|
return net.DialUnix("unix", nil, unixAddr)
|
|
}
|
|
}
|