Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
459e0d53
提交
459e0d53
authored
10月 08, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ipns TestFastRepublish
上级
ffe2bdce
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
127 行增加
和
25 行删除
+127
-25
ipns_test.go
fuse/ipns/ipns_test.go
+106
-2
ipns_unix.go
fuse/ipns/ipns_unix.go
+6
-1
repub_unix.go
fuse/ipns/repub_unix.go
+15
-22
没有找到文件。
fuse/ipns/ipns_test.go
浏览文件 @
459e0d53
...
...
@@ -9,7 +9,8 @@ import (
"time"
fstest
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil"
"github.com/jbenet/go-ipfs/core"
core
"github.com/jbenet/go-ipfs/core"
u
"github.com/jbenet/go-ipfs/util"
)
func
randBytes
(
size
int
)
[]
byte
{
...
...
@@ -19,7 +20,10 @@ func randBytes(size int) []byte {
}
func
writeFile
(
t
*
testing
.
T
,
size
int
,
path
string
)
[]
byte
{
data
:=
randBytes
(
size
)
return
writeFileData
(
t
,
randBytes
(
size
),
path
)
}
func
writeFileData
(
t
*
testing
.
T
,
data
[]
byte
,
path
string
)
[]
byte
{
fi
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -179,6 +183,106 @@ func TestAppendFile(t *testing.T) {
}
}
func
TestFastRepublish
(
t
*
testing
.
T
)
{
// make timeout noticeable.
osrt
:=
shortRepublishTimeout
shortRepublishTimeout
=
time
.
Millisecond
*
100
olrt
:=
longRepublishTimeout
longRepublishTimeout
=
time
.
Second
node
,
mnt
:=
setupIpnsTest
(
t
,
nil
)
h
,
err
:=
node
.
Identity
.
PrivKey
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pubkeyHash
:=
u
.
Key
(
h
)
.
Pretty
()
// set them back
defer
func
()
{
shortRepublishTimeout
=
osrt
longRepublishTimeout
=
olrt
mnt
.
Close
()
}()
closed
:=
make
(
chan
struct
{})
dataA
:=
[]
byte
(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
dataB
:=
[]
byte
(
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
)
fname
:=
mnt
.
Dir
+
"/local/file"
// get first resolved hash
log
.
Debug
(
"publishing first hash"
)
writeFileData
(
t
,
dataA
,
fname
)
// random
<-
time
.
After
(
shortRepublishTimeout
*
11
/
10
)
log
.
Debug
(
"resolving first hash"
)
resolvedHash
,
err
:=
node
.
Namesys
.
Resolve
(
pubkeyHash
)
if
err
!=
nil
{
t
.
Fatal
(
"resolve err:"
,
pubkeyHash
,
err
)
}
// constantly keep writing to the file
go
func
()
{
for
{
select
{
case
<-
closed
:
return
case
<-
time
.
After
(
shortRepublishTimeout
*
8
/
10
)
:
writeFileData
(
t
,
dataB
,
fname
)
}
}
}()
hasPublished
:=
func
()
bool
{
res
,
err
:=
node
.
Namesys
.
Resolve
(
pubkeyHash
)
if
err
!=
nil
{
t
.
Fatal
(
"resolve err: %v"
,
err
)
}
return
res
!=
resolvedHash
}
// test things
// at this point, should not have written dataA and not have written dataB
rbuf
,
err
:=
ioutil
.
ReadFile
(
fname
)
if
err
!=
nil
||
!
bytes
.
Equal
(
rbuf
,
dataA
)
{
t
.
Fatal
(
"Data inconsistent! %v %v"
,
err
,
string
(
rbuf
))
}
if
hasPublished
()
{
t
.
Fatal
(
"published (wrote)"
)
}
<-
time
.
After
(
shortRepublishTimeout
*
11
/
10
)
// at this point, should have written written dataB, but not published it
rbuf
,
err
=
ioutil
.
ReadFile
(
fname
)
if
err
!=
nil
||
!
bytes
.
Equal
(
rbuf
,
dataB
)
{
t
.
Fatal
(
"Data inconsistent! %v %v"
,
err
,
string
(
rbuf
))
}
if
hasPublished
()
{
t
.
Fatal
(
"published (wrote)"
)
}
<-
time
.
After
(
longRepublishTimeout
*
11
/
10
)
// at this point, should have written written dataB, and published it
rbuf
,
err
=
ioutil
.
ReadFile
(
fname
)
if
err
!=
nil
||
!
bytes
.
Equal
(
rbuf
,
dataB
)
{
t
.
Fatal
(
"Data inconsistent! %v %v"
,
err
,
string
(
rbuf
))
}
if
!
hasPublished
()
{
t
.
Fatal
(
"not published"
)
}
close
(
closed
)
}
// Test writing a medium sized file one byte at a time
func
TestMultiWrite
(
t
*
testing
.
T
)
{
_
,
mnt
:=
setupIpnsTest
(
t
,
nil
)
...
...
fuse/ipns/ipns_unix.go
浏览文件 @
459e0d53
...
...
@@ -21,6 +21,11 @@ import (
var
log
=
u
.
Logger
(
"ipns"
)
var
(
shortRepublishTimeout
=
time
.
Millisecond
*
5
longRepublishTimeout
=
time
.
Millisecond
*
500
)
// FileSystem is the readwrite IPNS Fuse Filesystem.
type
FileSystem
struct
{
Ipfs
*
core
.
IpfsNode
...
...
@@ -71,7 +76,7 @@ func CreateRoot(n *core.IpfsNode, keys []ci.PrivKey, ipfsroot string) (*Root, er
nd
:=
new
(
Node
)
nd
.
Ipfs
=
n
nd
.
key
=
k
nd
.
repub
=
NewRepublisher
(
nd
,
time
.
Millisecond
*
5
,
time
.
Millisecond
*
500
)
nd
.
repub
=
NewRepublisher
(
nd
,
shortRepublishTimeout
,
longRepublishTimeout
)
go
nd
.
repub
.
Run
()
...
...
fuse/ipns/repub_unix.go
浏览文件 @
459e0d53
...
...
@@ -22,28 +22,21 @@ func (np *Republisher) Run() {
for
_
=
range
np
.
Publish
{
quick
:=
time
.
After
(
np
.
TimeoutShort
)
longer
:=
time
.
After
(
np
.
TimeoutLong
)
for
{
select
{
case
<-
quick
:
//Do the publish!
log
.
Info
(
"Publishing Changes!"
)
err
:=
np
.
node
.
republishRoot
()
if
err
!=
nil
{
log
.
Critical
(
"republishRoot error: %s"
,
err
)
}
goto
done
case
<-
longer
:
//Do the publish!
log
.
Info
(
"Publishing Changes!"
)
err
:=
np
.
node
.
republishRoot
()
if
err
!=
nil
{
log
.
Critical
(
"republishRoot error: %s"
,
err
)
}
goto
done
case
<-
np
.
Publish
:
quick
=
time
.
After
(
np
.
TimeoutShort
)
}
wait
:
select
{
case
<-
quick
:
case
<-
longer
:
case
<-
np
.
Publish
:
quick
=
time
.
After
(
np
.
TimeoutShort
)
goto
wait
}
log
.
Info
(
"Publishing Changes!"
)
err
:=
np
.
node
.
republishRoot
()
if
err
!=
nil
{
log
.
Critical
(
"republishRoot error: %s"
,
err
)
}
done
:
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论