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
d3f5ee22
Commit
d3f5ee22
authored
Jan 22, 2018
by
ForrestWeston
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs for mfs system method impls
License: MIT Signed-off-by:
ForrestWeston
<
forrest@protocol.ai
>
parent
c73493e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
10 deletions
+17
-10
mfs/system.go
mfs/system.go
+17
-10
No files found.
mfs/system.go
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
...
...
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