Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
afe85ce1
Commit
afe85ce1
authored
10 years ago
by
Jeromy
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add in basic bandwidth tracking to the muxer
parent
4189d50d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
net/mux/mux.go
net/mux/mux.go
+27
-0
No files found.
net/mux/mux.go
View file @
afe85ce1
...
...
@@ -36,6 +36,12 @@ type Muxer struct {
ctx
context
.
Context
wg
sync
.
WaitGroup
bwiLock
sync
.
Mutex
bwIn
uint64
bwoLock
sync
.
Mutex
bwOut
uint64
*
msg
.
Pipe
}
...
...
@@ -76,6 +82,17 @@ func (m *Muxer) Start(ctx context.Context) error {
return
nil
}
func
(
m
*
Muxer
)
GetBandwidthTotals
()
(
in
uint64
,
out
uint64
)
{
m
.
bwiLock
.
Lock
()
in
=
m
.
bwIn
m
.
bwiLock
.
Unlock
()
m
.
bwoLock
.
Lock
()
out
=
m
.
bwOut
m
.
bwoLock
.
Unlock
()
return
}
// Stop stops muxer activity.
func
(
m
*
Muxer
)
Stop
()
{
if
m
.
cancel
==
nil
{
...
...
@@ -125,6 +142,11 @@ func (m *Muxer) handleIncomingMessages() {
// handleIncomingMessage routes message to the appropriate protocol.
func
(
m
*
Muxer
)
handleIncomingMessage
(
m1
msg
.
NetMessage
)
{
m
.
bwiLock
.
Lock
()
// TODO: compensate for overhead
m
.
bwIn
+=
uint64
(
len
(
m1
.
Data
()))
m
.
bwiLock
.
Unlock
()
data
,
pid
,
err
:=
unwrapData
(
m1
.
Data
())
if
err
!=
nil
{
log
.
Error
(
"muxer de-serializing error: %v"
,
err
)
...
...
@@ -173,6 +195,11 @@ func (m *Muxer) handleOutgoingMessage(pid ProtocolID, m1 msg.NetMessage) {
return
}
m
.
bwoLock
.
Lock
()
// TODO: compensate for overhead
m
.
bwOut
+=
uint64
(
len
(
data
))
m
.
bwoLock
.
Unlock
()
m2
:=
msg
.
New
(
m1
.
Peer
(),
data
)
select
{
case
m
.
GetPipe
()
.
Outgoing
<-
m2
:
...
...
This diff is collapsed.
Click to expand it.
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