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-routing
Commits
025a8f9d
Commit
025a8f9d
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address PR comments and add in more user feedback
parent
6ba53523
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
8 deletions
+13
-8
dht/dht.go
dht/dht.go
+3
-3
dht/routing.go
dht/routing.go
+5
-2
mock/centralized_client.go
mock/centralized_client.go
+3
-2
routing.go
routing.go
+2
-1
No files found.
dht/dht.go
View file @
025a8f9d
...
...
@@ -103,8 +103,8 @@ func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.ID) error {
// Ping new peer to register in their routing table
// NOTE: this should be done better...
if
err
:=
dht
.
Ping
(
ctx
,
npeer
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to ping newly connected peer: %s
\n
"
,
err
)
if
_
,
err
:=
dht
.
Ping
(
ctx
,
npeer
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to ping newly connected peer: %s"
,
err
)
}
log
.
Event
(
ctx
,
"connect"
,
dht
.
self
,
npeer
)
dht
.
Update
(
ctx
,
npeer
)
...
...
@@ -329,7 +329,7 @@ func (dht *IpfsDHT) PingRoutine(t time.Duration) {
peers
:=
dht
.
routingTable
.
NearestPeers
(
kb
.
ConvertKey
(
u
.
Key
(
id
)),
5
)
for
_
,
p
:=
range
peers
{
ctx
,
_
:=
context
.
WithTimeout
(
dht
.
Context
(),
time
.
Second
*
5
)
err
:=
dht
.
Ping
(
ctx
,
p
)
_
,
err
:=
dht
.
Ping
(
ctx
,
p
)
if
err
!=
nil
{
log
.
Errorf
(
"Ping error: %s"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
dht/routing.go
View file @
025a8f9d
...
...
@@ -3,6 +3,7 @@ package dht
import
(
"math"
"sync"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -434,12 +435,14 @@ func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<
}
// Ping a peer, log the time it took
func
(
dht
*
IpfsDHT
)
Ping
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
func
(
dht
*
IpfsDHT
)
Ping
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
time
.
Duration
,
error
)
{
// Thoughts: maybe this should accept an ID and do a peer lookup?
log
.
Debugf
(
"ping %s start"
,
p
)
before
:=
time
.
Now
()
pmes
:=
pb
.
NewMessage
(
pb
.
Message_PING
,
""
,
0
)
_
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
log
.
Debugf
(
"ping %s end (err = %s)"
,
p
,
err
)
return
err
return
time
.
Now
()
.
Sub
(
before
),
err
}
This diff is collapsed.
Click to expand it.
mock/centralized_client.go
View file @
025a8f9d
...
...
@@ -2,6 +2,7 @@ package mockrouting
import
(
"errors"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
...
...
@@ -79,8 +80,8 @@ func (c *client) Provide(_ context.Context, key u.Key) error {
return
c
.
server
.
Announce
(
info
,
key
)
}
func
(
c
*
client
)
Ping
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
return
nil
func
(
c
*
client
)
Ping
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
time
.
Duration
,
error
)
{
return
0
,
nil
}
var
_
routing
.
IpfsRouting
=
&
client
{}
This diff is collapsed.
Click to expand it.
routing.go
View file @
025a8f9d
...
...
@@ -3,6 +3,7 @@ package routing
import
(
"errors"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -38,5 +39,5 @@ type IpfsRouting interface {
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
peer
.
PeerInfo
,
error
)
// Ping a peer, log the time it took
Ping
(
context
.
Context
,
peer
.
ID
)
error
Ping
(
context
.
Context
,
peer
.
ID
)
(
time
.
Duration
,
error
)
}
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