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
8d746790
Unverified
Commit
8d746790
authored
Jun 10, 2020
by
Janoš Guljaš
Committed by
GitHub
Jun 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move pingpong api to debug api (#280)
parent
b5f84f47
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
38 additions
and
40 deletions
+38
-40
README.md
README.md
+2
-2
api.go
pkg/api/api.go
+4
-6
api_test.go
pkg/api/api_test.go
+3
-4
export_test.go
pkg/api/export_test.go
+2
-3
metrics.go
pkg/api/metrics.go
+0
-6
router.go
pkg/api/router.go
+0
-4
debugapi.go
pkg/debugapi/debugapi.go
+4
-0
debugapi_test.go
pkg/debugapi/debugapi_test.go
+3
-0
export_test.go
pkg/debugapi/export_test.go
+1
-0
pingpong.go
pkg/debugapi/pingpong.go
+1
-2
pingpong_test.go
pkg/debugapi/pingpong_test.go
+8
-8
router.go
pkg/debugapi/router.go
+4
-0
node.go
pkg/node/node.go
+6
-5
No files found.
README.md
View file @
8d746790
...
...
@@ -162,10 +162,10 @@ curl localhost:6062/addresses
Make sure that Debug API is enabled and address configured as in examples above.
And use that address in the API call on another node, for example, local node 1:
And use that address in the
Debug
API call on another node, for example, local node 1:
```
sh
curl
-XPOST
localhost:
808
1/pingpong/d4440baf2d79e481c3c6fd93a2014d2e6fe0386418829439f26d13a8253d04f1
curl
-XPOST
localhost:
606
1/pingpong/d4440baf2d79e481c3c6fd93a2014d2e6fe0386418829439f26d13a8253d04f1
```
## Generating protobuf
...
...
pkg/api/api.go
View file @
8d746790
...
...
@@ -9,7 +9,6 @@ import (
"github.com/ethersphere/bee/pkg/logging"
m
"github.com/ethersphere/bee/pkg/metrics"
"github.com/ethersphere/bee/pkg/pingpong"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/tags"
"github.com/ethersphere/bee/pkg/tracing"
...
...
@@ -27,7 +26,6 @@ type server struct {
}
type
Options
struct
{
Pingpong
pingpong
.
Interface
Tags
*
tags
.
Tags
Storer
storage
.
Storer
Logger
logging
.
Logger
...
...
pkg/api/api_test.go
View file @
8d746790
...
...
@@ -31,7 +31,6 @@ func newTestServer(t *testing.T, o testServerOptions) *http.Client {
o
.
Logger
=
logging
.
New
(
ioutil
.
Discard
,
0
)
}
s
:=
api
.
New
(
api
.
Options
{
Pingpong
:
o
.
Pingpong
,
Tags
:
o
.
Tags
,
Storer
:
o
.
Storer
,
Logger
:
o
.
Logger
,
...
...
pkg/api/export_test.go
View file @
8d746790
...
...
@@ -5,7 +5,6 @@
package
api
type
(
PingpongResponse
=
pingpongResponse
RawPostResponse
=
rawPostResponse
TagResponse
=
tagResponse
)
pkg/api/metrics.go
View file @
8d746790
...
...
@@ -38,12 +38,6 @@ func newMetrics() metrics {
Help
:
"Histogram of API response durations."
,
Buckets
:
[]
float64
{
0.01
,
0.1
,
0.25
,
0.5
,
1
,
2.5
,
5
,
10
},
}),
PingRequestCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
m
.
Namespace
,
Subsystem
:
subsystem
,
Name
:
"ping_request_count"
,
Help
:
"Number HTTP API ping requests."
,
}),
}
}
...
...
pkg/api/router.go
View file @
8d746790
...
...
@@ -28,10 +28,6 @@ func (s *server) setupRouting() {
fmt
.
Fprintln
(
w
,
"User-agent: *
\n
Disallow: /"
)
})
router
.
Handle
(
"/pingpong/{peer-id}"
,
jsonhttp
.
MethodHandler
{
"POST"
:
http
.
HandlerFunc
(
s
.
pingpongHandler
),
})
router
.
Handle
(
"/bzz-raw"
,
jsonhttp
.
MethodHandler
{
"POST"
:
http
.
HandlerFunc
(
s
.
rawUploadHandler
),
})
...
...
pkg/debugapi/debugapi.go
View file @
8d746790
...
...
@@ -10,10 +10,12 @@ import (
"github.com/ethersphere/bee/pkg/addressbook"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/pingpong"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags"
"github.com/ethersphere/bee/pkg/topology"
"github.com/ethersphere/bee/pkg/tracing"
"github.com/prometheus/client_golang/prometheus"
)
...
...
@@ -32,10 +34,12 @@ type server struct {
type
Options
struct
{
Overlay
swarm
.
Address
P2P
p2p
.
Service
Pingpong
pingpong
.
Interface
Addressbook
addressbook
.
GetPutter
TopologyDriver
topology
.
Notifier
Storer
storage
.
Storer
Logger
logging
.
Logger
Tracer
*
tracing
.
Tracer
Tags
*
tags
.
Tags
}
...
...
pkg/debugapi/debugapi_test.go
View file @
8d746790
...
...
@@ -16,6 +16,7 @@ import (
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/pingpong"
mockstore
"github.com/ethersphere/bee/pkg/statestore/mock"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
...
...
@@ -29,6 +30,7 @@ import (
type
testServerOptions
struct
{
Overlay
swarm
.
Address
P2P
p2p
.
Service
Pingpong
pingpong
.
Interface
Storer
storage
.
Storer
TopologyOpts
[]
mock
.
Option
Tags
*
tags
.
Tags
...
...
@@ -48,6 +50,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
s
:=
debugapi
.
New
(
debugapi
.
Options
{
Overlay
:
o
.
Overlay
,
P2P
:
o
.
P2P
,
Pingpong
:
o
.
Pingpong
,
Tags
:
o
.
Tags
,
Logger
:
logging
.
New
(
ioutil
.
Discard
,
0
),
Addressbook
:
addrbook
,
...
...
pkg/debugapi/export_test.go
View file @
8d746790
...
...
@@ -6,6 +6,7 @@ package debugapi
type
(
StatusResponse
=
statusResponse
PingpongResponse
=
pingpongResponse
PeerConnectResponse
=
peerConnectResponse
PeersResponse
=
peersResponse
AddressesResponse
=
addressesResponse
...
...
pkg/api/pingpong.go
→
pkg/
debug
api/pingpong.go
View file @
8d746790
...
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
api
package
debug
api
import
(
"errors"
...
...
@@ -44,7 +44,6 @@ func (s *server) pingpongHandler(w http.ResponseWriter, r *http.Request) {
jsonhttp
.
InternalServerError
(
w
,
nil
)
return
}
s
.
metrics
.
PingRequestCount
.
Inc
()
logger
.
Infof
(
"pingpong succeeded to peer %s"
,
peerID
)
jsonhttp
.
OK
(
w
,
pingpongResponse
{
...
...
pkg/api/pingpong_test.go
→
pkg/
debug
api/pingpong_test.go
View file @
8d746790
...
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
api_test
package
debug
api_test
import
(
"context"
...
...
@@ -11,7 +11,7 @@ import (
"testing"
"time"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/
debug
api"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/p2p"
...
...
@@ -36,39 +36,39 @@ func TestPingpong(t *testing.T) {
return
rtt
,
nil
})
client
:=
newTestServer
(
t
,
testServerOptions
{
ts
:=
newTestServer
(
t
,
testServerOptions
{
Pingpong
:
pingpongService
,
})
t
.
Run
(
"ok"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
client
,
http
.
MethodPost
,
"/pingpong/"
+
peerID
.
String
(),
nil
,
http
.
StatusOK
,
api
.
PingpongResponse
{
jsonhttptest
.
ResponseDirect
(
t
,
ts
.
Client
,
http
.
MethodPost
,
"/pingpong/"
+
peerID
.
String
(),
nil
,
http
.
StatusOK
,
debug
api
.
PingpongResponse
{
RTT
:
rtt
.
String
(),
})
})
t
.
Run
(
"peer not found"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
c
lient
,
http
.
MethodPost
,
"/pingpong/"
+
unknownPeerID
.
String
(),
nil
,
http
.
StatusNotFound
,
jsonhttp
.
StatusResponse
{
jsonhttptest
.
ResponseDirect
(
t
,
ts
.
C
lient
,
http
.
MethodPost
,
"/pingpong/"
+
unknownPeerID
.
String
(),
nil
,
http
.
StatusNotFound
,
jsonhttp
.
StatusResponse
{
Code
:
http
.
StatusNotFound
,
Message
:
"peer not found"
,
})
})
t
.
Run
(
"invalid peer address"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
c
lient
,
http
.
MethodPost
,
"/pingpong/invalid-address"
,
nil
,
http
.
StatusBadRequest
,
jsonhttp
.
StatusResponse
{
jsonhttptest
.
ResponseDirect
(
t
,
ts
.
C
lient
,
http
.
MethodPost
,
"/pingpong/invalid-address"
,
nil
,
http
.
StatusBadRequest
,
jsonhttp
.
StatusResponse
{
Code
:
http
.
StatusBadRequest
,
Message
:
"invalid peer address"
,
})
})
t
.
Run
(
"error"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
c
lient
,
http
.
MethodPost
,
"/pingpong/"
+
errorPeerID
.
String
(),
nil
,
http
.
StatusInternalServerError
,
jsonhttp
.
StatusResponse
{
jsonhttptest
.
ResponseDirect
(
t
,
ts
.
C
lient
,
http
.
MethodPost
,
"/pingpong/"
+
errorPeerID
.
String
(),
nil
,
http
.
StatusInternalServerError
,
jsonhttp
.
StatusResponse
{
Code
:
http
.
StatusInternalServerError
,
Message
:
http
.
StatusText
(
http
.
StatusInternalServerError
),
// do not leak internal error
})
})
t
.
Run
(
"get method not allowed"
,
func
(
t
*
testing
.
T
)
{
jsonhttptest
.
ResponseDirect
(
t
,
c
lient
,
http
.
MethodGet
,
"/pingpong/"
+
peerID
.
String
(),
nil
,
http
.
StatusMethodNotAllowed
,
jsonhttp
.
StatusResponse
{
jsonhttptest
.
ResponseDirect
(
t
,
ts
.
C
lient
,
http
.
MethodGet
,
"/pingpong/"
+
peerID
.
String
(),
nil
,
http
.
StatusMethodNotAllowed
,
jsonhttp
.
StatusResponse
{
Code
:
http
.
StatusMethodNotAllowed
,
Message
:
http
.
StatusText
(
http
.
StatusMethodNotAllowed
),
})
...
...
pkg/debugapi/router.go
View file @
8d746790
...
...
@@ -50,6 +50,10 @@ func (s *server) setupRouting() {
web
.
FinalHandlerFunc
(
s
.
statusHandler
),
))
router
.
Handle
(
"/pingpong/{peer-id}"
,
jsonhttp
.
MethodHandler
{
"POST"
:
http
.
HandlerFunc
(
s
.
pingpongHandler
),
})
router
.
Handle
(
"/addresses"
,
jsonhttp
.
MethodHandler
{
"GET"
:
http
.
HandlerFunc
(
s
.
addressesHandler
),
})
...
...
pkg/node/node.go
View file @
8d746790
...
...
@@ -242,7 +242,6 @@ func NewBee(o Options) (*Bee, error) {
if
o
.
APIAddr
!=
""
{
// API server
apiService
=
api
.
New
(
api
.
Options
{
Pingpong
:
pingPong
,
Tags
:
tag
,
Storer
:
ns
,
Logger
:
logger
,
...
...
@@ -275,7 +274,9 @@ func NewBee(o Options) (*Bee, error) {
debugAPIService
:=
debugapi
.
New
(
debugapi
.
Options
{
Overlay
:
address
,
P2P
:
p2ps
,
Pingpong
:
pingPong
,
Logger
:
logger
,
Tracer
:
tracer
,
Addressbook
:
addressbook
,
TopologyDriver
:
topologyDriver
,
Storer
:
storer
,
...
...
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