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
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package privval
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net"
|
|
|
|
"git.cw.tr/mukan-network/mukan-consensus/crypto/ed25519"
|
|
"git.cw.tr/mukan-network/mukan-consensus/libs/log"
|
|
cmtnet "git.cw.tr/mukan-network/mukan-consensus/libs/net"
|
|
)
|
|
|
|
// IsConnTimeout returns a boolean indicating whether the error is known to
|
|
// report that a connection timeout occurred. This detects both fundamental
|
|
// network timeouts, as well as ErrConnTimeout errors.
|
|
func IsConnTimeout(err error) bool {
|
|
_, ok := errors.Unwrap(err).(timeoutError)
|
|
switch {
|
|
case errors.As(err, &EndpointTimeoutError{}):
|
|
return true
|
|
case ok:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// NewSignerListener creates a new SignerListenerEndpoint using the corresponding listen address
|
|
func NewSignerListener(listenAddr string, logger log.Logger) (*SignerListenerEndpoint, error) {
|
|
var listener net.Listener
|
|
|
|
protocol, address := cmtnet.ProtocolAndAddress(listenAddr)
|
|
ln, err := net.Listen(protocol, address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch protocol {
|
|
case "unix":
|
|
listener = NewUnixListener(ln)
|
|
case "tcp":
|
|
// TODO: persist this key so external signer can actually authenticate us
|
|
listener = NewTCPListener(ln, ed25519.GenPrivKey())
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
"wrong listen address: expected either 'tcp' or 'unix' protocols, got %s",
|
|
protocol,
|
|
)
|
|
}
|
|
|
|
pve := NewSignerListenerEndpoint(logger.With("module", "privval"), listener)
|
|
|
|
return pve, nil
|
|
}
|
|
|
|
// GetFreeLocalhostAddrPort returns a free localhost:port address
|
|
func GetFreeLocalhostAddrPort() string {
|
|
port, err := cmtnet.GetFreePort()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return fmt.Sprintf("127.0.0.1:%d", port)
|
|
}
|