Skip to content
Snippets Groups Projects
Commit 01d62ba3 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

tweaks

parent 0564923c
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,7 @@ More detail in the doc below.
## TODO
Bugs
- [ ] initialize dd_keys for new node (→ bootstrap)
- [ ] fix merging blocked when inode unreachable, timeout seems ignored
- [ ] fix pubsub cid can not be fetched triggers pubsub abort (dirty workaround for know)
Features
......
......@@ -12,7 +12,7 @@ import type { Message, SignedMessage } from '@libp2p/interface'
export function buildStringPayload(ir: IndexRequest) {
let payload = `prefix: Duniter Datapod
time: ${ir.time}
kind: ${ir.kind.toV1()}
kind: ${ir.kind}
`
if (ir.data)
payload += `data: ${ir.data.toV1()}
......@@ -69,7 +69,7 @@ export function getPubSubHandler(
// TODO some validation on timestamp to prevent too much control on the key
// example: 0 < Date.now() - timestamp < 1 minute
const stringPayload = buildStringPayload(dag)
const isValid = isValidSignature(stringPayload, dag.sig, dag.pubkey)
const isValid = isValidSignature(stringPayload, dag.sig!, dag.pubkey)
if (isValid) {
// at this point we can apply different treatment based on the key
// we could for example have a trust list published in ipfs
......
......@@ -11,7 +11,7 @@ export const BASE = 16
export const KEYSIZE = (64 * Math.log(2)) / Math.log(BASE)
// empty root cid
export const EMPTY_NODE_CID = 'bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy'
export const EMPTY_NODE_CID = CID.parse('bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy')
// document kind of old cesium plus profile imported in the indexer
export const CESIUM_PLUS_PROFILE_IMPORT = 'cplus_raw'
......
import type { CID } from 'multiformats'
import { kubo } from '../kubo'
import { DD_ROOT_OPT, getSelfDdKeys } from './ipns'
import { DD_ROOT_OPT, DD_TAMT_HIST_OPT, getSelfDdKeys } from './ipns'
import { resolveHist } from '../processor'
import type { IndexHist } from '../types'
// setup the root index from scratch
// after that, an other node can setup its own root index from another peer
......@@ -8,3 +11,23 @@ export async function publishKeys() {
const cid = await kubo.dag.put(keys)
await kubo.name.publish(cid, DD_ROOT_OPT)
}
/// check that history is available else initialize it
export async function initHistIfNull(cid: CID): Promise<void> {
try {
await resolveHist()
} catch {
// define first history element
const firstHist: IndexHist = {
last_history: null,
current_index: cid,
number: 0,
timestamp: Date.now()
}
const firstHistCID = await kubo.dag.put(firstHist)
kubo.name
.publish(firstHistCID, DD_TAMT_HIST_OPT)
.then(() => console.log('initialize history to ' + DD_TAMT_HIST_OPT.key))
}
return
}
import { TOPIC } from '../consts'
import { timestampToKey, arrayToVinode, publishHistory, mergeInodesSyncCID, resolveHist } from '../processor'
import { timestampToKey, arrayToVinode, mergeInodesSyncCID, resolveHist } from '../processor'
import { getPubSubHandler } from '../collector'
import { KUBO_RPC, kubo, kubo2 } from '../kubo'
import type { IndexHist, IndexRequest } from '../types'
......@@ -8,6 +8,7 @@ import { events, evtype, indexKnownDiff, indexStart } from './handlers'
import type { DiffData } from './types'
import { getRootCIDfromArgs } from './utils'
import { DD_TAMT_HIST_OPT, DD_TAMT_OPT } from './ipns'
import { initHistIfNull } from './bootstrap'
// === HANDLERS ===
......@@ -161,6 +162,7 @@ let isProcessingQueue = false
/// global rootCID variable
// set it from CLI args
let rootCID = await getRootCIDfromArgs(process.argv, trusted_peer_list)
await initHistIfNull(rootCID) // make sure history is available until then
let histCID: CID = await resolveHist()
let hist: IndexHist = (await kubo.dag.get(histCID)).value
......
......@@ -27,7 +27,7 @@ function handleMessage(message: any) {
kubo.dag.get(cid).then(function (d) {
const dag = d.value as IndexRequest
const stringPayload = buildStringPayload(dag)
const isValid = isValidSignature(stringPayload, dag.sig, dag.pubkey)
const isValid = isValidSignature(stringPayload, dag.sig!, dag.pubkey)
if (isValid) {
// here we would do the processing
// addToIndex(cid, dag)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment