Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
07430569
提交
07430569
authored
6月 29, 2019
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: ignore stale APIs
fixes #5784
上级
8e5ea5f2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
85 行增加
和
135 行删除
+85
-135
main.go
cmd/ipfs/main.go
+82
-131
go.mod
go.mod
+1
-2
go.sum
go.sum
+2
-2
没有找到文件。
cmd/ipfs/main.go
浏览文件 @
07430569
...
...
@@ -21,7 +21,6 @@ import (
repo
"github.com/ipfs/go-ipfs/repo"
fsrepo
"github.com/ipfs/go-ipfs/repo/fsrepo"
osh
"github.com/Kubuxu/go-os-helper"
"github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-cmds/cli"
"github.com/ipfs/go-ipfs-cmds/http"
...
...
@@ -195,21 +194,90 @@ func checkDebug(req *cmds.Request) {
}
}
func
apiAddrOption
(
req
*
cmds
.
Request
)
(
ma
.
Multiaddr
,
error
)
{
apiAddrStr
,
apiSpecified
:=
req
.
Options
[
corecmds
.
ApiOption
]
.
(
string
)
if
!
apiSpecified
{
return
nil
,
nil
}
return
ma
.
NewMultiaddr
(
apiAddrStr
)
}
func
makeExecutor
(
req
*
cmds
.
Request
,
env
interface
{})
(
cmds
.
Executor
,
error
)
{
exe
:=
cmds
.
NewExecutor
(
req
.
Root
)
cctx
:=
env
.
(
*
oldcmds
.
Context
)
details
:=
commandDetails
(
req
.
Path
)
client
,
err
:=
commandShouldRunOnDaemon
(
*
details
,
req
,
env
.
(
*
oldcmds
.
Context
))
// Check if the command is disabled.
if
details
.
cannotRunOnClient
&&
details
.
cannotRunOnDaemon
{
return
nil
,
fmt
.
Errorf
(
"command disabled: %v"
,
req
.
Path
)
}
// Can we just run this locally?
if
!
details
.
cannotRunOnClient
&&
details
.
doesNotUseRepo
{
return
exe
,
nil
}
// Get the API option from the commandline.
apiAddr
,
err
:=
apiAddrOption
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
var
exctr
cmds
.
Executor
if
client
!=
nil
&&
!
req
.
Command
.
External
{
exctr
=
client
.
(
cmds
.
Executor
)
}
else
{
exctr
=
cmds
.
NewExecutor
(
req
.
Root
)
// Force the daemon when the API flag is passed (unless we're trying to
// _run_ the daemon).
daemonForced
:=
apiAddr
!=
nil
&&
req
.
Command
!=
daemonCmd
// Run this on the client if required.
if
details
.
cannotRunOnDaemon
||
req
.
Command
.
External
{
if
daemonForced
{
// User requested that the command be run on the daemon but we can't.
// NOTE: We drop this check for the `ipfs daemon` command.
return
nil
,
errors
.
New
(
"api flag specified but command cannot be run on the daemon"
)
}
return
exe
,
nil
}
// Finally, look in the repo for an API file.
if
apiAddr
==
nil
{
var
err
error
apiAddr
,
err
=
fsrepo
.
APIAddr
(
cctx
.
ConfigRoot
)
switch
err
{
case
nil
,
repo
.
ErrApiNotRunning
:
default
:
return
nil
,
err
}
}
return
exctr
,
nil
// Still no api specified? Run it on the client or fail.
if
apiAddr
==
nil
{
if
details
.
cannotRunOnClient
{
return
nil
,
fmt
.
Errorf
(
"command must be run on the daemon: %v"
,
req
.
Path
)
}
return
exe
,
nil
}
// Resolve the API addr.
apiAddr
,
err
=
resolveAddr
(
req
.
Context
,
apiAddr
)
if
err
!=
nil
{
return
nil
,
err
}
_
,
host
,
err
:=
manet
.
DialArgs
(
apiAddr
)
if
err
!=
nil
{
return
nil
,
err
}
// Construct the executor.
opts
:=
[]
http
.
ClientOpt
{
http
.
ClientWithAPIPrefix
(
corehttp
.
APIPath
),
}
// Fallback on a local executor if we (a) have a repo and (b) aren't
// forcing a daemon.
if
!
daemonForced
&&
fsrepo
.
IsInitialized
(
cctx
.
ConfigRoot
)
{
opts
=
append
(
opts
,
http
.
ClientWithFallback
(
exe
))
}
return
http
.
NewClient
(
host
,
opts
...
),
nil
}
func
checkPermissions
(
path
string
)
(
bool
,
error
)
{
...
...
@@ -227,7 +295,11 @@ func checkPermissions(path string) (bool, error) {
}
// commandDetails returns a command's details for the command given by |path|.
func
commandDetails
(
path
[]
string
)
*
cmdDetails
{
func
commandDetails
(
path
[]
string
)
cmdDetails
{
if
len
(
path
)
==
0
{
// special case root command
return
cmdDetails
{
doesNotUseRepo
:
true
}
}
var
details
cmdDetails
// find the last command in path that has a cmdDetailsMap entry
for
i
:=
range
path
{
...
...
@@ -235,67 +307,7 @@ func commandDetails(path []string) *cmdDetails {
details
=
cmdDetails
}
}
return
&
details
}
// commandShouldRunOnDaemon determines, from command details, whether a
// command ought to be executed on an ipfs daemon.
//
// It returns a client if the command should be executed on a daemon and nil if
// it should be executed on a client. It returns an error if the command must
// NOT be executed on either.
func
commandShouldRunOnDaemon
(
details
cmdDetails
,
req
*
cmds
.
Request
,
cctx
*
oldcmds
.
Context
)
(
http
.
Client
,
error
)
{
path
:=
req
.
Path
// root command.
if
len
(
path
)
<
1
{
return
nil
,
nil
}
if
details
.
cannotRunOnClient
&&
details
.
cannotRunOnDaemon
{
return
nil
,
fmt
.
Errorf
(
"command disabled: %s"
,
path
[
0
])
}
if
details
.
doesNotUseRepo
&&
details
.
canRunOnClient
()
{
return
nil
,
nil
}
// at this point need to know whether api is running. we defer
// to this point so that we don't check unnecessarily
// did user specify an api to use for this command?
apiAddrStr
,
_
:=
req
.
Options
[
corecmds
.
ApiOption
]
.
(
string
)
client
,
err
:=
getAPIClient
(
req
.
Context
,
cctx
.
ConfigRoot
,
apiAddrStr
)
if
err
==
repo
.
ErrApiNotRunning
{
if
apiAddrStr
!=
""
&&
req
.
Command
!=
daemonCmd
{
// if user SPECIFIED an api, and this cmd is not daemon
// we MUST use it. so error out.
return
nil
,
err
}
// ok for api not to be running
}
else
if
err
!=
nil
{
// some other api error
return
nil
,
err
}
if
client
!=
nil
{
if
details
.
cannotRunOnDaemon
{
// check if daemon locked. legacy error text, for now.
log
.
Debugf
(
"Command cannot run on daemon. Checking if daemon is locked"
)
if
daemonLocked
,
_
:=
fsrepo
.
LockedByOtherProcess
(
cctx
.
ConfigRoot
);
daemonLocked
{
return
nil
,
cmds
.
ClientError
(
"ipfs daemon is running. please stop it to run this command"
)
}
return
nil
,
nil
}
return
client
,
nil
}
if
details
.
cannotRunOnClient
{
return
nil
,
cmds
.
ClientError
(
"must run on the ipfs daemon"
)
}
return
nil
,
nil
return
details
}
func
getRepoPath
(
req
*
cmds
.
Request
)
(
string
,
error
)
{
...
...
@@ -366,67 +378,6 @@ func profileIfEnabled() (func(), error) {
return
func
()
{},
nil
}
var
apiFileErrorFmt
string
=
`Failed to parse '%[1]s/api' file.
error: %[2]s
If you're sure go-ipfs isn't running, you can just delete it.
`
var
checkIPFSUnixFmt
=
"Otherwise check:
\n\t
ps aux | grep ipfs"
var
checkIPFSWinFmt
=
"Otherwise check:
\n\t
tasklist | findstr ipfs"
// getAPIClient checks the repo, and the given options, checking for
// a running API service. if there is one, it returns a client.
// otherwise, it returns errApiNotRunning, or another error.
func
getAPIClient
(
ctx
context
.
Context
,
repoPath
,
apiAddrStr
string
)
(
http
.
Client
,
error
)
{
var
apiErrorFmt
string
switch
{
case
osh
.
IsUnix
()
:
apiErrorFmt
=
apiFileErrorFmt
+
checkIPFSUnixFmt
case
osh
.
IsWindows
()
:
apiErrorFmt
=
apiFileErrorFmt
+
checkIPFSWinFmt
default
:
apiErrorFmt
=
apiFileErrorFmt
}
var
addr
ma
.
Multiaddr
var
err
error
if
len
(
apiAddrStr
)
!=
0
{
addr
,
err
=
ma
.
NewMultiaddr
(
apiAddrStr
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
addr
.
Protocols
())
==
0
{
return
nil
,
fmt
.
Errorf
(
"multiaddr doesn't provide any protocols"
)
}
}
else
{
addr
,
err
=
fsrepo
.
APIAddr
(
repoPath
)
if
err
==
repo
.
ErrApiNotRunning
{
return
nil
,
err
}
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
apiErrorFmt
,
repoPath
,
err
.
Error
())
}
}
if
len
(
addr
.
Protocols
())
==
0
{
return
nil
,
fmt
.
Errorf
(
apiErrorFmt
,
repoPath
,
"multiaddr doesn't provide any protocols"
)
}
return
apiClientForAddr
(
ctx
,
addr
)
}
func
apiClientForAddr
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
http
.
Client
,
error
)
{
addr
,
err
:=
resolveAddr
(
ctx
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
return
http
.
NewClient
(
host
,
http
.
ClientWithAPIPrefix
(
corehttp
.
APIPath
)),
nil
}
func
resolveAddr
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
ma
.
Multiaddr
,
error
)
{
ctx
,
cancelFunc
:=
context
.
WithTimeout
(
ctx
,
10
*
time
.
Second
)
defer
cancelFunc
()
...
...
go.mod
浏览文件 @
07430569
...
...
@@ -2,7 +2,6 @@ module github.com/ipfs/go-ipfs
require (
bazil.org/fuse v0.0.0-20180421153158-65cc252bf669
github.com/Kubuxu/go-os-helper v0.0.1
github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd
github.com/blang/semver v3.5.1+incompatible
github.com/bren2010/proquint v0.0.0-20160323162903-38337c27106d
...
...
@@ -32,7 +31,7 @@ require (
github.com/ipfs/go-ipfs-blockstore v0.0.1
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-chunker v0.0.1
github.com/ipfs/go-ipfs-cmds v0.
0.1
0
github.com/ipfs/go-ipfs-cmds v0.
1.
0
github.com/ipfs/go-ipfs-config v0.0.6
github.com/ipfs/go-ipfs-ds-help v0.0.1
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
...
...
go.sum
浏览文件 @
07430569
...
...
@@ -247,8 +247,8 @@ github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IW
github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk=
github.com/ipfs/go-ipfs-chunker v0.0.1 h1:cHUUxKFQ99pozdahi+uSC/3Y6HeRpi9oTeUHbE27SEw=
github.com/ipfs/go-ipfs-chunker v0.0.1/go.mod h1:tWewYK0we3+rMbOh7pPFGDyypCtvGcBFymgY4rSDLAw=
github.com/ipfs/go-ipfs-cmds v0.
0.10 h1:4kA3E94HbDrLb4RZTkX3yXyUjKv50RfPz0Pv9xkP2cA
=
github.com/ipfs/go-ipfs-cmds v0.
0.1
0/go.mod h1:TiK4e7/V31tuEb8YWDF8lN3qrnDH+BS7ZqWIeYJlAs8=
github.com/ipfs/go-ipfs-cmds v0.
1.0 h1:0CEde9EcxByej8+L6d1PST57J4ambRPyCTjLG5Ymou8
=
github.com/ipfs/go-ipfs-cmds v0.
1.
0/go.mod h1:TiK4e7/V31tuEb8YWDF8lN3qrnDH+BS7ZqWIeYJlAs8=
github.com/ipfs/go-ipfs-config v0.0.5 h1:D9ek19anOzm8iYPvezeeamSg5mzwqKPb2jyAyJZT/4A=
github.com/ipfs/go-ipfs-config v0.0.5/go.mod h1:IGkVTacurWv9WFKc7IBPjHGM/7hi6+PEClqUb/l2BIM=
github.com/ipfs/go-ipfs-config v0.0.6 h1:jzK9Tl8S0oWBir3F5ObtGgnHRPdqQ0MYiCmwXtV3Ps4=
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论