Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6458ddcd
提交
6458ddcd
authored
10月 19, 2014
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flesh out pinning object, needs tests and cli wiring still
上级
4d63820b
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
370 行增加
和
70 行删除
+370
-70
Godeps.json
Godeps/Godeps.json
+1
-1
doc.go
...ce/src/github.com/jbenet/datastore.go/keytransform/doc.go
+25
-0
interface.go
.../github.com/jbenet/datastore.go/keytransform/interface.go
+34
-0
doc.go
...space/src/github.com/jbenet/datastore.go/namespace/doc.go
+24
-0
example_test.go
.../github.com/jbenet/datastore.go/namespace/example_test.go
+30
-0
namespace.go
...src/github.com/jbenet/datastore.go/namespace/namespace.go
+44
-0
namespace_test.go
...ithub.com/jbenet/datastore.go/namespace/namespace_test.go
+72
-0
fs_test.go
...orkspace/src/github.com/jbenet/go-datastore/fs/fs_test.go
+18
-4
io.go
...ps/_workspace/src/github.com/jbenet/go-datastore/io/io.go
+0
-44
dbset.go
blocks/set/dbset.go
+5
-7
set.go
blocks/set/set.go
+35
-0
indirect.go
pin/indirect.go
+25
-9
pin.go
pin/pin.go
+57
-5
没有找到文件。
Godeps/Godeps.json
浏览文件 @
6458ddcd
{
{
"ImportPath"
:
"github.com/jbenet/go-ipfs"
,
"ImportPath"
:
"github.com/jbenet/go-ipfs"
,
"GoVersion"
:
"go1.3"
,
"GoVersion"
:
"go1.3
.3
"
,
"Packages"
:
[
"Packages"
:
[
"./..."
"./..."
],
],
...
...
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/doc.go
0 → 100644
浏览文件 @
6458ddcd
// Package keytransform introduces a Datastore Shim that transforms keys before
// passing them to its child. It can be used to manipulate what keys look like
// to the user, for example namespacing keys, reversing them, etc.
//
// Use the Wrap function to wrap a datastore with any KeyTransform.
// A KeyTransform is simply an interface with two functions, a conversion and
// its inverse. For example:
//
// import (
// ktds "github.com/jbenet/datastore.go/keytransform"
// ds "github.com/jbenet/datastore.go"
// )
//
// func reverseKey(k ds.Key) ds.Key {
// return k.Reverse()
// }
//
// func invertKeys(d ds.Datastore) {
// return ktds.Wrap(d, &ktds.Pair{
// Convert: reverseKey,
// Invert: reverseKey, // reverse is its own inverse.
// })
// }
//
package
keytransform
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/interface.go
0 → 100644
浏览文件 @
6458ddcd
package
keytransform
import
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
// KeyMapping is a function that maps one key to annother
type
KeyMapping
func
(
ds
.
Key
)
ds
.
Key
// KeyTransform is an object with a pair of functions for (invertibly)
// transforming keys
type
KeyTransform
interface
{
ConvertKey
(
ds
.
Key
)
ds
.
Key
InvertKey
(
ds
.
Key
)
ds
.
Key
}
// Datastore is a keytransform.Datastore
type
Datastore
interface
{
ds
.
Shim
KeyTransform
}
// Wrap wraps a given datastore with a KeyTransform function.
// The resulting wrapped datastore will use the transform on all Datastore
// operations.
func
Wrap
(
child
ds
.
Datastore
,
t
KeyTransform
)
Datastore
{
if
t
==
nil
{
panic
(
"t (KeyTransform) is nil"
)
}
if
child
==
nil
{
panic
(
"child (ds.Datastore) is nil"
)
}
return
&
ktds
{
child
:
child
,
KeyTransform
:
t
}
}
Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace/doc.go
0 → 100644
浏览文件 @
6458ddcd
// Package namespace introduces a namespace Datastore Shim, which basically
// mounts the entire child datastore under a prefix.
//
// Use the Wrap function to wrap a datastore with any Key prefix. For example:
//
// import (
// "fmt"
//
// ds "github.com/jbenet/datastore.go"
// nsds "github.com/jbenet/datastore.go/namespace"
// )
//
// func main() {
// mp := ds.NewMapDatastore()
// ns := nsds.Wrap(mp, ds.NewKey("/foo/bar"))
//
// // in the Namespace Datastore:
// ns.Put(ds.NewKey("/beep"), "boop")
// v2, _ := ns.Get(ds.NewKey("/beep")) // v2 == "boop"
//
// // and, in the underlying MapDatastore:
// v3, _ := mp.Get(ds.NewKey("/foo/bar/beep")) // v3 == "boop"
// }
package
namespace
Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace/example_test.go
0 → 100644
浏览文件 @
6458ddcd
package
namespace_test
import
(
"fmt"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
nsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace"
)
func
Example
()
{
mp
:=
ds
.
NewMapDatastore
()
ns
:=
nsds
.
Wrap
(
mp
,
ds
.
NewKey
(
"/foo/bar"
))
k
:=
ds
.
NewKey
(
"/beep"
)
v
:=
"boop"
ns
.
Put
(
k
,
v
)
fmt
.
Printf
(
"ns.Put %s %s
\n
"
,
k
,
v
)
v2
,
_
:=
ns
.
Get
(
k
)
fmt
.
Printf
(
"ns.Get %s -> %s
\n
"
,
k
,
v2
)
k3
:=
ds
.
NewKey
(
"/foo/bar/beep"
)
v3
,
_
:=
mp
.
Get
(
k3
)
fmt
.
Printf
(
"mp.Get %s -> %s
\n
"
,
k3
,
v3
)
// Output:
// ns.Put /beep -> boop
// ns.Get /beep -> boop
// mp.Get /foo/bar/beep -> boop
}
Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace/namespace.go
0 → 100644
浏览文件 @
6458ddcd
package
namespace
import
(
"fmt"
"strings"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
ktds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform"
)
// PrefixTransform constructs a KeyTransform with a pair of functions that
// add or remove the given prefix key.
//
// Warning: will panic if prefix not found when it should be there. This is
// to avoid insidious data inconsistency errors.
func
PrefixTransform
(
prefix
ds
.
Key
)
ktds
.
KeyTransform
{
return
&
ktds
.
Pair
{
// Convert adds the prefix
Convert
:
func
(
k
ds
.
Key
)
ds
.
Key
{
return
prefix
.
Child
(
k
)
},
// Invert removes the prefix. panics if prefix not found.
Invert
:
func
(
k
ds
.
Key
)
ds
.
Key
{
if
!
prefix
.
IsAncestorOf
(
k
)
{
fmt
.
Errorf
(
"Expected prefix (%s) in key (%s)"
,
prefix
,
k
)
panic
(
"expected prefix not found"
)
}
s
:=
strings
.
TrimPrefix
(
k
.
String
(),
prefix
.
String
())
return
ds
.
NewKey
(
s
)
},
}
}
// Wrap wraps a given datastore with a key-prefix.
func
Wrap
(
child
ds
.
Datastore
,
prefix
ds
.
Key
)
ktds
.
Datastore
{
if
child
==
nil
{
panic
(
"child (ds.Datastore) is nil"
)
}
return
ktds
.
Wrap
(
child
,
PrefixTransform
(
prefix
))
}
Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace/namespace_test.go
0 → 100644
浏览文件 @
6458ddcd
package
namespace_test
import
(
"bytes"
"sort"
"testing"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
ns
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace"
.
"launchpad.net/gocheck"
)
// Hook up gocheck into the "go test" runner.
func
Test
(
t
*
testing
.
T
)
{
TestingT
(
t
)
}
type
DSSuite
struct
{}
var
_
=
Suite
(
&
DSSuite
{})
func
(
ks
*
DSSuite
)
TestBasic
(
c
*
C
)
{
mpds
:=
ds
.
NewMapDatastore
()
nsds
:=
ns
.
Wrap
(
mpds
,
ds
.
NewKey
(
"abc"
))
keys
:=
strsToKeys
([]
string
{
"foo"
,
"foo/bar"
,
"foo/bar/baz"
,
"foo/barb"
,
"foo/bar/bazb"
,
"foo/bar/baz/barb"
,
})
for
_
,
k
:=
range
keys
{
err
:=
nsds
.
Put
(
k
,
[]
byte
(
k
.
String
()))
c
.
Check
(
err
,
Equals
,
nil
)
}
for
_
,
k
:=
range
keys
{
v1
,
err
:=
nsds
.
Get
(
k
)
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v1
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
v2
,
err
:=
mpds
.
Get
(
ds
.
NewKey
(
"abc"
)
.
Child
(
k
))
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v2
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
}
listA
,
errA
:=
mpds
.
KeyList
()
listB
,
errB
:=
nsds
.
KeyList
()
c
.
Check
(
errA
,
Equals
,
nil
)
c
.
Check
(
errB
,
Equals
,
nil
)
c
.
Check
(
len
(
listA
),
Equals
,
len
(
listB
))
// sort them cause yeah.
sort
.
Sort
(
ds
.
KeySlice
(
listA
))
sort
.
Sort
(
ds
.
KeySlice
(
listB
))
for
i
,
kA
:=
range
listA
{
kB
:=
listB
[
i
]
c
.
Check
(
nsds
.
InvertKey
(
kA
),
Equals
,
kB
)
c
.
Check
(
kA
,
Equals
,
nsds
.
ConvertKey
(
kB
))
}
}
func
strsToKeys
(
strs
[]
string
)
[]
ds
.
Key
{
keys
:=
make
([]
ds
.
Key
,
len
(
strs
))
for
i
,
s
:=
range
strs
{
keys
[
i
]
=
ds
.
NewKey
(
s
)
}
return
keys
}
Godeps/_workspace/src/github.com/jbenet/go-datastore/fs/fs_test.go
浏览文件 @
6458ddcd
...
@@ -2,6 +2,7 @@ package fs_test
...
@@ -2,6 +2,7 @@ package fs_test
import
(
import
(
"bytes"
"bytes"
"sort"
"testing"
"testing"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
...
@@ -12,10 +13,7 @@ import (
...
@@ -12,10 +13,7 @@ import (
// Hook up gocheck into the "go test" runner.
// Hook up gocheck into the "go test" runner.
func
Test
(
t
*
testing
.
T
)
{
TestingT
(
t
)
}
func
Test
(
t
*
testing
.
T
)
{
TestingT
(
t
)
}
type
DSSuite
struct
{
type
DSSuite
struct
{}
dir
string
ds
ds
.
Datastore
}
var
_
=
Suite
(
&
DSSuite
{})
var
_
=
Suite
(
&
DSSuite
{})
...
@@ -54,6 +52,22 @@ func (ks *DSSuite) TestBasic(c *C) {
...
@@ -54,6 +52,22 @@ func (ks *DSSuite) TestBasic(c *C) {
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
c
.
Check
(
bytes
.
Equal
(
v
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
}
}
listA
,
errA
:=
mpds
.
KeyList
()
listB
,
errB
:=
ktds
.
KeyList
()
c
.
Check
(
errA
,
Equals
,
nil
)
c
.
Check
(
errB
,
Equals
,
nil
)
c
.
Check
(
len
(
listA
),
Equals
,
len
(
listB
))
// sort them cause yeah.
sort
.
Sort
(
ds
.
KeySlice
(
listA
))
sort
.
Sort
(
ds
.
KeySlice
(
listB
))
for
i
,
kA
:=
range
listA
{
kB
:=
listB
[
i
]
c
.
Check
(
pair
.
Invert
(
kA
),
Equals
,
kB
)
c
.
Check
(
kA
,
Equals
,
pair
.
Convert
(
kB
))
}
}
}
func
strsToKeys
(
strs
[]
string
)
[]
ds
.
Key
{
func
strsToKeys
(
strs
[]
string
)
[]
ds
.
Key
{
...
...
Godeps/_workspace/src/github.com/jbenet/go-datastore/io/io.go
deleted
100644 → 0
浏览文件 @
4d63820b
package
leveldb
import
(
"bytes"
"io"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
)
// CastAsReader does type assertions to find the type of a value and attempts
// to turn it into an io.Reader. If not possible, will return ds.ErrInvalidType
func
CastAsReader
(
value
interface
{})
(
io
.
Reader
,
error
)
{
switch
v
:=
value
.
(
type
)
{
case
io
.
Reader
:
return
v
,
nil
case
[]
byte
:
return
bytes
.
NewReader
(
v
),
nil
case
string
:
return
bytes
.
NewReader
([]
byte
(
v
)),
nil
default
:
return
nil
,
ds
.
ErrInvalidType
}
}
// // CastAsWriter does type assertions to find the type of a value and attempts
// // to turn it into an io.Writer. If not possible, will return ds.ErrInvalidType
// func CastAsWriter(value interface{}) (err error) {
// switch v := value.(type) {
// case io.Reader:
// return v, nil
//
// case []byte:
// return bytes.NewReader(v), nil
//
// case string:
// return bytes.NewReader([]byte(v)), nil
//
// default:
// return nil, ds.ErrInvalidType
// }
// }
blocks/set/dbset.go
浏览文件 @
6458ddcd
...
@@ -9,19 +9,17 @@ import (
...
@@ -9,19 +9,17 @@ import (
type
datastoreBlockSet
struct
{
type
datastoreBlockSet
struct
{
dstore
ds
.
Datastore
dstore
ds
.
Datastore
bset
BlockSet
bset
BlockSet
prefix
string
}
}
func
NewDBWrapperSet
(
d
ds
.
Datastore
,
prefix
string
,
bset
BlockSet
)
BlockSet
{
func
NewDBWrapperSet
(
d
ds
.
Datastore
,
bset
BlockSet
)
BlockSet
{
return
&
datastoreBlockSet
{
return
&
datastoreBlockSet
{
dstore
:
d
,
dstore
:
d
,
bset
:
bset
,
bset
:
bset
,
prefix
:
prefix
,
}
}
}
}
func
(
d
*
datastoreBlockSet
)
AddBlock
(
k
util
.
Key
)
{
func
(
d
*
datastoreBlockSet
)
AddBlock
(
k
util
.
Key
)
{
err
:=
d
.
dstore
.
Put
(
d
.
prefixKey
(
k
),
[]
byte
{})
err
:=
d
.
dstore
.
Put
(
k
.
DsKey
(
),
[]
byte
{})
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"blockset put error: %s"
,
err
)
log
.
Error
(
"blockset put error: %s"
,
err
)
}
}
...
@@ -32,7 +30,7 @@ func (d *datastoreBlockSet) AddBlock(k util.Key) {
...
@@ -32,7 +30,7 @@ func (d *datastoreBlockSet) AddBlock(k util.Key) {
func
(
d
*
datastoreBlockSet
)
RemoveBlock
(
k
util
.
Key
)
{
func
(
d
*
datastoreBlockSet
)
RemoveBlock
(
k
util
.
Key
)
{
d
.
bset
.
RemoveBlock
(
k
)
d
.
bset
.
RemoveBlock
(
k
)
if
!
d
.
bset
.
HasKey
(
k
)
{
if
!
d
.
bset
.
HasKey
(
k
)
{
d
.
dstore
.
Delete
(
d
.
prefixKey
(
k
))
d
.
dstore
.
Delete
(
k
.
DsKey
(
))
}
}
}
}
...
@@ -44,6 +42,6 @@ func (d *datastoreBlockSet) GetBloomFilter() bloom.Filter {
...
@@ -44,6 +42,6 @@ func (d *datastoreBlockSet) GetBloomFilter() bloom.Filter {
return
d
.
bset
.
GetBloomFilter
()
return
d
.
bset
.
GetBloomFilter
()
}
}
func
(
d
*
datastoreBlockSet
)
prefixKey
(
k
util
.
Key
)
ds
.
Key
{
func
(
d
*
datastoreBlockSet
)
GetKeys
()
[]
util
.
Key
{
return
(
util
.
Key
(
d
.
prefix
)
+
k
)
.
DsKey
()
return
d
.
bset
.
GetKeys
()
}
}
blocks/set/set.go
浏览文件 @
6458ddcd
package
set
package
set
import
(
import
(
"errors"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
"github.com/jbenet/go-ipfs/blocks/bloom"
"github.com/jbenet/go-ipfs/blocks/bloom"
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util"
)
)
...
@@ -12,6 +16,29 @@ type BlockSet interface {
...
@@ -12,6 +16,29 @@ type BlockSet interface {
RemoveBlock
(
util
.
Key
)
RemoveBlock
(
util
.
Key
)
HasKey
(
util
.
Key
)
bool
HasKey
(
util
.
Key
)
bool
GetBloomFilter
()
bloom
.
Filter
GetBloomFilter
()
bloom
.
Filter
GetKeys
()
[]
util
.
Key
}
func
SimpleSetFromKeys
(
keys
[]
util
.
Key
)
BlockSet
{
sbs
:=
&
simpleBlockSet
{
blocks
:
make
(
map
[
util
.
Key
]
struct
{})}
for
_
,
k
:=
range
keys
{
sbs
.
blocks
[
k
]
=
struct
{}{}
}
return
sbs
}
func
SetFromDatastore
(
d
ds
.
Datastore
,
k
ds
.
Key
)
(
BlockSet
,
error
)
{
ikeys
,
err
:=
d
.
Get
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
keys
,
ok
:=
ikeys
.
([]
util
.
Key
)
if
!
ok
{
return
nil
,
errors
.
New
(
"Incorrect type for keys from datastore"
)
}
return
SimpleSetFromKeys
(
keys
),
nil
}
}
func
NewSimpleBlockSet
()
BlockSet
{
func
NewSimpleBlockSet
()
BlockSet
{
...
@@ -42,3 +69,11 @@ func (b *simpleBlockSet) GetBloomFilter() bloom.Filter {
...
@@ -42,3 +69,11 @@ func (b *simpleBlockSet) GetBloomFilter() bloom.Filter {
}
}
return
f
return
f
}
}
func
(
b
*
simpleBlockSet
)
GetKeys
()
[]
util
.
Key
{
var
out
[]
util
.
Key
for
k
,
_
:=
range
b
.
blocks
{
out
=
append
(
out
,
k
)
}
return
out
}
pin/indirect.go
浏览文件 @
6458ddcd
package
pin
package
pin
import
(
import
(
"errors"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
bc
"github.com/jbenet/go-ipfs/blocks/set"
"github.com/jbenet/go-ipfs/blocks/set"
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util"
)
)
type
indirectPin
struct
{
type
indirectPin
struct
{
blockset
bc
.
BlockSet
blockset
set
.
BlockSet
refCounts
map
[
util
.
Key
]
int
refCounts
map
[
util
.
Key
]
int
}
}
func
loadBlockSet
(
d
ds
.
Datastore
)
(
bc
.
BlockSet
,
map
[
util
.
Key
]
int
)
{
func
NewIndirectPin
(
dstore
ds
.
Datastore
)
*
indirectPin
{
panic
(
"Not yet implemented!"
)
return
&
indirectPin
{
return
nil
,
nil
blockset
:
set
.
NewDBWrapperSet
(
dstore
,
set
.
NewSimpleBlockSet
()),
refCounts
:
make
(
map
[
util
.
Key
]
int
),
}
}
}
func
newIndirectPin
(
d
ds
.
Datastore
)
indirectPin
{
func
loadIndirPin
(
d
ds
.
Datastore
,
k
ds
.
Key
)
(
*
indirectPin
,
error
)
{
// suppose the blockset actually takes blocks, not just keys
irefcnt
,
err
:=
d
.
Get
(
k
)
bs
,
rc
:=
loadBlockSet
(
d
)
if
err
!=
nil
{
return
indirectPin
{
bs
,
rc
}
return
nil
,
err
}
refcnt
,
ok
:=
irefcnt
.
(
map
[
util
.
Key
]
int
)
if
!
ok
{
return
nil
,
errors
.
New
(
"invalid type from datastore"
)
}
var
keys
[]
util
.
Key
for
k
,
_
:=
range
refcnt
{
keys
=
append
(
keys
,
k
)
}
return
&
indirectPin
{
blockset
:
set
.
SimpleSetFromKeys
(
keys
),
refCounts
:
refcnt
},
nil
}
}
func
(
i
*
indirectPin
)
Increment
(
k
util
.
Key
)
{
func
(
i
*
indirectPin
)
Increment
(
k
util
.
Key
)
{
...
...
pin/pin.go
浏览文件 @
6458ddcd
package
pin
package
pin
import
(
import
(
//ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
nsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/namespace"
"github.com/jbenet/go-ipfs/blocks/set"
"github.com/jbenet/go-ipfs/blocks/set"
mdag
"github.com/jbenet/go-ipfs/merkledag"
mdag
"github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util"
)
)
var
recursePinDatastoreKey
=
ds
.
NewKey
(
"/local/pins/recursive/keys"
)
var
directPinDatastoreKey
=
ds
.
NewKey
(
"/local/pins/direct/keys"
)
var
indirectPinDatastoreKey
=
ds
.
NewKey
(
"/local/pins/indirect/keys"
)
type
Pinner
interface
{
type
Pinner
interface
{
Pin
(
*
mdag
.
Node
,
bool
)
error
Pin
(
*
mdag
.
Node
,
bool
)
error
Unpin
(
util
.
Key
,
bool
)
error
Unpin
(
util
.
Key
,
bool
)
error
Flush
()
error
}
}
type
pinner
struct
{
type
pinner
struct
{
recursePin
set
.
BlockSet
recursePin
set
.
BlockSet
directPin
set
.
BlockSet
directPin
set
.
BlockSet
indirPin
indirectPin
indirPin
*
indirectPin
dserv
*
mdag
.
DAGService
dserv
*
mdag
.
DAGService
dstore
ds
.
Datastore
dstore
ds
.
Datastore
}
}
...
@@ -23,14 +31,17 @@ type pinner struct {
...
@@ -23,14 +31,17 @@ type pinner struct {
func
NewPinner
(
dstore
ds
.
Datastore
,
serv
*
mdag
.
DAGService
)
Pinner
{
func
NewPinner
(
dstore
ds
.
Datastore
,
serv
*
mdag
.
DAGService
)
Pinner
{
// Load set from given datastore...
// Load set from given datastore...
rc
set
:=
set
.
NewDBWrapperSet
(
dstore
,
"/pinned/recurse/"
,
set
.
NewSimpleBlockSet
()
)
rc
ds
:=
nsds
.
Wrap
(
dstore
,
recursePinDatastoreKey
)
dirset
:=
set
.
NewDBWrapperSet
(
dstore
,
"/pinned/direct/"
,
set
.
NewSimpleBlockSet
())
rcset
:=
set
.
NewDBWrapperSet
(
rcds
,
set
.
NewSimpleBlockSet
())
nsdstore
:=
dstore
// WRAP IN NAMESPACE
dirds
:=
nsds
.
Wrap
(
dstore
,
directPinDatastoreKey
)
dirset
:=
set
.
NewDBWrapperSet
(
dirds
,
set
.
NewSimpleBlockSet
())
nsdstore
:=
nsds
.
Wrap
(
dstore
,
indirectPinDatastoreKey
)
return
&
pinner
{
return
&
pinner
{
recursePin
:
rcset
,
recursePin
:
rcset
,
directPin
:
dirset
,
directPin
:
dirset
,
indirPin
:
n
ewIndirectPin
(
nsdstore
),
indirPin
:
N
ewIndirectPin
(
nsdstore
),
dserv
:
serv
,
dserv
:
serv
,
dstore
:
dstore
,
dstore
:
dstore
,
}
}
...
@@ -126,3 +137,44 @@ func (p *pinner) IsPinned(key util.Key) bool {
...
@@ -126,3 +137,44 @@ func (p *pinner) IsPinned(key util.Key) bool {
p
.
directPin
.
HasKey
(
key
)
||
p
.
directPin
.
HasKey
(
key
)
||
p
.
indirPin
.
HasKey
(
key
)
p
.
indirPin
.
HasKey
(
key
)
}
}
func
LoadPinner
(
d
ds
.
Datastore
)
(
Pinner
,
error
)
{
p
:=
new
(
pinner
)
var
err
error
p
.
recursePin
,
err
=
set
.
SetFromDatastore
(
d
,
recursePinDatastoreKey
)
if
err
!=
nil
{
return
nil
,
err
}
p
.
directPin
,
err
=
set
.
SetFromDatastore
(
d
,
directPinDatastoreKey
)
if
err
!=
nil
{
return
nil
,
err
}
p
.
indirPin
,
err
=
loadIndirPin
(
d
,
indirectPinDatastoreKey
)
if
err
!=
nil
{
return
nil
,
err
}
return
p
,
nil
}
func
(
p
*
pinner
)
Flush
()
error
{
recurse
:=
p
.
recursePin
.
GetKeys
()
err
:=
p
.
dstore
.
Put
(
recursePinDatastoreKey
,
recurse
)
if
err
!=
nil
{
return
err
}
direct
:=
p
.
directPin
.
GetKeys
()
err
=
p
.
dstore
.
Put
(
directPinDatastoreKey
,
direct
)
if
err
!=
nil
{
return
err
}
err
=
p
.
dstore
.
Put
(
indirectPinDatastoreKey
,
p
.
indirPin
.
refCounts
)
if
err
!=
nil
{
return
err
}
return
nil
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论