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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
Duniter Datapod
Commits
95cdec7b
Commit
95cdec7b
authored
6 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
add check on IR data cid
parent
42fedf0a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/collector.ts
+15
-12
15 additions, 12 deletions
src/collector.ts
src/indexer/handlers.ts
+3
-2
3 additions, 2 deletions
src/indexer/handlers.ts
with
18 additions
and
14 deletions
src/collector.ts
+
15
−
12
View file @
95cdec7b
...
@@ -105,24 +105,27 @@ export function getPubSubHandler(
...
@@ -105,24 +105,27 @@ export function getPubSubHandler(
// build index request from dag or throw error
// build index request from dag or throw error
function
dagAsIndexRequest
(
dag
:
any
):
IndexRequest
{
function
dagAsIndexRequest
(
dag
:
any
):
IndexRequest
{
// check fields
// 1. kind must be a string with a length lower than 64
assert
(
typeof
dag
.
kind
===
"
string
"
)
assert
(
dag
.
kind
.
length
<=
64
)
// 2. time must be not too old (one minute for example)
// should not be in the future
// (prevents too much control on the storage key)
assert
(
typeof
dag
.
time
===
"
number
"
)
assert
(
Date
.
now
()
-
dag
.
time
<
MAX_IR_TIME_DIFF
)
// 3. data must be null or a cid
if
(
dag
.
data
!=
null
)
{
assert
(
!!
CID
.
asCID
(
dag
.
data
))
}
// all checks passed, pubkey and signature are checked later on
// extracts fields of interest from dag
// extracts fields of interest from dag
// note: extra fields are theoretically allowed but will not be taken into account and not saved
// note: extra fields are theoretically allowed but will not be taken into account and not saved
const
ir
:
IndexRequest
=
{
return
{
kind
:
dag
.
kind
,
kind
:
dag
.
kind
,
time
:
dag
.
time
,
time
:
dag
.
time
,
data
:
dag
.
data
,
data
:
dag
.
data
,
pubkey
:
dag
.
pubkey
,
pubkey
:
dag
.
pubkey
,
sig
:
dag
.
sig
sig
:
dag
.
sig
}
}
// check fields
// 1. kind must be a string with a lenght lower than 64
assert
(
typeof
ir
.
kind
===
"
string
"
)
assert
(
ir
.
kind
.
length
<=
64
)
// 2. time must be not too old (one minute for example)
// should not be in the future
// prevents too much control on the storage key
assert
(
typeof
ir
.
time
===
"
number
"
)
assert
(
Date
.
now
()
-
ir
.
time
<
MAX_IR_TIME_DIFF
)
// all checks passed
return
ir
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/indexer/handlers.ts
+
3
−
2
View file @
95cdec7b
...
@@ -57,7 +57,7 @@ export enum evtype {
...
@@ -57,7 +57,7 @@ export enum evtype {
/// ----- pubsub message handler -----
/// ----- pubsub message handler -----
export
async
function
validMessageHandler
(
_cid
:
CID
,
ir
:
IndexRequest
):
Promise
<
void
>
{
export
async
function
validMessageHandler
(
_cid
:
CID
,
ir
:
IndexRequest
):
Promise
<
void
>
{
// store the index request locally
// store the index request locally
(it is safe because of checks in collector)
kubo
.
dag
kubo
.
dag
.
put
(
ir
)
.
put
(
ir
)
.
then
((
cid
)
=>
{
.
then
((
cid
)
=>
{
...
@@ -65,7 +65,7 @@ export async function validMessageHandler(_cid: CID, ir: IndexRequest): Promise<
...
@@ -65,7 +65,7 @@ export async function validMessageHandler(_cid: CID, ir: IndexRequest): Promise<
// however, only the final index request cid is taken into account for safety
// however, only the final index request cid is taken into account for safety
if
(
cid
.
toString
()
!=
_cid
.
toString
())
console
.
log
(
'
👾
'
,
cid
,
'
!=
'
,
_cid
)
if
(
cid
.
toString
()
!=
_cid
.
toString
())
console
.
log
(
'
👾
'
,
cid
,
'
!=
'
,
_cid
)
console
.
log
(
'
adding valid index request to process queue
'
)
console
.
log
(
'
adding valid index request to process queue
'
)
// pin the index request we just added
//
asynchronously
pin the index request we just added
(non recursive at this point)
kubo
.
pin
.
add
(
cid
).
catch
(()
=>
console
.
log
(
`📌📌 could not pin index request that we just added
${
cid
}
`
))
kubo
.
pin
.
add
(
cid
).
catch
(()
=>
console
.
log
(
`📌📌 could not pin index request that we just added
${
cid
}
`
))
// add index request to the process list
// add index request to the process list
GLOB_processQueue
.
push
([
cid
,
ir
])
GLOB_processQueue
.
push
([
cid
,
ir
])
...
@@ -222,6 +222,7 @@ export async function takeFromMergeQueue() {
...
@@ -222,6 +222,7 @@ export async function takeFromMergeQueue() {
const
awaitedItems
=
await
Promise
.
all
(
items
)
const
awaitedItems
=
await
Promise
.
all
(
items
)
// awaitedItems.forEach(([c, _ir]) => {
// awaitedItems.forEach(([c, _ir]) => {
// // make sure to pin the index request to be able to serve its content later
// // make sure to pin the index request to be able to serve its content later
// // note: pubsub IRs are already pinned but peers IRs might not be
// kubo.pin.add(c, { recursive: true }).catch((_e) => console.log(`📌 could not pin remote index request ${c}`))
// kubo.pin.add(c, { recursive: true }).catch((_e) => console.log(`📌 could not pin remote index request ${c}`))
// })
// })
// add index requests to process queue
// add index requests to process queue
...
...
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