Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
0bfcf7ea
提交
0bfcf7ea
authored
2月 06, 2019
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
namecache: remove pin for now
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
4f56358a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
21 行增加
和
64 行删除
+21
-64
follow.go
core/commands/name/follow.go
+2
-2
namecache.go
namecache/namecache.go
+14
-57
persistent.go
namecache/persistent.go
+5
-5
没有找到文件。
core/commands/name/follow.go
浏览文件 @
0bfcf7ea
...
@@ -55,7 +55,7 @@ Follows an IPNS name by periodically resolving in the backround.
...
@@ -55,7 +55,7 @@ Follows an IPNS name by periodically resolving in the backround.
return
cmdkit
.
Errorf
(
cmdkit
.
ErrClient
,
"IPNS Namecache is not available"
)
return
cmdkit
.
Errorf
(
cmdkit
.
ErrClient
,
"IPNS Namecache is not available"
)
}
}
p
in
,
_
:=
req
.
Options
[
"pin
"
]
.
(
bool
)
p
refetch
,
_
:=
req
.
Options
[
"prefetch
"
]
.
(
bool
)
refrS
,
_
:=
req
.
Options
[
"refresh-interval"
]
.
(
string
)
refrS
,
_
:=
req
.
Options
[
"refresh-interval"
]
.
(
string
)
refr
:=
nc
.
DefaultFollowInterval
refr
:=
nc
.
DefaultFollowInterval
...
@@ -67,7 +67,7 @@ Follows an IPNS name by periodically resolving in the backround.
...
@@ -67,7 +67,7 @@ Follows an IPNS name by periodically resolving in the backround.
}
}
for
_
,
name
:=
range
req
.
Arguments
{
for
_
,
name
:=
range
req
.
Arguments
{
err
=
n
.
Namecache
.
Follow
(
name
,
p
in
,
refr
)
err
=
n
.
Namecache
.
Follow
(
name
,
p
refetch
,
refr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
namecache/namecache.go
浏览文件 @
0bfcf7ea
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"time"
"time"
namesys
"github.com/ipfs/go-ipfs/namesys"
namesys
"github.com/ipfs/go-ipfs/namesys"
pin
"github.com/ipfs/go-ipfs/pin"
uio
"gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs/io"
uio
"gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs/io"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
...
@@ -29,8 +28,8 @@ var log = logging.Logger("namecache")
...
@@ -29,8 +28,8 @@ var log = logging.Logger("namecache")
// NameCache represents a following cache of names
// NameCache represents a following cache of names
type
NameCache
interface
{
type
NameCache
interface
{
// Follow starts following name
, pinning it if dopin is true
// Follow starts following name
Follow
(
name
string
,
dopin
bool
,
followInterval
time
.
Duration
)
error
Follow
(
name
string
,
prefetch
bool
,
followInterval
time
.
Duration
)
error
// Unofollow cancels a follow
// Unofollow cancels a follow
Unfollow
(
name
string
)
error
Unfollow
(
name
string
)
error
// ListFollows returns a list of followed names
// ListFollows returns a list of followed names
...
@@ -39,7 +38,6 @@ type NameCache interface {
...
@@ -39,7 +38,6 @@ type NameCache interface {
type
nameCache
struct
{
type
nameCache
struct
{
nsys
namesys
.
NameSystem
nsys
namesys
.
NameSystem
pinning
pin
.
Pinner
dag
ipld
.
NodeGetter
dag
ipld
.
NodeGetter
bstore
bstore
.
GCBlockstore
bstore
bstore
.
GCBlockstore
...
@@ -48,11 +46,10 @@ type nameCache struct {
...
@@ -48,11 +46,10 @@ type nameCache struct {
mx
sync
.
Mutex
mx
sync
.
Mutex
}
}
func
NewNameCache
(
ctx
context
.
Context
,
nsys
namesys
.
NameSystem
,
pinning
pin
.
Pinner
,
dag
ipld
.
NodeGetter
,
bstore
bstore
.
GCBlockstore
)
NameCache
{
func
NewNameCache
(
ctx
context
.
Context
,
nsys
namesys
.
NameSystem
,
dag
ipld
.
NodeGetter
,
bstore
bstore
.
GCBlockstore
)
NameCache
{
return
&
nameCache
{
return
&
nameCache
{
ctx
:
ctx
,
ctx
:
ctx
,
nsys
:
nsys
,
nsys
:
nsys
,
pinning
:
pinning
,
dag
:
dag
,
dag
:
dag
,
bstore
:
bstore
,
bstore
:
bstore
,
follows
:
make
(
map
[
string
]
func
()),
follows
:
make
(
map
[
string
]
func
()),
...
@@ -61,7 +58,7 @@ func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinn
...
@@ -61,7 +58,7 @@ func NewNameCache(ctx context.Context, nsys namesys.NameSystem, pinning pin.Pinn
// Follow spawns a goroutine that periodically resolves a name
// Follow spawns a goroutine that periodically resolves a name
// and (when dopin is true) pins it in the background
// and (when dopin is true) pins it in the background
func
(
nc
*
nameCache
)
Follow
(
name
string
,
dopin
bool
,
followInterval
time
.
Duration
)
error
{
func
(
nc
*
nameCache
)
Follow
(
name
string
,
prefetch
bool
,
followInterval
time
.
Duration
)
error
{
nc
.
mx
.
Lock
()
nc
.
mx
.
Lock
()
defer
nc
.
mx
.
Unlock
()
defer
nc
.
mx
.
Unlock
()
...
@@ -74,7 +71,7 @@ func (nc *nameCache) Follow(name string, dopin bool, followInterval time.Duratio
...
@@ -74,7 +71,7 @@ func (nc *nameCache) Follow(name string, dopin bool, followInterval time.Duratio
}
}
ctx
,
cancel
:=
context
.
WithCancel
(
nc
.
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
nc
.
ctx
)
go
nc
.
followName
(
ctx
,
name
,
dopin
,
followInterval
)
go
nc
.
followName
(
ctx
,
name
,
prefetch
,
followInterval
)
nc
.
follows
[
name
]
=
cancel
nc
.
follows
[
name
]
=
cancel
return
nil
return
nil
...
@@ -112,10 +109,9 @@ func (nc *nameCache) ListFollows() []string {
...
@@ -112,10 +109,9 @@ func (nc *nameCache) ListFollows() []string {
return
follows
return
follows
}
}
func
(
nc
*
nameCache
)
followName
(
ctx
context
.
Context
,
name
string
,
dopin
bool
,
followInterval
time
.
Duration
)
{
func
(
nc
*
nameCache
)
followName
(
ctx
context
.
Context
,
name
string
,
prefetch
bool
,
followInterval
time
.
Duration
)
{
// if cid != nil, we have created a new pin that is updated on changes and
// if cid != nil, we have prefetched data under the node
// unpinned on cancel
c
,
err
:=
nc
.
resolveAndFetch
(
ctx
,
name
,
prefetch
)
c
,
err
:=
nc
.
resolveAndPin
(
ctx
,
name
,
dopin
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Error following %s: %s"
,
name
,
err
.
Error
())
log
.
Errorf
(
"Error following %s: %s"
,
name
,
err
.
Error
())
}
}
...
@@ -129,7 +125,7 @@ func (nc *nameCache) followName(ctx context.Context, name string, dopin bool, fo
...
@@ -129,7 +125,7 @@ func (nc *nameCache) followName(ctx context.Context, name string, dopin bool, fo
if
c
!=
cid
.
Undef
{
if
c
!=
cid
.
Undef
{
c
,
err
=
nc
.
resolveAndUpdate
(
ctx
,
name
,
c
)
c
,
err
=
nc
.
resolveAndUpdate
(
ctx
,
name
,
c
)
}
else
{
}
else
{
c
,
err
=
nc
.
resolveAnd
Pin
(
ctx
,
name
,
dopin
)
c
,
err
=
nc
.
resolveAnd
Fetch
(
ctx
,
name
,
prefetch
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -137,24 +133,18 @@ func (nc *nameCache) followName(ctx context.Context, name string, dopin bool, fo
...
@@ -137,24 +133,18 @@ func (nc *nameCache) followName(ctx context.Context, name string, dopin bool, fo
}
}
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
if
c
!=
cid
.
Undef
{
err
=
nc
.
unpin
(
c
)
if
err
!=
nil
{
log
.
Errorf
(
"Error unpinning %s: %s"
,
name
,
err
.
Error
())
}
}
return
return
}
}
}
}
}
}
func
(
nc
*
nameCache
)
resolveAnd
Pin
(
ctx
context
.
Context
,
name
string
,
dopin
bool
)
(
cid
.
Cid
,
error
)
{
func
(
nc
*
nameCache
)
resolveAnd
Fetch
(
ctx
context
.
Context
,
name
string
,
prefetch
bool
)
(
cid
.
Cid
,
error
)
{
ptr
,
err
:=
nc
.
resolve
(
ctx
,
name
)
ptr
,
err
:=
nc
.
resolve
(
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cid
.
Undef
,
err
return
cid
.
Undef
,
err
}
}
if
!
dopin
{
if
!
prefetch
{
return
cid
.
Undef
,
nil
return
cid
.
Undef
,
nil
}
}
...
@@ -165,30 +155,15 @@ func (nc *nameCache) resolveAndPin(ctx context.Context, name string, dopin bool)
...
@@ -165,30 +155,15 @@ func (nc *nameCache) resolveAndPin(ctx context.Context, name string, dopin bool)
defer
nc
.
bstore
.
PinLock
()
.
Unlock
()
defer
nc
.
bstore
.
PinLock
()
.
Unlock
()
_
,
pinned
,
err
:=
nc
.
pinning
.
IsPinned
(
c
)
if
pinned
||
err
!=
nil
{
return
cid
.
Undef
,
err
}
n
,
err
:=
nc
.
pathToNode
(
ctx
,
ptr
)
n
,
err
:=
nc
.
pathToNode
(
ctx
,
ptr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cid
.
Undef
,
err
return
cid
.
Undef
,
err
}
}
log
.
Debugf
(
"pinning %s"
,
c
.
String
())
err
=
nc
.
pinning
.
Pin
(
ctx
,
n
,
true
)
if
err
!=
nil
{
return
cid
.
Undef
,
err
}
err
=
nc
.
pinning
.
Flush
()
return
c
,
err
return
c
,
err
}
}
func
(
nc
*
nameCache
)
resolveAndUpdate
(
ctx
context
.
Context
,
name
string
,
oldcid
cid
.
Cid
)
(
cid
.
Cid
,
error
)
{
func
(
nc
*
nameCache
)
resolveAndUpdate
(
ctx
context
.
Context
,
name
string
,
oldcid
cid
.
Cid
)
(
cid
.
Cid
,
error
)
{
ptr
,
err
:=
nc
.
resolve
(
ctx
,
name
)
ptr
,
err
:=
nc
.
resolve
(
ctx
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cid
.
Undef
,
err
return
cid
.
Undef
,
err
...
@@ -203,31 +178,11 @@ func (nc *nameCache) resolveAndUpdate(ctx context.Context, name string, oldcid c
...
@@ -203,31 +178,11 @@ func (nc *nameCache) resolveAndUpdate(ctx context.Context, name string, oldcid c
return
oldcid
,
nil
return
oldcid
,
nil
}
}
defer
nc
.
bstore
.
PinLock
()
.
Unlock
()
// TODO: handle prefetching
log
.
Debugf
(
"Updating pin %s -> %s"
,
oldcid
.
String
(),
newcid
.
String
())
err
=
nc
.
pinning
.
Update
(
ctx
,
oldcid
,
newcid
,
true
)
if
err
!=
nil
{
return
oldcid
,
err
}
err
=
nc
.
pinning
.
Flush
()
return
newcid
,
err
return
newcid
,
err
}
}
func
(
nc
*
nameCache
)
unpin
(
cid
cid
.
Cid
)
error
{
defer
nc
.
bstore
.
PinLock
()
.
Unlock
()
err
:=
nc
.
pinning
.
Unpin
(
nc
.
ctx
,
cid
,
true
)
if
err
!=
nil
{
return
err
}
return
nc
.
pinning
.
Flush
()
}
func
(
nc
*
nameCache
)
resolve
(
ctx
context
.
Context
,
name
string
)
(
path
.
Path
,
error
)
{
func
(
nc
*
nameCache
)
resolve
(
ctx
context
.
Context
,
name
string
)
(
path
.
Path
,
error
)
{
log
.
Debugf
(
"resolving %s"
,
name
)
log
.
Debugf
(
"resolving %s"
,
name
)
...
@@ -241,6 +196,8 @@ func (nc *nameCache) resolve(ctx context.Context, name string) (path.Path, error
...
@@ -241,6 +196,8 @@ func (nc *nameCache) resolve(ctx context.Context, name string) (path.Path, error
log
.
Debugf
(
"resolved %s to %s"
,
name
,
p
)
log
.
Debugf
(
"resolved %s to %s"
,
name
,
p
)
// TODO: handle prefetching
return
p
,
nil
return
p
,
nil
}
}
...
...
namecache/persistent.go
浏览文件 @
0bfcf7ea
...
@@ -20,7 +20,7 @@ type persistent struct {
...
@@ -20,7 +20,7 @@ type persistent struct {
}
}
type
follow
struct
{
type
follow
struct
{
P
in
bool
P
refetch
bool
Deadline
time
.
Time
Deadline
time
.
Time
}
}
...
@@ -37,7 +37,7 @@ func NewPersistentCache(base NameCache, d ds.Datastore) (NameCache, error) {
...
@@ -37,7 +37,7 @@ func NewPersistentCache(base NameCache, d ds.Datastore) (NameCache, error) {
if
err
:=
json
.
Unmarshal
(
e
.
Value
,
&
f
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
e
.
Value
,
&
f
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
err
:=
base
.
Follow
(
e
.
Key
,
f
.
P
in
,
time
.
Now
()
.
Sub
(
f
.
Deadline
));
err
!=
nil
{
if
err
:=
base
.
Follow
(
e
.
Key
,
f
.
P
refetch
,
time
.
Now
()
.
Sub
(
f
.
Deadline
));
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -49,16 +49,16 @@ func NewPersistentCache(base NameCache, d ds.Datastore) (NameCache, error) {
...
@@ -49,16 +49,16 @@ func NewPersistentCache(base NameCache, d ds.Datastore) (NameCache, error) {
},
nil
},
nil
}
}
func
(
p
*
persistent
)
Follow
(
name
string
,
dopin
bool
,
followInterval
time
.
Duration
)
error
{
func
(
p
*
persistent
)
Follow
(
name
string
,
prefetch
bool
,
followInterval
time
.
Duration
)
error
{
b
,
err
:=
json
.
Marshal
(
&
follow
{
b
,
err
:=
json
.
Marshal
(
&
follow
{
P
in
:
dopin
,
P
refetch
:
prefetch
,
Deadline
:
time
.
Now
()
.
Add
(
followInterval
),
Deadline
:
time
.
Now
()
.
Add
(
followInterval
),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
p
.
NameCache
.
Follow
(
name
,
dopin
,
followInterval
);
err
!=
nil
{
if
err
:=
p
.
NameCache
.
Follow
(
name
,
prefetch
,
followInterval
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
ds
.
Put
(
ds
.
NewKey
(
name
),
b
)
return
p
.
ds
.
Put
(
ds
.
NewKey
(
name
),
b
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论