2018-09-24 14:43:53 +02:00
|
|
|
package connecter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/zrepl/zrepl/config"
|
2018-10-11 21:20:55 +02:00
|
|
|
"github.com/zrepl/zrepl/daemon/transport/serve"
|
2018-09-24 14:43:53 +02:00
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LocalConnecter struct {
|
2018-10-11 13:06:47 +02:00
|
|
|
listenerName string
|
2018-09-24 14:43:53 +02:00
|
|
|
clientIdentity string
|
|
|
|
}
|
|
|
|
|
|
|
|
func LocalConnecterFromConfig(in *config.LocalConnect) (*LocalConnecter, error) {
|
|
|
|
if in.ClientIdentity == "" {
|
|
|
|
return nil, fmt.Errorf("ClientIdentity must not be empty")
|
|
|
|
}
|
2018-10-11 13:06:47 +02:00
|
|
|
if in.ListenerName == "" {
|
|
|
|
return nil, fmt.Errorf("ListenerName must not be empty")
|
|
|
|
}
|
|
|
|
return &LocalConnecter{listenerName: in.ListenerName, clientIdentity: in.ClientIdentity}, nil
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LocalConnecter) Connect(dialCtx context.Context) (conn net.Conn, err error) {
|
2018-10-11 13:06:47 +02:00
|
|
|
l := serve.GetLocalListener(c.listenerName)
|
|
|
|
return l.Connect(dialCtx, c.clientIdentity)
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|
|
|
|
|