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
p2p
go-p2p-kad-dht
Commits
c29e3e29
Commit
c29e3e29
authored
Jun 17, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement some simple dht request read timeouts
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
3f05aa05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
dht.go
dht.go
+40
-3
dht_net.go
dht_net.go
+9
-0
No files found.
dht.go
View file @
c29e3e29
...
...
@@ -107,6 +107,16 @@ func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID,
pmes
:=
pb
.
NewMessage
(
pb
.
Message_PUT_VALUE
,
string
(
key
),
0
)
pmes
.
Record
=
rec
rpmes
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
switch
err
{
case
ErrReadTimeout
:
log
.
Errorf
(
"read timeout: %s %s"
,
p
,
key
)
fallthrough
default
:
return
err
case
nil
:
break
}
if
err
!=
nil
{
return
err
}
...
...
@@ -164,7 +174,16 @@ func (dht *IpfsDHT) getValueSingle(ctx context.Context, p peer.ID,
defer
log
.
EventBegin
(
ctx
,
"getValueSingle"
,
p
,
&
key
)
.
Done
()
pmes
:=
pb
.
NewMessage
(
pb
.
Message_GET_VALUE
,
string
(
key
),
0
)
return
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
resp
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
switch
err
{
case
nil
:
return
resp
,
nil
case
ErrReadTimeout
:
log
.
Errorf
(
"read timeout: %s %s"
,
p
,
key
)
fallthrough
default
:
return
nil
,
err
}
}
// getLocal attempts to retrieve the value from the datastore
...
...
@@ -238,14 +257,32 @@ func (dht *IpfsDHT) findPeerSingle(ctx context.Context, p peer.ID, id peer.ID) (
defer
log
.
EventBegin
(
ctx
,
"findPeerSingle"
,
p
,
id
)
.
Done
()
pmes
:=
pb
.
NewMessage
(
pb
.
Message_FIND_NODE
,
string
(
id
),
0
)
return
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
resp
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
switch
err
{
case
nil
:
return
resp
,
nil
case
ErrReadTimeout
:
log
.
Errorf
(
"read timeout: %s %s"
,
p
,
id
)
fallthrough
default
:
return
nil
,
err
}
}
func
(
dht
*
IpfsDHT
)
findProvidersSingle
(
ctx
context
.
Context
,
p
peer
.
ID
,
key
key
.
Key
)
(
*
pb
.
Message
,
error
)
{
defer
log
.
EventBegin
(
ctx
,
"findProvidersSingle"
,
p
,
&
key
)
.
Done
()
pmes
:=
pb
.
NewMessage
(
pb
.
Message_GET_PROVIDERS
,
string
(
key
),
0
)
return
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
resp
,
err
:=
dht
.
sendRequest
(
ctx
,
p
,
pmes
)
switch
err
{
case
nil
:
return
resp
,
nil
case
ErrReadTimeout
:
log
.
Errorf
(
"read timeout: %s %s"
,
p
,
key
)
fallthrough
default
:
return
nil
,
err
}
}
// nearestPeersToQuery returns the routing tables closest peers.
...
...
dht_net.go
View file @
c29e3e29
package
dht
import
(
"fmt"
"sync"
"time"
...
...
@@ -12,6 +13,9 @@ import (
inet
"gx/ipfs/QmdBpVuSYuTGDA8Kn66CbKvEThXqKUh2nTANZEhzSxqrmJ/go-libp2p/p2p/net"
)
var
dhtReadMessageTimeout
=
time
.
Minute
var
ErrReadTimeout
=
fmt
.
Errorf
(
"timed out reading response"
)
// handleNewStream implements the inet.StreamHandler
func
(
dht
*
IpfsDHT
)
handleNewStream
(
s
inet
.
Stream
)
{
go
dht
.
handleNewMessage
(
s
)
...
...
@@ -232,10 +236,15 @@ func (ms *messageSender) ctxReadMsg(ctx context.Context, mes *pb.Message) error
errc
<-
r
.
ReadMsg
(
mes
)
}(
ms
.
r
)
t
:=
time
.
NewTimer
(
dhtReadMessageTimeout
)
defer
t
.
Stop
()
select
{
case
err
:=
<-
errc
:
return
err
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
t
.
C
:
return
ErrReadTimeout
}
}
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