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.

37 lines
824 B
Go

package store
import (
"net"
"time"
)
// networkLayer represents the connection between nodes.
type networkLayer struct {
ln net.Listener
addr net.Addr
}
// newNetworkLayer returns a new instance of networkLayer.
func newNetworkLayer(ln net.Listener) *networkLayer {
return &networkLayer{
ln: ln,
addr: ln.Addr(),
}
}
// Addr returns the local address for the layer.
func (l *networkLayer) Addr() net.Addr {
return l.addr
}
// Dial creates a new network connection.
func (l *networkLayer) Dial(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("tcp", addr, timeout)
}
// Accept waits for the next connection.
func (l *networkLayer) Accept() (net.Conn, error) { return l.ln.Accept() }
// Close closes the layer.
func (l *networkLayer) Close() error { return l.ln.Close() }