Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
50aea072
提交
50aea072
authored
12月 10, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi.WithOptions
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
c832a32a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
94 行增加
和
71 行删除
+94
-71
coreapi.go
core/coreapi/coreapi.go
+88
-71
coreapi.go
core/coreapi/interface/coreapi.go
+6
-0
没有找到文件。
core/coreapi/coreapi.go
浏览文件 @
50aea072
...
...
@@ -17,6 +17,7 @@ import (
"context"
"errors"
"fmt"
"github.com/ipfs/go-ipfs/core"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
...
...
@@ -25,18 +26,18 @@ import (
"github.com/ipfs/go-ipfs/repo"
ci
"gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
"gx/ipfs/QmP2g3VxmC7g7fyRJDj1VJ72KHZbJ9UW24YjSWEj1XTb4H/go-ipfs-exchange-interface"
exchange
"gx/ipfs/QmP2g3VxmC7g7fyRJDj1VJ72KHZbJ9UW24YjSWEj1XTb4H/go-ipfs-exchange-interface"
bserv
"gx/ipfs/QmPoh3SrQzFBWtdGK6qmHDV4EanKR6kYPj4DD3J2NLoEmZ/go-blockservice"
"gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
"gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
"gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
routing
"gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
blockstore
"gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
peer
"gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
pstore
"gx/ipfs/QmZ9zH2FnLcxv1xyzFeUpDUeo55xEhZQHgveZijcxr7TLj/go-libp2p-peerstore"
pubsub
"gx/ipfs/QmaqGyUhWLsJbVo1QAujSu13mxNjFJ98Kt2VWGSnShGE1Q/go-libp2p-pubsub"
ipld
"gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
logging
"gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
dag
"gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
offlineroute
"gx/ipfs/QmdmWkx54g7VfVyxeG8ic84uf4G6Eq1GohuyKA3XDuJ8oC/go-ipfs-routing/offline"
"gx/ipfs/QmfARXVCzpwFXQdepAJZuqyNDgV9doEsMnVCo1ssmuSe1U/go-libp2p-record"
record
"gx/ipfs/QmfARXVCzpwFXQdepAJZuqyNDgV9doEsMnVCo1ssmuSe1U/go-libp2p-record"
p2phost
"gx/ipfs/QmfD51tKgJiTMnW9JEiDiPwsCY4mqUoxkhKhBfyW12spTC/go-libp2p-host"
)
...
...
@@ -45,7 +46,7 @@ var log = logging.Logger("core/coreapi")
type
CoreAPI
struct
{
nctx
context
.
Context
identity
peer
.
ID
//TODO: check mutable structs
identity
peer
.
ID
privateKey
ci
.
PrivKey
repo
repo
.
Repo
...
...
@@ -69,16 +70,80 @@ type CoreAPI struct {
// TODO: this can be generalized to all functions when we implement some
// api based security mechanism
isPublishAllowed
func
()
error
// ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE
nd
*
core
.
IpfsNode
}
// NewCoreAPI creates new instance of IPFS CoreAPI backed by go-ipfs Node.
func
NewCoreAPI
(
n
*
core
.
IpfsNode
,
opts
...
options
.
ApiOption
)
(
coreiface
.
CoreAPI
,
error
)
{
return
(
&
CoreAPI
{
nd
:
n
})
.
WithOptions
(
opts
...
)
}
// Unixfs returns the UnixfsAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Unixfs
()
coreiface
.
UnixfsAPI
{
return
(
*
UnixfsAPI
)(
api
)
}
// Block returns the BlockAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Block
()
coreiface
.
BlockAPI
{
return
(
*
BlockAPI
)(
api
)
}
// Dag returns the DagAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Dag
()
coreiface
.
DagAPI
{
return
(
*
DagAPI
)(
api
)
}
// Name returns the NameAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Name
()
coreiface
.
NameAPI
{
return
(
*
NameAPI
)(
api
)
}
// Key returns the KeyAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Key
()
coreiface
.
KeyAPI
{
return
(
*
KeyAPI
)(
api
)
}
// Object returns the ObjectAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Object
()
coreiface
.
ObjectAPI
{
return
(
*
ObjectAPI
)(
api
)
}
// Pin returns the PinAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Pin
()
coreiface
.
PinAPI
{
return
(
*
PinAPI
)(
api
)
}
// Dht returns the DhtAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Dht
()
coreiface
.
DhtAPI
{
return
(
*
DhtAPI
)(
api
)
}
// Swarm returns the SwarmAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Swarm
()
coreiface
.
SwarmAPI
{
return
(
*
SwarmAPI
)(
api
)
}
// PubSub returns the PubSubAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
PubSub
()
coreiface
.
PubSubAPI
{
return
(
*
PubSubAPI
)(
api
)
}
// WithOptions returns api with global options applied
func
(
api
*
CoreAPI
)
WithOptions
(
opts
...
options
.
ApiOption
)
(
coreiface
.
CoreAPI
,
error
)
{
settings
,
err
:=
options
.
ApiOptions
(
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
api
:=
&
CoreAPI
{
if
api
.
nd
==
nil
{
return
nil
,
errors
.
New
(
"cannot apply options to api without node"
)
}
n
:=
api
.
nd
subApi
:=
&
CoreAPI
{
nctx
:
n
.
Context
(),
identity
:
n
.
Identity
,
...
...
@@ -99,9 +164,11 @@ func NewCoreAPI(n *core.IpfsNode, opts ...options.ApiOption) (coreiface.CoreAPI,
exchange
:
n
.
Exchange
,
pubSub
:
n
.
PubSub
,
nd
:
n
,
}
a
pi
.
routing
=
func
(
allowOffline
bool
)
(
routing
.
IpfsRouting
,
error
)
{
subA
pi
.
routing
=
func
(
allowOffline
bool
)
(
routing
.
IpfsRouting
,
error
)
{
if
!
n
.
OnlineMode
()
{
if
!
allowOffline
{
return
nil
,
coreiface
.
ErrOffline
...
...
@@ -109,8 +176,8 @@ func NewCoreAPI(n *core.IpfsNode, opts ...options.ApiOption) (coreiface.CoreAPI,
if
err
:=
n
.
SetupOfflineRouting
();
err
!=
nil
{
return
nil
,
err
}
a
pi
.
privateKey
=
n
.
PrivateKey
a
pi
.
namesys
=
n
.
Namesys
subA
pi
.
privateKey
=
n
.
PrivateKey
subA
pi
.
namesys
=
n
.
Namesys
return
n
.
Routing
,
nil
}
if
!
settings
.
Offline
{
...
...
@@ -120,7 +187,6 @@ func NewCoreAPI(n *core.IpfsNode, opts ...options.ApiOption) (coreiface.CoreAPI,
return
nil
,
coreiface
.
ErrOffline
}
//todo: might want to cache this
cfg
,
err
:=
n
.
Repo
.
Config
()
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -134,13 +200,13 @@ func NewCoreAPI(n *core.IpfsNode, opts ...options.ApiOption) (coreiface.CoreAPI,
return
nil
,
fmt
.
Errorf
(
"cannot specify negative resolve cache size"
)
}
offroute
:=
offlineroute
.
NewOfflineRouter
(
api
.
repo
.
Datastore
(),
a
pi
.
recordValidator
)
api
.
namesys
=
namesys
.
NewNameSystem
(
offroute
,
a
pi
.
repo
.
Datastore
(),
cs
)
offroute
:=
offlineroute
.
NewOfflineRouter
(
subApi
.
repo
.
Datastore
(),
subA
pi
.
recordValidator
)
subApi
.
namesys
=
namesys
.
NewNameSystem
(
offroute
,
subA
pi
.
repo
.
Datastore
(),
cs
)
return
offroute
,
nil
}
a
pi
.
isPublishAllowed
=
func
()
error
{
subA
pi
.
isPublishAllowed
=
func
()
error
{
if
n
.
Mounts
.
Ipns
!=
nil
&&
n
.
Mounts
.
Ipns
.
IsActive
()
{
return
errors
.
New
(
"cannot manually publish while IPNS is mounted"
)
}
...
...
@@ -148,71 +214,22 @@ func NewCoreAPI(n *core.IpfsNode, opts ...options.ApiOption) (coreiface.CoreAPI,
}
if
settings
.
Offline
{
a
pi
.
peerstore
=
nil
a
pi
.
peerHost
=
nil
a
pi
.
namesys
=
nil
a
pi
.
recordValidator
=
nil
a
pi
.
exchange
=
nil
subA
pi
.
peerstore
=
nil
subA
pi
.
peerHost
=
nil
subA
pi
.
namesys
=
nil
subA
pi
.
recordValidator
=
nil
subA
pi
.
exchange
=
nil
}
return
api
,
nil
}
// Unixfs returns the UnixfsAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Unixfs
()
coreiface
.
UnixfsAPI
{
return
(
*
UnixfsAPI
)(
api
)
}
// Block returns the BlockAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Block
()
coreiface
.
BlockAPI
{
return
(
*
BlockAPI
)(
api
)
}
// Dag returns the DagAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Dag
()
coreiface
.
DagAPI
{
return
(
*
DagAPI
)(
api
)
}
// Name returns the NameAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Name
()
coreiface
.
NameAPI
{
return
(
*
NameAPI
)(
api
)
}
// Key returns the KeyAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Key
()
coreiface
.
KeyAPI
{
return
(
*
KeyAPI
)(
api
)
}
// Object returns the ObjectAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Object
()
coreiface
.
ObjectAPI
{
return
(
*
ObjectAPI
)(
api
)
}
// Pin returns the PinAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Pin
()
coreiface
.
PinAPI
{
return
(
*
PinAPI
)(
api
)
}
// Dht returns the DhtAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Dht
()
coreiface
.
DhtAPI
{
return
(
*
DhtAPI
)(
api
)
}
// Swarm returns the SwarmAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Swarm
()
coreiface
.
SwarmAPI
{
return
(
*
SwarmAPI
)(
api
)
}
// PubSub returns the PubSubAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
PubSub
()
coreiface
.
PubSubAPI
{
return
(
*
PubSubAPI
)(
api
)
return
subApi
,
nil
}
// getSession returns new api backed by the same node with a read-only session DAG
func
(
api
*
CoreAPI
)
getSession
(
ctx
context
.
Context
)
*
CoreAPI
{
sesApi
:=
*
api
//TODO: we may want to apply this to other things too
// TODO: We could also apply this to api.blocks, and compose into writable api,
// but this requires some changes in blockservice/merkledag
sesApi
.
dag
=
dag
.
NewReadOnlyDagService
(
dag
.
NewSession
(
ctx
,
api
.
dag
))
return
&
sesApi
...
...
core/coreapi/interface/coreapi.go
浏览文件 @
50aea072
...
...
@@ -5,6 +5,8 @@ package iface
import
(
"context"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
ipld
"gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
)
...
...
@@ -46,4 +48,8 @@ type CoreAPI interface {
// ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node
ResolveNode
(
context
.
Context
,
Path
)
(
ipld
.
Node
,
error
)
// WithOptions creates new instance of CoreAPI based on this instance with
// a set of options applied
WithOptions
(
...
options
.
ApiOption
)
(
CoreAPI
,
error
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论