mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 14:22:16 +00:00
* Fix maligned structs * Fix interfacer errors * Revert accidental go.mod and go.sum changes * Revert P2PConfig struct maligned reorder * Revert PeerRoundState struct maligned reordering * Revert RoundState struct maligned reordering * Reorder WSClient struct * Revert accidental type change * Clean up type change * Clean up type changes * Revert to types.ABCIApplicationServer in GRPCServer struct * Revert maligned changes to BaseConfig struct * Fix tests in io_test.go * Fix client_test package tests * Fix reactor tests in consensus package * Fix new interfacer errors
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package privval
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/tendermint/tendermint/crypto"
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
p2pconn "github.com/tendermint/tendermint/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 := cmn.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)
|
|
}
|
|
}
|