mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-09 07:05:47 +02:00
rpc rewrite: control RPCs using gRPC + separate RPC for data transfer
transport/ssh: update go-netssh to new version => supports CloseWrite and Deadlines => build: require Go 1.11 (netssh requires it)
This commit is contained in:
57
rpc/rpc_mux.go
Normal file
57
rpc/rpc_mux.go
Normal file
@ -0,0 +1,57 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
"github.com/zrepl/zrepl/rpc/transportmux"
|
||||
"github.com/zrepl/zrepl/util/envconst"
|
||||
)
|
||||
|
||||
type demuxedListener struct {
|
||||
control, data transport.AuthenticatedListener
|
||||
}
|
||||
|
||||
const (
|
||||
transportmuxLabelControl string = "zrepl_control"
|
||||
transportmuxLabelData string = "zrepl_data"
|
||||
)
|
||||
|
||||
func demux(serveCtx context.Context, listener transport.AuthenticatedListener) demuxedListener {
|
||||
listeners, err := transportmux.Demux(
|
||||
serveCtx, listener,
|
||||
[]string{transportmuxLabelControl, transportmuxLabelData},
|
||||
envconst.Duration("ZREPL_TRANSPORT_DEMUX_TIMEOUT", 10*time.Second),
|
||||
)
|
||||
if err != nil {
|
||||
// transportmux API guarantees that the returned error can only be due
|
||||
// to invalid API usage (i.e. labels too long)
|
||||
panic(err)
|
||||
}
|
||||
return demuxedListener{
|
||||
control: listeners[transportmuxLabelControl],
|
||||
data: listeners[transportmuxLabelData],
|
||||
}
|
||||
}
|
||||
|
||||
type muxedConnecter struct {
|
||||
control, data transport.Connecter
|
||||
}
|
||||
|
||||
func mux(rawConnecter transport.Connecter) muxedConnecter {
|
||||
muxedConnecters, err := transportmux.MuxConnecter(
|
||||
rawConnecter,
|
||||
[]string{transportmuxLabelControl, transportmuxLabelData},
|
||||
envconst.Duration("ZREPL_TRANSPORT_MUX_TIMEOUT", 10*time.Second),
|
||||
)
|
||||
if err != nil {
|
||||
// transportmux API guarantees that the returned error can only be due
|
||||
// to invalid API usage (i.e. labels too long)
|
||||
panic(err)
|
||||
}
|
||||
return muxedConnecter{
|
||||
control: muxedConnecters[transportmuxLabelControl],
|
||||
data: muxedConnecters[transportmuxLabelData],
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user