Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
go-ipfs
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
ipfs
go-ipfs
Commits
d3f5ee22
Commit
d3f5ee22
authored
7 years ago
by
ForrestWeston
Browse files
Options
Downloads
Patches
Plain Diff
docs for mfs system method impls
License: MIT Signed-off-by:
ForrestWeston
<
forrest@protocol.ai
>
parent
c73493e9
Branches
Branches containing commit
Tags
v1.14.0
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mfs/system.go
+17
-10
17 additions, 10 deletions
mfs/system.go
with
17 additions
and
10 deletions
mfs/system.go
+
17
−
10
View file @
d3f5ee22
...
...
@@ -41,19 +41,19 @@ const (
TDir
)
// FSNode represents any node (directory, root, or file) in the mfs filesystem
// FSNode represents any node (directory, root, or file) in the mfs filesystem
.
type
FSNode
interface
{
GetNode
()
(
node
.
Node
,
error
)
Flush
()
error
Type
()
NodeType
}
// Root represents the root of a filesystem tree
// Root represents the root of a filesystem tree
.
type
Root
struct
{
// node is the merkledag root
// node is the merkledag root
.
node
*
dag
.
ProtoNode
// val represents the node. It can either be a File or a Directory
// val represents the node. It can either be a File or a Directory
.
val
FSNode
repub
*
Republisher
...
...
@@ -63,9 +63,10 @@ type Root struct {
Type
string
}
// PubFunc is the function used by the `publish()` method.
type
PubFunc
func
(
context
.
Context
,
*
cid
.
Cid
)
error
//
n
ewRoot creates a new Root and starts up a republisher routine for it
//
N
ewRoot creates a new Root and starts up a republisher routine for it
.
func
NewRoot
(
parent
context
.
Context
,
ds
dag
.
DAGService
,
node
*
dag
.
ProtoNode
,
pf
PubFunc
)
(
*
Root
,
error
)
{
var
repub
*
Republisher
...
...
@@ -107,10 +108,13 @@ func NewRoot(parent context.Context, ds dag.DAGService, node *dag.ProtoNode, pf
return
root
,
nil
}
// GetValue returns the value of Root.
func
(
kr
*
Root
)
GetValue
()
FSNode
{
return
kr
.
val
}
// Flush signals that an update has occurred since the last publish,
// and updates the Root republisher.
func
(
kr
*
Root
)
Flush
()
error
{
nd
,
err
:=
kr
.
GetValue
()
.
GetNode
()
if
err
!=
nil
{
...
...
@@ -154,7 +158,7 @@ func (kr *Root) FlushMemFree(ctx context.Context) error {
}
// closeChild implements the childCloser interface, and signals to the publisher that
// there are changes ready to be published
// there are changes ready to be published
.
func
(
kr
*
Root
)
closeChild
(
name
string
,
nd
node
.
Node
,
sync
bool
)
error
{
c
,
err
:=
kr
.
dserv
.
Add
(
nd
)
if
err
!=
nil
{
...
...
@@ -181,7 +185,7 @@ func (kr *Root) Close() error {
return
nil
}
// Republisher manages when to publish a given entry
// Republisher manages when to publish a given entry
.
type
Republisher
struct
{
TimeoutLong
time
.
Duration
TimeoutShort
time
.
Duration
...
...
@@ -198,7 +202,7 @@ type Republisher struct {
}
// NewRepublisher creates a new Republisher object to republish the given root
// using the given short and long time intervals
// using the given short and long time intervals
.
func
NewRepublisher
(
ctx
context
.
Context
,
pf
PubFunc
,
tshort
,
tlong
time
.
Duration
)
*
Republisher
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
return
&
Republisher
{
...
...
@@ -218,6 +222,8 @@ func (p *Republisher) setVal(c *cid.Cid) {
p
.
val
=
c
}
// WaitPub Returns immediately if `lastpub` value is consistent with the
// current value `val`, else will block until `val` has been published.
func
(
p
*
Republisher
)
WaitPub
()
{
p
.
lk
.
Lock
()
consistent
:=
p
.
lastpub
==
p
.
val
...
...
@@ -239,7 +245,7 @@ func (p *Republisher) Close() error {
// Touch signals that an update has occurred since the last publish.
// Multiple consecutive touches may extend the time period before
// the next Publish occurs in order to more efficiently batch updates
// the next Publish occurs in order to more efficiently batch updates
.
func
(
np
*
Republisher
)
Update
(
c
*
cid
.
Cid
)
{
np
.
setVal
(
c
)
select
{
...
...
@@ -248,7 +254,7 @@ func (np *Republisher) Update(c *cid.Cid) {
}
}
// Run is the main republisher loop
// Run is the main republisher loop
.
func
(
np
*
Republisher
)
Run
()
{
for
{
select
{
...
...
@@ -284,6 +290,7 @@ func (np *Republisher) Run() {
}
}
// publish calls the `PubFunc`.
func
(
np
*
Republisher
)
publish
(
ctx
context
.
Context
)
error
{
np
.
lk
.
Lock
()
topub
:=
np
.
val
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment