Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
60830079
提交
60830079
authored
7月 20, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a global timeout flag for to be setting timeouts
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
13d49d9a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
38 行增加
和
19 行删除
+38
-19
handler.go
commands/http/handler.go
+28
-11
option.go
commands/option.go
+8
-5
block.go
core/commands/block.go
+1
-2
ls.go
core/commands/ls.go
+1
-1
没有找到文件。
commands/http/handler.go
浏览文件 @
60830079
...
...
@@ -7,6 +7,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/rs/cors"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
...
...
@@ -106,20 +107,36 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
ctx
,
cancel
:=
context
.
WithCancel
(
node
.
Context
())
defer
cancel
()
/*
TODO(cryptix): the next line looks very fishy to me..
It looks like the the context for the command request beeing prepared here is shared across all incoming requests..
I assume it really isn't because ServeHTTP() doesn't take a pointer receiver, but it's really subtule..
tout
,
found
,
err
:=
req
.
Option
(
"timeout"
)
.
String
()
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
var
ctx
context
.
Context
if
found
{
duration
,
err
:=
time
.
ParseDuration
(
tout
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"error parsing timeout option: %s"
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
Shouldn't the context be just put on the command request?
tctx
,
cancel
:=
context
.
WithTimeout
(
node
.
Context
(),
duration
)
defer
cancel
()
ctx
=
tctx
}
else
{
cctx
,
cancel
:=
context
.
WithCancel
(
node
.
Context
())
defer
cancel
()
ctx
=
cctx
}
ps: take note of the name clash - commands.Context != context.Context
*/
i
.
ctx
.
Context
=
ctx
req
.
SetContext
(
i
.
ctx
)
//
ps: take note of the name clash - commands.Context != context.Context
cmdctx
:=
i
.
ctx
cmd
ctx
.
Context
=
ctx
req
.
SetContext
(
cmd
ctx
)
// call the command
res
:=
i
.
root
.
Call
(
req
)
...
...
commands/option.go
浏览文件 @
60830079
...
...
@@ -154,22 +154,25 @@ func (ov OptionValue) String() (value string, found bool, err error) {
// Flag names
const
(
EncShort
=
"enc"
EncLong
=
"encoding"
RecShort
=
"r"
RecLong
=
"recursive"
ChanOpt
=
"stream-channels"
EncShort
=
"enc"
EncLong
=
"encoding"
RecShort
=
"r"
RecLong
=
"recursive"
ChanOpt
=
"stream-channels"
TimeoutOpt
=
"timeout"
)
// options that are used by this package
var
OptionEncodingType
=
StringOption
(
EncShort
,
EncLong
,
"The encoding type the output should be encoded with (json, xml, or text)"
)
var
OptionRecursivePath
=
BoolOption
(
RecShort
,
RecLong
,
"Add directory paths recursively"
)
var
OptionStreamChannels
=
BoolOption
(
ChanOpt
,
"Stream channel output"
)
var
OptionTimeout
=
StringOption
(
TimeoutOpt
,
"set a global timeout on the command"
)
// global options, added to every command
var
globalOptions
=
[]
Option
{
OptionEncodingType
,
OptionStreamChannels
,
OptionTimeout
,
}
// the above array of Options, wrapped in a Command
...
...
core/commands/block.go
浏览文件 @
60830079
...
...
@@ -9,7 +9,6 @@ import (
"strings"
mh
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/blocks"
key
"github.com/ipfs/go-ipfs/blocks/key"
cmds
"github.com/ipfs/go-ipfs/commands"
...
...
@@ -178,7 +177,7 @@ func getBlockForKey(req cmds.Request, skey string) (*blocks.Block, error) {
}
k
:=
key
.
Key
(
h
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
context
.
TODO
()
,
k
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
req
.
Context
()
.
Context
,
k
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
core/commands/ls.go
浏览文件 @
60830079
...
...
@@ -81,7 +81,7 @@ it contains, with the following format:
Links
:
make
([]
LsLink
,
len
(
dagnode
.
Links
)),
}
for
j
,
link
:=
range
dagnode
.
Links
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
TODO
()
,
time
.
Minute
)
ctx
,
cancel
:=
context
.
WithTimeout
(
req
.
Context
()
.
Context
,
time
.
Minute
)
defer
cancel
()
link
.
Node
,
err
=
link
.
GetNode
(
ctx
,
node
.
DAG
)
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论