format source tree using goimports
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
"github.com/zrepl/zrepl/replication/logic/pdu"
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/stream"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
@@ -214,13 +215,12 @@ func (c *Client) ReqRecv(ctx context.Context, req *pdu.ReceiveReq, streamCopier
|
||||
return res.res, cause
|
||||
}
|
||||
|
||||
|
||||
func (c *Client) ReqPing(ctx context.Context, req *pdu.PingReq) (*pdu.PingRes, error) {
|
||||
conn, err := c.getWire(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer c.putWire(conn)
|
||||
defer c.putWire(conn)
|
||||
|
||||
if err := c.send(ctx, conn, EndpointPing, req, nil); err != nil {
|
||||
return nil, err
|
||||
@@ -232,4 +232,4 @@ func (c *Client) ReqPing(ctx context.Context, req *pdu.PingReq) (*pdu.PingRes, e
|
||||
}
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"github.com/zrepl/zrepl/replication/logic/pdu"
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/stream"
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/base2bufpool"
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/timeoutconn"
|
||||
)
|
||||
|
||||
@@ -3,8 +3,8 @@ package frameconn
|
||||
import "sync"
|
||||
|
||||
type shutdownFSM struct {
|
||||
mtx sync.Mutex
|
||||
state shutdownFSMState
|
||||
mtx sync.Mutex
|
||||
state shutdownFSMState
|
||||
}
|
||||
|
||||
type shutdownFSMState uint32
|
||||
@@ -16,7 +16,7 @@ const (
|
||||
|
||||
func newShutdownFSM() *shutdownFSM {
|
||||
fsm := &shutdownFSM{
|
||||
state: shutdownStateOpen,
|
||||
state: shutdownStateOpen,
|
||||
}
|
||||
return fsm
|
||||
}
|
||||
@@ -34,4 +34,3 @@ func (f *shutdownFSM) IsShuttingDown() bool {
|
||||
defer f.mtx.Unlock()
|
||||
return f.state != shutdownStateOpen
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,3 @@ func TestIsPublicFrameType(t *testing.T) {
|
||||
assert.True(t, IsPublicFrameType(255))
|
||||
assert.False(t, IsPublicFrameType(rstFrameType))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/frameconn"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"github.com/zrepl/zrepl/rpc/dataconn/heartbeatconn"
|
||||
"github.com/zrepl/zrepl/util/socketpair"
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
netssh "github.com/problame/go-netssh"
|
||||
"github.com/zrepl/yaml-config"
|
||||
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
transportconfig "github.com/zrepl/zrepl/transport/fromconfig"
|
||||
|
||||
@@ -85,7 +85,7 @@ func (CloseWrite) receiver(wire transport.Wire) {
|
||||
|
||||
// consume half the test data, then detect an error, send it and CloseWrite
|
||||
|
||||
r := io.LimitReader(wire, int64(5 * len(closeWriteTestSendData)/3))
|
||||
r := io.LimitReader(wire, int64(5*len(closeWriteTestSendData)/3))
|
||||
_, err := io.Copy(ioutil.Discard, r)
|
||||
noerror(err)
|
||||
|
||||
@@ -103,7 +103,7 @@ func (CloseWrite) receiver(wire transport.Wire) {
|
||||
// io.Copy masks io.EOF to nil, and we expect io.EOF from the client's Close() call
|
||||
log.Panicf("unexpected error returned from reading conn: %s", err)
|
||||
}
|
||||
|
||||
|
||||
closeErr := wire.Close()
|
||||
log.Printf("closeErr=%T %s", closeErr, closeErr)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zrepl/zrepl/util/socketpair"
|
||||
)
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/peer"
|
||||
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
)
|
||||
|
||||
type Logger = logger.Logger
|
||||
|
||||
@@ -5,10 +5,11 @@ package pdu
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
math "math"
|
||||
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
||||
@@ -25,8 +25,9 @@ package netadaptor
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"net"
|
||||
|
||||
"github.com/zrepl/zrepl/logger"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
)
|
||||
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/zrepl/zrepl/replication/logic"
|
||||
"github.com/zrepl/zrepl/replication/logic/pdu"
|
||||
"github.com/zrepl/zrepl/rpc/dataconn"
|
||||
@@ -158,7 +159,7 @@ func (c *Client) WaitForConnectivity(ctx context.Context) error {
|
||||
time.Sleep(envconst.Duration("ZREPL_RPC_DATACONN_PING_SLEEP", 1*time.Second))
|
||||
continue
|
||||
}
|
||||
// it's not a dial timeout,
|
||||
// it's not a dial timeout,
|
||||
checkRes(data, dataErr, loggers.Data, &dataOk)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -115,4 +115,3 @@ package rpc
|
||||
// - remove the comments //
|
||||
// - vim: set virtualedit+=all
|
||||
// - vim: set ft=text
|
||||
|
||||
|
||||
+1
-1
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
"github.com/zrepl/zrepl/rpc/transportmux"
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
"github.com/zrepl/zrepl/util/envconst"
|
||||
)
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ func (l *demuxListener) Accept(ctx context.Context) (*transport.AuthConn, error)
|
||||
return res.conn, res.err
|
||||
}
|
||||
|
||||
type demuxAddr struct {}
|
||||
type demuxAddr struct{}
|
||||
|
||||
func (demuxAddr) Network() string { return "demux" }
|
||||
func (demuxAddr) String() string { return "demux" }
|
||||
func (demuxAddr) String() string { return "demux" }
|
||||
|
||||
func (l *demuxListener) Addr() net.Addr {
|
||||
return demuxAddr{}
|
||||
@@ -64,7 +64,7 @@ func (l *demuxListener) Close() error { return nil } // TODO
|
||||
// This is a protocol constant, changing it breaks the wire protocol.
|
||||
const LabelLen = 64
|
||||
|
||||
func padLabel(out []byte, label string) (error) {
|
||||
func padLabel(out []byte, label string) error {
|
||||
if len(label) > LabelLen {
|
||||
return fmt.Errorf("label %q exceeds max length (is %d, max %d)", label, len(label), LabelLen)
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func Demux(ctx context.Context, rawListener transport.AuthenticatedListener, lab
|
||||
|
||||
type labeledConnecter struct {
|
||||
label []byte
|
||||
transport.Connecter
|
||||
transport.Connecter
|
||||
}
|
||||
|
||||
func (c labeledConnecter) Connect(ctx context.Context) (transport.Wire, error) {
|
||||
@@ -202,4 +202,3 @@ func MuxConnecter(rawConnecter transport.Connecter, labels []string, timeout tim
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
type HandshakeMessage struct {
|
||||
ProtocolVersion int
|
||||
Extensions []string
|
||||
Extensions []string
|
||||
}
|
||||
|
||||
// A HandshakeError describes what went wrong during the handshake.
|
||||
@@ -25,7 +25,7 @@ type HandshakeMessage struct {
|
||||
type HandshakeError struct {
|
||||
msg string
|
||||
// If not nil, the underlying IO error that caused the handshake to fail.
|
||||
IOError error
|
||||
IOError error
|
||||
isAcceptError bool
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ func (e HandshakeError) Error() string { return e.msg }
|
||||
// Like with net.OpErr (Go issue 6163), a client failing to handshake
|
||||
// should be a temporary Accept error toward the Listener .
|
||||
func (e HandshakeError) Temporary() bool {
|
||||
if e.isAcceptError {
|
||||
if e.isAcceptError {
|
||||
return true
|
||||
}
|
||||
te, ok := e.IOError.(interface{ Temporary() bool });
|
||||
te, ok := e.IOError.(interface{ Temporary() bool })
|
||||
return ok && te.Temporary()
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ func (e HandshakeError) Timeout() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func hsErr(format string, args... interface{}) *HandshakeError {
|
||||
func hsErr(format string, args ...interface{}) *HandshakeError {
|
||||
return &HandshakeError{msg: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
func hsIOErr(err error, format string, args... interface{}) *HandshakeError {
|
||||
func hsIOErr(err error, format string, args ...interface{}) *HandshakeError {
|
||||
return &HandshakeError{IOError: err, msg: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func (m *HandshakeMessage) DecodeReader(r io.Reader, maxLen int) error {
|
||||
if exts[len(exts)-1] != "" {
|
||||
return hsErr("unexpected data trailing after last extension newline")
|
||||
}
|
||||
m.Extensions = exts[0:len(exts)-1]
|
||||
m.Extensions = exts[0 : len(exts)-1]
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -160,7 +160,7 @@ const HandshakeMessageMaxLen = 16 * 4096
|
||||
func DoHandshakeVersion(conn net.Conn, deadline time.Time, version int) *HandshakeError {
|
||||
ours := HandshakeMessage{
|
||||
ProtocolVersion: version,
|
||||
Extensions: nil,
|
||||
Extensions: nil,
|
||||
}
|
||||
hsb, err := ours.Encode()
|
||||
if err != nil {
|
||||
|
||||
@@ -3,13 +3,15 @@ package versionhandshake
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zrepl/zrepl/util/socketpair"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zrepl/zrepl/util/socketpair"
|
||||
)
|
||||
|
||||
func TestHandshakeMessage_Encode(t *testing.T) {
|
||||
@@ -23,8 +25,6 @@ func TestHandshakeMessage_Encode(t *testing.T) {
|
||||
enc := string(encB)
|
||||
t.Logf("enc: %s", enc)
|
||||
|
||||
|
||||
|
||||
assert.False(t, strings.ContainsAny(enc[0:10], " "))
|
||||
assert.True(t, enc[10] == ' ')
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestHandshakeMessage_Encode(t *testing.T) {
|
||||
|
||||
func TestHandshakeMessage_Encode_InvalidProtocolVersion(t *testing.T) {
|
||||
|
||||
for _, pv := range []int{-1, 0, 10000, 10001} {
|
||||
for _, pv := range []int{-1, 0, 10000, 10001} {
|
||||
t.Logf("testing invalid protocol version = %v", pv)
|
||||
msg := HandshakeMessage{
|
||||
ProtocolVersion: pv,
|
||||
@@ -68,7 +68,7 @@ func TestHandshakeMessage_DecodeReader(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
out := HandshakeMessage{}
|
||||
err = out.DecodeReader(bytes.NewReader([]byte(enc)), 4 * 4096)
|
||||
err = out.DecodeReader(bytes.NewReader([]byte(enc)), 4*4096)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2342, out.ProtocolVersion)
|
||||
assert.Equal(t, 2, len(out.Extensions))
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/zrepl/zrepl/transport"
|
||||
)
|
||||
|
||||
type HandshakeConnecter struct {
|
||||
connecter transport.Connecter
|
||||
timeout time.Duration
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (c HandshakeConnecter) Connect(ctx context.Context) (transport.Wire, error) {
|
||||
@@ -31,17 +32,17 @@ func (c HandshakeConnecter) Connect(ctx context.Context) (transport.Wire, error)
|
||||
func Connecter(connecter transport.Connecter, timeout time.Duration) HandshakeConnecter {
|
||||
return HandshakeConnecter{
|
||||
connecter: connecter,
|
||||
timeout: timeout,
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// wrapper type that performs a a protocol version handshake before returning the connection
|
||||
type HandshakeListener struct {
|
||||
l transport.AuthenticatedListener
|
||||
l transport.AuthenticatedListener
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (l HandshakeListener) Addr() (net.Addr) { return l.l.Addr() }
|
||||
func (l HandshakeListener) Addr() net.Addr { return l.l.Addr() }
|
||||
|
||||
func (l HandshakeListener) Close() error { return l.l.Close() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user