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
0bb6a9cf
Commit
0bb6a9cf
authored
Jan 27, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add basic peer connect endpoint to debugapi
parent
a15ec594
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
6 deletions
+49
-6
debugapi.go
pkg/debugapi/debugapi.go
+4
-1
peer.go
pkg/debugapi/peer.go
+35
-0
router.go
pkg/debugapi/router.go
+7
-4
node.go
pkg/node/node.go
+3
-1
No files found.
pkg/debugapi/debugapi.go
View file @
0bb6a9cf
...
...
@@ -7,6 +7,7 @@ package debugapi
import
(
"net/http"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/prometheus/client_golang/prometheus"
)
...
...
@@ -22,7 +23,9 @@ type server struct {
metricsRegistry
*
prometheus
.
Registry
}
type
Options
struct
{}
type
Options
struct
{
P2P
p2p
.
Service
}
func
New
(
o
Options
)
Service
{
s
:=
&
server
{
...
...
pkg/debugapi/peer.go
0 → 100644
View file @
0bb6a9cf
// 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.
package
debugapi
import
(
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/multiformats/go-multiaddr"
)
type
peerConnectResponse
struct
{
Address
string
}
func
(
s
*
server
)
peerConnectHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
addr
,
err
:=
multiaddr
.
NewMultiaddr
(
"/"
+
mux
.
Vars
(
r
)[
"multi-address"
])
if
err
!=
nil
{
panic
(
err
)
}
address
,
err
:=
s
.
P2P
.
Connect
(
r
.
Context
(),
addr
)
if
err
!=
nil
{
panic
(
err
)
}
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
peerConnectResponse
{
Address
:
address
,
});
err
!=
nil
{
panic
(
err
)
}
}
pkg/debugapi/router.go
View file @
0bb6a9cf
...
...
@@ -10,6 +10,7 @@ import (
"net/http/pprof"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
"resenje.org/web"
)
...
...
@@ -22,7 +23,7 @@ func (s *server) setupRouting() {
promhttp
.
HandlerFor
(
s
.
metricsRegistry
,
promhttp
.
HandlerOpts
{}),
))
internalRouter
:=
http
.
NewServeMux
()
internalRouter
:=
mux
.
NewRouter
()
internalBaseRouter
.
Handle
(
"/"
,
web
.
ChainHandlers
(
handlers
.
CompressHandler
,
web
.
NoCacheHeadersHandler
,
...
...
@@ -30,9 +31,6 @@ func (s *server) setupRouting() {
))
internalRouter
.
Handle
(
"/"
,
http
.
NotFoundHandler
())
internalRouter
.
HandleFunc
(
"/health"
,
s
.
statusHandler
)
internalRouter
.
HandleFunc
(
"/readiness"
,
s
.
statusHandler
)
internalRouter
.
Handle
(
"/debug/pprof/"
,
http
.
HandlerFunc
(
pprof
.
Index
))
internalRouter
.
Handle
(
"/debug/pprof/cmdline"
,
http
.
HandlerFunc
(
pprof
.
Cmdline
))
internalRouter
.
Handle
(
"/debug/pprof/profile"
,
http
.
HandlerFunc
(
pprof
.
Profile
))
...
...
@@ -41,5 +39,10 @@ func (s *server) setupRouting() {
internalRouter
.
Handle
(
"/debug/vars"
,
expvar
.
Handler
())
internalRouter
.
HandleFunc
(
"/health"
,
s
.
statusHandler
)
internalRouter
.
HandleFunc
(
"/readiness"
,
s
.
statusHandler
)
internalRouter
.
HandleFunc
(
"/connect/{multi-address:.+}"
,
s
.
peerConnectHandler
)
s
.
Handler
=
internalBaseRouter
}
pkg/node/node.go
View file @
0bb6a9cf
...
...
@@ -103,7 +103,9 @@ func NewBee(o Options) (*Bee, error) {
if
o
.
DebugAPIAddr
!=
""
{
// Debug API server
debugAPIService
:=
debugapi
.
New
(
debugapi
.
Options
{})
debugAPIService
:=
debugapi
.
New
(
debugapi
.
Options
{
P2P
:
p2ps
,
})
// register metrics from components
debugAPIService
.
MustRegisterMetrics
(
p2ps
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
pingPong
.
Metrics
()
...
)
...
...
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