Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter Datapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
nodes
Duniter Datapod
Commits
04b2522c
Commit
04b2522c
authored
Mar 30, 2024
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
fix unchanged node
parent
fab786d9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/p2p.ts
+1
-1
1 addition, 1 deletion
src/p2p.ts
src/processor.ts
+26
-5
26 additions, 5 deletions
src/processor.ts
with
27 additions
and
6 deletions
src/p2p.ts
+
1
−
1
View file @
04b2522c
...
...
@@ -8,7 +8,7 @@ import type { PubSub } from '@libp2p/interface'
export
const
local_peer
=
[
'
/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWF44SaSomGuUSNycgpkRwQcxcsMYeNbtn6XCHPR2ojodv
'
,
'
/ip4/127.0.0.1/udp/4001/quic-v1/p2p/12D3KooWF44SaSomGuUSNycgpkRwQcxcsMYeNbtn6XCHPR2ojodv
'
,
'
/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiC
QEENr7FShHOkuCAUCgW-oahGIGj0Mk3tOHXQjrsWGWQ/certhash/uEiCG3LMdW9dtRC_kXft2TlE66kZ4RX1MzQksLwxRgbJMVw
/p2p/12D3KooWF44SaSomGuUSNycgpkRwQcxcsMYeNbtn6XCHPR2ojodv
'
'
/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiC
G3LMdW9dtRC_kXft2TlE66kZ4RX1MzQksLwxRgbJMVw/certhash/uEiC6q4csXlqjvPg_z28SK2fu59NKwOLBDud7j-6Cdn958Q
/p2p/12D3KooWF44SaSomGuUSNycgpkRwQcxcsMYeNbtn6XCHPR2ojodv
'
]
export
const
TOPIC
=
'
ddd
'
...
...
This diff is collapsed.
Click to expand it.
src/processor.ts
+
26
−
5
View file @
04b2522c
...
...
@@ -12,19 +12,26 @@ export async function addToIndexQueue(cid: CID, request: IndexRequest) {
// https://polkadot-blockchain-academy.github.io/pba-book/substrate/storage/slides.html#/
// key size can be expressed in x chars depending on base
const
size
=
64
*
Math
.
log
(
2
)
/
Math
.
log
(
16
)
const
size
=
(
64
*
Math
.
log
(
2
)
)
/
Math
.
log
(
16
)
const
key
=
request
.
timestamp
.
toString
(
BASE
).
padStart
(
size
,
'
0
'
)
console
.
log
(
'
key:
'
+
key
)
// console.log('cid: ' + cid.toString())
for
await
(
const
name
of
kubo
.
name
.
resolve
(
IPNS
,
{
nocache
:
true
}))
{
console
.
log
(
'
initializing root node from ipns
'
)
//
console.log('initializing root node from ipns')
const
rootCID
=
CID
.
parse
(
name
.
slice
(
6
))
const
dag
:
IndexInode
=
(
await
kubo
.
dag
.
get
(
rootCID
)).
value
const
newRootCID
=
await
processInode
(
dag
,
key
,
cid
)
await
kubo
.
name
.
publish
(
newRootCID
,
{
ttl
:
'
1s
'
})
console
.
log
(
'
new root cid published:
'
+
newRootCID
.
toString
())
}
}
async
function
processInode
(
node
:
IndexInode
,
key
:
string
,
val
:
CID
):
Promise
<
CID
>
{
// console.log("key: " + key)
// bucket
const
b
=
parseInt
(
key
[
0
],
BASE
)
// if bucket is available, place leaf in it
...
...
@@ -34,28 +41,42 @@ async function processInode(node: IndexInode, key: string, val: CID): Promise<CI
// must share bucket with a node
const
[
k1
,
cid1
]
=
node
.
children
[
b
]
as
[
string
,
CID
]
const
comp
=
compareKey
(
k1
,
key
)
// console.log(comp)
switch
(
comp
.
type
)
{
case
resultType
.
Enter
:
const
e
=
comp
as
enterResult
const
enterNode
=
(
await
kubo
.
dag
.
get
(
cid1
)).
value
as
IndexInode
node
.
children
[
b
]
=
[
e
.
common
,
await
processInode
(
enterNode
,
e
.
nk
,
val
)]
console
.
log
(
'
enter "
'
+
e
.
common
+
'
" key "
'
+
e
.
nk
+
'
"
'
)
const
enterNode
:
IndexInode
|
IndexLeaf
=
(
await
kubo
.
dag
.
get
(
cid1
)).
value
const
enterNodeAsLeaf
=
enterNode
as
IndexLeaf
const
enterNodeAsInode
=
enterNode
as
IndexInode
if
(
enterNodeAsLeaf
.
leaf
)
{
// we can not enter a leaf at this stage
throw
Error
(
'
should not enter a leaf, this should have been an end
'
)
}
node
.
children
[
b
]
=
[
e
.
common
,
await
processInode
(
enterNodeAsInode
,
e
.
nk
,
val
)]
break
case
resultType
.
End
:
console
.
log
(
'
end
'
)
const
otherLeaf
=
(
await
kubo
.
dag
.
get
(
cid1
)).
value
as
IndexLeaf
node
.
children
[
b
]
=
[
k1
,
await
processLeaf
(
otherLeaf
,
val
)]
break
case
resultType
.
Diff
:
const
c
=
comp
as
diffResult
console
.
log
(
'
diff on "
'
+
c
.
common
+
'
" keys "
'
+
c
.
nk1
+
'
" / "
'
+
c
.
nk2
+
'
"
'
)
const
newNode
=
emptyInode
()
newNode
.
children
[
c
.
b1
]
=
[
c
.
nk1
,
cid1
]
newNode
.
children
[
c
.
b2
]
=
[
c
.
nk2
,
await
processLeaf
(
emptyLeaf
(),
val
)]
const
newNodeCid
=
await
kubo
.
dag
.
put
(
newNode
)
node
.
children
[
b
]
=
[
c
.
common
,
newNodeCid
]
break
}
}
// now that we have the new node save it and return
const
newCid
:
CID
=
await
kubo
.
dag
.
put
(
node
)
console
.
log
(
'
new inode:
'
+
newCid
.
toString
())
return
newCid
}
...
...
@@ -119,7 +140,7 @@ function compareKey(k1: string, k2: string): compResult {
type
:
resultType
.
Enter
,
common
,
b
,
nk
:
k2
.
slice
(
b
)
nk
:
k2
.
slice
(
common
.
length
)
}
}
else
{
// we reached the end
...
...
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
sign in
to comment