mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-17 10:21:00 +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:
70
rpc/dataconn/dataconn_shared.go
Normal file
70
rpc/dataconn/dataconn_shared.go
Normal file
@ -0,0 +1,70 @@
|
||||
package dataconn
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/stream"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
)
|
||||
|
||||
const (
|
||||
EndpointSend string = "/v1/send"
|
||||
EndpointRecv string = "/v1/recv"
|
||||
)
|
||||
|
||||
const (
|
||||
ReqHeader uint32 = 1 + iota
|
||||
ReqStructured
|
||||
ResHeader
|
||||
ResStructured
|
||||
ZFSStream
|
||||
)
|
||||
|
||||
// Note that changing theses constants may break interop with other clients
|
||||
// Aggressive with timing, conservative (future compatible) with buffer sizes
|
||||
const (
|
||||
HeartbeatInterval = 5 * time.Second
|
||||
HeartbeatPeerTimeout = 10 * time.Second
|
||||
RequestHeaderMaxSize = 1 << 15
|
||||
RequestStructuredMaxSize = 1 << 22
|
||||
ResponseHeaderMaxSize = 1 << 15
|
||||
ResponseStructuredMaxSize = 1 << 23
|
||||
)
|
||||
|
||||
// the following are protocol constants
|
||||
const (
|
||||
responseHeaderHandlerOk = "HANDLER OK\n"
|
||||
responseHeaderHandlerErrorPrefix = "HANDLER ERROR:\n"
|
||||
)
|
||||
|
||||
type streamCopier struct {
|
||||
mtx sync.Mutex
|
||||
used bool
|
||||
streamConn *stream.Conn
|
||||
closeStreamOnClose bool
|
||||
}
|
||||
|
||||
// WriteStreamTo implements zfs.StreamCopier
|
||||
func (s *streamCopier) WriteStreamTo(w io.Writer) zfs.StreamCopierError {
|
||||
s.mtx.Lock()
|
||||
defer s.mtx.Unlock()
|
||||
if s.used {
|
||||
panic("streamCopier used mulitple times")
|
||||
}
|
||||
s.used = true
|
||||
return s.streamConn.ReadStreamInto(w, ZFSStream)
|
||||
}
|
||||
|
||||
// Close implements zfs.StreamCopier
|
||||
func (s *streamCopier) Close() error {
|
||||
// only record the close here, what we do actually depends on whether
|
||||
// the streamCopier is instantiated server-side or client-side
|
||||
s.mtx.Lock()
|
||||
defer s.mtx.Unlock()
|
||||
if s.closeStreamOnClose {
|
||||
return s.streamConn.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user