Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
dde397eb
Unverified
提交
dde397eb
authored
3月 08, 2019
作者:
Michael Avila
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor per code climate rules
License: MIT Signed-off-by:
Michael Avila
<
davidmichaelavila@gmail.com
>
上级
bfcea27d
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
42 行增加
和
37 行删除
+42
-37
builder.go
core/builder.go
+1
-1
core.go
core/core.go
+1
-1
coreapi.go
core/coreapi/coreapi.go
+1
-1
provider.go
core/coreapi/provider.go
+4
-2
offline.go
provider/offline.go
+2
-1
provider.go
provider/provider.go
+2
-2
queue.go
provider/queue.go
+31
-29
没有找到文件。
core/builder.go
浏览文件 @
dde397eb
...
...
@@ -277,7 +277,7 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
n
.
Resolver
=
resolver
.
NewBasicResolver
(
n
.
DAG
)
// Provider
queue
,
err
:=
provider
.
NewQueue
(
"provider-v1"
,
ctx
,
n
.
Repo
.
Datastore
())
queue
,
err
:=
provider
.
NewQueue
(
ctx
,
"provider-v1"
,
n
.
Repo
.
Datastore
())
if
err
!=
nil
{
return
err
}
...
...
core/core.go
浏览文件 @
dde397eb
...
...
@@ -125,7 +125,7 @@ type IpfsNode struct {
Routing
routing
.
IpfsRouting
// the routing system. recommend ipfs-dht
Exchange
exchange
.
Interface
// the block exchange + strategy (bitswap)
Namesys
namesys
.
NameSystem
// the name system, resolves paths to hashes
Provider
provider
.
Provider
// the value provider system
Provider
provider
.
Provider
// the value provider system
Reprovider
*
rp
.
Reprovider
// the value reprovider system
IpnsRepub
*
ipnsrp
.
Republisher
...
...
core/coreapi/coreapi.go
浏览文件 @
dde397eb
...
...
@@ -20,8 +20,8 @@ import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/namesys"
"github.com/ipfs/go-ipfs/provider"
"github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/provider"
"github.com/ipfs/go-ipfs/repo"
bserv
"github.com/ipfs/go-blockservice"
...
...
core/coreapi/provider.go
浏览文件 @
dde397eb
...
...
@@ -4,8 +4,10 @@ import (
cid
"github.com/ipfs/go-cid"
)
// ProviderAPI brings Provider behavior to CoreAPI
type
ProviderAPI
CoreAPI
func
(
api
*
ProviderAPI
)
Provide
(
root
cid
.
Cid
)
error
{
return
api
.
provider
.
Provide
(
root
)
// Provide the given cid using the current provider
func
(
api
*
ProviderAPI
)
Provide
(
cid
cid
.
Cid
)
error
{
return
api
.
provider
.
Provide
(
cid
)
}
provider/offline.go
浏览文件 @
dde397eb
...
...
@@ -2,8 +2,9 @@ package provider
import
"github.com/ipfs/go-cid"
type
offlineProvider
struct
{}
type
offlineProvider
struct
{}
// NewOfflineProvider creates a Provider that does nothing
func
NewOfflineProvider
()
Provider
{
return
&
offlineProvider
{}
}
...
...
provider/provider.go
浏览文件 @
dde397eb
...
...
@@ -18,13 +18,12 @@ const (
provideOutgoingWorkerLimit
=
8
)
// Provider announces blocks to the network
type
Provider
interface
{
Run
()
Provide
(
cid
.
Cid
)
error
}
// Provider announces blocks to the network, tracks which blocks are
// being provided, and untracks blocks when they're no longer in the blockstore.
type
provider
struct
{
ctx
context
.
Context
// the CIDs for which provide announcements should be made
...
...
@@ -33,6 +32,7 @@ type provider struct {
contentRouting
routing
.
ContentRouting
}
// NewProvider creates a provider that announces blocks to the network using a content router
func
NewProvider
(
ctx
context
.
Context
,
queue
*
Queue
,
contentRouting
routing
.
ContentRouting
)
Provider
{
return
&
provider
{
ctx
:
ctx
,
...
...
provider/queue.go
浏览文件 @
dde397eb
...
...
@@ -17,11 +17,12 @@ import (
// not removed from the datastore until you call Complete() on the entry you
// receive.
type
Entry
struct
{
cid
cid
.
Cid
key
ds
.
Key
cid
cid
.
Cid
key
ds
.
Key
queue
*
Queue
}
// Complete the entry by removing it from the queue
func
(
e
*
Entry
)
Complete
()
error
{
return
e
.
queue
.
remove
(
e
.
key
)
}
...
...
@@ -41,36 +42,37 @@ type Queue struct {
tail
uint64
head
uint64
lock
sync
.
Mutex
lock
sync
.
Mutex
datastore
ds
.
Datastore
dequeue
chan
*
Entry
dequeue
chan
*
Entry
notEmpty
chan
struct
{}
isRunning
bool
}
func
NewQueue
(
name
string
,
ctx
context
.
Context
,
datastore
ds
.
Datastore
)
(
*
Queue
,
error
)
{
namespaced
:=
namespace
.
Wrap
(
datastore
,
ds
.
NewKey
(
"/"
+
name
+
"/queue/"
))
head
,
tail
,
err
:=
getQueueHeadTail
(
name
,
ctx
,
namespaced
)
// NewQueue creates a queue for cids
func
NewQueue
(
ctx
context
.
Context
,
name
string
,
datastore
ds
.
Datastore
)
(
*
Queue
,
error
)
{
namespaced
:=
namespace
.
Wrap
(
datastore
,
ds
.
NewKey
(
"/"
+
name
+
"/queue/"
))
head
,
tail
,
err
:=
getQueueHeadTail
(
ctx
,
name
,
namespaced
)
if
err
!=
nil
{
return
nil
,
err
}
q
:=
&
Queue
{
name
:
name
,
ctx
:
ctx
,
head
:
head
,
tail
:
tail
,
lock
:
sync
.
Mutex
{},
name
:
name
,
ctx
:
ctx
,
head
:
head
,
tail
:
tail
,
lock
:
sync
.
Mutex
{},
datastore
:
namespaced
,
dequeue
:
make
(
chan
*
Entry
),
notEmpty
:
make
(
chan
struct
{}),
dequeue
:
make
(
chan
*
Entry
),
notEmpty
:
make
(
chan
struct
{}),
isRunning
:
false
,
}
return
q
,
nil
}
//
Put
a cid in the queue
//
Enqueue puts
a cid in the queue
func
(
q
*
Queue
)
Enqueue
(
cid
cid
.
Cid
)
error
{
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
...
...
@@ -95,21 +97,18 @@ func (q *Queue) Enqueue(cid cid.Cid) error {
return
nil
}
//
Remove an entry from the queue.
//
Dequeue returns a channel that if listened to will remove entries from the queue
func
(
q
*
Queue
)
Dequeue
()
<-
chan
*
Entry
{
return
q
.
dequeue
}
// IsEmpty returns whether or not the queue has any items
func
(
q
*
Queue
)
IsEmpty
()
bool
{
return
(
q
.
tail
-
q
.
head
)
==
0
}
func
(
q
*
Queue
)
remove
(
key
ds
.
Key
)
error
{
return
q
.
datastore
.
Delete
(
key
)
}
// dequeue items when the dequeue channel is available to
// be written to
// Run dequeues items when the dequeue channel is available to
// be written to.
func
(
q
*
Queue
)
Run
()
{
q
.
isRunning
=
true
go
func
()
{
...
...
@@ -178,9 +177,9 @@ func (q *Queue) next() (*Entry, error) {
return
nil
,
err
}
entry
:=
&
Entry
{
cid
:
id
,
key
:
nextKey
,
entry
:=
&
Entry
{
cid
:
id
,
key
:
nextKey
,
queue
:
q
,
}
...
...
@@ -194,14 +193,14 @@ func (q *Queue) queueKey(id uint64) ds.Key {
}
// crawl over the queue entries to find the head and tail
func
getQueueHeadTail
(
name
string
,
ctx
context
.
Context
,
datastore
ds
.
Datastore
)
(
uint64
,
uint64
,
error
)
{
func
getQueueHeadTail
(
ctx
context
.
Context
,
name
string
,
datastore
ds
.
Datastore
)
(
uint64
,
uint64
,
error
)
{
query
:=
query
.
Query
{}
results
,
err
:=
datastore
.
Query
(
query
)
if
err
!=
nil
{
return
0
,
0
,
err
}
var
tail
uint64
=
0
var
tail
uint64
var
head
uint64
=
math
.
MaxUint64
for
entry
:=
range
results
.
Next
()
{
select
{
...
...
@@ -219,8 +218,8 @@ func getQueueHeadTail(name string, ctx context.Context, datastore ds.Datastore)
head
=
id
}
if
(
id
+
1
)
>
tail
{
tail
=
(
id
+
1
)
if
(
id
+
1
)
>
tail
{
tail
=
(
id
+
1
)
}
}
if
err
:=
results
.
Close
();
err
!=
nil
{
...
...
@@ -233,3 +232,6 @@ func getQueueHeadTail(name string, ctx context.Context, datastore ds.Datastore)
return
head
,
tail
,
nil
}
func
(
q
*
Queue
)
remove
(
key
ds
.
Key
)
error
{
return
q
.
datastore
.
Delete
(
key
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论