Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
9f65e813
Commit
9f65e813
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix purge
parent
bd26d29c
No related branches found
No related tags found
1 merge request
!60
Revert "Fail a test to be sure it works"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
storage/purge.go
+42
-20
42 additions, 20 deletions
storage/purge.go
wasm/follow.go
+2
-4
2 additions, 4 deletions
wasm/follow.go
with
44 additions
and
24 deletions
storage/purge.go
+
42
−
20
View file @
9f65e813
...
@@ -12,51 +12,66 @@ package storage
...
@@ -12,51 +12,66 @@ package storage
import
(
import
(
"github.com/hack-pad/go-indexeddb/idb"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
"github.com/pkg/errors"
"gitlab.com/elixxir/client/storage/utility"
"gitlab.com/elixxir/xxdk-wasm/utils"
"gitlab.com/elixxir/xxdk-wasm/utils"
"sync/atomic"
"sync/atomic"
"syscall/js"
"syscall/js"
)
)
//
N
umClientsRunning is an atomic that tracks the current number of Cmix
//
n
umClientsRunning is an atomic that tracks the current number of Cmix
// followers that have been started. Every time one is started, this counter
// followers that have been started. Every time one is started, this counter
// must be incremented and every time one is stopped, it must be decremented.
// must be incremented and every time one is stopped, it must be decremented.
//
//
// This variable is an atomic. Only access it with atomic functions
// This variable is an atomic. Only access it with atomic functions
var
NumClientsRunning
uint64
var
numClientsRunning
uint64
// IncrementNumClientsRunning increments the number client tracker. This should
// be called when starting the network follower.
func
IncrementNumClientsRunning
()
{
atomic
.
AddUint64
(
&
numClientsRunning
,
1
)
}
// DecrementNumClientsRunning decrements the number client tracker. This should
// be called when stopping the network follower.
func
DecrementNumClientsRunning
()
{
atomic
.
AddUint64
(
&
numClientsRunning
,
^
uint64
(
0
))
}
// Purge clears all local storage and indexedDb databases saved by this WASM
// Purge clears all local storage and indexedDb databases saved by this WASM
// binary. All Cmix followers must be closed and the user's password is
// binary. This can only occur when no cMix followers are running. The user's
// required.
// password is required.
//
// Warning: This deletes all storage local to the webpage running this WASM.
// Only use if you want to destroy everything.
//
//
// Parameters:
// Parameters:
// - args[0] - The user-supplied password (string).
// - args[0] - Storage directory path (string). This is the same directory path
// passed into [wasm.NewCmix].
// - args[1] - The user-supplied password (string). This is the same password
// passed into [wasm.NewCmix].
//
//
// Returns:
// Returns:
// - Throws a TypeError if the password is incorrect or if not all
Cm
ix
// - Throws a TypeError if the password is incorrect or if not all
cM
ix
// followers have been stopped.
// followers have been stopped.
func
Purge
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
func
Purge
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
storageDirectory
:=
args
[
0
]
.
String
()
userPassword
:=
args
[
1
]
.
String
()
// Check the password
// Check the password
if
!
verifyPassword
(
args
[
0
]
.
String
()
)
{
if
!
verifyPassword
(
userPassword
)
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
New
(
"invalid password"
))
utils
.
Throw
(
utils
.
TypeError
,
errors
.
New
(
"invalid password"
))
return
nil
return
nil
}
}
// Verify all Cmix followers are stopped
// Verify all Cmix followers are stopped
if
n
:=
atomic
.
LoadUint64
(
&
N
umClientsRunning
);
n
!=
0
{
if
n
:=
atomic
.
LoadUint64
(
&
n
umClientsRunning
);
n
!=
0
{
utils
.
Throw
(
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
utils
.
TypeError
,
errors
.
Errorf
(
"%d
Cm
ix followers running"
,
n
))
"%d
cM
ix followers running
; all need to be stopped
"
,
n
))
return
nil
return
nil
}
}
// Get all indexedDb database names
// Get all indexedDb database names
databaseList
,
err
:=
GetIndexedDbList
()
databaseList
,
err
:=
GetIndexedDbList
()
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Throw
(
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
utils
.
TypeError
,
errors
.
Errorf
(
"failed to get list of indexedDb database names: %+v"
,
err
))
"failed to get list of indexedDb database names: %+v"
,
err
))
return
nil
return
nil
}
}
...
@@ -64,16 +79,23 @@ func Purge(_ js.Value, args []js.Value) interface{} {
...
@@ -64,16 +79,23 @@ func Purge(_ js.Value, args []js.Value) interface{} {
for
dbName
:=
range
databaseList
{
for
dbName
:=
range
databaseList
{
_
,
err
=
idb
.
Global
()
.
DeleteDatabase
(
dbName
)
_
,
err
=
idb
.
Global
()
.
DeleteDatabase
(
dbName
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Throw
(
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
utils
.
TypeError
,
errors
.
Errorf
(
"failed to delete indexedDb database %q: %+v"
,
dbName
,
err
))
"failed to delete indexedDb database %q: %+v"
,
dbName
,
err
))
return
nil
return
nil
}
}
}
}
//
Clear WASM
local storage
//
Get
local storage
ls
:=
GetLocalStorage
()
ls
:=
GetLocalStorage
()
// Clear all local storage saved by this WASM project
ls
.
ClearWASM
()
ls
.
ClearWASM
()
// Clear all EKV from local storage
ls
.
ClearPrefix
(
storageDirectory
)
// Clear all NDFs saved to local storage
ls
.
ClearPrefix
(
utility
.
NdfStorageKeyNamePrefix
)
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
wasm/follow.go
+
2
−
4
View file @
9f65e813
...
@@ -12,7 +12,6 @@ package wasm
...
@@ -12,7 +12,6 @@ package wasm
import
(
import
(
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/utils"
"gitlab.com/elixxir/xxdk-wasm/utils"
"sync/atomic"
"syscall/js"
"syscall/js"
)
)
...
@@ -62,8 +61,7 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} {
...
@@ -62,8 +61,7 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} {
return
nil
return
nil
}
}
atomic
.
AddUint64
(
&
storage
.
NumClientsRunning
,
1
)
storage
.
IncrementNumClientsRunning
()
return
nil
return
nil
}
}
...
@@ -81,8 +79,8 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} {
...
@@ -81,8 +79,8 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} {
utils
.
Throw
(
utils
.
TypeError
,
err
)
utils
.
Throw
(
utils
.
TypeError
,
err
)
return
nil
return
nil
}
}
atomic
.
AddUint64
(
&
storage
.
NumClientsRunning
,
^
uint64
(
0
))
storage
.
DecrementNumClientsRunning
()
return
nil
return
nil
}
}
...
...
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