Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4d63820b
Commit
4d63820b
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move indirect pinning to its own structure
parent
51879e96
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
43 deletions
+50
-43
blocks/set/refset.go
blocks/set/refset.go
+0
-39
pin/indirect.go
pin/indirect.go
+43
-0
pin/pin.go
pin/pin.go
+7
-4
No files found.
blocks/set/refset.go
deleted
100644 → 0
View file @
51879e96
package
set
import
(
"github.com/jbenet/go-ipfs/blocks/bloom"
"github.com/jbenet/go-ipfs/util"
)
type
refCntBlockSet
struct
{
blocks
map
[
util
.
Key
]
int
}
func
NewRefCountBlockSet
()
BlockSet
{
return
&
refCntBlockSet
{
blocks
:
make
(
map
[
util
.
Key
]
int
)}
}
func
(
r
*
refCntBlockSet
)
AddBlock
(
k
util
.
Key
)
{
r
.
blocks
[
k
]
++
}
func
(
r
*
refCntBlockSet
)
RemoveBlock
(
k
util
.
Key
)
{
v
,
ok
:=
r
.
blocks
[
k
]
if
!
ok
{
return
}
if
v
<=
1
{
delete
(
r
.
blocks
,
k
)
}
else
{
r
.
blocks
[
k
]
=
v
-
1
}
}
func
(
r
*
refCntBlockSet
)
HasKey
(
k
util
.
Key
)
bool
{
_
,
ok
:=
r
.
blocks
[
k
]
return
ok
}
func
(
r
*
refCntBlockSet
)
GetBloomFilter
()
bloom
.
Filter
{
return
nil
}
This diff is collapsed.
Click to expand it.
pin/indirect.go
0 → 100644
View file @
4d63820b
package
pin
import
(
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/util"
)
type
indirectPin
struct
{
blockset
bc
.
BlockSet
refCounts
map
[
util
.
Key
]
int
}
func
loadBlockSet
(
d
ds
.
Datastore
)
(
bc
.
BlockSet
,
map
[
util
.
Key
]
int
)
{
panic
(
"Not yet implemented!"
)
return
nil
,
nil
}
func
newIndirectPin
(
d
ds
.
Datastore
)
indirectPin
{
// suppose the blockset actually takes blocks, not just keys
bs
,
rc
:=
loadBlockSet
(
d
)
return
indirectPin
{
bs
,
rc
}
}
func
(
i
*
indirectPin
)
Increment
(
k
util
.
Key
)
{
c
:=
i
.
refCounts
[
k
]
i
.
refCounts
[
k
]
=
c
+
1
if
c
<=
0
{
i
.
blockset
.
AddBlock
(
k
)
}
}
func
(
i
*
indirectPin
)
Decrement
(
k
util
.
Key
)
{
c
:=
i
.
refCounts
[
k
]
-
1
i
.
refCounts
[
k
]
=
c
if
c
<=
0
{
i
.
blockset
.
RemoveBlock
(
k
)
}
}
func
(
i
*
indirectPin
)
HasKey
(
k
util
.
Key
)
bool
{
return
i
.
blockset
.
HasKey
(
k
)
}
This diff is collapsed.
Click to expand it.
pin/pin.go
View file @
4d63820b
...
...
@@ -15,19 +15,22 @@ type Pinner interface {
type
pinner
struct
{
recursePin
set
.
BlockSet
directPin
set
.
BlockSet
indirPin
set
.
BlockSet
indirPin
indirectPin
dserv
*
mdag
.
DAGService
dstore
ds
.
Datastore
}
func
NewPinner
(
dstore
ds
.
Datastore
,
serv
*
mdag
.
DAGService
)
Pinner
{
// Load set from given datastore...
rcset
:=
set
.
NewDBWrapperSet
(
dstore
,
"/pinned/recurse/"
,
set
.
NewSimpleBlockSet
())
dirset
:=
set
.
NewDBWrapperSet
(
dstore
,
"/pinned/direct/"
,
set
.
NewSimpleBlockSet
())
indset
:=
set
.
NewDBWrapperSet
(
dstore
,
"/pinned/indirect/"
,
set
.
NewRefCountBlockSet
())
nsdstore
:=
dstore
// WRAP IN NAMESPACE
return
&
pinner
{
recursePin
:
rcset
,
directPin
:
dirset
,
indirPin
:
indset
,
indirPin
:
newIndirectPin
(
nsdstore
)
,
dserv
:
serv
,
dstore
:
dstore
,
}
...
...
@@ -99,7 +102,7 @@ func (p *pinner) pinIndirectRecurse(node *mdag.Node) error {
return
err
}
p
.
indirPin
.
AddBlock
(
k
)
p
.
indirPin
.
Increment
(
k
)
return
p
.
pinLinks
(
node
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment