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
a8ab35cf
Commit
a8ab35cf
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
god grant us all merciful deaths
parent
bca02b91
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!23
god grant us all merciful deaths
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexedDb/init.go
+30
-22
30 additions, 22 deletions
indexedDb/init.go
with
30 additions
and
22 deletions
indexedDb/init.go
+
30
−
22
View file @
a8ab35cf
...
...
@@ -11,6 +11,7 @@ package indexedDb
import
(
"github.com/pkg/errors"
"gitlab.com/elixxir/crypto/broadcast"
cryptoChannel
"gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/xxdk-wasm/storage"
"syscall/js"
...
...
@@ -94,27 +95,7 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher,
return
nil
,
err
}
// FIXME: The below is a hack that for some reason prevents moving on with
// uninitialized database despite the previous call to Await.
// It would be idea to find a different solution.
// Close and open again to ensure the state is finalized
err
=
db
.
Close
()
if
err
!=
nil
{
return
nil
,
err
}
openRequest
,
err
=
idb
.
Global
()
.
Open
(
ctx
,
databaseName
,
currentVersion
,
func
(
db
*
idb
.
Database
,
oldVersion
,
newVersion
uint
)
error
{
return
nil
})
if
err
!=
nil
{
return
nil
,
err
}
// Wait for database open to finish
db
,
err
=
openRequest
.
Await
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
// Save the encryption status to storage
encryptionStatus
:=
encryption
!=
nil
loadedEncryptionStatus
,
err
:=
storage
.
StoreIndexedDbEncryptionStatus
(
databaseName
,
encryptionStatus
)
...
...
@@ -122,13 +103,17 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher,
return
nil
,
err
}
// Verify encryption status does not change
if
encryptionStatus
!=
loadedEncryptionStatus
{
return
nil
,
errors
.
New
(
"Cannot load database with different encryption status."
)
}
else
if
!
encryptionStatus
{
jww
.
WARN
.
Printf
(
"IndexedDb encryption disabled!"
)
}
return
&
wasmModel
{
db
:
db
,
receivedMessageCB
:
cb
,
cipher
:
encryption
},
err
// Attempt to ensure the database has been properly initialized
wrapper
:=
&
wasmModel
{
db
:
db
,
receivedMessageCB
:
cb
,
cipher
:
encryption
}
return
wrapper
,
wrapper
.
hackTestDb
()
}
// v1Upgrade performs the v0 -> v1 database upgrade.
...
...
@@ -195,3 +180,26 @@ func v1Upgrade(db *idb.Database) error {
return
nil
}
// hackTestDb is a horrible function that exists as the result of an extremely
// long discussion about why initializing the IndexedDb sometimes silently
// fails. It ultimately tries to prevent an unrecoverable situation by actually
// inserting some nonsense data and then checking to see if it persists.
// If this function still exists in 2023, god help us all. Amen.
func
(
w
*
wasmModel
)
hackTestDb
()
error
{
testId
:=
&
id
.
DummyUser
testChannel
:=
&
broadcast
.
Channel
{
ReceptionID
:
testId
,
Name
:
"test"
,
Description
:
"test"
,
}
w
.
JoinChannel
(
testChannel
)
result
,
err
:=
w
.
get
(
channelsStoreName
,
js
.
ValueOf
(
testId
.
String
()))
if
err
!=
nil
{
return
err
}
if
len
(
result
)
==
0
{
return
errors
.
Errorf
(
"Failed to test db, record not present"
)
}
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