1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
989 B
Go

package store
import (
"net"
"time"
"github.com/hashicorp/raft"
)
// Listener is the interface expected by the Store for Transports.
type Listener interface {
net.Listener
Dial(address string, timeout time.Duration) (net.Conn, error)
}
// Transport is the network service provided to Raft, and wraps a Listener.
type Transport struct {
ln Listener
}
// NewTransport returns an initialized Transport.
func NewTransport(ln Listener) *Transport {
return &Transport{
ln: ln,
}
}
// Dial creates a new network connection.
func (t *Transport) Dial(addr raft.ServerAddress, timeout time.Duration) (net.Conn, error) {
return t.ln.Dial(string(addr), timeout)
}
// Accept waits for the next connection.
func (t *Transport) Accept() (net.Conn, error) {
return t.ln.Accept()
}
// Close closes the transport
func (t *Transport) Close() error {
return t.ln.Close()
}
// Addr returns the binding address of the transport.
func (t *Transport) Addr() net.Addr {
return t.ln.Addr()
}