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

refac ipns

parent 2aab9278
Branches
No related tags found
No related merge requests found
...@@ -7,7 +7,6 @@ import { RouterLink } from "vue-router"; ...@@ -7,7 +7,6 @@ import { RouterLink } from "vue-router";
<nav> <nav>
<RouterLink to="/">Home</RouterLink> <RouterLink to="/">Home</RouterLink>
<RouterLink to="/kubo">Kubo</RouterLink> <RouterLink to="/kubo">Kubo</RouterLink>
<RouterLink to="/ipns">IPNS</RouterLink>
<RouterLink to="/index">Index</RouterLink> <RouterLink to="/index">Index</RouterLink>
<RouterLink to="/diff">Diff</RouterLink> <RouterLink to="/diff">Diff</RouterLink>
<RouterLink to="/io">IO</RouterLink> <RouterLink to="/io">IO</RouterLink>
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
*::after { *::after {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
font-weight: normal;
} }
body { body {
......
...@@ -10,5 +10,5 @@ const short = computed(() => props.ipns.slice(0, 5) + '...' + props.ipns.slice(- ...@@ -10,5 +10,5 @@ const short = computed(() => props.ipns.slice(0, 5) + '...' + props.ipns.slice(-
</script> </script>
<template> <template>
<a target="_blank" :href="gatewayUrlIPNS(ipns)" class="mono">{{ short }}</a> <a target="_blank" :href="gatewayUrlIPNS(ipns)" class="mono"><slot>{{ short }}</slot></a>
</template> </template>
...@@ -11,9 +11,6 @@ export async function getSelfDdKeys(): Promise<DdKeys> { ...@@ -11,9 +11,6 @@ export async function getSelfDdKeys(): Promise<DdKeys> {
tamt: ks.get('dd_tamt')!, tamt: ks.get('dd_tamt')!,
tamt_hist: ks.get('dd_tamt_hist')!, tamt_hist: ks.get('dd_tamt_hist')!,
profiles: ks.get('dd_profiles')!, profiles: ks.get('dd_profiles')!,
ui_client_demo: ks.get('dd_ui_client_demo') || null,
ui_client_demo_hist: ks.get('dd_ui_client_demo_hist') || null,
ui_admin: ks.get('dd_ui_admin') || null
} }
return keys return keys
} }
......
...@@ -8,11 +8,8 @@ export interface DiffData { ...@@ -8,11 +8,8 @@ export interface DiffData {
newItems: Array<[CID, IndexRequest]> newItems: Array<[CID, IndexRequest]>
} }
// this object allows to share a single ipns key with other datapods // this object allows to share a single ipns key with other datapods
// so that they use components as bootstrap // so that they use components as bootstrap
// each key can be replaced by their own version if they publish something in their name
// or keep pointing to a name maintained by someone else
export interface DdKeys { export interface DdKeys {
// root entry mapping to all the other ones below // root entry mapping to all the other ones below
root: string root: string
...@@ -22,10 +19,6 @@ export interface DdKeys { ...@@ -22,10 +19,6 @@ export interface DdKeys {
tamt_hist: string tamt_hist: string
// C+ profiles kinds grouped in a single tree for efficient indexing // C+ profiles kinds grouped in a single tree for efficient indexing
profiles: string profiles: string
// demo client UI
ui_client_demo: string | null
// history of demo client UI
ui_client_demo_hist: string | null
// node admin UI
ui_admin: string | null
} }
// names of keys for iter since we can not easily get them programatically
export const ddKeysNames = ['root', 'tamt', 'tamt_hist', 'profiles']
...@@ -10,9 +10,8 @@ ...@@ -10,9 +10,8 @@
</p> </p>
<h2>Main menu</h2> <h2>Main menu</h2>
<ul> <ul>
<li><RouterLink to="/">Home</RouterLink> -- here</li> <li><RouterLink to="/">Home</RouterLink> here</li>
<li><RouterLink to="/kubo">Kubo</RouterLink></li> <li><RouterLink to="/kubo">Kubo</RouterLink></li>
<li><RouterLink to="/ipns">IPNS</RouterLink></li>
<li><RouterLink to="/index">Index</RouterLink></li> <li><RouterLink to="/index">Index</RouterLink></li>
<li><RouterLink to="/diff">Diff</RouterLink></li> <li><RouterLink to="/diff">Diff</RouterLink></li>
<li><RouterLink to="/io">IO</RouterLink></li> <li><RouterLink to="/io">IO</RouterLink></li>
...@@ -21,6 +20,7 @@ ...@@ -21,6 +20,7 @@
<h2>Not in main menu</h2> <h2>Not in main menu</h2>
<ul> <ul>
<li><RouterLink to="/feed">Feed</RouterLink></li> <li><RouterLink to="/feed">Feed</RouterLink></li>
<li><RouterLink to="/ipns">IPNS</RouterLink></li>
</ul> </ul>
</main> </main>
</template> </template>
......
<script setup lang="ts"> <script setup lang="ts">
import { ref, type Ref, computed, onMounted, reactive, type ShallowReactive } from 'vue'
import { kubo } from '@/kubo' import { kubo } from '@/kubo'
import { emptyInode, type IndexHist } from '../types' import { emptyInode, type IndexHist } from '../types'
import { EMPTY_NODE_CID } from '../consts' import { EMPTY_NODE_CID } from '../consts'
import { CID } from 'multiformats' import { CID } from 'multiformats'
import { ref, type Ref, computed, onMounted } from 'vue' import { ddKeys as _ddKeys } from '../indexer/ipns'
import { ddKeys } from '../indexer/ipns' import { ddKeysNames, type DdKeys } from '../indexer/types'
import IpnsLink from '@/components/IpnsLink.vue'
import CidLink from '@/components/CidLink.vue'
const targetMsg = ref('') const ddKeys = _ddKeys as any // for easy manipulation
const targetCID: Ref<CID | null> = ref(null)
const histCID: Ref<CID | null> = ref(null)
const isValid = computed(() => { const targetCids: ShallowReactive<any> = reactive({})
const targetCidsMsg: ShallowReactive<any> = reactive({})
function set(k: string) {
try { try {
CID.parse(targetMsg.value) const cid = CID.parse(targetCidsMsg[k])
return true targetCidsMsg[k] = ''
} catch { kubo.name
return false .publish(cid, { key: 'dd_' + k, ttl: '1s' })
.then(() => {
targetCids[k] = cid.toString()
if (k == 'tamt') {
// track it on the history
updateHist(cid)
} }
}) })
.catch((e) => {
console.log(e)
targetCidsMsg[k] = 'error publishing'
})
} catch (e) {
console.log(e)
targetCidsMsg[k] = 'can not parse CID'
}
}
// inits indexing and publishes ipns entry for it function reinitialize(k: string) {
async function initIndex() { switch (k) {
targetCID.value = EMPTY_NODE_CID case 'tamt': {
// publish result to ipns console.log('reinitialize tamt')
kubo.name.publish(EMPTY_NODE_CID, { ttl: '1s', key: 'self' }).then(console.log) targetCidsMsg.tamt = EMPTY_NODE_CID.toString()
// track it on the history set(k)
updateHist(EMPTY_NODE_CID) break
}
case 'tamt_hist': {
console.log('reinitialize tamt history')
initTamtHistOn(ddKeys.tamt)
break
}
case 'profiles': {
console.log('reinitialize profiles')
break
}
default:
console.log('unimplemented')
}
} }
// inits indexing and publishes ipns entry for it // inits indexing and publishes ipns entry for it
async function initIndexHist() { async function initTamtHistOn(cid: CID) {
const firstHist: IndexHist = { const firstHist: IndexHist = {
last_history: null, last_history: null,
current_index: targetCID.value!, current_index: cid,
number: 0, number: 0,
timestamp: Date.now() timestamp: Date.now()
} }
const firstHistCID = await kubo.dag.put(firstHist) const firstHistCID = await kubo.dag.put(firstHist)
kubo.name.publish(firstHistCID, { ttl: '1s', key: 'index_history' }).then(console.log) kubo.name.publish(firstHistCID, { key: 'dd_tamt_hist', ttl: '1s' }).then(console.log)
} }
// resolve given ipns // resolve given ipns
async function resolveIPNS(ipns: string): Promise<CID> { async function resolveIPNS(ipns: string): Promise<CID> {
let cid = null for await (const name of kubo.name.resolve(ipns, { nocache: true, timeout: 100 })) {
for await (const name of kubo.name.resolve(ipns, { nocache: true })) { return CID.parse(name.slice(6))
cid = CID.parse(name.slice(6))
} }
return cid! throw Error('could not resolve')
} }
// update history chain with new cid // update history chain with new cid
async function updateHist(cid: CID) { async function updateHist(cid: CID): Promise<CID> {
const lastHistCID = await resolveIPNS(ddKeys.tamt_hist) const lastHistCID = await resolveIPNS(ddKeys.tamt_hist)
const lastHist = (await kubo.dag.get(lastHistCID)).value const lastHist = (await kubo.dag.get(lastHistCID)).value
const newHist: IndexHist = { const newHist: IndexHist = {
...@@ -61,48 +91,75 @@ async function updateHist(cid: CID) { ...@@ -61,48 +91,75 @@ async function updateHist(cid: CID) {
} }
const newHistCID = await kubo.dag.put(newHist) const newHistCID = await kubo.dag.put(newHist)
kubo.name.publish(newHistCID, { ttl: '1s', key: 'index_history' }) kubo.name.publish(newHistCID, { ttl: '1s', key: 'index_history' })
} return newHistCID
// publish cid to IPNS
function setTargetCid() {
if (isValid.value) {
const cid = CID.parse(targetMsg.value)
targetCID.value = cid
kubo.name.publish(cid, { ttl: '1s' })
} else {
targetCID.value = null
}
} }
onMounted(() => { onMounted(() => {
resolveIPNS(ddKeys.tamt).then((c) => (targetCID.value = c)) for (let k of ddKeysNames) {
resolveIPNS(ddKeys.tamt_hist).then((c) => (histCID.value = c)) resolveIPNS(ddKeys[k])
.then((c) => (targetCids[k] = c?.toString()))
.catch(console.log)
}
}) })
</script> </script>
<template> <template>
<div> <div>
<h1>IPNS</h1> <h1>IPNS</h1>
<p>Info about IPNS entries</p> <p>Info about Datapod IPNS entries. These keys are named with a "dd_" prefix.</p>
<h2>Index root</h2>
<p>Root node IPNS</p>
<p class="mono">{{ ddKeys.tamt }}</p>
<p>is pointing to</p>
<p class="mono">{{ targetCID }}</p>
<p>initialize empty index: <button @click="initIndex">reinitialize ⚠️</button></p>
<p> <p>
or set to custom CID <br /> To see all keys available in the node, not restricted to these ones, go to
<input v-model="targetMsg" @keyup.enter="setTargetCid" size="50" /> <RouterLink to="/kubo">Kubo view</RouterLink>.
<button v-on:click="setTargetCid">Set ⚠️</button>
</p> </p>
<h2>Index history</h2> <ul>
<p>History IPNS</p> <li><b>dd_root</b> points to the object listing all the keys</li>
<p class="mono">{{ ddKeys.tamt_hist }}</p> <li>
<p>is pointing to</p> <b>dd_tamt</b> points to the root node of the TAMT, see more on <RouterLink to="/index">index view</RouterLink>.
<p class="mono">{{ histCID }}</p> </li>
<p>reinitialize history to current target cid <button @click="initIndexHist">reinitialize ⚠️</button></p> <li>
<p>and got to <RouterLink to="/index">index</RouterLink> to see more about index history</p> <b>dd_tamt_hist</b> points to the head of the history of TAMT root, see more on
<RouterLink to="/index">index view</RouterLink>.
</li>
<li><b>dd_profiles</b> points to the root node of profiles index</li>
</ul>
<p>
In the table below you can edit your IPNS entires. Think of it as DNS and keep in mind that the datapod is using
it.
</p>
<br />
<table>
<thead>
<tr>
<th>name</th>
<th>target</th>
<th>set target</th>
<th>⚠️ reset</th>
</tr>
</thead>
<tbody>
<tr v-for="k in ddKeysNames">
<td>
<IpnsLink :ipns="ddKeys[k]">dd_{{ k }}</IpnsLink>
</td>
<td><CidLink v-if="targetCids[k]" :cid="targetCids[k]" /><template v-else>undefined</template></td>
<template v-if="k == 'root'">
<td class="center">-</td>
<td class="center">-</td>
</template>
<template v-else>
<td>
<input size="40" @keyup.enter="set(k)" v-model="targetCidsMsg[k]" /><button @click="set(k)">set</button>
</td>
<td class="center"><button @click="reinitialize(k)">reset</button></td>
</template>
</tr>
</tbody>
</table>
</div> </div>
</template> </template>
<style scoped></style> <style scoped>
.center {
text-align: center;
}
</style>
...@@ -49,6 +49,7 @@ refresh() ...@@ -49,6 +49,7 @@ refresh()
<p v-else>loading stats...<br /><br /><br /><br /><br /></p> <p v-else>loading stats...<br /><br /><br /><br /><br /></p>
<h2>Keys</h2> <h2>Keys</h2>
<p>Key prefixed by "dd" are used by the datapod. They should be listed in object published on dd_root.</p> <p>Key prefixed by "dd" are used by the datapod. They should be listed in object published on dd_root.</p>
<p>To inspect and edit IPNS entries, go to <RouterLink to="/ipns">IPNS view</RouterLink>.</p>
<table> <table>
<thead> <thead>
<tr> <tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment