Commit f8886987 authored by Petar Radovic's avatar Petar Radovic

ack to return overlay

parent 91dbcfdf
...@@ -3,6 +3,7 @@ module github.com/ethersphere/bee ...@@ -3,6 +3,7 @@ module github.com/ethersphere/bee
go 1.13 go 1.13
require ( require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/gogo/protobuf v1.3.1 github.com/gogo/protobuf v1.3.1
github.com/gorilla/handlers v1.4.2 github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.3 github.com/gorilla/mux v1.7.3
......
...@@ -20,6 +20,7 @@ github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcug ...@@ -20,6 +20,7 @@ github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcug
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
......
...@@ -6,7 +6,6 @@ package handshake ...@@ -6,7 +6,6 @@ package handshake
import ( import (
"fmt" "fmt"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb" "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb"
...@@ -35,7 +34,7 @@ func New(overlay string, networkID int32, logger logging.Logger) *Service { ...@@ -35,7 +34,7 @@ func New(overlay string, networkID int32, logger logging.Logger) *Service {
func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) { func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) {
w, r := protobuf.NewWriterAndReader(stream) w, r := protobuf.NewWriterAndReader(stream)
var resp pb.ShakeHand var resp pb.ShakeHandAck
if err := w.WriteMsg(&pb.ShakeHand{ if err := w.WriteMsg(&pb.ShakeHand{
Address: s.overlay, Address: s.overlay,
NetworkID: s.networkID, NetworkID: s.networkID,
...@@ -48,15 +47,15 @@ func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) { ...@@ -48,15 +47,15 @@ func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) {
return nil, fmt.Errorf("handshake read message: %w", err) return nil, fmt.Errorf("handshake read message: %w", err)
} }
if err := w.WriteMsg(&pb.Ack{}); err != nil { if err := w.WriteMsg(&pb.Ack{Address: resp.ShakeHand.Address}); err != nil {
return nil, fmt.Errorf("handshake write message: %w", err) return nil, fmt.Errorf("ack write message: %w", err)
} }
s.logger.Tracef("handshake read response: %s", resp.Address) s.logger.Tracef("handshake read response: %s", resp.ShakeHand.Address)
return &Info{ return &Info{
Address: resp.Address, Address: resp.ShakeHand.Address,
NetworkID: resp.NetworkID, NetworkID: resp.ShakeHand.NetworkID,
Light: resp.Light, Light: resp.ShakeHand.Light,
}, nil }, nil
} }
...@@ -70,16 +69,19 @@ func (s *Service) Handle(stream p2p.Stream) (i *Info, err error) { ...@@ -70,16 +69,19 @@ func (s *Service) Handle(stream p2p.Stream) (i *Info, err error) {
} }
s.logger.Tracef("handshake handler received request %s", req.Address) s.logger.Tracef("handshake handler received request %s", req.Address)
if err := w.WriteMsg(&pb.ShakeHand{ if err := w.WriteMsg(&pb.ShakeHandAck{
Address: s.overlay, ShakeHand: &pb.ShakeHand{
NetworkID: s.networkID, Address: s.overlay,
NetworkID: s.networkID,
},
Ack: &pb.Ack{Address: req.Address},
}); err != nil { }); err != nil {
return nil, fmt.Errorf("handshake handler write message: %w", err) return nil, fmt.Errorf("handshake handler write message: %w", err)
} }
var ack pb.Ack var ack pb.Ack
if err := r.ReadMsg(&ack); err != nil { if err := r.ReadMsg(&ack); err != nil {
return nil, fmt.Errorf("handshake handler read message: %w", err) return nil, fmt.Errorf("ack read message: %w", err)
} }
s.logger.Tracef("handshake handled response: %s", s.overlay) s.logger.Tracef("handshake handled response: %s", s.overlay)
......
...@@ -16,25 +16,43 @@ import ( ...@@ -16,25 +16,43 @@ import (
) )
type StreamMock struct { type StreamMock struct {
readBuffer *bytes.Buffer readBuffer *bytes.Buffer
writeBuffer *bytes.Buffer writeBuffer *bytes.Buffer
readError error writeCounter int
writeError error readCounter int
readError error
writeError error
readErrCheckmark int
writeErrCheckmark int
}
func (s *StreamMock) setReadErr(err error, checkmark int) {
s.readError = err
s.readErrCheckmark = checkmark
}
func (s *StreamMock) setWriteErr(err error, checkmark int) {
s.writeError = err
s.writeErrCheckmark = checkmark
} }
func (s *StreamMock) Read(p []byte) (n int, err error) { func (s *StreamMock) Read(p []byte) (n int, err error) {
if s.readError != nil { if s.readError != nil && s.readErrCheckmark <= s.readCounter {
return 0, s.readError return 0, s.readError
} }
s.readCounter++
return s.readBuffer.Read(p) return s.readBuffer.Read(p)
} }
func (s *StreamMock) Write(p []byte) (n int, err error) { func (s *StreamMock) Write(p []byte) (n int, err error) {
if s.writeError != nil { if s.writeError != nil && s.writeErrCheckmark <= s.writeCounter {
return 0, s.writeError return 0, s.writeError
} }
s.writeCounter++
return s.writeBuffer.Write(p) return s.writeBuffer.Write(p)
} }
...@@ -64,10 +82,13 @@ func TestHandshake(t *testing.T) { ...@@ -64,10 +82,13 @@ func TestHandshake(t *testing.T) {
stream2 := &StreamMock{readBuffer: &buffer2, writeBuffer: &buffer1} stream2 := &StreamMock{readBuffer: &buffer2, writeBuffer: &buffer1}
w, r := protobuf.NewWriterAndReader(stream2) w, r := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHand{ if err := w.WriteMsg(&pb.ShakeHandAck{
Address: expectedInfo.Address, ShakeHand: &pb.ShakeHand{
NetworkID: expectedInfo.NetworkID, Address: expectedInfo.Address,
Light: expectedInfo.Light, NetworkID: expectedInfo.NetworkID,
Light: expectedInfo.Light,
},
Ack: &pb.Ack{},
}); err != nil { }); err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -86,10 +107,11 @@ func TestHandshake(t *testing.T) { ...@@ -86,10 +107,11 @@ func TestHandshake(t *testing.T) {
} }
}) })
t.Run("ERROR - write error ", func(t *testing.T) { t.Run("ERROR - shakehand write error ", func(t *testing.T) {
testErr := errors.New("test error") testErr := errors.New("test error")
expectedErr := fmt.Errorf("handshake write message: %w", testErr) expectedErr := fmt.Errorf("handshake write message: %w", testErr)
stream := &StreamMock{writeError: testErr} stream := &StreamMock{}
stream.setWriteErr(testErr, 0)
res, err := handshakeService.Handshake(stream) res, err := handshakeService.Handshake(stream)
if err == nil || err.Error() != expectedErr.Error() { if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err) t.Fatal("expected:", expectedErr, "got:", err)
...@@ -100,10 +122,11 @@ func TestHandshake(t *testing.T) { ...@@ -100,10 +122,11 @@ func TestHandshake(t *testing.T) {
} }
}) })
t.Run("ERROR - read error ", func(t *testing.T) { t.Run("ERROR - shakehand read error ", func(t *testing.T) {
testErr := errors.New("test error") testErr := errors.New("test error")
expectedErr := fmt.Errorf("handshake read message: %w", testErr) expectedErr := fmt.Errorf("handshake read message: %w", testErr)
stream := &StreamMock{writeBuffer: &bytes.Buffer{}, readError: testErr} stream := &StreamMock{writeBuffer: &bytes.Buffer{}}
stream.setReadErr(testErr, 0)
res, err := handshakeService.Handshake(stream) res, err := handshakeService.Handshake(stream)
if err == nil || err.Error() != expectedErr.Error() { if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err) t.Fatal("expected:", expectedErr, "got:", err)
...@@ -113,6 +136,44 @@ func TestHandshake(t *testing.T) { ...@@ -113,6 +136,44 @@ func TestHandshake(t *testing.T) {
t.Fatal("handshake returned non-nil res") t.Fatal("handshake returned non-nil res")
} }
}) })
t.Run("ERROR - ack write error ", func(t *testing.T) {
testErr := errors.New("test error")
expectedErr := fmt.Errorf("ack write message: %w", testErr)
expectedInfo := Info{
Address: "node2",
NetworkID: 1,
Light: false,
}
var buffer1 bytes.Buffer
var buffer2 bytes.Buffer
stream1 := &StreamMock{readBuffer: &buffer1, writeBuffer: &buffer2}
stream1.setWriteErr(testErr, 1)
stream2 := &StreamMock{readBuffer: &buffer2, writeBuffer: &buffer1}
w, _ := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHandAck{
ShakeHand: &pb.ShakeHand{
Address: expectedInfo.Address,
NetworkID: expectedInfo.NetworkID,
Light: expectedInfo.Light,
},
Ack: &pb.Ack{Address: info.Address},
}); err != nil {
t.Fatal(err)
}
res, err := handshakeService.Handshake(stream1)
if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err)
}
if res != nil {
t.Fatal("handshake returned non-nil res")
}
})
} }
func TestHandle(t *testing.T) { func TestHandle(t *testing.T) {
...@@ -146,7 +207,7 @@ func TestHandle(t *testing.T) { ...@@ -146,7 +207,7 @@ func TestHandle(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err := w.WriteMsg(&pb.Ack{}); err != nil { if err := w.WriteMsg(&pb.Ack{Address: node2Info.Address}); err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -160,12 +221,12 @@ func TestHandle(t *testing.T) { ...@@ -160,12 +221,12 @@ func TestHandle(t *testing.T) {
} }
_, r := protobuf.NewWriterAndReader(stream2) _, r := protobuf.NewWriterAndReader(stream2)
var got pb.ShakeHand var got pb.ShakeHandAck
if err := r.ReadMsg(&got); err != nil { if err := r.ReadMsg(&got); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if nodeInfo != Info(got) { if nodeInfo != Info(*got.ShakeHand) {
t.Fatalf("got %+v, expected %+v", got, node2Info) t.Fatalf("got %+v, expected %+v", got, node2Info)
} }
}) })
...@@ -173,7 +234,8 @@ func TestHandle(t *testing.T) { ...@@ -173,7 +234,8 @@ func TestHandle(t *testing.T) {
t.Run("ERROR - read error ", func(t *testing.T) { t.Run("ERROR - read error ", func(t *testing.T) {
testErr := errors.New("test error") testErr := errors.New("test error")
expectedErr := fmt.Errorf("handshake handler read message: %w", testErr) expectedErr := fmt.Errorf("handshake handler read message: %w", testErr)
stream := &StreamMock{readError: testErr} stream := &StreamMock{}
stream.setReadErr(testErr, 0)
res, err := handshakeService.Handle(stream) res, err := handshakeService.Handle(stream)
if err == nil || err.Error() != expectedErr.Error() { if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err) t.Fatal("expected:", expectedErr, "got:", err)
...@@ -189,7 +251,7 @@ func TestHandle(t *testing.T) { ...@@ -189,7 +251,7 @@ func TestHandle(t *testing.T) {
expectedErr := fmt.Errorf("handshake handler write message: %w", testErr) expectedErr := fmt.Errorf("handshake handler write message: %w", testErr)
var buffer bytes.Buffer var buffer bytes.Buffer
stream := &StreamMock{readBuffer: &buffer, writeBuffer: &buffer} stream := &StreamMock{readBuffer: &buffer, writeBuffer: &buffer}
stream.setWriteErr(testErr, 1)
w, _ := protobuf.NewWriterAndReader(stream) w, _ := protobuf.NewWriterAndReader(stream)
if err := w.WriteMsg(&pb.ShakeHand{ if err := w.WriteMsg(&pb.ShakeHand{
Address: "node1", Address: "node1",
...@@ -199,7 +261,6 @@ func TestHandle(t *testing.T) { ...@@ -199,7 +261,6 @@ func TestHandle(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
stream.writeError = testErr
res, err := handshakeService.Handle(stream) res, err := handshakeService.Handle(stream)
if err == nil || err.Error() != expectedErr.Error() { if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err) t.Fatal("expected:", expectedErr, "got:", err)
...@@ -209,4 +270,38 @@ func TestHandle(t *testing.T) { ...@@ -209,4 +270,38 @@ func TestHandle(t *testing.T) {
t.Fatal("handshake returned non-nil res") t.Fatal("handshake returned non-nil res")
} }
}) })
t.Run("ERROR - ack read error ", func(t *testing.T) {
testErr := errors.New("test error")
expectedErr := fmt.Errorf("ack read message: %w", testErr)
node2Info := Info{
Address: "node2",
NetworkID: 1,
Light: false,
}
var buffer1 bytes.Buffer
var buffer2 bytes.Buffer
stream1 := &StreamMock{readBuffer: &buffer1, writeBuffer: &buffer2}
stream2 := &StreamMock{readBuffer: &buffer2, writeBuffer: &buffer1}
stream1.setReadErr(testErr, 1)
w, _ := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHand{
Address: node2Info.Address,
NetworkID: node2Info.NetworkID,
Light: node2Info.Light,
}); err != nil {
t.Fatal(err)
}
res, err := handshakeService.Handle(stream1)
if err == nil || err.Error() != expectedErr.Error() {
t.Fatal("expected:", expectedErr, "got:", err)
}
if res != nil {
t.Fatal("handshake returned non-nil res")
}
})
} }
...@@ -82,14 +82,67 @@ func (m *ShakeHand) GetLight() bool { ...@@ -82,14 +82,67 @@ func (m *ShakeHand) GetLight() bool {
return false return false
} }
type ShakeHandAck struct {
ShakeHand *ShakeHand `protobuf:"bytes,1,opt,name=ShakeHand,proto3" json:"ShakeHand,omitempty"`
Ack *Ack `protobuf:"bytes,2,opt,name=Ack,proto3" json:"Ack,omitempty"`
}
func (m *ShakeHandAck) Reset() { *m = ShakeHandAck{} }
func (m *ShakeHandAck) String() string { return proto.CompactTextString(m) }
func (*ShakeHandAck) ProtoMessage() {}
func (*ShakeHandAck) Descriptor() ([]byte, []int) {
return fileDescriptor_a77305914d5d202f, []int{1}
}
func (m *ShakeHandAck) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ShakeHandAck) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ShakeHandAck.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ShakeHandAck) XXX_Merge(src proto.Message) {
xxx_messageInfo_ShakeHandAck.Merge(m, src)
}
func (m *ShakeHandAck) XXX_Size() int {
return m.Size()
}
func (m *ShakeHandAck) XXX_DiscardUnknown() {
xxx_messageInfo_ShakeHandAck.DiscardUnknown(m)
}
var xxx_messageInfo_ShakeHandAck proto.InternalMessageInfo
func (m *ShakeHandAck) GetShakeHand() *ShakeHand {
if m != nil {
return m.ShakeHand
}
return nil
}
func (m *ShakeHandAck) GetAck() *Ack {
if m != nil {
return m.Ack
}
return nil
}
type Ack struct { type Ack struct {
Address string `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"`
} }
func (m *Ack) Reset() { *m = Ack{} } func (m *Ack) Reset() { *m = Ack{} }
func (m *Ack) String() string { return proto.CompactTextString(m) } func (m *Ack) String() string { return proto.CompactTextString(m) }
func (*Ack) ProtoMessage() {} func (*Ack) ProtoMessage() {}
func (*Ack) Descriptor() ([]byte, []int) { func (*Ack) Descriptor() ([]byte, []int) {
return fileDescriptor_a77305914d5d202f, []int{1} return fileDescriptor_a77305914d5d202f, []int{2}
} }
func (m *Ack) XXX_Unmarshal(b []byte) error { func (m *Ack) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b) return m.Unmarshal(b)
...@@ -118,25 +171,36 @@ func (m *Ack) XXX_DiscardUnknown() { ...@@ -118,25 +171,36 @@ func (m *Ack) XXX_DiscardUnknown() {
var xxx_messageInfo_Ack proto.InternalMessageInfo var xxx_messageInfo_Ack proto.InternalMessageInfo
func (m *Ack) GetAddress() string {
if m != nil {
return m.Address
}
return ""
}
func init() { func init() {
proto.RegisterType((*ShakeHand)(nil), "pb.ShakeHand") proto.RegisterType((*ShakeHand)(nil), "pb.ShakeHand")
proto.RegisterType((*ShakeHandAck)(nil), "pb.ShakeHandAck")
proto.RegisterType((*Ack)(nil), "pb.Ack") proto.RegisterType((*Ack)(nil), "pb.Ack")
} }
func init() { proto.RegisterFile("handshake.proto", fileDescriptor_a77305914d5d202f) } func init() { proto.RegisterFile("handshake.proto", fileDescriptor_a77305914d5d202f) }
var fileDescriptor_a77305914d5d202f = []byte{ var fileDescriptor_a77305914d5d202f = []byte{
// 155 bytes of a gzipped FileDescriptorProto // 201 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x48, 0xcc, 0x4b, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcf, 0x48, 0xcc, 0x4b,
0x29, 0xce, 0x48, 0xcc, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52, 0x29, 0xce, 0x48, 0xcc, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52,
0x8a, 0xe4, 0xe2, 0x0c, 0x06, 0x09, 0x79, 0x24, 0xe6, 0xa5, 0x08, 0x49, 0x70, 0xb1, 0x3b, 0xa6, 0x8a, 0xe4, 0xe2, 0x0c, 0x06, 0x09, 0x79, 0x24, 0xe6, 0xa5, 0x08, 0x49, 0x70, 0xb1, 0x3b, 0xa6,
0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x42, 0x32, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x42, 0x32,
0x5c, 0x9c, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0x9e, 0x2e, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x5c, 0x9c, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0x9e, 0x2e, 0x12, 0x4c, 0x0a, 0x8c, 0x1a,
0xac, 0x41, 0x08, 0x01, 0x21, 0x11, 0x2e, 0x56, 0x9f, 0xcc, 0xf4, 0x8c, 0x12, 0x09, 0x66, 0x05, 0xac, 0x41, 0x08, 0x01, 0x21, 0x11, 0x2e, 0x56, 0x9f, 0xcc, 0xf4, 0x8c, 0x12, 0x09, 0x66, 0x05,
0x46, 0x0d, 0x8e, 0x20, 0x08, 0x47, 0x89, 0x95, 0x8b, 0xd9, 0x31, 0x39, 0xdb, 0x49, 0xe2, 0xc4, 0x46, 0x0d, 0x8e, 0x20, 0x08, 0x47, 0x29, 0x8c, 0x8b, 0x07, 0x6e, 0xb4, 0x63, 0x72, 0xb6, 0x90,
0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0x36, 0x92, 0x55, 0x60, 0xf3, 0xb9, 0x8d, 0x78, 0xf5, 0x0a, 0x92, 0xf4, 0xe0, 0x82, 0x41, 0x48,
0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0x92, 0xd8, 0xc0, 0xce, 0x30, 0x06, 0x04, 0x00, 0x4e, 0x91, 0xe4, 0x62, 0x76, 0x4c, 0xce, 0x06, 0x5b, 0xc5, 0x6d, 0xc4, 0x0e, 0x52, 0xe6, 0x98,
0x00, 0xff, 0xff, 0x63, 0xb7, 0x44, 0x98, 0x99, 0x00, 0x00, 0x00, 0x9c, 0x1d, 0x04, 0x12, 0x53, 0x92, 0x07, 0x4b, 0xe1, 0x76, 0xac, 0x93, 0xc4, 0x89, 0x47, 0x72,
0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7,
0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0x3d, 0x6e, 0x0c, 0x08, 0x00, 0x00, 0xff,
0xff, 0x75, 0x16, 0xc0, 0x1d, 0x0b, 0x01, 0x00, 0x00,
} }
func (m *ShakeHand) Marshal() (dAtA []byte, err error) { func (m *ShakeHand) Marshal() (dAtA []byte, err error) {
...@@ -184,6 +248,53 @@ func (m *ShakeHand) MarshalToSizedBuffer(dAtA []byte) (int, error) { ...@@ -184,6 +248,53 @@ func (m *ShakeHand) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil return len(dAtA) - i, nil
} }
func (m *ShakeHandAck) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ShakeHandAck) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ShakeHandAck) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.Ack != nil {
{
size, err := m.Ack.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintHandshake(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
if m.ShakeHand != nil {
{
size, err := m.ShakeHand.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintHandshake(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Ack) Marshal() (dAtA []byte, err error) { func (m *Ack) Marshal() (dAtA []byte, err error) {
size := m.Size() size := m.Size()
dAtA = make([]byte, size) dAtA = make([]byte, size)
...@@ -204,6 +315,13 @@ func (m *Ack) MarshalToSizedBuffer(dAtA []byte) (int, error) { ...@@ -204,6 +315,13 @@ func (m *Ack) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i _ = i
var l int var l int
_ = l _ = l
if len(m.Address) > 0 {
i -= len(m.Address)
copy(dAtA[i:], m.Address)
i = encodeVarintHandshake(dAtA, i, uint64(len(m.Address)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil return len(dAtA) - i, nil
} }
...@@ -237,12 +355,33 @@ func (m *ShakeHand) Size() (n int) { ...@@ -237,12 +355,33 @@ func (m *ShakeHand) Size() (n int) {
return n return n
} }
func (m *ShakeHandAck) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.ShakeHand != nil {
l = m.ShakeHand.Size()
n += 1 + l + sovHandshake(uint64(l))
}
if m.Ack != nil {
l = m.Ack.Size()
n += 1 + l + sovHandshake(uint64(l))
}
return n
}
func (m *Ack) Size() (n int) { func (m *Ack) Size() (n int) {
if m == nil { if m == nil {
return 0 return 0
} }
var l int var l int
_ = l _ = l
l = len(m.Address)
if l > 0 {
n += 1 + l + sovHandshake(uint64(l))
}
return n return n
} }
...@@ -376,6 +515,131 @@ func (m *ShakeHand) Unmarshal(dAtA []byte) error { ...@@ -376,6 +515,131 @@ func (m *ShakeHand) Unmarshal(dAtA []byte) error {
} }
return nil return nil
} }
func (m *ShakeHandAck) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHandshake
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ShakeHandAck: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ShakeHandAck: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ShakeHand", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHandshake
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthHandshake
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthHandshake
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.ShakeHand == nil {
m.ShakeHand = &ShakeHand{}
}
if err := m.ShakeHand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Ack", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHandshake
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthHandshake
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthHandshake
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Ack == nil {
m.Ack = &Ack{}
}
if err := m.Ack.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipHandshake(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthHandshake
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthHandshake
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Ack) Unmarshal(dAtA []byte) error { func (m *Ack) Unmarshal(dAtA []byte) error {
l := len(dAtA) l := len(dAtA)
iNdEx := 0 iNdEx := 0
...@@ -405,6 +669,38 @@ func (m *Ack) Unmarshal(dAtA []byte) error { ...@@ -405,6 +669,38 @@ func (m *Ack) Unmarshal(dAtA []byte) error {
return fmt.Errorf("proto: Ack: illegal tag %d (wire type %d)", fieldNum, wire) return fmt.Errorf("proto: Ack: illegal tag %d (wire type %d)", fieldNum, wire)
} }
switch fieldNum { switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowHandshake
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthHandshake
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthHandshake
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Address = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipHandshake(dAtA[iNdEx:]) skippy, err := skipHandshake(dAtA[iNdEx:])
......
...@@ -11,5 +11,11 @@ message ShakeHand { ...@@ -11,5 +11,11 @@ message ShakeHand {
bool Light = 3; bool Light = 3;
} }
message Ack {} message ShakeHandAck {
ShakeHand ShakeHand = 1;
Ack Ack = 2;
}
message Ack {
string Address = 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment