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-dms3
Commits
c4fa995f
Commit
c4fa995f
authored
Sep 16, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Peer: change locking to whole Peer object.
parent
5dea3845
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
peer/peer.go
peer/peer.go
+14
-6
No files found.
peer/peer.go
View file @
c4fa995f
...
...
@@ -38,8 +38,9 @@ type Peer struct {
PrivKey
ic
.
PrivKey
PubKey
ic
.
PubKey
latency
time
.
Duration
latenLock
sync
.
RWMutex
latency
time
.
Duration
sync
.
RWMutex
}
// Key returns the ID as a Key (string) for maps.
...
...
@@ -49,6 +50,9 @@ func (p *Peer) Key() u.Key {
// AddAddress adds the given Multiaddr address to Peer's addresses.
func
(
p
*
Peer
)
AddAddress
(
a
*
ma
.
Multiaddr
)
{
p
.
Lock
()
defer
p
.
Unlock
()
for
_
,
addr
:=
range
p
.
Addresses
{
if
addr
.
Equal
(
a
)
{
return
...
...
@@ -59,6 +63,9 @@ func (p *Peer) AddAddress(a *ma.Multiaddr) {
// NetAddress returns the first Multiaddr found for a given network.
func
(
p
*
Peer
)
NetAddress
(
n
string
)
*
ma
.
Multiaddr
{
p
.
RLock
()
defer
p
.
RUnlock
()
for
_
,
a
:=
range
p
.
Addresses
{
ps
,
err
:=
a
.
Protocols
()
if
err
!=
nil
{
...
...
@@ -76,17 +83,18 @@ func (p *Peer) NetAddress(n string) *ma.Multiaddr {
// GetLatency retrieves the current latency measurement.
func
(
p
*
Peer
)
GetLatency
()
(
out
time
.
Duration
)
{
p
.
latenLock
.
RLock
()
p
.
RLock
()
out
=
p
.
latency
p
.
latenLock
.
RUnlock
()
p
.
RUnlock
()
return
}
// SetLatency sets the latency measurement.
// TODO: Instead of just keeping a single number,
// keep a running average over the last hour or so
// Yep, should be EWMA or something. (-jbenet)
func
(
p
*
Peer
)
SetLatency
(
laten
time
.
Duration
)
{
p
.
latenLock
.
Lock
()
p
.
Lock
()
p
.
latency
=
laten
p
.
latenLock
.
Unlock
()
p
.
Unlock
()
}
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