Revision 2d510d2f272c7b96926477987ef7b7e9e3f5667c authored by Anton Kaliaev on 20 January 2020, 10:41:26 UTC, committed by GitHub on 20 January 2020, 10:41:26 UTC
* rpc: update urls to rpc website

* rpc: check blockMeta is not nil in Commit

Refs #4319
1 parent 9cbfe79
Raw File
socket_dialers.go
package privval

import (
	"net"
	"time"

	"github.com/pkg/errors"
	"github.com/tendermint/tendermint/crypto"
	tmnet "github.com/tendermint/tendermint/libs/net"
	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 := tmnet.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)
	}
}
back to top