Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
beb70c94
提交
beb70c94
authored
12月 09, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #436 from jbenet/feat/context-clues
add UUID to root context
上级
11df4d5b
fb45e7b7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
36 行增加
和
31 行删除
+36
-31
init.go
cmd/ipfs/init.go
+4
-1
main.go
cmd/ipfs/main.go
+25
-23
core.go
core/core.go
+2
-4
core_test.go
core/core_test.go
+4
-2
message.go
net/message/message.go
+1
-1
没有找到文件。
cmd/ipfs/init.go
浏览文件 @
beb70c94
...
...
@@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
cmds
"github.com/jbenet/go-ipfs/commands"
config
"github.com/jbenet/go-ipfs/config"
core
"github.com/jbenet/go-ipfs/core"
...
...
@@ -118,11 +119,13 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
// minted node. On success, it calls onSuccess
func
addTheWelcomeFile
(
conf
*
config
.
Config
)
error
{
// TODO extract this file creation operation into a function
nd
,
err
:=
core
.
NewIpfsNode
(
conf
,
false
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
nd
,
err
:=
core
.
NewIpfsNode
(
ctx
,
conf
,
false
)
if
err
!=
nil
{
return
err
}
defer
nd
.
Close
()
defer
cancel
()
// Set up default file
reader
:=
bytes
.
NewBufferString
(
welcomeMsg
)
...
...
cmd/ipfs/main.go
浏览文件 @
beb70c94
...
...
@@ -59,7 +59,7 @@ type cmdInvocation struct {
func
main
()
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
runtime
.
GOMAXPROCS
(
3
)
// FIXME rm arbitrary choice for n
ctx
:=
context
.
Background
(
)
ctx
:=
eventlog
.
ContextWithLoggable
(
context
.
Background
(),
eventlog
.
Uuid
(
"session"
)
)
var
err
error
var
invoc
cmdInvocation
defer
invoc
.
close
()
...
...
@@ -82,7 +82,7 @@ func main() {
}
// parse the commandline into a command invocation
parseErr
:=
invoc
.
Parse
(
os
.
Args
[
1
:
])
parseErr
:=
invoc
.
Parse
(
ctx
,
os
.
Args
[
1
:
])
// BEFORE handling the parse error, if we have enough information
// AND the user requested help, print it out and exit
...
...
@@ -172,25 +172,27 @@ func (i *cmdInvocation) Run(ctx context.Context) (output io.Reader, err error) {
return
res
.
Reader
()
}
func
(
i
*
cmdInvocation
)
constructNode
()
(
*
core
.
IpfsNode
,
error
)
{
if
i
.
req
==
nil
{
return
nil
,
errors
.
New
(
"constructing node without a request"
)
}
func
(
i
*
cmdInvocation
)
constructNodeFunc
(
ctx
context
.
Context
)
func
()
(
*
core
.
IpfsNode
,
error
)
{
return
func
()
(
*
core
.
IpfsNode
,
error
)
{
if
i
.
req
==
nil
{
return
nil
,
errors
.
New
(
"constructing node without a request"
)
}
ctx
:=
i
.
req
.
Context
()
if
ctx
==
nil
{
return
nil
,
errors
.
New
(
"constructing node without a request context"
)
}
cmd
ctx
:=
i
.
req
.
Context
()
if
cmd
ctx
==
nil
{
return
nil
,
errors
.
New
(
"constructing node without a request context"
)
}
cfg
,
err
:=
ctx
.
GetConfig
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"constructing node without a config: %s"
,
err
)
}
cfg
,
err
:=
cmd
ctx
.
GetConfig
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"constructing node without a config: %s"
,
err
)
}
// ok everything is good. set it on the invocation (for ownership)
// and return it.
i
.
node
,
err
=
core
.
NewIpfsNode
(
cfg
,
ctx
.
Online
)
return
i
.
node
,
err
// ok everything is good. set it on the invocation (for ownership)
// and return it.
i
.
node
,
err
=
core
.
NewIpfsNode
(
ctx
,
cfg
,
cmdctx
.
Online
)
return
i
.
node
,
err
}
}
func
(
i
*
cmdInvocation
)
close
()
{
...
...
@@ -203,7 +205,7 @@ func (i *cmdInvocation) close() {
}
}
func
(
i
*
cmdInvocation
)
Parse
(
args
[]
string
)
error
{
func
(
i
*
cmdInvocation
)
Parse
(
ctx
context
.
Context
,
args
[]
string
)
error
{
var
err
error
i
.
req
,
i
.
cmd
,
i
.
path
,
err
=
cmdsCli
.
Parse
(
args
,
os
.
Stdin
,
Root
)
...
...
@@ -218,12 +220,12 @@ func (i *cmdInvocation) Parse(args []string) error {
log
.
Debugf
(
"config path is %s"
,
configPath
)
// this sets up the function that will initialize the config lazily.
ctx
:=
i
.
req
.
Context
()
ctx
.
ConfigRoot
=
configPath
ctx
.
LoadConfig
=
loadConfig
c
mdc
tx
:=
i
.
req
.
Context
()
c
mdc
tx
.
ConfigRoot
=
configPath
c
mdc
tx
.
LoadConfig
=
loadConfig
// this sets up the function that will initialize the node
// this is so that we can construct the node lazily.
c
tx
.
ConstructNode
=
i
.
constructNode
c
mdctx
.
ConstructNode
=
i
.
constructNodeFunc
(
ctx
)
// if no encoding was specified by user, default to plaintext encoding
// (if command doesn't support plaintext, use JSON instead)
...
...
core/core.go
浏览文件 @
beb70c94
...
...
@@ -98,7 +98,7 @@ type Mounts struct {
}
// NewIpfsNode constructs a new IpfsNode based on the given config.
func
NewIpfsNode
(
cfg
*
config
.
Config
,
online
bool
)
(
n
*
IpfsNode
,
err
error
)
{
func
NewIpfsNode
(
c
tx
context
.
Context
,
c
fg
*
config
.
Config
,
online
bool
)
(
n
*
IpfsNode
,
err
error
)
{
success
:=
false
// flip to true after all sub-system inits succeed
defer
func
()
{
if
!
success
&&
n
!=
nil
{
...
...
@@ -110,14 +110,12 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
return
nil
,
debugerror
.
Errorf
(
"configuration required"
)
}
// derive this from a higher context.
ctx
:=
context
.
TODO
()
n
=
&
IpfsNode
{
onlineMode
:
online
,
Config
:
cfg
,
}
n
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
n
.
teardown
)
ctx
=
n
.
Context
()
ctx
=
n
.
Context
Closer
.
Context
()
// setup datastore.
if
n
.
Datastore
,
err
=
makeDatastore
(
cfg
.
Datastore
);
err
!=
nil
{
...
...
core/core_test.go
浏览文件 @
beb70c94
...
...
@@ -5,9 +5,11 @@ import (
config
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/peer"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
func
TestInitialization
(
t
*
testing
.
T
)
{
ctx
:=
context
.
TODO
()
id
:=
testIdentity
good
:=
[]
*
config
.
Config
{
...
...
@@ -44,14 +46,14 @@ func TestInitialization(t *testing.T) {
}
for
i
,
c
:=
range
good
{
n
,
err
:=
NewIpfsNode
(
c
,
false
)
n
,
err
:=
NewIpfsNode
(
c
tx
,
c
,
false
)
if
n
==
nil
||
err
!=
nil
{
t
.
Error
(
"Should have constructed."
,
i
,
err
)
}
}
for
i
,
c
:=
range
bad
{
n
,
err
:=
NewIpfsNode
(
c
,
false
)
n
,
err
:=
NewIpfsNode
(
c
tx
,
c
,
false
)
if
n
!=
nil
||
err
==
nil
{
t
.
Error
(
"Should have failed to construct."
,
i
)
}
...
...
net/message/message.go
浏览文件 @
beb70c94
...
...
@@ -39,7 +39,7 @@ func (m *message) Data() []byte {
func
(
m
*
message
)
Loggable
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"netMessage"
:
map
[
string
]
interface
{}{
"recipient"
:
m
.
Peer
(),
"recipient"
:
m
.
Peer
()
.
Loggable
()
,
// TODO sizeBytes? bytes? lenBytes?
"size"
:
len
(
m
.
Data
()),
},
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论