Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6a894d6e
提交
6a894d6e
authored
5月 31, 2016
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2696 from ipfs/feature/Offline-2393
Offline daemon mode
上级
4974a02f
3a89cbbe
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
45 行增加
和
8 行删除
+45
-8
daemon.go
cmd/ipfs/daemon.go
+9
-2
core.go
core/core.go
+4
-0
gateway_handler.go
core/corehttp/gateway_handler.go
+6
-1
test-lib.sh
test/sharness/lib/test-lib.sh
+6
-5
t0040-add-and-cat.sh
test/sharness/t0040-add-and-cat.sh
+7
-0
t0061-daemon-opts.sh
test/sharness/t0061-daemon-opts.sh
+13
-0
没有找到文件。
cmd/ipfs/daemon.go
浏览文件 @
6a894d6e
...
@@ -42,6 +42,7 @@ const (
...
@@ -42,6 +42,7 @@ const (
unencryptTransportKwd
=
"disable-transport-encryption"
unencryptTransportKwd
=
"disable-transport-encryption"
enableGCKwd
=
"enable-gc"
enableGCKwd
=
"enable-gc"
adjustFDLimitKwd
=
"manage-fdlimit"
adjustFDLimitKwd
=
"manage-fdlimit"
offlineKwd
=
"offline"
// apiAddrKwd = "address-api"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
// swarmAddrKwd = "address-swarm"
)
)
...
@@ -136,6 +137,7 @@ future version, along with this notice. Please move to setting the HTTP Headers.
...
@@ -136,6 +137,7 @@ future version, along with this notice. Please move to setting the HTTP Headers.
cmds
.
BoolOption
(
unencryptTransportKwd
,
"Disable transport encryption (for debugging protocols)"
)
.
Default
(
false
),
cmds
.
BoolOption
(
unencryptTransportKwd
,
"Disable transport encryption (for debugging protocols)"
)
.
Default
(
false
),
cmds
.
BoolOption
(
enableGCKwd
,
"Enable automatic periodic repo garbage collection"
)
.
Default
(
false
),
cmds
.
BoolOption
(
enableGCKwd
,
"Enable automatic periodic repo garbage collection"
)
.
Default
(
false
),
cmds
.
BoolOption
(
adjustFDLimitKwd
,
"Check and raise file descriptor limits if needed"
)
.
Default
(
false
),
cmds
.
BoolOption
(
adjustFDLimitKwd
,
"Check and raise file descriptor limits if needed"
)
.
Default
(
false
),
cmds
.
BoolOption
(
offlineKwd
,
"Run offline. Do not connect to the rest of the network but provide local API."
)
.
Default
(
false
),
// TODO: add way to override addresses. tricky part: updating the config if also --init.
// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
...
@@ -226,9 +228,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
...
@@ -226,9 +228,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
// Start assembling node config
// Start assembling node config
ncfg
:=
&
core
.
BuildCfg
{
ncfg
:=
&
core
.
BuildCfg
{
Online
:
true
,
Repo
:
repo
,
Repo
:
repo
,
}
}
offline
,
_
,
_
:=
req
.
Option
(
offlineKwd
)
.
Bool
()
ncfg
.
Online
=
!
offline
routingOption
,
_
,
err
:=
req
.
Option
(
routingOptionKwd
)
.
String
()
routingOption
,
_
,
err
:=
req
.
Option
(
routingOptionKwd
)
.
String
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -416,6 +419,10 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
...
@@ -416,6 +419,10 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
// printSwarmAddrs prints the addresses of the host
// printSwarmAddrs prints the addresses of the host
func
printSwarmAddrs
(
node
*
core
.
IpfsNode
)
{
func
printSwarmAddrs
(
node
*
core
.
IpfsNode
)
{
if
!
node
.
OnlineMode
()
{
fmt
.
Println
(
"Swarm not listening, running in offline mode."
)
return
}
var
addrs
[]
string
var
addrs
[]
string
for
_
,
addr
:=
range
node
.
PeerHost
.
Addrs
()
{
for
_
,
addr
:=
range
node
.
PeerHost
.
Addrs
()
{
addrs
=
append
(
addrs
,
addr
.
String
())
addrs
=
append
(
addrs
,
addr
.
String
())
...
...
core/core.go
浏览文件 @
6a894d6e
...
@@ -510,6 +510,10 @@ func (n *IpfsNode) loadFilesRoot() error {
...
@@ -510,6 +510,10 @@ func (n *IpfsNode) loadFilesRoot() error {
// uses it to instantiate a routing system in offline mode.
// uses it to instantiate a routing system in offline mode.
// This is primarily used for offline ipns modifications.
// This is primarily used for offline ipns modifications.
func
(
n
*
IpfsNode
)
SetupOfflineRouting
()
error
{
func
(
n
*
IpfsNode
)
SetupOfflineRouting
()
error
{
if
n
.
Routing
!=
nil
{
// Routing was already set up
return
nil
}
err
:=
n
.
LoadPrivateKey
()
err
:=
n
.
LoadPrivateKey
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
core/corehttp/gateway_handler.go
浏览文件 @
6a894d6e
...
@@ -159,7 +159,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
...
@@ -159,7 +159,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
}
}
nd
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
))
nd
,
err
:=
core
.
Resolve
(
ctx
,
i
.
node
,
path
.
Path
(
urlPath
))
if
err
!=
nil
{
// If node is in offline mode the error code and message should be different
if
err
==
core
.
ErrNoNamesys
&&
!
i
.
node
.
OnlineMode
()
{
w
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
fmt
.
Fprint
(
w
,
"Could not resolve path. Node is in offline mode."
)
return
}
else
if
err
!=
nil
{
webError
(
w
,
"Path Resolve error"
,
err
,
http
.
StatusBadRequest
)
webError
(
w
,
"Path Resolve error"
,
err
,
http
.
StatusBadRequest
)
return
return
}
}
...
...
test/sharness/lib/test-lib.sh
浏览文件 @
6a894d6e
...
@@ -194,12 +194,13 @@ test_set_address_vars() {
...
@@ -194,12 +194,13 @@ test_set_address_vars() {
GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
'
'
if
ipfs swarm addrs
local
>
/dev/null 2>&1
;
then
test_expect_success
"set swarm address vars"
'
test_expect_success
"set swarm address vars"
'
ipfs swarm addrs local > addrs_out &&
ipfs swarm addrs local > addrs_out &&
SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
'
'
fi
}
}
test_launch_ipfs_daemon
()
{
test_launch_ipfs_daemon
()
{
...
...
test/sharness/t0040-add-and-cat.sh
浏览文件 @
6a894d6e
...
@@ -392,4 +392,11 @@ test_expect_success "ipfs cat file fails" '
...
@@ -392,4 +392,11 @@ test_expect_success "ipfs cat file fails" '
test_add_named_pipe
""
test_add_named_pipe
""
# Test daemon in offline mode
test_launch_ipfs_daemon
--offline
test_add_cat_file
test_kill_ipfs_daemon
test_done
test_done
test/sharness/t0061-daemon-opts.sh
浏览文件 @
6a894d6e
...
@@ -35,4 +35,17 @@ test_expect_success 'transport should be unencrypted' '
...
@@ -35,4 +35,17 @@ test_expect_success 'transport should be unencrypted' '
test_kill_ipfs_daemon
test_kill_ipfs_daemon
test_launch_ipfs_daemon
--offline
gwyaddr
=
$GWAY_ADDR
apiaddr
=
$API_ADDR
test_expect_success
'gateway should work in offline mode'
'
echo "hello mars :$gwyaddr :$apiaddr" >expected &&
HASH=$(ipfs add -q expected) &&
curl -sfo actual1 "http://$gwyaddr/ipfs/$HASH" &&
test_cmp expected actual1
'
test_kill_ipfs_daemon
test_done
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论