Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
405d49a9
Commit
405d49a9
authored
Nov 10, 2016
by
Jeromy Johnson
Committed by
GitHub
Nov 10, 2016
Browse files
Merge pull request #151 from libp2p/feat/optional-metrics
make bandwidth metrics optional
parents
647d20ae
077aae47
Changes
4
Show whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
405d49a9
...
...
@@ -58,7 +58,6 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
bwc
:
metrics
.
NewBandwidthCounter
(),
}
h
.
proc
=
goprocess
.
WithTeardown
(
func
()
error
{
...
...
@@ -90,6 +89,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
}
h
.
ids
.
Reporter
=
h
.
bwc
net
.
SetConnHandler
(
h
.
newConnHandler
)
net
.
SetStreamHandler
(
h
.
newStreamHandler
)
...
...
@@ -217,7 +218,11 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
s
.
SetProtocol
(
selpid
)
h
.
Peerstore
()
.
AddProtocols
(
p
,
selected
)
return
mstream
.
WrapStream
(
s
,
h
.
bwc
),
nil
if
h
.
bwc
!=
nil
{
s
=
mstream
.
WrapStream
(
s
,
h
.
bwc
)
}
return
s
,
nil
}
func
pidsToStrings
(
pids
[]
protocol
.
ID
)
[]
string
{
...
...
@@ -250,11 +255,13 @@ func (h *BasicHost) newStream(ctx context.Context, p peer.ID, pid protocol.ID) (
s
.
SetProtocol
(
pid
)
logStream
:=
mstream
.
WrapStream
(
s
,
h
.
bwc
)
if
h
.
bwc
!=
nil
{
s
=
mstream
.
WrapStream
(
s
,
h
.
bwc
)
}
lzcon
:=
msmux
.
NewMSSelect
(
logStream
,
string
(
pid
))
lzcon
:=
msmux
.
NewMSSelect
(
s
,
string
(
pid
))
return
&
streamWrapper
{
Stream
:
logStream
,
Stream
:
s
,
rw
:
lzcon
,
},
nil
}
...
...
p2p/host/routed/routed.go
View file @
405d49a9
...
...
@@ -9,7 +9,6 @@ import (
logging
"github.com/ipfs/go-log"
lgbl
"github.com/libp2p/go-libp2p-loggables"
metrics
"github.com/libp2p/go-libp2p-metrics"
inet
"github.com/libp2p/go-libp2p-net"
peer
"github.com/libp2p/go-libp2p-peer"
pstore
"github.com/libp2p/go-libp2p-peerstore"
...
...
@@ -18,7 +17,7 @@ import (
msmux
"github.com/whyrusleeping/go-multistream"
)
var
log
=
logging
.
Logger
(
"
github.com/libp2p/go-libp2p/p2p/host/
routed"
)
var
log
=
logging
.
Logger
(
"routed
host
"
)
// AddressTTL is the expiry time for our addresses.
// We expire them quickly.
...
...
@@ -126,8 +125,4 @@ func (rh *RoutedHost) Close() error {
return
rh
.
host
.
Close
()
}
func
(
rh
*
RoutedHost
)
GetBandwidthReporter
()
metrics
.
Reporter
{
return
rh
.
host
.
GetBandwidthReporter
()
}
var
_
(
host
.
Host
)
=
(
*
RoutedHost
)(
nil
)
p2p/protocol/identify/id.go
View file @
405d49a9
...
...
@@ -13,6 +13,7 @@ import (
ic
"github.com/libp2p/go-libp2p-crypto"
host
"github.com/libp2p/go-libp2p-host"
lgbl
"github.com/libp2p/go-libp2p-loggables"
metrics
"github.com/libp2p/go-libp2p-metrics"
mstream
"github.com/libp2p/go-libp2p-metrics/stream"
inet
"github.com/libp2p/go-libp2p-net"
peer
"github.com/libp2p/go-libp2p-peer"
...
...
@@ -42,6 +43,7 @@ const ClientVersion = "go-libp2p/3.3.4"
type
IDService
struct
{
Host
host
.
Host
Reporter
metrics
.
Reporter
// connections undergoing identification
// for wait purposes
currid
map
[
inet
.
Conn
]
chan
struct
{}
...
...
@@ -91,8 +93,9 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
s
.
SetProtocol
(
ID
)
bwc
:=
ids
.
Host
.
GetBandwidthReporter
()
s
=
mstream
.
WrapStream
(
s
,
bwc
)
if
ids
.
Reporter
!=
nil
{
s
=
mstream
.
WrapStream
(
s
,
ids
.
Reporter
)
}
// ok give the response to our handler.
if
err
:=
msmux
.
SelectProtoOrFail
(
ID
,
s
);
err
!=
nil
{
...
...
@@ -118,8 +121,9 @@ func (ids *IDService) RequestHandler(s inet.Stream) {
defer
s
.
Close
()
c
:=
s
.
Conn
()
bwc
:=
ids
.
Host
.
GetBandwidthReporter
()
s
=
mstream
.
WrapStream
(
s
,
bwc
)
if
ids
.
Reporter
!=
nil
{
s
=
mstream
.
WrapStream
(
s
,
ids
.
Reporter
)
}
w
:=
ggio
.
NewDelimitedWriter
(
s
)
mes
:=
pb
.
Identify
{}
...
...
package.json
View file @
405d49a9
...
...
@@ -211,9 +211,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
U5qKZsCG1Wg38jwg8XezBdc3fBGMMZjM7YFMAhunC1Yh
"
,
"hash"
:
"Qm
b6UFbVu1grhv5o5KnouvtZ6cqdrjXj6zLejAHWunxgCt
"
,
"name"
:
"go-libp2p-host"
,
"version"
:
"1.
2
.0"
"version"
:
"1.
3
.0"
},
{
"author"
:
"whyrusleeping"
,
...
...
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