Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
501abdd1
提交
501abdd1
authored
8月 11, 2018
作者:
Raúl Kripalani
提交者:
Steven Allen
8月 22, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP DNS resolution for API endpoint on ipfs bin (#5249)
License: MIT Signed-off-by:
Raúl Kripalani
<
raul.kripalani@consensys.net
>
上级
4fd8a6ef
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
6 行删除
+33
-6
main.go
cmd/ipfs/main.go
+27
-6
package.json
package.json
+6
-0
没有找到文件。
cmd/ipfs/main.go
浏览文件 @
501abdd1
...
...
@@ -34,6 +34,7 @@ import (
osh
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
ma
"gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
loggables
"gx/ipfs/QmZ4zF1mBrt8C2mSCM4ZYE4aAnv78f7GvrzufJC4G5tecK/go-libp2p-loggables"
mdns
"gx/ipfs/QmfXU2MhWoegxHoeMd3A2ytL2P6CY4FfqGWc23LTNWBwZt/go-multiaddr-dns"
)
// log is the command logger
...
...
@@ -235,7 +236,7 @@ func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, cctx *oldcm
// did user specify an api to use for this command?
apiAddrStr
,
_
:=
req
.
Options
[
corecmds
.
ApiOption
]
.
(
string
)
client
,
err
:=
getApiClient
(
cctx
.
ConfigRoot
,
apiAddrStr
)
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
...
...
@@ -406,7 +407,7 @@ var checkIPFSWinFmt = "Otherwise check:\n\ttasklist | 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
(
repoPath
,
apiAddrStr
string
)
(
http
.
Client
,
error
)
{
func
getApiClient
(
ctx
context
.
Context
,
repoPath
,
apiAddrStr
string
)
(
http
.
Client
,
error
)
{
var
apiErrorFmt
string
switch
{
case
osh
.
IsUnix
()
:
...
...
@@ -440,14 +441,34 @@ func getApiClient(repoPath, apiAddrStr string) (http.Client, error) {
if
len
(
addr
.
Protocols
())
==
0
{
return
nil
,
fmt
.
Errorf
(
apiErrorFmt
,
repoPath
,
"multiaddr doesn't provide any protocols"
)
}
return
apiClientForAddr
(
addr
)
return
apiClientForAddr
(
ctx
,
addr
)
}
func
apiClientForAddr
(
addr
ma
.
Multiaddr
)
(
http
.
Client
,
error
)
{
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
func
apiClientForAddr
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
)
(
http
.
Client
,
error
)
{
addrs
,
err
:=
mdns
.
Resolve
(
ctx
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
return
http
.
NewClient
(
host
,
http
.
ClientWithAPIPrefix
(
corehttp
.
APIPath
)),
nil
dialer
:=
&
manet
.
Dialer
{}
for
_
,
addr
:=
range
addrs
{
ctx
,
cancelFunc
:=
context
.
WithTimeout
(
ctx
,
5
*
time
.
Second
)
defer
cancelFunc
()
conn
,
err
:=
dialer
.
DialContext
(
ctx
,
addr
)
if
err
!=
nil
{
log
.
Errorf
(
"connection to %s failed, error: %s"
,
addr
,
err
)
continue
}
conn
.
Close
()
_
,
host
,
err
:=
manet
.
DialArgs
(
addr
)
if
err
!=
nil
{
continue
}
return
http
.
NewClient
(
host
,
http
.
ClientWithAPIPrefix
(
corehttp
.
APIPath
)),
nil
}
return
nil
,
errors
.
New
(
"non-resolvable API endpoint"
)
}
package.json
浏览文件 @
501abdd1
...
...
@@ -539,6 +539,12 @@
"hash"
:
"QmPyxJ2QS7L5FhGkNYkNcXHGjDhvGHueJ4auqAstFHYxy5"
,
"name"
:
"go-cidutil"
,
"version"
:
"0.0.2"
},
{
"author"
:
"lgierth"
,
"hash"
:
"QmfXU2MhWoegxHoeMd3A2ytL2P6CY4FfqGWc23LTNWBwZt"
,
"name"
:
"go-multiaddr-dns"
,
"version"
:
"0.2.4"
}
],
"gxVersion"
:
"0.10.0"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论