Commit 2022d5b2 authored by Janos Guljas's avatar Janos Guljas

move pingpong proto definitions into their own package

parent 889f2221
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate sh -c "protoc -I . -I \"$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)/protobuf\" --gogofaster_out=. pingpong.proto"
// Package pb holds only Protocol Buffer definitions and generated code.
package pb
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: pingpong.proto
package pingpong
package pb
import (
fmt "fmt"
......@@ -111,8 +111,8 @@ func (m *Pong) GetResponse() string {
}
func init() {
proto.RegisterType((*Ping)(nil), "pingpong.Ping")
proto.RegisterType((*Pong)(nil), "pingpong.Pong")
proto.RegisterType((*Ping)(nil), "pb.Ping")
proto.RegisterType((*Pong)(nil), "pb.Pong")
}
func init() { proto.RegisterFile("pingpong.proto", fileDescriptor_1cfbf639ab46154b) }
......@@ -120,13 +120,13 @@ func init() { proto.RegisterFile("pingpong.proto", fileDescriptor_1cfbf639ab4615
var fileDescriptor_1cfbf639ab46154b = []byte{
// 122 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0xc8, 0xcc, 0x4b,
0x2f, 0xc8, 0xcf, 0x4b, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf1, 0x95, 0x94,
0xb8, 0x58, 0x02, 0x32, 0xf3, 0xd2, 0x85, 0xa4, 0xb8, 0x38, 0xdc, 0x8b, 0x52, 0x53, 0x4b, 0x32,
0xf3, 0xd2, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xe0, 0x7c, 0xb0, 0x9a, 0x7c, 0x88, 0x9a,
0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x98, 0x1a, 0x18, 0xdf, 0x49, 0xe2, 0xc4, 0x23,
0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2,
0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0x92, 0xd8, 0xc0, 0x56, 0x1a, 0x03, 0x02, 0x00, 0x00,
0xff, 0xff, 0xa8, 0xfc, 0xee, 0x94, 0x84, 0x00, 0x00, 0x00,
0x2f, 0xc8, 0xcf, 0x4b, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2a, 0x48, 0x52, 0x52,
0xe2, 0x62, 0x09, 0xc8, 0xcc, 0x4b, 0x17, 0x92, 0xe2, 0xe2, 0x70, 0x2f, 0x4a, 0x4d, 0x2d, 0xc9,
0xcc, 0x4b, 0x97, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0xf3, 0xc1, 0x6a, 0xf2, 0x21, 0x6a,
0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x61, 0x6a, 0x60, 0x7c, 0x27, 0x89, 0x13, 0x8f,
0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b,
0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0x5b, 0x66, 0x0c, 0x08, 0x00, 0x00,
0xff, 0xff, 0x8c, 0xe4, 0x0f, 0x96, 0x7e, 0x00, 0x00, 0x00,
}
func (m *Ping) Marshal() (dAtA []byte, err error) {
......
......@@ -4,7 +4,7 @@
syntax = "proto3";
package pingpong;
package pb;
message Ping {
string Greeting = 1;
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate sh -c "protoc -I . -I \"$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)/protobuf\" --gogofaster_out=. pingpong.proto"
package pingpong
import (
......@@ -13,6 +12,7 @@ import (
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/protobuf"
"github.com/ethersphere/bee/pkg/pingpong/pb"
)
const (
......@@ -67,9 +67,9 @@ func (s *Service) Ping(ctx context.Context, address string, msgs ...string) (rtt
w, r := protobuf.NewWriterAndReader(stream)
var pong Pong
var pong pb.Pong
for _, msg := range msgs {
if err := w.WriteMsg(&Ping{
if err := w.WriteMsg(&pb.Ping{
Greeting: msg,
}); err != nil {
return 0, fmt.Errorf("write message: %w", err)
......@@ -93,7 +93,7 @@ func (s *Service) Handler(peer p2p.Peer, stream p2p.Stream) error {
w, r := protobuf.NewWriterAndReader(stream)
defer stream.Close()
var ping Ping
var ping pb.Ping
for {
if err := r.ReadMsg(&ping); err != nil {
if err == io.EOF {
......@@ -104,7 +104,7 @@ func (s *Service) Handler(peer p2p.Peer, stream p2p.Stream) error {
s.logger.Debugf("got ping: %q", ping.Greeting)
s.metrics.PingReceivedCount.Inc()
if err := w.WriteMsg(&Pong{
if err := w.WriteMsg(&pb.Pong{
Response: "{" + ping.Greeting + "}",
}); err != nil {
return fmt.Errorf("write message: %w", err)
......
......@@ -18,6 +18,7 @@ import (
"github.com/ethersphere/bee/pkg/p2p/mock"
"github.com/ethersphere/bee/pkg/p2p/protobuf"
"github.com/ethersphere/bee/pkg/pingpong"
"github.com/ethersphere/bee/pkg/pingpong/pb"
)
func TestPing(t *testing.T) {
......@@ -75,14 +76,14 @@ func TestPing(t *testing.T) {
wantGreetings := greetings
messages, err := protobuf.ReadMessages(
bytes.NewReader(record.In()),
func() protobuf.Message { return new(pingpong.Ping) },
func() protobuf.Message { return new(pb.Ping) },
)
if err != nil {
t.Fatal(err)
}
var gotGreetings []string
for _, m := range messages {
gotGreetings = append(gotGreetings, m.(*pingpong.Ping).Greeting)
gotGreetings = append(gotGreetings, m.(*pb.Ping).Greeting)
}
if fmt.Sprint(gotGreetings) != fmt.Sprint(wantGreetings) {
t.Errorf("got greetings %v, want %v", gotGreetings, wantGreetings)
......@@ -95,14 +96,14 @@ func TestPing(t *testing.T) {
}
messages, err = protobuf.ReadMessages(
bytes.NewReader(record.Out()),
func() protobuf.Message { return new(pingpong.Pong) },
func() protobuf.Message { return new(pb.Pong) },
)
if err != nil {
t.Fatal(err)
}
var gotResponses []string
for _, m := range messages {
gotResponses = append(gotResponses, m.(*pingpong.Pong).Response)
gotResponses = append(gotResponses, m.(*pb.Pong).Response)
}
if fmt.Sprint(gotResponses) != fmt.Sprint(wantResponses) {
t.Errorf("got responses %v, want %v", gotResponses, wantResponses)
......
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