Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
a47d1b03
提交
a47d1b03
authored
12月 14, 2016
作者:
Jeromy Johnson
提交者:
GitHub
12月 14, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3501 from ipfs/feat/namesys/publish-cache
namesys: add entry to DHT cache after publish
上级
edeffa55
6a9009b8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
47 行增加
和
6 行删除
+47
-6
namesys.go
namesys/namesys.go
+44
-4
publisher.go
namesys/publisher.go
+3
-2
没有找到文件。
namesys/namesys.go
浏览文件 @
a47d1b03
package
namesys
import
(
"context"
"strings"
"time"
context
"context"
path
"github.com/ipfs/go-ipfs/path"
ds
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
routing
"gx/ipfs/QmbkGVaN9W6RYJK4Ws5FvMKXKDqdRQ5snhtaa92qP6L8eU/go-libp2p-routing"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
ci
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
)
...
...
@@ -87,9 +89,47 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
// Publish implements Publisher
func
(
ns
*
mpns
)
Publish
(
ctx
context
.
Context
,
name
ci
.
PrivKey
,
value
path
.
Path
)
error
{
return
ns
.
publishers
[
"/ipns/"
]
.
Publish
(
ctx
,
name
,
value
)
err
:=
ns
.
publishers
[
"/ipns/"
]
.
Publish
(
ctx
,
name
,
value
)
if
err
!=
nil
{
return
err
}
ns
.
addToDHTCache
(
name
,
value
,
time
.
Now
()
.
Add
(
DefaultRecordTTL
))
return
nil
}
func
(
ns
*
mpns
)
PublishWithEOL
(
ctx
context
.
Context
,
name
ci
.
PrivKey
,
value
path
.
Path
,
eol
time
.
Time
)
error
{
err
:=
ns
.
publishers
[
"/ipns/"
]
.
PublishWithEOL
(
ctx
,
name
,
value
,
eol
)
if
err
!=
nil
{
return
err
}
ns
.
addToDHTCache
(
name
,
value
,
eol
)
return
nil
}
func
(
ns
*
mpns
)
PublishWithEOL
(
ctx
context
.
Context
,
name
ci
.
PrivKey
,
val
path
.
Path
,
eol
time
.
Time
)
error
{
return
ns
.
publishers
[
"/ipns/"
]
.
PublishWithEOL
(
ctx
,
name
,
val
,
eol
)
func
(
ns
*
mpns
)
addToDHTCache
(
key
ci
.
PrivKey
,
value
path
.
Path
,
eol
time
.
Time
)
{
var
err
error
value
,
err
=
path
.
ParsePath
(
value
.
String
())
if
err
!=
nil
{
log
.
Error
(
"could not parse path"
)
return
}
name
,
err
:=
peer
.
IDFromPrivateKey
(
key
)
if
err
!=
nil
{
log
.
Error
(
"while adding to cache, could not get peerid from private key"
)
return
}
rr
,
ok
:=
ns
.
resolvers
[
"dht"
]
.
(
*
routingResolver
)
if
!
ok
{
// should never happen, purely for sanity
log
.
Panicf
(
"unexpected type %T as DHT resolver."
,
ns
.
resolvers
[
"dht"
])
}
if
time
.
Now
()
.
Add
(
DefaultResolverCacheTTL
)
.
Before
(
eol
)
{
eol
=
time
.
Now
()
.
Add
(
DefaultResolverCacheTTL
)
}
rr
.
cache
.
Add
(
name
.
Pretty
(),
cacheEntry
{
val
:
value
,
eol
:
eol
,
})
}
namesys/publisher.go
浏览文件 @
a47d1b03
...
...
@@ -32,7 +32,8 @@ var ErrExpiredRecord = errors.New("expired record")
// unknown validity type.
var
ErrUnrecognizedValidity
=
errors
.
New
(
"unrecognized validity type"
)
var
PublishPutValTimeout
=
time
.
Minute
const
PublishPutValTimeout
=
time
.
Minute
const
DefaultRecordTTL
=
24
*
time
.
Hour
// ipnsPublisher is capable of publishing and resolving names to the IPFS
// routing system.
...
...
@@ -53,7 +54,7 @@ func NewRoutingPublisher(route routing.ValueStore, ds ds.Datastore) *ipnsPublish
// and publishes it out to the routing system
func
(
p
*
ipnsPublisher
)
Publish
(
ctx
context
.
Context
,
k
ci
.
PrivKey
,
value
path
.
Path
)
error
{
log
.
Debugf
(
"Publish %s"
,
value
)
return
p
.
PublishWithEOL
(
ctx
,
k
,
value
,
time
.
Now
()
.
Add
(
time
.
Hour
*
24
))
return
p
.
PublishWithEOL
(
ctx
,
k
,
value
,
time
.
Now
()
.
Add
(
DefaultRecordTTL
))
}
// PublishWithEOL is a temporary stand in for the ipns records implementation
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论