Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
2022d5b2
Commit
2022d5b2
authored
Jan 27, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move pingpong proto definitions into their own package
parent
889f2221
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
20 deletions
+29
-20
doc.go
pkg/pingpong/pb/doc.go
+8
-0
pingpong.pb.go
pkg/pingpong/pb/pingpong.pb.go
+10
-10
pingpong.proto
pkg/pingpong/pb/pingpong.proto
+1
-1
pingpong.go
pkg/pingpong/pingpong.go
+5
-5
pingpong_test.go
pkg/pingpong/pingpong_test.go
+5
-4
No files found.
pkg/pingpong/pb/doc.go
0 → 100644
View file @
2022d5b2
// 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
pkg/pingpong/pingpong.pb.go
→
pkg/pingpong/p
b/p
ingpong.pb.go
View file @
2022d5b2
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: pingpong.proto
package
p
ingpong
package
p
b
import
(
fmt
"fmt"
...
...
@@ -111,8 +111,8 @@ func (m *Pong) GetResponse() string {
}
func
init
()
{
proto
.
RegisterType
((
*
Ping
)(
nil
),
"p
ingpong
.Ping"
)
proto
.
RegisterType
((
*
Pong
)(
nil
),
"p
ingpong
.Pong"
)
proto
.
RegisterType
((
*
Ping
)(
nil
),
"p
b
.Ping"
)
proto
.
RegisterType
((
*
Pong
)(
nil
),
"p
b
.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
,
0x
e2
,
0x80
,
0xf1
,
0x95
,
0x94
,
0x
b8
,
0x58
,
0x02
,
0x32
,
0xf3
,
0xd2
,
0x85
,
0xa4
,
0xb8
,
0x38
,
0xdc
,
0x8b
,
0x52
,
0x53
,
0x4b
,
0x32
,
0x
f3
,
0xd2
,
0x25
,
0x18
,
0x15
,
0x18
,
0x35
,
0x38
,
0x83
,
0xe0
,
0x7c
,
0xb0
,
0x9a
,
0x7c
,
0x88
,
0x9
a
,
0x
a0
,
0xd4
,
0xe2
,
0x82
,
0xfc
,
0xbc
,
0xe2
,
0x54
,
0x98
,
0x1a
,
0x18
,
0xdf
,
0x49
,
0xe2
,
0xc4
,
0x23
,
0x
39
,
0xc6
,
0x0b
,
0x8f
,
0xe4
,
0x18
,
0x1f
,
0x3c
,
0x92
,
0x63
,
0x9c
,
0xf0
,
0x58
,
0x8e
,
0xe1
,
0xc2
,
0x
63
,
0x39
,
0x86
,
0x1b
,
0x8f
,
0xe5
,
0x18
,
0x92
,
0xd8
,
0xc0
,
0x56
,
0x1a
,
0x03
,
0x02
,
0x00
,
0x00
,
0xff
,
0xff
,
0x
a8
,
0xfc
,
0xee
,
0x94
,
0x84
,
0x00
,
0x00
,
0x00
,
0x2f
,
0xc8
,
0xcf
,
0x4b
,
0xd7
,
0x2b
,
0x28
,
0xca
,
0x2f
,
0xc9
,
0x17
,
0x
62
,
0x2a
,
0x48
,
0x52
,
0x52
,
0x
e2
,
0x62
,
0x09
,
0xc8
,
0xcc
,
0x4b
,
0x17
,
0x92
,
0xe2
,
0xe2
,
0x70
,
0x2f
,
0x4a
,
0x4d
,
0x2d
,
0xc9
,
0x
cc
,
0x4b
,
0x97
,
0x60
,
0x54
,
0x60
,
0xd4
,
0xe0
,
0x0c
,
0x82
,
0xf3
,
0xc1
,
0x6a
,
0xf2
,
0x21
,
0x6
a
,
0x
82
,
0x52
,
0x8b
,
0x0b
,
0xf2
,
0xf3
,
0x8a
,
0x53
,
0x61
,
0x6a
,
0x60
,
0x7c
,
0x27
,
0x89
,
0x13
,
0x8f
,
0x
e4
,
0x18
,
0x2f
,
0x3c
,
0x92
,
0x63
,
0x7c
,
0xf0
,
0x48
,
0x8e
,
0x71
,
0xc2
,
0x63
,
0x39
,
0x86
,
0x0b
,
0x
8f
,
0xe5
,
0x18
,
0x6e
,
0x3c
,
0x96
,
0x63
,
0x48
,
0x62
,
0x03
,
0x5b
,
0x66
,
0x0c
,
0x08
,
0x00
,
0x00
,
0xff
,
0xff
,
0x
8c
,
0xe4
,
0x0f
,
0x96
,
0x7e
,
0x00
,
0x00
,
0x00
,
}
func
(
m
*
Ping
)
Marshal
()
(
dAtA
[]
byte
,
err
error
)
{
...
...
pkg/pingpong/pingpong.proto
→
pkg/pingpong/p
b/p
ingpong.proto
View file @
2022d5b2
...
...
@@ -4,7 +4,7 @@
syntax
=
"proto3"
;
package
p
ingpong
;
package
p
b
;
message
Ping
{
string
Greeting
=
1
;
...
...
pkg/pingpong/pingpong.go
View file @
2022d5b2
...
...
@@ -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
)
...
...
pkg/pingpong/pingpong_test.go
View file @
2022d5b2
...
...
@@ -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
(
p
ingpong
.
Ping
)
},
func
()
protobuf
.
Message
{
return
new
(
p
b
.
Ping
)
},
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
gotGreetings
[]
string
for
_
,
m
:=
range
messages
{
gotGreetings
=
append
(
gotGreetings
,
m
.
(
*
p
ingpong
.
Ping
)
.
Greeting
)
gotGreetings
=
append
(
gotGreetings
,
m
.
(
*
p
b
.
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
(
p
ingpong
.
Pong
)
},
func
()
protobuf
.
Message
{
return
new
(
p
b
.
Pong
)
},
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
gotResponses
[]
string
for
_
,
m
:=
range
messages
{
gotResponses
=
append
(
gotResponses
,
m
.
(
*
p
ingpong
.
Pong
)
.
Response
)
gotResponses
=
append
(
gotResponses
,
m
.
(
*
p
b
.
Pong
)
.
Response
)
}
if
fmt
.
Sprint
(
gotResponses
)
!=
fmt
.
Sprint
(
wantResponses
)
{
t
.
Errorf
(
"got responses %v, want %v"
,
gotResponses
,
wantResponses
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment