Commit 226b12d1 authored by Petar Radovic's avatar Petar Radovic

renamed handshake proto messages

parent da8b085c
......@@ -6,6 +6,7 @@ package handshake
import (
"fmt"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb"
......@@ -35,8 +36,8 @@ func New(overlay swarm.Address, networkID int32, logger logging.Logger) *Service
func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) {
w, r := protobuf.NewWriterAndReader(stream)
var resp pb.ShakeHandAck
if err := w.WriteMsg(&pb.ShakeHand{
var resp pb.SynPlusAck
if err := w.WriteMsg(&pb.Syn{
Address: s.overlay.Bytes(),
NetworkID: s.networkID,
}); err != nil {
......@@ -47,18 +48,18 @@ func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) {
return nil, fmt.Errorf("read message: %w", err)
}
if err := w.WriteMsg(&pb.Ack{Address: resp.ShakeHand.Address}); err != nil {
if err := w.WriteMsg(&pb.Ack{Address: resp.Syn.Address}); err != nil {
return nil, fmt.Errorf("ack: write message: %w", err)
}
address := swarm.NewAddress(resp.ShakeHand.Address)
address := swarm.NewAddress(resp.Syn.Address)
s.logger.Tracef("handshake finished for peer %s", address)
return &Info{
Address: address,
NetworkID: resp.ShakeHand.NetworkID,
Light: resp.ShakeHand.Light,
NetworkID: resp.Syn.NetworkID,
Light: resp.Syn.Light,
}, nil
}
......@@ -66,13 +67,13 @@ func (s *Service) Handle(stream p2p.Stream) (i *Info, err error) {
w, r := protobuf.NewWriterAndReader(stream)
defer stream.Close()
var req pb.ShakeHand
var req pb.Syn
if err := r.ReadMsg(&req); err != nil {
return nil, fmt.Errorf("read message: %w", err)
}
if err := w.WriteMsg(&pb.ShakeHandAck{
ShakeHand: &pb.ShakeHand{
if err := w.WriteMsg(&pb.SynPlusAck{
Syn: &pb.Syn{
Address: s.overlay.Bytes(),
NetworkID: s.networkID,
},
......
......@@ -41,8 +41,8 @@ func TestHandshake(t *testing.T) {
stream2 := mock.NewStream(&buffer2, &buffer1)
w, r := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHandAck{
ShakeHand: &pb.ShakeHand{
if err := w.WriteMsg(&pb.SynPlusAck{
Syn: &pb.Syn{
Address: expectedInfo.Address.Bytes(),
NetworkID: expectedInfo.NetworkID,
Light: expectedInfo.Light,
......@@ -64,7 +64,7 @@ func TestHandshake(t *testing.T) {
}
})
t.Run("ERROR - shakehand write error ", func(t *testing.T) {
t.Run("ERROR - Syn write error ", func(t *testing.T) {
testErr := errors.New("test error")
expectedErr := fmt.Errorf("write message: %w", testErr)
stream := &mock.StreamMock{}
......@@ -79,7 +79,7 @@ func TestHandshake(t *testing.T) {
}
})
t.Run("ERROR - shakehand read error ", func(t *testing.T) {
t.Run("ERROR - Syn read error ", func(t *testing.T) {
testErr := errors.New("test error")
expectedErr := fmt.Errorf("read message: %w", testErr)
stream := mock.NewStream(nil, &bytes.Buffer{})
......@@ -110,8 +110,8 @@ func TestHandshake(t *testing.T) {
stream2 := mock.NewStream(&buffer2, &buffer1)
w, _ := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHandAck{
ShakeHand: &pb.ShakeHand{
if err := w.WriteMsg(&pb.SynPlusAck{
Syn: &pb.Syn{
Address: expectedInfo.Address.Bytes(),
NetworkID: expectedInfo.NetworkID,
Light: expectedInfo.Light,
......@@ -157,7 +157,7 @@ func TestHandle(t *testing.T) {
stream2 := mock.NewStream(&buffer2, &buffer1)
w, _ := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHand{
if err := w.WriteMsg(&pb.Syn{
Address: node2Info.Address.Bytes(),
NetworkID: node2Info.NetworkID,
Light: node2Info.Light,
......@@ -177,15 +177,15 @@ func TestHandle(t *testing.T) {
testInfo(t, *res, node2Info)
_, r := protobuf.NewWriterAndReader(stream2)
var got pb.ShakeHandAck
var got pb.SynPlusAck
if err := r.ReadMsg(&got); err != nil {
t.Fatal(err)
}
testInfo(t, nodeInfo, Info{
Address: swarm.NewAddress(got.ShakeHand.Address),
NetworkID: got.ShakeHand.NetworkID,
Light: got.ShakeHand.Light,
Address: swarm.NewAddress(got.Syn.Address),
NetworkID: got.Syn.NetworkID,
Light: got.Syn.Light,
})
})
......@@ -211,7 +211,7 @@ func TestHandle(t *testing.T) {
stream := mock.NewStream(&buffer, &buffer)
stream.SetWriteErr(testErr, 1)
w, _ := protobuf.NewWriterAndReader(stream)
if err := w.WriteMsg(&pb.ShakeHand{
if err := w.WriteMsg(&pb.Syn{
Address: node1Addr.Bytes(),
NetworkID: 0,
Light: false,
......@@ -244,7 +244,7 @@ func TestHandle(t *testing.T) {
stream2 := mock.NewStream(&buffer2, &buffer1)
stream1.SetReadErr(testErr, 1)
w, _ := protobuf.NewWriterAndReader(stream2)
if err := w.WriteMsg(&pb.ShakeHand{
if err := w.WriteMsg(&pb.Syn{
Address: node2Info.Address.Bytes(),
NetworkID: node2Info.NetworkID,
Light: node2Info.Light,
......
......@@ -22,24 +22,24 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ShakeHand struct {
type Syn struct {
Address []byte `protobuf:"bytes,1,opt,name=Address,proto3" json:"Address,omitempty"`
NetworkID int32 `protobuf:"varint,2,opt,name=NetworkID,proto3" json:"NetworkID,omitempty"`
Light bool `protobuf:"varint,3,opt,name=Light,proto3" json:"Light,omitempty"`
}
func (m *ShakeHand) Reset() { *m = ShakeHand{} }
func (m *ShakeHand) String() string { return proto.CompactTextString(m) }
func (*ShakeHand) ProtoMessage() {}
func (*ShakeHand) Descriptor() ([]byte, []int) {
func (m *Syn) Reset() { *m = Syn{} }
func (m *Syn) String() string { return proto.CompactTextString(m) }
func (*Syn) ProtoMessage() {}
func (*Syn) Descriptor() ([]byte, []int) {
return fileDescriptor_a77305914d5d202f, []int{0}
}
func (m *ShakeHand) XXX_Unmarshal(b []byte) error {
func (m *Syn) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ShakeHand) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
func (m *Syn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ShakeHand.Marshal(b, m, deterministic)
return xxx_messageInfo_Syn.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
......@@ -49,56 +49,56 @@ func (m *ShakeHand) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return b[:n], nil
}
}
func (m *ShakeHand) XXX_Merge(src proto.Message) {
xxx_messageInfo_ShakeHand.Merge(m, src)
func (m *Syn) XXX_Merge(src proto.Message) {
xxx_messageInfo_Syn.Merge(m, src)
}
func (m *ShakeHand) XXX_Size() int {
func (m *Syn) XXX_Size() int {
return m.Size()
}
func (m *ShakeHand) XXX_DiscardUnknown() {
xxx_messageInfo_ShakeHand.DiscardUnknown(m)
func (m *Syn) XXX_DiscardUnknown() {
xxx_messageInfo_Syn.DiscardUnknown(m)
}
var xxx_messageInfo_ShakeHand proto.InternalMessageInfo
var xxx_messageInfo_Syn proto.InternalMessageInfo
func (m *ShakeHand) GetAddress() []byte {
func (m *Syn) GetAddress() []byte {
if m != nil {
return m.Address
}
return nil
}
func (m *ShakeHand) GetNetworkID() int32 {
func (m *Syn) GetNetworkID() int32 {
if m != nil {
return m.NetworkID
}
return 0
}
func (m *ShakeHand) GetLight() bool {
func (m *Syn) GetLight() bool {
if m != nil {
return m.Light
}
return false
}
type ShakeHandAck struct {
ShakeHand *ShakeHand `protobuf:"bytes,1,opt,name=ShakeHand,proto3" json:"ShakeHand,omitempty"`
type SynPlusAck struct {
Syn *Syn `protobuf:"bytes,1,opt,name=Syn,proto3" json:"Syn,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) {
func (m *SynPlusAck) Reset() { *m = SynPlusAck{} }
func (m *SynPlusAck) String() string { return proto.CompactTextString(m) }
func (*SynPlusAck) ProtoMessage() {}
func (*SynPlusAck) Descriptor() ([]byte, []int) {
return fileDescriptor_a77305914d5d202f, []int{1}
}
func (m *ShakeHandAck) XXX_Unmarshal(b []byte) error {
func (m *SynPlusAck) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ShakeHandAck) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
func (m *SynPlusAck) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ShakeHandAck.Marshal(b, m, deterministic)
return xxx_messageInfo_SynPlusAck.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
......@@ -108,26 +108,26 @@ func (m *ShakeHandAck) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
return b[:n], nil
}
}
func (m *ShakeHandAck) XXX_Merge(src proto.Message) {
xxx_messageInfo_ShakeHandAck.Merge(m, src)
func (m *SynPlusAck) XXX_Merge(src proto.Message) {
xxx_messageInfo_SynPlusAck.Merge(m, src)
}
func (m *ShakeHandAck) XXX_Size() int {
func (m *SynPlusAck) XXX_Size() int {
return m.Size()
}
func (m *ShakeHandAck) XXX_DiscardUnknown() {
xxx_messageInfo_ShakeHandAck.DiscardUnknown(m)
func (m *SynPlusAck) XXX_DiscardUnknown() {
xxx_messageInfo_SynPlusAck.DiscardUnknown(m)
}
var xxx_messageInfo_ShakeHandAck proto.InternalMessageInfo
var xxx_messageInfo_SynPlusAck proto.InternalMessageInfo
func (m *ShakeHandAck) GetShakeHand() *ShakeHand {
func (m *SynPlusAck) GetSyn() *Syn {
if m != nil {
return m.ShakeHand
return m.Syn
}
return nil
}
func (m *ShakeHandAck) GetAck() *Ack {
func (m *SynPlusAck) GetAck() *Ack {
if m != nil {
return m.Ack
}
......@@ -179,31 +179,31 @@ func (m *Ack) GetAddress() []byte {
}
func init() {
proto.RegisterType((*ShakeHand)(nil), "pb.ShakeHand")
proto.RegisterType((*ShakeHandAck)(nil), "pb.ShakeHandAck")
proto.RegisterType((*Syn)(nil), "pb.Syn")
proto.RegisterType((*SynPlusAck)(nil), "pb.SynPlusAck")
proto.RegisterType((*Ack)(nil), "pb.Ack")
}
func init() { proto.RegisterFile("handshake.proto", fileDescriptor_a77305914d5d202f) }
var fileDescriptor_a77305914d5d202f = []byte{
// 201 bytes of a gzipped FileDescriptorProto
// 200 bytes of a gzipped FileDescriptorProto
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,
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, 0xf0, 0x04, 0xc1, 0xb8, 0x42, 0x32,
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,
0x46, 0x0d, 0x8e, 0x20, 0x08, 0x47, 0x29, 0x8c, 0x8b, 0x07, 0x6e, 0xb4, 0x63, 0x72, 0xb6, 0x90,
0x36, 0x92, 0x55, 0x60, 0xf3, 0xb9, 0x8d, 0x78, 0xf5, 0x0a, 0x92, 0xf4, 0xe0, 0x82, 0x41, 0x48,
0x4e, 0x91, 0xe4, 0x62, 0x76, 0x4c, 0xce, 0x06, 0x5b, 0xc5, 0x6d, 0xc4, 0x0e, 0x52, 0xe6, 0x98,
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, 0x3e, 0xb7, 0x4c, 0x93, 0x0b, 0x01, 0x00, 0x00,
}
func (m *ShakeHand) Marshal() (dAtA []byte, err error) {
0x0a, 0xe6, 0x62, 0x0e, 0xae, 0xcc, 0x13, 0x92, 0xe0, 0x62, 0x77, 0x4c, 0x49, 0x29, 0x4a, 0x2d,
0x2e, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x82, 0x71, 0x85, 0x64, 0xb8, 0x38, 0xfd, 0x52,
0x4b, 0xca, 0xf3, 0x8b, 0xb2, 0x3d, 0x5d, 0x24, 0x98, 0x14, 0x18, 0x35, 0x58, 0x83, 0x10, 0x02,
0x42, 0x22, 0x5c, 0xac, 0x3e, 0x99, 0xe9, 0x19, 0x25, 0x12, 0xcc, 0x0a, 0x8c, 0x1a, 0x1c, 0x41,
0x10, 0x8e, 0x92, 0x13, 0x17, 0x57, 0x70, 0x65, 0x5e, 0x40, 0x4e, 0x69, 0xb1, 0x63, 0x72, 0xb6,
0x90, 0x24, 0xd8, 0x0a, 0xb0, 0xb9, 0xdc, 0x46, 0xec, 0x7a, 0x05, 0x49, 0x7a, 0xc1, 0x95, 0x79,
0x41, 0x60, 0x6b, 0x25, 0xb9, 0x98, 0x1d, 0x93, 0xb3, 0xc1, 0xc6, 0x42, 0xa5, 0x1c, 0x93, 0xb3,
0x83, 0x40, 0x62, 0x4a, 0xf2, 0x60, 0x29, 0xdc, 0x0e, 0x73, 0x92, 0x38, 0xf1, 0x48, 0x8e, 0xf1,
0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e,
0xe1, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0xb0, 0xf7, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff,
0x1b, 0xbc, 0x78, 0x5e, 0xf1, 0x00, 0x00, 0x00,
}
func (m *Syn) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
......@@ -213,12 +213,12 @@ func (m *ShakeHand) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
func (m *ShakeHand) MarshalTo(dAtA []byte) (int, error) {
func (m *Syn) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ShakeHand) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *Syn) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
......@@ -248,7 +248,7 @@ func (m *ShakeHand) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *ShakeHandAck) Marshal() (dAtA []byte, err error) {
func (m *SynPlusAck) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
......@@ -258,12 +258,12 @@ func (m *ShakeHandAck) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
func (m *ShakeHandAck) MarshalTo(dAtA []byte) (int, error) {
func (m *SynPlusAck) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ShakeHandAck) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *SynPlusAck) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
......@@ -280,9 +280,9 @@ func (m *ShakeHandAck) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i--
dAtA[i] = 0x12
}
if m.ShakeHand != nil {
if m.Syn != nil {
{
size, err := m.ShakeHand.MarshalToSizedBuffer(dAtA[:i])
size, err := m.Syn.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
......@@ -336,7 +336,7 @@ func encodeVarintHandshake(dAtA []byte, offset int, v uint64) int {
dAtA[offset] = uint8(v)
return base
}
func (m *ShakeHand) Size() (n int) {
func (m *Syn) Size() (n int) {
if m == nil {
return 0
}
......@@ -355,14 +355,14 @@ func (m *ShakeHand) Size() (n int) {
return n
}
func (m *ShakeHandAck) Size() (n int) {
func (m *SynPlusAck) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.ShakeHand != nil {
l = m.ShakeHand.Size()
if m.Syn != nil {
l = m.Syn.Size()
n += 1 + l + sovHandshake(uint64(l))
}
if m.Ack != nil {
......@@ -391,7 +391,7 @@ func sovHandshake(x uint64) (n int) {
func sozHandshake(x uint64) (n int) {
return sovHandshake(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *ShakeHand) Unmarshal(dAtA []byte) error {
func (m *Syn) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
......@@ -414,10 +414,10 @@ func (m *ShakeHand) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ShakeHand: wiretype end group for non-group")
return fmt.Errorf("proto: Syn: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ShakeHand: illegal tag %d (wire type %d)", fieldNum, wire)
return fmt.Errorf("proto: Syn: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
......@@ -517,7 +517,7 @@ func (m *ShakeHand) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ShakeHandAck) Unmarshal(dAtA []byte) error {
func (m *SynPlusAck) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
......@@ -540,15 +540,15 @@ func (m *ShakeHandAck) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ShakeHandAck: wiretype end group for non-group")
return fmt.Errorf("proto: SynPlusAck: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ShakeHandAck: illegal tag %d (wire type %d)", fieldNum, wire)
return fmt.Errorf("proto: SynPlusAck: 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)
return fmt.Errorf("proto: wrong wireType = %d for field Syn", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
......@@ -575,10 +575,10 @@ func (m *ShakeHandAck) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.ShakeHand == nil {
m.ShakeHand = &ShakeHand{}
if m.Syn == nil {
m.Syn = &Syn{}
}
if err := m.ShakeHand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
if err := m.Syn.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
......
......@@ -5,14 +5,14 @@ syntax = "proto3";
package pb;
message ShakeHand {
message Syn {
bytes Address = 1;
int32 NetworkID = 2;
bool Light = 3;
}
message ShakeHandAck {
ShakeHand ShakeHand = 1;
message SynPlusAck {
Syn Syn = 1;
Ack Ack = 2;
}
......
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