Compare commits
No commits in common. "main" and "main" have entirely different histories.
@ -31,7 +31,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
out/TildeFriends-release.fdroid.apk
|
out/TildeFriends-release.fdroid.apk
|
||||||
out/winrelease/tildefriends.standalone.exe
|
out/winrelease/tildefriends.exe
|
||||||
out/tildefriends-x86_64.AppImage
|
out/tildefriends-x86_64.AppImage
|
||||||
out/release/tildefriends.standalone
|
out/release/tildefriends.standalone
|
||||||
out/armrelease/tildefriends.standalone
|
out/armrelease/tildefriends.standalone
|
||||||
|
@ -127,7 +127,6 @@ WINDOWS_TARGETS := \
|
|||||||
out/winrelease/tildefriends.exe
|
out/winrelease/tildefriends.exe
|
||||||
ifeq ($(HAVE_WIN),1)
|
ifeq ($(HAVE_WIN),1)
|
||||||
BUILD_TYPES += windebug winrelease
|
BUILD_TYPES += windebug winrelease
|
||||||
all: out/windebug/tildefriends.standalone.exe out/winrelease/tildefriends.standalone.exe
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
AARCH64_TARGETS := \
|
AARCH64_TARGETS := \
|
||||||
@ -1092,7 +1091,6 @@ out/%.app/tildefriends.png: src/ios/tildefriends.png
|
|||||||
@cp -v $< $@
|
@cp -v $< $@
|
||||||
|
|
||||||
out/data.zip: $(RAW_FILES)
|
out/data.zip: $(RAW_FILES)
|
||||||
@echo [zip] $@
|
|
||||||
@zip -u $@ -q -9 $(RAW_FILES)
|
@zip -u $@ -q -9 $(RAW_FILES)
|
||||||
|
|
||||||
out/tildefriends-%.app/tildefriends: out/%/tildefriends out/tildefriends-%.app/Info.plist out/tildefriends-%.app/tildefriends.png out/data.zip
|
out/tildefriends-%.app/tildefriends: out/%/tildefriends out/tildefriends-%.app/Info.plist out/tildefriends-%.app/tildefriends.png out/data.zip
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "➡️",
|
"emoji": "➡️"
|
||||||
"previous": "&YDDSzbRD8NFAykYlZnk4r4hAK5qXjT5LmKE6rhS1s+A=.sha256"
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ async function contacts_internal(id, last_row_id, following, max_row_id) {
|
|||||||
result.blocking = result.blocking || {};
|
result.blocking = result.blocking || {};
|
||||||
let contacts = await query(
|
let contacts = await query(
|
||||||
`
|
`
|
||||||
SELECT json(content) AS content FROM messages
|
SELECT content FROM messages
|
||||||
WHERE author = ? AND
|
WHERE author = ? AND
|
||||||
rowid > ? AND
|
rowid > ? AND
|
||||||
rowid <= ? AND
|
rowid <= ? AND
|
||||||
@ -189,6 +189,50 @@ async function fetch_about(db, ids, users) {
|
|||||||
return Object.assign({}, users);
|
return Object.assign({}, users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getAbout(db, id) {
|
||||||
|
if (g_about_cache[id]) {
|
||||||
|
return g_about_cache[id];
|
||||||
|
}
|
||||||
|
let o = await db.get(id + ':about');
|
||||||
|
const k_version = 4;
|
||||||
|
let f = o ? JSON.parse(o) : o;
|
||||||
|
if (!f || f.version != k_version) {
|
||||||
|
f = {about: {}, sequence: 0, version: k_version};
|
||||||
|
}
|
||||||
|
await ssb.sqlAsync(
|
||||||
|
'SELECT ' +
|
||||||
|
' sequence, ' +
|
||||||
|
' content ' +
|
||||||
|
'FROM messages ' +
|
||||||
|
'WHERE ' +
|
||||||
|
' author = ?1 AND ' +
|
||||||
|
' sequence > ?2 AND ' +
|
||||||
|
" json_extract(content, '$.type') = 'about' AND " +
|
||||||
|
" json_extract(content, '$.about') = ?1 " +
|
||||||
|
'UNION SELECT MAX(sequence) as sequence, NULL FROM messages WHERE author = ?1 ' +
|
||||||
|
'ORDER BY sequence',
|
||||||
|
[id, f.sequence],
|
||||||
|
function (row) {
|
||||||
|
f.sequence = row.sequence;
|
||||||
|
if (row.content) {
|
||||||
|
let about = {};
|
||||||
|
try {
|
||||||
|
about = JSON.parse(row.content);
|
||||||
|
} catch {}
|
||||||
|
delete about.about;
|
||||||
|
delete about.type;
|
||||||
|
f.about = Object.assign(f.about, about);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let j = JSON.stringify(f);
|
||||||
|
if (o != j) {
|
||||||
|
await db.set(id + ':about', j);
|
||||||
|
}
|
||||||
|
g_about_cache[id] = f.about;
|
||||||
|
return f.about;
|
||||||
|
}
|
||||||
|
|
||||||
async function getSize(db, id) {
|
async function getSize(db, id) {
|
||||||
let size = 0;
|
let size = 0;
|
||||||
await ssb.sqlAsync(
|
await ssb.sqlAsync(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "🦀",
|
"emoji": "🦀",
|
||||||
"previous": "&jbL9Ab+XdvWnZbb50yimceFHR7XFDfBSWv9/XrbZ82I=.sha256"
|
"previous": "&bBoMW+AjErDfa483Mg3+h1L25xfDDeVSpcfD9WAwL3U=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@ tfrpc.register(async function createIdentity() {
|
|||||||
tfrpc.register(async function getServerIdentity() {
|
tfrpc.register(async function getServerIdentity() {
|
||||||
return ssb.getServerIdentity();
|
return ssb.getServerIdentity();
|
||||||
});
|
});
|
||||||
|
tfrpc.register(async function setServerFollowingMe(id, following) {
|
||||||
|
return ssb.setServerFollowingMe(id, following);
|
||||||
|
});
|
||||||
tfrpc.register(async function getIdentities() {
|
tfrpc.register(async function getIdentities() {
|
||||||
return ssb.getIdentities();
|
return ssb.getIdentities();
|
||||||
});
|
});
|
||||||
@ -103,10 +106,6 @@ tfrpc.register(async function getActiveIdentity() {
|
|||||||
tfrpc.register(async function sync() {
|
tfrpc.register(async function sync() {
|
||||||
return await ssb.sync();
|
return await ssb.sync();
|
||||||
});
|
});
|
||||||
tfrpc.register(async function url() {
|
|
||||||
return core.url;
|
|
||||||
});
|
|
||||||
|
|
||||||
core.register('onBroadcastsChanged', async function () {
|
core.register('onBroadcastsChanged', async function () {
|
||||||
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,7 @@ function textNode(text) {
|
|||||||
function linkNode(text, link) {
|
function linkNode(text, link) {
|
||||||
const linkNode = new commonmark.Node('link', undefined);
|
const linkNode = new commonmark.Node('link', undefined);
|
||||||
if (link.startsWith('#')) {
|
if (link.startsWith('#')) {
|
||||||
linkNode.destination = `#${encodeURIComponent(link)}`;
|
linkNode.destination = `#${encodeURIComponent('#' + link)}`;
|
||||||
} else {
|
} else {
|
||||||
linkNode.destination = link;
|
linkNode.destination = link;
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@ class TfElement extends LitElement {
|
|||||||
channels: {type: Array},
|
channels: {type: Array},
|
||||||
channels_unread: {type: Object},
|
channels_unread: {type: Object},
|
||||||
channels_latest: {type: Object},
|
channels_latest: {type: Object},
|
||||||
guest: {type: Boolean},
|
|
||||||
url: {type: String},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,9 +66,7 @@ class TfElement extends LitElement {
|
|||||||
async initial_load() {
|
async initial_load() {
|
||||||
let whoami = await tfrpc.rpc.getActiveIdentity();
|
let whoami = await tfrpc.rpc.getActiveIdentity();
|
||||||
let ids = (await tfrpc.rpc.getIdentities()) || [];
|
let ids = (await tfrpc.rpc.getIdentities()) || [];
|
||||||
this.url = await tfrpc.rpc.url();
|
|
||||||
this.whoami = whoami ?? (ids.length ? ids[0] : undefined);
|
this.whoami = whoami ?? (ids.length ? ids[0] : undefined);
|
||||||
this.guest = !this.whoami?.length;
|
|
||||||
this.ids = ids;
|
this.ids = ids;
|
||||||
await this.load_channels();
|
await this.load_channels();
|
||||||
}
|
}
|
||||||
@ -274,74 +270,31 @@ class TfElement extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get_latest_private(following) {
|
async get_latest_private(following) {
|
||||||
const k_version = 1;
|
|
||||||
// { "version": 1, "range": [1234, 5678], messages: [ "%1.sha256", "%2.sha256", ... ], latest: rowid }
|
|
||||||
let cache = JSON.parse(
|
|
||||||
(await tfrpc.rpc.databaseGet(`private:${this.whoami}`)) ?? '{}'
|
|
||||||
);
|
|
||||||
if (cache.version !== k_version) {
|
|
||||||
cache = {
|
|
||||||
version: k_version,
|
|
||||||
messages: [],
|
|
||||||
range: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let latest = (
|
let latest = (
|
||||||
await tfrpc.rpc.query('SELECT MAX(rowid) AS latest FROM messages')
|
await tfrpc.rpc.query('SELECT MAX(rowid) AS latest FROM messages')
|
||||||
)[0].latest;
|
)[0].latest;
|
||||||
let ranges = [];
|
const k_chunk_count = 256;
|
||||||
const k_chunk_size = 512;
|
while (latest - k_chunk_count >= 0) {
|
||||||
if (cache.range.length) {
|
|
||||||
for (let i = cache.range[1]; i < latest; i += k_chunk_size) {
|
|
||||||
ranges.push([i, Math.min(i + k_chunk_size, latest), true]);
|
|
||||||
}
|
|
||||||
for (let i = cache.range[0]; i >= 0; i -= k_chunk_size) {
|
|
||||||
ranges.push([
|
|
||||||
Math.max(i - k_chunk_size, 0),
|
|
||||||
Math.min(cache.range[0], i + k_chunk_size),
|
|
||||||
false,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < latest; i += k_chunk_size) {
|
|
||||||
ranges.push([i, Math.min(i + k_chunk_size, latest), true]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(cache);
|
|
||||||
for (let range of ranges) {
|
|
||||||
let messages = await tfrpc.rpc.query(
|
let messages = await tfrpc.rpc.query(
|
||||||
`
|
`
|
||||||
SELECT messages.rowid, messages.id, json(content) AS content
|
SELECT messages.rowid, messages.id, previous, author, sequence, timestamp, hash, json(content) AS content, signature
|
||||||
FROM messages
|
FROM messages
|
||||||
|
JOIN json_each(?1) AS following ON messages.author = following.value
|
||||||
WHERE
|
WHERE
|
||||||
messages.rowid > ?1 AND
|
messages.rowid > ?2 AND
|
||||||
messages.rowid <= ?2 AND
|
messages.rowid <= ?3 AND
|
||||||
json(messages.content) LIKE '"%'
|
json(messages.content) LIKE '"%'
|
||||||
ORDER BY sequence DESC
|
ORDER BY sequence DESC
|
||||||
`,
|
`,
|
||||||
[range[0], range[1]]
|
[JSON.stringify(following), latest - k_chunk_count, latest]
|
||||||
);
|
);
|
||||||
messages = (await this.decrypt(messages)).filter((x) => x.decrypted);
|
messages = (await this.decrypt(messages)).filter((x) => x.decrypted);
|
||||||
if (messages.length) {
|
if (messages.length) {
|
||||||
cache.latest = Math.max(
|
return Math.max(...messages.map((x) => x.rowid));
|
||||||
cache.latest ?? 0,
|
|
||||||
...messages.map((x) => x.rowid)
|
|
||||||
);
|
|
||||||
if (range[2]) {
|
|
||||||
cache.messages = [...cache.messages, ...messages.map((x) => x.id)];
|
|
||||||
} else {
|
|
||||||
cache.messages = [...messages.map((x) => x.id), ...cache.messages];
|
|
||||||
}
|
}
|
||||||
|
latest -= k_chunk_count;
|
||||||
}
|
}
|
||||||
cache.range[0] = Math.min(cache.range[0] ?? range[0], range[0]);
|
return -1;
|
||||||
cache.range[1] = Math.max(cache.range[1] ?? range[1], range[1]);
|
|
||||||
await tfrpc.rpc.databaseSet(
|
|
||||||
`private:${this.whoami}`,
|
|
||||||
JSON.stringify(cache)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
console.log(cache);
|
|
||||||
return cache.latest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async load_channels_latest(following) {
|
async load_channels_latest(following) {
|
||||||
@ -441,9 +394,7 @@ class TfElement extends LitElement {
|
|||||||
);
|
);
|
||||||
this.following = Object.keys(following);
|
this.following = Object.keys(following);
|
||||||
this.users = users;
|
this.users = users;
|
||||||
console.log(
|
console.log(`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`);
|
||||||
`load finished ${whoami} => ${this.whoami} in ${(new Date() - start_time) / 1000}`
|
|
||||||
);
|
|
||||||
this.whoami = whoami;
|
this.whoami = whoami;
|
||||||
this.loaded = whoami;
|
this.loaded = whoami;
|
||||||
}
|
}
|
||||||
@ -593,20 +544,8 @@ class TfElement extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
let contents = this.guest
|
let contents =
|
||||||
? html`<div
|
!this.loaded || this.loading
|
||||||
class="w3-display-middle w3-panel w3-theme-l5 w3-card-4 w3-padding-large w3-round-xlarge w3-xlarge w3-container"
|
|
||||||
>
|
|
||||||
<p>⚠️🦀 Must be logged in to Tilde Friends to scuttle here. 🦀⚠️</p>
|
|
||||||
<footer class="w3-center">
|
|
||||||
<a
|
|
||||||
class="w3-button w3-theme-d1"
|
|
||||||
href=${`/login?return=${encodeURIComponent(this.url)}`}
|
|
||||||
>Login</a
|
|
||||||
>
|
|
||||||
</footer>
|
|
||||||
</div>`
|
|
||||||
: !this.loaded || this.loading
|
|
||||||
? html`<div
|
? html`<div
|
||||||
class="w3-display-middle w3-panel w3-theme-l5 w3-card-4 w3-padding-large w3-round-xlarge w3-xlarge"
|
class="w3-display-middle w3-panel w3-theme-l5 w3-card-4 w3-padding-large w3-round-xlarge w3-xlarge"
|
||||||
>
|
>
|
||||||
@ -620,7 +559,7 @@ class TfElement extends LitElement {
|
|||||||
class="w3-theme-dark"
|
class="w3-theme-dark"
|
||||||
>
|
>
|
||||||
<div style="flex: 0 0">${tabs}</div>
|
<div style="flex: 0 0">${tabs}</div>
|
||||||
<div style="flex: 1 1; overflow: auto; contain: layout">
|
<div style="flex: 1 1; overflow: scroll; contain: layout">
|
||||||
${contents}
|
${contents}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -605,11 +605,7 @@ class TfComposeElement extends LitElement {
|
|||||||
<footer class="w3-container">
|
<footer class="w3-container">
|
||||||
${this.render_attach_app()} ${this.render_content_warning()}
|
${this.render_attach_app()} ${this.render_content_warning()}
|
||||||
${this.render_new_thread()}
|
${this.render_new_thread()}
|
||||||
<button
|
<button class="w3-button w3-theme-d1" id="submit" @click=${this.submit}>
|
||||||
class="w3-button w3-theme-d1"
|
|
||||||
id="submit"
|
|
||||||
@click=${this.submit}
|
|
||||||
>
|
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.attach}>
|
<button class="w3-button w3-theme-d1" @click=${this.attach}>
|
||||||
|
@ -97,13 +97,6 @@ class TfMessageElement extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_json(value) {
|
|
||||||
let json = JSON.stringify(value, null, 2);
|
|
||||||
return html`
|
|
||||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">${json}</pre>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
render_raw() {
|
render_raw() {
|
||||||
let raw = {
|
let raw = {
|
||||||
id: this.message?.id,
|
id: this.message?.id,
|
||||||
@ -115,7 +108,9 @@ class TfMessageElement extends LitElement {
|
|||||||
content: this.message?.content,
|
content: this.message?.content,
|
||||||
signature: this.message?.signature,
|
signature: this.message?.signature,
|
||||||
};
|
};
|
||||||
return this.render_json(raw);
|
return html`<div style="white-space: pre-wrap">
|
||||||
|
${JSON.stringify(raw, null, 2)}
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
vote(emoji) {
|
vote(emoji) {
|
||||||
@ -195,7 +190,7 @@ class TfMessageElement extends LitElement {
|
|||||||
|
|
||||||
render_mention(mention) {
|
render_mention(mention) {
|
||||||
if (!mention?.link || typeof mention.link != 'string') {
|
if (!mention?.link || typeof mention.link != 'string') {
|
||||||
return this.render_json(mention);
|
return html` <pre>${JSON.stringify(mention)}</pre>`;
|
||||||
} else if (
|
} else if (
|
||||||
mention?.link?.startsWith('&') &&
|
mention?.link?.startsWith('&') &&
|
||||||
mention?.type?.startsWith('image/')
|
mention?.type?.startsWith('image/')
|
||||||
@ -246,17 +241,16 @@ class TfMessageElement extends LitElement {
|
|||||||
) {
|
) {
|
||||||
return html` <a href=${`/${mention.link}/view`}>${mention.name}</a>`;
|
return html` <a href=${`/${mention.link}/view`}>${mention.name}</a>`;
|
||||||
} else {
|
} else {
|
||||||
return this.render_json(mention);
|
return html` <pre style="white-space: pre-wrap">
|
||||||
|
${JSON.stringify(mention, null, 2)}</pre
|
||||||
|
>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_mentions() {
|
render_mentions() {
|
||||||
let mentions = this.message?.content?.mentions || [];
|
let mentions = this.message?.content?.mentions || [];
|
||||||
mentions = mentions.filter(
|
mentions = mentions.filter(
|
||||||
(x) =>
|
(x) => this.message?.content?.text?.indexOf(x.link) === -1
|
||||||
this.message?.content?.text?.indexOf(
|
|
||||||
typeof x === 'string' ? x : x.link
|
|
||||||
) === -1
|
|
||||||
);
|
);
|
||||||
if (mentions.length) {
|
if (mentions.length) {
|
||||||
let self = this;
|
let self = this;
|
||||||
@ -363,38 +357,31 @@ class TfMessageElement extends LitElement {
|
|||||||
return channels.map((x) => html`<tf-tag tag=${x}></tf-tag>`);
|
return channels.map((x) => html`<tf-tag tag=${x}></tf-tag>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_background() {
|
render() {
|
||||||
return this.message?.decrypted
|
|
||||||
? 'w3-pale-red'
|
|
||||||
: this.message?.rowid >= this.channel_unread
|
|
||||||
? 'w3-theme-d2'
|
|
||||||
: 'w3-theme-d4';
|
|
||||||
}
|
|
||||||
|
|
||||||
get_content() {
|
|
||||||
let content = this.message?.content;
|
let content = this.message?.content;
|
||||||
if (this.message?.decrypted?.type == 'post') {
|
if (this.message?.decrypted?.type == 'post') {
|
||||||
content = this.message.decrypted;
|
content = this.message.decrypted;
|
||||||
}
|
}
|
||||||
return content;
|
let class_background = this.message?.decrypted
|
||||||
}
|
? 'w3-pale-red'
|
||||||
|
: this.message?.rowid >= this.channel_unread
|
||||||
render_raw_button() {
|
? 'w3-theme-d2'
|
||||||
let content = this.get_content();
|
: 'w3-theme-d4';
|
||||||
|
let self = this;
|
||||||
let raw_button;
|
let raw_button;
|
||||||
switch (this.format) {
|
switch (this.format) {
|
||||||
case 'raw':
|
case 'raw':
|
||||||
if (content?.type == 'post' || content?.type == 'blog') {
|
if (content?.type == 'post' || content?.type == 'blog') {
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'md')}
|
@click=${() => (self.format = 'md')}
|
||||||
>
|
>
|
||||||
Markdown
|
Markdown
|
||||||
</button>`;
|
</button>`;
|
||||||
} else {
|
} else {
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'message')}
|
@click=${() => (self.format = 'message')}
|
||||||
>
|
>
|
||||||
Message
|
Message
|
||||||
</button>`;
|
</button>`;
|
||||||
@ -403,7 +390,7 @@ class TfMessageElement extends LitElement {
|
|||||||
case 'md':
|
case 'md':
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'message')}
|
@click=${() => (self.format = 'message')}
|
||||||
>
|
>
|
||||||
Message
|
Message
|
||||||
</button>`;
|
</button>`;
|
||||||
@ -411,7 +398,7 @@ class TfMessageElement extends LitElement {
|
|||||||
case 'decrypted':
|
case 'decrypted':
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'raw')}
|
@click=${() => (self.format = 'raw')}
|
||||||
>
|
>
|
||||||
Raw
|
Raw
|
||||||
</button>`;
|
</button>`;
|
||||||
@ -420,78 +407,35 @@ class TfMessageElement extends LitElement {
|
|||||||
if (this.message.decrypted) {
|
if (this.message.decrypted) {
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'decrypted')}
|
@click=${() => (self.format = 'decrypted')}
|
||||||
>
|
>
|
||||||
Decrypted
|
Decrypted
|
||||||
</button>`;
|
</button>`;
|
||||||
} else {
|
} else {
|
||||||
raw_button = html`<button
|
raw_button = html`<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() => (this.format = 'raw')}
|
@click=${() => (self.format = 'raw')}
|
||||||
>
|
>
|
||||||
Raw
|
Raw
|
||||||
</button>`;
|
</button>`;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return raw_button;
|
function small_frame(inner) {
|
||||||
}
|
let body;
|
||||||
|
|
||||||
render_header() {
|
|
||||||
let is_encrypted = this.message?.decrypted
|
|
||||||
? html`<span class="w3-bar-item">🔓</span>`
|
|
||||||
: typeof this.message?.content == 'string'
|
|
||||||
? html`<span class="w3-bar-item">🔒</span>`
|
|
||||||
: undefined;
|
|
||||||
return html`
|
return html`
|
||||||
<header class="w3-bar">
|
<div
|
||||||
<span class="w3-bar-item">
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
style="margin-top: 8px; padding: 16px; display: inline-block; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
</span>
|
>
|
||||||
${is_encrypted}
|
<tf-user id=${self.message.author} .users=${self.users}></tf-user>
|
||||||
<span class="w3-bar-item w3-right">${this.render_raw_button()}</span>
|
<span style="padding-right: 8px; text-wrap: nowrap"
|
||||||
<span class="w3-bar-item w3-right" style="text-wrap: nowrap"
|
><a tfarget="_top" href=${'#' + encodeURIComponent(self.message.id)}
|
||||||
><a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
|
||||||
>%</a
|
>%</a
|
||||||
>
|
>
|
||||||
${new Date(this.message.timestamp).toLocaleString()}</span
|
${new Date(self.message.timestamp).toLocaleString()}</span
|
||||||
>
|
>
|
||||||
</header>
|
${raw_button} ${self.format == 'raw' ? self.render_raw() : inner}
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
render_frame(inner) {
|
|
||||||
return html`
|
|
||||||
<style>
|
|
||||||
code {
|
|
||||||
white-space: pre-wrap;
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
}
|
|
||||||
div {
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
}
|
|
||||||
img {
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div
|
|
||||||
class="w3-card-4 ${this.class_background()} w3-border-theme w3-margin-top"
|
|
||||||
style="overflow: auto; overflow-wrap: anywhere; display: block; max-width: 100%"
|
|
||||||
>
|
|
||||||
${inner}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
render_small_frame(inner) {
|
|
||||||
let self = this;
|
|
||||||
return this.render_frame(html`
|
|
||||||
${self.render_header()}
|
|
||||||
${self.format == 'raw'
|
|
||||||
? html`<div class="w3-container">${self.render_raw()}</div>`
|
|
||||||
: inner}
|
|
||||||
${self.render_votes()}
|
${self.render_votes()}
|
||||||
${(self.message.child_messages || []).map(
|
${(self.message.child_messages || []).map(
|
||||||
(x) => html`
|
(x) => html`
|
||||||
@ -506,50 +450,15 @@ class TfMessageElement extends LitElement {
|
|||||||
></tf-message>
|
></tf-message>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
render_actions() {
|
|
||||||
let content = this.get_content();
|
|
||||||
let reply =
|
|
||||||
this.drafts[this.message?.id] !== undefined
|
|
||||||
? html`
|
|
||||||
<tf-compose
|
|
||||||
whoami=${this.whoami}
|
|
||||||
.users=${this.users}
|
|
||||||
root=${content.root || this.message.id}
|
|
||||||
branch=${this.message.id}
|
|
||||||
.drafts=${this.drafts}
|
|
||||||
@tf-discard=${this.discard_reply}
|
|
||||||
author=${this.message.author}
|
|
||||||
></tf-compose>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.show_reply}>
|
|
||||||
Reply
|
|
||||||
</button>
|
|
||||||
`;
|
|
||||||
return html`
|
|
||||||
<div class="w3-section w3-container">
|
|
||||||
${reply}
|
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
|
||||||
React
|
|
||||||
</button>
|
|
||||||
${this.render_children()}
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
|
||||||
let content = this.message?.content;
|
|
||||||
if (this.message?.decrypted?.type == 'post') {
|
|
||||||
content = this.message.decrypted;
|
|
||||||
}
|
|
||||||
let class_background = this.class_background();
|
|
||||||
let self = this;
|
|
||||||
if (this.message?.type === 'contact_group') {
|
if (this.message?.type === 'contact_group') {
|
||||||
return this.render_frame(
|
return html` <div
|
||||||
html` ${this.message.messages.map(
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
|
style="margin-top: 8px; padding: 16px; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
|
>
|
||||||
|
${this.message.messages.map(
|
||||||
(x) =>
|
(x) =>
|
||||||
html`<tf-message
|
html`<tf-message
|
||||||
.message=${x}
|
.message=${x}
|
||||||
@ -560,11 +469,14 @@ class TfMessageElement extends LitElement {
|
|||||||
channel=${this.channel}
|
channel=${this.channel}
|
||||||
channel_unread=${this.channel_unread}
|
channel_unread=${this.channel_unread}
|
||||||
></tf-message>`
|
></tf-message>`
|
||||||
)}`
|
)}
|
||||||
);
|
</div>`;
|
||||||
} else if (this.message.placeholder) {
|
} else if (this.message.placeholder) {
|
||||||
return this.render_frame(
|
return html` <div
|
||||||
html` <a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
|
style="margin-top: 8px; padding: 16px; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
|
>
|
||||||
|
<a target="_top" href=${'#' + encodeURIComponent(this.message.id)}
|
||||||
>${this.message.id}</a
|
>${this.message.id}</a
|
||||||
>
|
>
|
||||||
(placeholder)
|
(placeholder)
|
||||||
@ -581,17 +493,15 @@ class TfMessageElement extends LitElement {
|
|||||||
channel_unread=${this.channel_unread}
|
channel_unread=${this.channel_unread}
|
||||||
></tf-message>
|
></tf-message>
|
||||||
`
|
`
|
||||||
)}`
|
)}
|
||||||
);
|
</div>`;
|
||||||
} else if (typeof content?.type === 'string') {
|
} else if (typeof (content?.type === 'string')) {
|
||||||
if (content.type == 'about') {
|
if (content.type == 'about') {
|
||||||
let name;
|
let name;
|
||||||
let image;
|
let image;
|
||||||
let description;
|
let description;
|
||||||
if (content.name !== undefined) {
|
if (content.name !== undefined) {
|
||||||
name = html`<div>
|
name = html`<div><b>Name:</b> ${content.name}</div>`;
|
||||||
<b>Name:</b> ${content.name}
|
|
||||||
</div>`;
|
|
||||||
}
|
}
|
||||||
if (content.image !== undefined) {
|
if (content.image !== undefined) {
|
||||||
image = html`
|
image = html`
|
||||||
@ -600,30 +510,22 @@ class TfMessageElement extends LitElement {
|
|||||||
}
|
}
|
||||||
if (content.description !== undefined) {
|
if (content.description !== undefined) {
|
||||||
description = html`
|
description = html`
|
||||||
<div
|
<div style="flex: 1 0 50%; overflow-wrap: anywhere">
|
||||||
style="flex: 1 0 50%; overflow-wrap: anywhere"
|
|
||||||
>
|
|
||||||
<div>${unsafeHTML(tfutils.markdown(content.description))}</div>
|
<div>${unsafeHTML(tfutils.markdown(content.description))}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
let update =
|
let update =
|
||||||
content.about == this.message.author
|
content.about == this.message.author
|
||||||
? html`<div style="font-weight: bold">
|
? html`<div style="font-weight: bold">Updated profile.</div>`
|
||||||
Updated profile.
|
|
||||||
</div>`
|
|
||||||
: html`<div style="font-weight: bold">
|
: html`<div style="font-weight: bold">
|
||||||
Updated profile for
|
Updated profile for
|
||||||
<tf-user id=${content.about} .users=${this.users}></tf-user>.
|
<tf-user id=${content.about} .users=${this.users}></tf-user>.
|
||||||
</div>`;
|
</div>`;
|
||||||
return this.render_small_frame(html`
|
return small_frame(html` ${update} ${name} ${image} ${description} `);
|
||||||
<div class="w3-container">
|
|
||||||
<p>${update} ${name} ${image} ${description}</p>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
} else if (content.type == 'contact') {
|
} else if (content.type == 'contact') {
|
||||||
return html`
|
return html`
|
||||||
<div class="w3-padding">
|
<div>
|
||||||
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
||||||
is
|
is
|
||||||
${content.blocking === true
|
${content.blocking === true
|
||||||
@ -642,6 +544,24 @@ class TfMessageElement extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else if (content.type == 'post') {
|
} else if (content.type == 'post') {
|
||||||
|
let reply =
|
||||||
|
this.drafts[this.message?.id] !== undefined
|
||||||
|
? html`
|
||||||
|
<tf-compose
|
||||||
|
whoami=${this.whoami}
|
||||||
|
.users=${this.users}
|
||||||
|
root=${content.root || this.message.id}
|
||||||
|
branch=${this.message.id}
|
||||||
|
.drafts=${this.drafts}
|
||||||
|
@tf-discard=${this.discard_reply}
|
||||||
|
author=${this.message.author}
|
||||||
|
></tf-compose>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<button class="w3-button w3-theme-d1" @click=${this.show_reply}>
|
||||||
|
Reply
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
let self = this;
|
let self = this;
|
||||||
let body;
|
let body;
|
||||||
switch (this.format) {
|
switch (this.format) {
|
||||||
@ -658,7 +578,11 @@ class TfMessageElement extends LitElement {
|
|||||||
body = unsafeHTML(tfutils.markdown(content.text));
|
body = unsafeHTML(tfutils.markdown(content.text));
|
||||||
break;
|
break;
|
||||||
case 'decrypted':
|
case 'decrypted':
|
||||||
body = this.render_json(content);
|
body = html`<pre
|
||||||
|
style="white-space: pre-wrap; overflow-wrap: anywhere"
|
||||||
|
>
|
||||||
|
${JSON.stringify(content, null, 2)}</pre
|
||||||
|
>`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let content_warning = html`
|
let content_warning = html`
|
||||||
@ -680,22 +604,108 @@ class TfMessageElement extends LitElement {
|
|||||||
? html` ${content_warning} ${content_html} `
|
? html` ${content_warning} ${content_html} `
|
||||||
: content_warning
|
: content_warning
|
||||||
: content_html;
|
: content_html;
|
||||||
return this.render_frame(html`
|
let is_encrypted = this.message?.decrypted
|
||||||
${this.render_header()}
|
? html`<span style="align-self: center">🔓</span>`
|
||||||
<div class="w3-container">${payload}</div>
|
: undefined;
|
||||||
${this.render_votes()} ${this.render_actions()}
|
return html`
|
||||||
|
<style>
|
||||||
|
code {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div
|
||||||
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
|
style="margin-top: 8px; padding: 16px; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
|
>
|
||||||
|
<div style="display: flex; flex-direction: row">
|
||||||
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
||||||
|
${is_encrypted}
|
||||||
|
<span style="flex: 1"></span>
|
||||||
|
<span style="padding-right: 8px; text-wrap: nowrap"
|
||||||
|
><a
|
||||||
|
target="_top"
|
||||||
|
href=${'#' + encodeURIComponent(self.message.id)}
|
||||||
|
>%</a
|
||||||
|
>
|
||||||
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
||||||
|
>
|
||||||
|
<span>${raw_button}</span>
|
||||||
</div>
|
</div>
|
||||||
`);
|
${payload} ${this.render_votes()}
|
||||||
|
<footer class="w3-container">
|
||||||
|
${reply}
|
||||||
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
||||||
|
React
|
||||||
|
</button>
|
||||||
|
${!content.root && this.message.rowid < this.channel_unread
|
||||||
|
? html`
|
||||||
|
<button
|
||||||
|
class="w3-button w3-theme-d1"
|
||||||
|
@click=${this.mark_unread}
|
||||||
|
>
|
||||||
|
Mark Unread
|
||||||
|
</button>
|
||||||
|
`
|
||||||
|
: undefined}
|
||||||
|
${this.render_children()}
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
} else if (content.type === 'issue') {
|
} else if (content.type === 'issue') {
|
||||||
return this.render_frame(html`
|
let is_encrypted = this.message?.decrypted
|
||||||
${this.render_header()} ${content.text} ${this.render_votes()}
|
? html`<span style="align-self: center">🔓</span>`
|
||||||
|
: undefined;
|
||||||
|
return html`
|
||||||
|
<style>
|
||||||
|
code {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div
|
||||||
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
|
style="margin-top: 8px; padding: 16px; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
|
>
|
||||||
|
<div style="display: flex; flex-direction: row">
|
||||||
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
||||||
|
${is_encrypted}
|
||||||
|
<span style="flex: 1"></span>
|
||||||
|
<span style="padding-right: 8px; text-wrap: nowrap"
|
||||||
|
><a
|
||||||
|
target="_top"
|
||||||
|
href=${'#' + encodeURIComponent(self.message.id)}
|
||||||
|
>%</a
|
||||||
|
>
|
||||||
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
||||||
|
>
|
||||||
|
<span>${raw_button}</span>
|
||||||
|
</div>
|
||||||
|
${content.text} ${this.render_votes()}
|
||||||
<footer class="w3-container">
|
<footer class="w3-container">
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
||||||
React
|
React
|
||||||
</button>
|
</button>
|
||||||
${this.render_children()}
|
${this.render_children()}
|
||||||
</footer>
|
</footer>
|
||||||
`);
|
</div>
|
||||||
|
`;
|
||||||
} else if (content.type === 'blog') {
|
} else if (content.type === 'blog') {
|
||||||
let self = this;
|
let self = this;
|
||||||
tfrpc.rpc.get_blob(content.blog).then(function (data) {
|
tfrpc.rpc.get_blob(content.blog).then(function (data) {
|
||||||
@ -731,14 +741,71 @@ class TfMessageElement extends LitElement {
|
|||||||
`;
|
`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this.render_frame(html`
|
let reply =
|
||||||
${this.render_header()}
|
this.drafts[this.message?.id] !== undefined
|
||||||
|
? html`
|
||||||
|
<tf-compose
|
||||||
|
whoami=${this.whoami}
|
||||||
|
.users=${this.users}
|
||||||
|
root=${content.root || this.message.id}
|
||||||
|
branch=${this.message.id}
|
||||||
|
.drafts=${this.drafts}
|
||||||
|
@tf-discard=${this.discard_reply}
|
||||||
|
author=${this.message.author}
|
||||||
|
></tf-compose>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<button class="w3-button w3-theme-d1" @click=${this.show_reply}>
|
||||||
|
Reply
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
return html`
|
||||||
|
<style>
|
||||||
|
code {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div
|
||||||
|
class="w3-card-4 ${class_background} w3-border-theme"
|
||||||
|
style="margin-top: 8px; padding: 16px; overflow: scroll; overflow-wrap: anywhere; display: block; max-width: 100%"
|
||||||
|
>
|
||||||
|
<div style="display: flex; flex-direction: row">
|
||||||
|
<tf-user id=${this.message.author} .users=${this.users}></tf-user>
|
||||||
|
<span style="flex: 1"></span>
|
||||||
|
<span style="padding-right: 8px; text-wrap: nowrap"
|
||||||
|
><a
|
||||||
|
target="_top"
|
||||||
|
href=${'#' + encodeURIComponent(self.message.id)}
|
||||||
|
>%</a
|
||||||
|
>
|
||||||
|
${new Date(this.message.timestamp).toLocaleString()}</span
|
||||||
|
>
|
||||||
|
<span>${raw_button}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>${body}</div>
|
<div>${body}</div>
|
||||||
${this.render_mentions()} ${this.render_votes()}
|
${this.render_mentions()}
|
||||||
${this.render_actions()}
|
${this.render_votes()}
|
||||||
`);
|
<footer class="w3-content">
|
||||||
|
${reply}
|
||||||
|
<button class="w3-button w3-theme-d1" @click=${this.react}>
|
||||||
|
React
|
||||||
|
</button>
|
||||||
|
${this.render_children()}
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
} else if (content.type === 'pub') {
|
} else if (content.type === 'pub') {
|
||||||
return this.render_small_frame(
|
return small_frame(
|
||||||
html` <style>
|
html` <style>
|
||||||
span {
|
span {
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
@ -756,42 +823,35 @@ class TfMessageElement extends LitElement {
|
|||||||
</span>`
|
</span>`
|
||||||
);
|
);
|
||||||
} else if (content.type === 'channel') {
|
} else if (content.type === 'channel') {
|
||||||
return this.render_small_frame(html`
|
return small_frame(html`
|
||||||
<div class="w3-container">
|
<div>
|
||||||
<p>
|
|
||||||
${content.subscribed ? 'subscribed to' : 'unsubscribed from'}
|
${content.subscribed ? 'subscribed to' : 'unsubscribed from'}
|
||||||
<a href=${'#' + encodeURIComponent('#' + content.channel)}
|
<a href=${'#' + encodeURIComponent('#' + content.channel)}
|
||||||
>#${content.channel}</a
|
>#${content.channel}</a
|
||||||
>
|
>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
} else if (typeof this.message.content == 'string') {
|
} else if (typeof this.message.content == 'string') {
|
||||||
if (this.message?.decrypted) {
|
if (this.message?.decrypted) {
|
||||||
if (this.format == 'decrypted') {
|
if (this.format == 'decrypted') {
|
||||||
return this.render_small_frame(
|
return small_frame(
|
||||||
html`<span class="w3-container">🔓</span> ${this.render_json(
|
html`<span>🔓</span>
|
||||||
this.message.decrypted
|
<pre>${JSON.stringify(this.message.decrypted, null, 2)}</pre>`
|
||||||
)}`
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame(
|
return small_frame(
|
||||||
html`<span class="w3-container">🔓</span>
|
html`<span>🔓</span>
|
||||||
<div class="w3-container">${this.message.decrypted.type}</div>`
|
<div>${this.message.decrypted.type}</div>`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame();
|
return small_frame(html`<span>🔒</span>`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame(
|
return small_frame(html`<div><b>type</b>: ${content.type}</div>`);
|
||||||
html`<div class="w3-container"><b>type</b>: ${content.type}</div>`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else if (typeof this.message.content == 'string') {
|
|
||||||
return this.render_small_frame();
|
|
||||||
} else {
|
} else {
|
||||||
return this.render_small_frame(this.render_raw());
|
return small_frame(this.render_raw());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ class TfProfileElement extends LitElement {
|
|||||||
id: {type: String},
|
id: {type: String},
|
||||||
users: {type: Object},
|
users: {type: Object},
|
||||||
size: {type: Number},
|
size: {type: Number},
|
||||||
|
server_follows_me: {type: Boolean},
|
||||||
following: {type: Boolean},
|
following: {type: Boolean},
|
||||||
blocking: {type: Boolean},
|
blocking: {type: Boolean},
|
||||||
};
|
};
|
||||||
@ -26,6 +27,7 @@ class TfProfileElement extends LitElement {
|
|||||||
this.id = null;
|
this.id = null;
|
||||||
this.users = {};
|
this.users = {};
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
|
this.server_follows_me = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
@ -61,6 +63,26 @@ class TfProfileElement extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initial_load() {
|
||||||
|
this.server_follows_me = undefined;
|
||||||
|
let server_id = await tfrpc.rpc.getServerIdentity();
|
||||||
|
let followed = await tfrpc.rpc.query(
|
||||||
|
`
|
||||||
|
SELECT json_extract(content, '$.following') AS following
|
||||||
|
FROM messages
|
||||||
|
WHERE author = ? AND
|
||||||
|
json_extract(content, '$.type') = 'contact' AND
|
||||||
|
json_extract(content, '$.contact') = ? ORDER BY sequence DESC LIMIT 1
|
||||||
|
`,
|
||||||
|
[server_id, this.whoami]
|
||||||
|
);
|
||||||
|
let is_followed = false;
|
||||||
|
for (let row of followed) {
|
||||||
|
is_followed = row.following != 0;
|
||||||
|
}
|
||||||
|
this.server_follows_me = is_followed;
|
||||||
|
}
|
||||||
|
|
||||||
modify(change) {
|
modify(change) {
|
||||||
tfrpc.rpc
|
tfrpc.rpc
|
||||||
.appendMessage(
|
.appendMessage(
|
||||||
@ -153,11 +175,31 @@ class TfProfileElement extends LitElement {
|
|||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async server_follow_me(follow) {
|
||||||
|
try {
|
||||||
|
await tfrpc.rpc.setServerFollowingMe(this.whoami, follow);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.initial_load();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
copy_id() {
|
copy_id() {
|
||||||
navigator.clipboard.writeText(this.id);
|
navigator.clipboard.writeText(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (
|
||||||
|
this.id == this.whoami &&
|
||||||
|
this.editing &&
|
||||||
|
this.server_follows_me === undefined
|
||||||
|
) {
|
||||||
|
this.initial_load();
|
||||||
|
}
|
||||||
this.load();
|
this.load();
|
||||||
let self = this;
|
let self = this;
|
||||||
let profile = this.users[this.id] || {};
|
let profile = this.users[this.id] || {};
|
||||||
@ -174,6 +216,22 @@ class TfProfileElement extends LitElement {
|
|||||||
let block;
|
let block;
|
||||||
if (this.id === this.whoami) {
|
if (this.id === this.whoami) {
|
||||||
if (this.editing) {
|
if (this.editing) {
|
||||||
|
let server_follow;
|
||||||
|
if (this.server_follows_me === true) {
|
||||||
|
server_follow = html`<button
|
||||||
|
class="w3-button w3-theme-d1"
|
||||||
|
@click=${() => this.server_follow_me(false)}
|
||||||
|
>
|
||||||
|
Server, Stop Following Me
|
||||||
|
</button>`;
|
||||||
|
} else if (this.server_follows_me === false) {
|
||||||
|
server_follow = html`<button
|
||||||
|
class="w3-button w3-theme-d1"
|
||||||
|
@click=${() => this.server_follow_me(true)}
|
||||||
|
>
|
||||||
|
Server, Follow Me
|
||||||
|
</button>`;
|
||||||
|
}
|
||||||
edit = html`
|
edit = html`
|
||||||
<button
|
<button
|
||||||
id="save_profile"
|
id="save_profile"
|
||||||
@ -185,6 +243,7 @@ class TfProfileElement extends LitElement {
|
|||||||
<button class="w3-button w3-theme-d1" @click=${this.discard_edits}>
|
<button class="w3-button w3-theme-d1" @click=${this.discard_edits}>
|
||||||
Discard
|
Discard
|
||||||
</button>
|
</button>
|
||||||
|
${server_follow}
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
edit = html`<button
|
edit = html`<button
|
||||||
@ -217,12 +276,13 @@ class TfProfileElement extends LitElement {
|
|||||||
let edit_profile = this.editing
|
let edit_profile = this.editing
|
||||||
? html`
|
? html`
|
||||||
<div style="flex: 1 0 50%; display: flex; flex-direction: column; gap: 8px">
|
<div style="flex: 1 0 50%; display: flex; flex-direction: column; gap: 8px">
|
||||||
|
<div class="w3-container">
|
||||||
<div>
|
<div>
|
||||||
<label for="name">Name:</label>
|
<label for="name">Name:</label>
|
||||||
<input class="w3-input w3-theme-d1" type="text" id="name" value=${this.editing.name} @input=${(event) => (this.editing = Object.assign({}, this.editing, {name: event.srcElement.value}))} placeholder="Choose a name"></input>
|
<input class="w3-input w3-theme-d1" type="text" id="name" value=${this.editing.name} @input=${(event) => (this.editing = Object.assign({}, this.editing, {name: event.srcElement.value}))}></input>
|
||||||
</div>
|
</div>
|
||||||
<div><label for="description">Description:</label></div>
|
<div><label for="description">Description:</label></div>
|
||||||
<textarea class="w3-input w3-theme-d1" style="resize: vertical" rows="8" id="description" @input=${(event) => (this.editing = Object.assign({}, this.editing, {description: event.srcElement.value}))} placeholder="Tell people a little bit about yourself here, if you like.">${this.editing.description}</textarea>
|
<textarea class="w3-input w3-theme-d1" style="resize: vertical" rows="8" id="description" @input=${(event) => (this.editing = Object.assign({}, this.editing, {description: event.srcElement.value}))}>${this.editing.description}</textarea>
|
||||||
<div>
|
<div>
|
||||||
<label for="public_web_hosting">Public Web Hosting:</label>
|
<label for="public_web_hosting">Public Web Hosting:</label>
|
||||||
<input class="w3-check w3-theme-d1" type="checkbox" id="public_web_hosting" ?checked=${this.editing.publicWebHosting} @input=${(event) => (self.editing = Object.assign({}, self.editing, {publicWebHosting: event.srcElement.checked}))}></input>
|
<input class="w3-check w3-theme-d1" type="checkbox" id="public_web_hosting" ?checked=${this.editing.publicWebHosting} @input=${(event) => (self.editing = Object.assign({}, self.editing, {publicWebHosting: event.srcElement.checked}))}></input>
|
||||||
@ -230,6 +290,7 @@ class TfProfileElement extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
<button class="w3-button w3-theme-d1" @click=${this.attach_image}>Attach Image</button>
|
<button class="w3-button w3-theme-d1" @click=${this.attach_image}>Attach Image</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
: null;
|
: null;
|
||||||
let image =
|
let image =
|
||||||
@ -241,10 +302,8 @@ class TfProfileElement extends LitElement {
|
|||||||
<p><tf-user id=${this.id} .users=${this.users}></tf-user> (${tfutils.human_readable_size(this.size)})</p>
|
<p><tf-user id=${this.id} .users=${this.users}></tf-user> (${tfutils.human_readable_size(this.size)})</p>
|
||||||
</header>
|
</header>
|
||||||
<div class="w3-container">
|
<div class="w3-container">
|
||||||
<div class="w3-margin-bottom" style="display: flex; flex-direction: row">
|
<input type="text" class="w3-input w3-border w3-theme-d1" readonly value=${this.id}></input>
|
||||||
<input type="text" class="w3-input w3-border w3-theme-d1" style="display: flex 1 1" readonly value=${this.id}></input>
|
<button class="w3-button w3-theme-d1 w3-ripple" @click=${this.copy_id}>Copy</button>
|
||||||
<button class="w3-button w3-theme-d1 w3-ripple" style="flex: 0 0 auto" @click=${this.copy_id}>Copy</button>
|
|
||||||
</div>
|
|
||||||
<div style="display: flex; flex-direction: row; gap: 1em">
|
<div style="display: flex; flex-direction: row; gap: 1em">
|
||||||
${edit_profile}
|
${edit_profile}
|
||||||
<div style="flex: 1 0 50%">
|
<div style="flex: 1 0 50%">
|
||||||
|
@ -396,9 +396,9 @@ function is_dark(hex, value) {
|
|||||||
function generated() {
|
function generated() {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let k_color = rgb_to_hex([
|
let k_color = rgb_to_hex([
|
||||||
(now.getDay() * 128) / 6,
|
now.getDay() * 255 / 6,
|
||||||
(now.getHours() * 128) / 23,
|
now.getHours() * 255 / 23,
|
||||||
(now.getSeconds() * 128) / 59,
|
now.getSeconds() * 255 / 59,
|
||||||
]);
|
]);
|
||||||
//let k_color = '#034f84';
|
//let k_color = '#034f84';
|
||||||
//let k_color = rgb_to_hex([Math.random() * 256, Math.random() * 256, Math.random() * 256]);
|
//let k_color = rgb_to_hex([Math.random() * 256, Math.random() * 256, Math.random() * 256]);
|
||||||
|
@ -196,16 +196,9 @@ class TfTabNewsElement extends LitElement {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div class="w3-bar-item w3-theme-d2">Connections</div>
|
<div class="w3-bar-item w3-theme-d2">Connections</div>
|
||||||
${this.connections.map(
|
${this.connections.map((x) => (html`
|
||||||
(x) => html`
|
<tf-user class="w3-bar-item" style="max-width: 100%" id=${x.id} .users=${this.users}></tf-user>
|
||||||
<tf-user
|
`))}
|
||||||
class="w3-bar-item"
|
|
||||||
style="max-width: 100%"
|
|
||||||
id=${x.id}
|
|
||||||
.users=${this.users}
|
|
||||||
></tf-user>
|
|
||||||
`
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="w3-overlay"
|
class="w3-overlay"
|
||||||
@ -241,7 +234,7 @@ class TfTabNewsElement extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
${this.render_sidebar()}
|
${this.render_sidebar()}
|
||||||
<div
|
<div
|
||||||
style="margin-left: 2in; padding: 0px; top: 0; max-height: 100%; overflow: auto"
|
style="margin-left: 2in; padding: 0px; top: 0; max-height: 100%; overflow: scroll"
|
||||||
id="main"
|
id="main"
|
||||||
class="w3-main"
|
class="w3-main"
|
||||||
>
|
>
|
||||||
|
@ -19,7 +19,7 @@ class TfTagElement extends LitElement {
|
|||||||
let number = this.count ? html` (${this.count})` : undefined;
|
let number = this.count ? html` (${this.count})` : undefined;
|
||||||
return html`<a
|
return html`<a
|
||||||
href=${'#' + encodeURIComponent(this.tag)}
|
href=${'#' + encodeURIComponent(this.tag)}
|
||||||
class="w3-tag w3-theme-d1 w3-round-4 w3-button"
|
style="display: inline-block; margin: 3px; border: 1px solid black; background-color: #444; padding: 4px; border-radius: 3px"
|
||||||
>${this.tag}${number}</a
|
>${this.tag}${number}</a
|
||||||
>`;
|
>`;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,7 @@ class TfUserElement extends LitElement {
|
|||||||
>?</span
|
>?</span
|
||||||
>`;
|
>`;
|
||||||
let name = this.users?.[this.id]?.name;
|
let name = this.users?.[this.id]?.name;
|
||||||
name = html`<a target="_top" href=${'#' + this.id}
|
name = html`<a target="_top" href=${'#' + this.id}>${name !== undefined ? name : this.id}</a>`
|
||||||
>${name !== undefined ? name : this.id}</a
|
|
||||||
>`;
|
|
||||||
|
|
||||||
if (this.users[this.id]) {
|
if (this.users[this.id]) {
|
||||||
let image_link = this.users[this.id].image;
|
let image_link = this.users[this.id].image;
|
||||||
@ -41,9 +39,7 @@ class TfUserElement extends LitElement {
|
|||||||
/>`;
|
/>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return html` <div
|
return html` <div style="display: inline-block; vertical-align: middle; font-weight: bold; text-wrap: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis">
|
||||||
style="display: inline-block; vertical-align: middle; font-weight: bold; text-wrap: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis"
|
|
||||||
>
|
|
||||||
${image} ${name}
|
${image} ${name}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
13
core/core.js
13
core/core.js
@ -577,6 +577,19 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
imports.ssb.setServerFollowingMe = function (id, following) {
|
||||||
|
if (
|
||||||
|
process.credentials &&
|
||||||
|
process.credentials.session &&
|
||||||
|
process.credentials.session.name
|
||||||
|
) {
|
||||||
|
return ssb.setServerFollowingMe(
|
||||||
|
process.credentials.session.name,
|
||||||
|
id,
|
||||||
|
following
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
imports.ssb.swapWithServerIdentity = function (id) {
|
imports.ssb.swapWithServerIdentity = function (id) {
|
||||||
if (
|
if (
|
||||||
process.credentials &&
|
process.credentials &&
|
||||||
|
2
deps/codemirror/cm6.js
vendored
2
deps/codemirror/cm6.js
vendored
File diff suppressed because one or more lines are too long
12
deps/codemirror_src/package-lock.json
generated
vendored
12
deps/codemirror_src/package-lock.json
generated
vendored
@ -98,9 +98,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@codemirror/language": {
|
"node_modules/@codemirror/language": {
|
||||||
"version": "6.10.8",
|
"version": "6.10.7",
|
||||||
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.10.8.tgz",
|
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.10.7.tgz",
|
||||||
"integrity": "sha512-wcP8XPPhDH2vTqf181U8MbZnW+tDyPYy0UzVOa+oHORjyT+mhhom9vBd7dApJwoDz9Nb/a8kHjJIsuA/t8vNFw==",
|
"integrity": "sha512-aOswhVOLYhMNeqykt4P7+ukQSpGL0ynZYaEyFDVHE7fl2xgluU3yuE9MdgYNfw6EmaNidoFMIQ2iTh1ADrnT6A==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/state": "^6.0.0",
|
"@codemirror/state": "^6.0.0",
|
||||||
@ -278,9 +278,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lezer/json": {
|
"node_modules/@lezer/json": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@lezer/json/-/json-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@lezer/json/-/json-1.0.2.tgz",
|
||||||
"integrity": "sha512-BP9KzdF9Y35PDpv04r0VeSTKDeox5vVr3efE7eBbx3r4s3oNLfunchejZhjArmeieBH+nVOpgIiBJpEAv8ilqQ==",
|
"integrity": "sha512-xHT2P4S5eeCYECyKNPhr4cbEL9tc8w83SPwRC373o9uEdrvGKTZoJVAGxpOsZckMlEh9W23Pc72ew918RWQOBQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lezer/common": "^1.2.0",
|
"@lezer/common": "^1.2.0",
|
||||||
|
396
src/main.c
396
src/main.c
@ -15,7 +15,6 @@
|
|||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -43,7 +42,7 @@
|
|||||||
|
|
||||||
struct backtrace_state* g_backtrace_state;
|
struct backtrace_state* g_backtrace_state;
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
#if !defined(TARGET_OS_IPHONE)
|
||||||
static const char* _get_db_path()
|
static const char* _get_db_path()
|
||||||
{
|
{
|
||||||
const char* k_db_path_default = "db.sqlite";
|
const char* k_db_path_default = "db.sqlite";
|
||||||
@ -144,14 +143,9 @@ static void _create_directories_for_file(const char* path, int mode)
|
|||||||
static int _tf_command_export(const char* file, int argc, char* argv[]);
|
static int _tf_command_export(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_import(const char* file, int argc, char* argv[]);
|
static int _tf_command_import(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_publish(const char* file, int argc, char* argv[]);
|
static int _tf_command_publish(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_private(const char* file, int argc, char* argv[]);
|
|
||||||
static int _tf_command_run(const char* file, int argc, char* argv[]);
|
static int _tf_command_run(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
|
static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_has_blob(const char* file, int argc, char* argv[]);
|
|
||||||
static int _tf_command_store_blob(const char* file, int argc, char* argv[]);
|
static int _tf_command_store_blob(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_get_sequence(const char* file, int argc, char* argv[]);
|
|
||||||
static int _tf_command_get_identity(const char* file, int argc, char* argv[]);
|
|
||||||
static int _tf_command_get_profile(const char* file, int argc, char* argv[]);
|
|
||||||
static int _tf_command_test(const char* file, int argc, char* argv[]);
|
static int _tf_command_test(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_verify(const char* file, int argc, char* argv[]);
|
static int _tf_command_verify(const char* file, int argc, char* argv[]);
|
||||||
static int _tf_command_usage(const char* file);
|
static int _tf_command_usage(const char* file);
|
||||||
@ -169,11 +163,6 @@ const command_t k_commands[] = {
|
|||||||
{ "import", _tf_command_import, "Import apps to SSB." },
|
{ "import", _tf_command_import, "Import apps to SSB." },
|
||||||
{ "export", _tf_command_export, "Export apps from SSB." },
|
{ "export", _tf_command_export, "Export apps from SSB." },
|
||||||
{ "publish", _tf_command_publish, "Append a message to a feed." },
|
{ "publish", _tf_command_publish, "Append a message to a feed." },
|
||||||
{ "private", _tf_command_private, "Append a private post message to a feed." },
|
|
||||||
{ "get_sequence", _tf_command_get_sequence, "Get the last sequence number for a feed." },
|
|
||||||
{ "get_identity", _tf_command_get_identity, "Get the server account identity." },
|
|
||||||
{ "get_profile", _tf_command_get_profile, "Get profile information for the given identity." },
|
|
||||||
{ "has_blob", _tf_command_has_blob, "Check whether a blob is in the blob store." },
|
|
||||||
{ "store_blob", _tf_command_store_blob, "Write a file to the blob store." },
|
{ "store_blob", _tf_command_store_blob, "Write a file to the blob store." },
|
||||||
{ "verify", _tf_command_verify, "Verify a feed." },
|
{ "verify", _tf_command_verify, "Verify a feed." },
|
||||||
{ "test", _tf_command_test, "Test SSB." },
|
{ "test", _tf_command_test, "Test SSB." },
|
||||||
@ -507,139 +496,6 @@ static int _tf_command_publish(const char* file, int argc, char* argv[])
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _tf_command_private(const char* file, int argc, char* argv[])
|
|
||||||
{
|
|
||||||
const char* user = NULL;
|
|
||||||
const char* identity = NULL;
|
|
||||||
const char* default_db_path = _get_db_path();
|
|
||||||
const char* db_path = default_db_path;
|
|
||||||
const char* text = NULL;
|
|
||||||
const char* recipients = NULL;
|
|
||||||
bool show_usage = false;
|
|
||||||
|
|
||||||
while (!show_usage)
|
|
||||||
{
|
|
||||||
static const struct option k_options[] = {
|
|
||||||
{ "user", required_argument, NULL, 'u' },
|
|
||||||
{ "id", required_argument, NULL, 'i' },
|
|
||||||
{ "recipients", required_argument, NULL, 'r' },
|
|
||||||
{ "db-path", required_argument, NULL, 'd' },
|
|
||||||
{ "text", required_argument, NULL, 'c' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
|
||||||
{ 0 },
|
|
||||||
};
|
|
||||||
int c = getopt_long(argc, argv, "u:i:d:t:r:h", k_options, NULL);
|
|
||||||
if (c == -1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
case 'h':
|
|
||||||
default:
|
|
||||||
show_usage = true;
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
user = optarg;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
identity = optarg;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
db_path = optarg;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
text = optarg;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
recipients = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (show_usage || !user || !identity || !recipients || !text)
|
|
||||||
{
|
|
||||||
tf_printf("\n%s private [options]\n\n", file);
|
|
||||||
tf_printf("options:\n");
|
|
||||||
tf_printf(" -u, --user user User owning identity with which to publish.\n");
|
|
||||||
tf_printf(" -i, --id identity Identity with which to publish message.\n");
|
|
||||||
tf_printf(" -r, --recipients recipients Recipient identities.\n");
|
|
||||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
|
||||||
tf_printf(" -t, --text text Private post text.\n");
|
|
||||||
tf_printf(" -h, --help Show this usage information.\n");
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = EXIT_FAILURE;
|
|
||||||
tf_printf("Posting %s as account %s belonging to %s...\n", text, identity, user);
|
|
||||||
_create_directories_for_file(db_path, 0700);
|
|
||||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
|
||||||
uint8_t private_key[512] = { 0 };
|
|
||||||
const char* recipient_list[k_max_private_message_recipients] = { 0 };
|
|
||||||
int recipient_count = 0;
|
|
||||||
|
|
||||||
recipient_list[recipient_count++] = identity;
|
|
||||||
|
|
||||||
if (tf_ssb_db_identity_get_private_key(ssb, user, identity, private_key, sizeof(private_key)))
|
|
||||||
{
|
|
||||||
char* copy = tf_strdup(recipients);
|
|
||||||
char* next = NULL;
|
|
||||||
const char* it = strtok_r(copy, ",", &next);
|
|
||||||
while (it)
|
|
||||||
{
|
|
||||||
if (recipient_count == k_max_private_message_recipients)
|
|
||||||
{
|
|
||||||
tf_printf("Too many recipients (max %d).\n", k_max_private_message_recipients);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
recipient_list[recipient_count++] = it;
|
|
||||||
it = strtok_r(NULL, ",", &next);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSContext* context = tf_ssb_get_context(ssb);
|
|
||||||
JSValue message = JS_NewObject(context);
|
|
||||||
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "post"));
|
|
||||||
JS_SetPropertyStr(context, message, "text", JS_NewString(context, text));
|
|
||||||
JSValue recps = JS_NewArray(context);
|
|
||||||
for (int i = 0; i < recipient_count; i++)
|
|
||||||
{
|
|
||||||
JS_SetPropertyUint32(context, recps, i, JS_NewString(context, recipient_list[i]));
|
|
||||||
}
|
|
||||||
JS_SetPropertyStr(context, message, "recps", recps);
|
|
||||||
JSValue json = JS_JSONStringify(context, message, JS_NULL, JS_NULL);
|
|
||||||
const char* message_str = JS_ToCString(context, json);
|
|
||||||
char* encrypted = tf_ssb_private_message_encrypt(private_key, recipient_list, recipient_count, message_str, strlen(message_str));
|
|
||||||
if (encrypted)
|
|
||||||
{
|
|
||||||
int64_t sequence = 0;
|
|
||||||
char previous[k_id_base64_len] = { 0 };
|
|
||||||
tf_ssb_db_get_latest_message_by_author(ssb, identity, &sequence, previous, sizeof(previous));
|
|
||||||
|
|
||||||
JSValue content = JS_NewString(context, encrypted);
|
|
||||||
JSValue to_publish = tf_ssb_sign_message(ssb, identity, private_key, content, previous, sequence);
|
|
||||||
tf_ssb_verify_strip_and_store_message(ssb, to_publish, _tf_published_callback, &result);
|
|
||||||
JS_FreeValue(context, to_publish);
|
|
||||||
JS_FreeValue(context, content);
|
|
||||||
}
|
|
||||||
tf_free(encrypted);
|
|
||||||
JS_FreeCString(context, message_str);
|
|
||||||
JS_FreeValue(context, json);
|
|
||||||
JS_FreeValue(context, message);
|
|
||||||
tf_free(copy);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tf_printf("Did not find private key for identity %s belonging to %s.\n", identity, user);
|
|
||||||
}
|
|
||||||
done:
|
|
||||||
tf_ssb_destroy(ssb);
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _tf_command_store_blob(const char* file, int argc, char* argv[])
|
static int _tf_command_store_blob(const char* file, int argc, char* argv[])
|
||||||
{
|
{
|
||||||
const char* default_db_path = _get_db_path();
|
const char* default_db_path = _get_db_path();
|
||||||
@ -736,231 +592,6 @@ static int _tf_command_store_blob(const char* file, int argc, char* argv[])
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _tf_command_has_blob(const char* file, int argc, char* argv[])
|
|
||||||
{
|
|
||||||
const char* default_db_path = _get_db_path();
|
|
||||||
const char* db_path = default_db_path;
|
|
||||||
const char* blob_id = NULL;
|
|
||||||
bool show_usage = false;
|
|
||||||
|
|
||||||
while (!show_usage)
|
|
||||||
{
|
|
||||||
static const struct option k_options[] = {
|
|
||||||
{ "db-path", required_argument, NULL, 'd' },
|
|
||||||
{ "blob_id", required_argument, NULL, 'b' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
|
||||||
{ 0 },
|
|
||||||
};
|
|
||||||
int c = getopt_long(argc, argv, "d:b:h", k_options, NULL);
|
|
||||||
if (c == -1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
case 'h':
|
|
||||||
default:
|
|
||||||
show_usage = true;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
db_path = optarg;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
blob_id = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (show_usage || !blob_id)
|
|
||||||
{
|
|
||||||
tf_printf("\n%s has_blob [options]\n\n", file);
|
|
||||||
tf_printf("options:\n");
|
|
||||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
|
||||||
tf_printf(" -b, --blob_id blob_id ID of blob to query.\n");
|
|
||||||
tf_printf(" -h, --help Show this usage information.\n");
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3* db = NULL;
|
|
||||||
sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, NULL);
|
|
||||||
tf_ssb_db_init_reader(db);
|
|
||||||
bool has = tf_ssb_db_blob_has(db, blob_id);
|
|
||||||
sqlite3_close(db);
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
tf_printf("%s\n", has ? "true" : "false");
|
|
||||||
return has ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _tf_command_get_sequence(const char* file, int argc, char* argv[])
|
|
||||||
{
|
|
||||||
const char* default_db_path = _get_db_path();
|
|
||||||
const char* db_path = default_db_path;
|
|
||||||
const char* identity = NULL;
|
|
||||||
bool show_usage = false;
|
|
||||||
|
|
||||||
while (!show_usage)
|
|
||||||
{
|
|
||||||
static const struct option k_options[] = {
|
|
||||||
{ "db-path", required_argument, NULL, 'd' },
|
|
||||||
{ "id", required_argument, NULL, 'i' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
|
||||||
{ 0 },
|
|
||||||
};
|
|
||||||
int c = getopt_long(argc, argv, "d:i:h", k_options, NULL);
|
|
||||||
if (c == -1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
case 'h':
|
|
||||||
default:
|
|
||||||
show_usage = true;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
db_path = optarg;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
identity = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (show_usage || !identity)
|
|
||||||
{
|
|
||||||
tf_printf("\n%s get_sequence [options]\n\n", file);
|
|
||||||
tf_printf("options:\n");
|
|
||||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
|
||||||
tf_printf(" -i, --identity identity Account from which to get latest sequence number.\n");
|
|
||||||
tf_printf(" -h, --help Show this usage information.\n");
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
|
||||||
int64_t sequence = -1;
|
|
||||||
int result = tf_ssb_db_get_latest_message_by_author(ssb, identity, &sequence, NULL, 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
tf_printf("%" PRId64 "\n", sequence);
|
|
||||||
tf_ssb_destroy(ssb);
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _tf_command_get_identity(const char* file, int argc, char* argv[])
|
|
||||||
{
|
|
||||||
const char* default_db_path = _get_db_path();
|
|
||||||
const char* db_path = default_db_path;
|
|
||||||
bool show_usage = false;
|
|
||||||
|
|
||||||
while (!show_usage)
|
|
||||||
{
|
|
||||||
static const struct option k_options[] = {
|
|
||||||
{ "db-path", required_argument, NULL, 'd' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
|
||||||
{ 0 },
|
|
||||||
};
|
|
||||||
int c = getopt_long(argc, argv, "d:i:h", k_options, NULL);
|
|
||||||
if (c == -1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
case 'h':
|
|
||||||
default:
|
|
||||||
show_usage = true;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
db_path = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (show_usage)
|
|
||||||
{
|
|
||||||
tf_printf("\n%s get_identity [options]\n\n", file);
|
|
||||||
tf_printf("options:\n");
|
|
||||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
|
||||||
tf_printf(" -h, --help Show this usage information.\n");
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
char id[k_id_base64_len] = { 0 };
|
|
||||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
|
||||||
int result = tf_ssb_whoami(ssb, id, sizeof(id)) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
tf_printf("%s\n", id);
|
|
||||||
tf_ssb_destroy(ssb);
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _tf_command_get_profile(const char* file, int argc, char* argv[])
|
|
||||||
{
|
|
||||||
const char* default_db_path = _get_db_path();
|
|
||||||
const char* db_path = default_db_path;
|
|
||||||
const char* identity = NULL;
|
|
||||||
bool show_usage = false;
|
|
||||||
|
|
||||||
while (!show_usage)
|
|
||||||
{
|
|
||||||
static const struct option k_options[] = {
|
|
||||||
{ "db-path", required_argument, NULL, 'd' },
|
|
||||||
{ "id", required_argument, NULL, 'i' },
|
|
||||||
{ "help", no_argument, NULL, 'h' },
|
|
||||||
{ 0 },
|
|
||||||
};
|
|
||||||
int c = getopt_long(argc, argv, "d:i:h", k_options, NULL);
|
|
||||||
if (c == -1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '?':
|
|
||||||
case 'h':
|
|
||||||
default:
|
|
||||||
show_usage = true;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
db_path = optarg;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
identity = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (show_usage || !identity)
|
|
||||||
{
|
|
||||||
tf_printf("\n%s get_profile [options]\n\n", file);
|
|
||||||
tf_printf("options:\n");
|
|
||||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
|
||||||
tf_printf(" -i, --identity identity Account from which to get latest sequence number.\n");
|
|
||||||
tf_printf(" -h, --help Show this usage information.\n");
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3* db = NULL;
|
|
||||||
sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, NULL);
|
|
||||||
tf_ssb_db_init_reader(db);
|
|
||||||
const char* profile = tf_ssb_db_get_profile(db, identity);
|
|
||||||
tf_printf("%s\n", profile);
|
|
||||||
sqlite3_close(db);
|
|
||||||
tf_free((void*)profile);
|
|
||||||
tf_free((void*)default_db_path);
|
|
||||||
return profile != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _tf_command_verify(const char* file, int argc, char* argv[])
|
static int _tf_command_verify(const char* file, int argc, char* argv[])
|
||||||
{
|
{
|
||||||
const char* identity = NULL;
|
const char* identity = NULL;
|
||||||
@ -1377,21 +1008,6 @@ static void _error_handler(int sig)
|
|||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
static LONG WINAPI _win32_exception_handler(EXCEPTION_POINTERS* info)
|
|
||||||
{
|
|
||||||
if (info->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION || info->ExceptionRecord->ExceptionCode == STATUS_ILLEGAL_INSTRUCTION ||
|
|
||||||
info->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW || info->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION)
|
|
||||||
{
|
|
||||||
const char* stack = tf_util_backtrace_string();
|
|
||||||
tf_printf("ERROR:\n%s\n", stack);
|
|
||||||
tf_free((void*)stack);
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void _startup(int argc, char* argv[])
|
static void _startup(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char buffer[8] = { 0 };
|
char buffer[8] = { 0 };
|
||||||
@ -1425,24 +1041,20 @@ static void _startup(int argc, char* argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool use_error_handler = false;
|
bool use_error_handler = false;
|
||||||
#if defined(__ANDROID__) || defined(_WIN32)
|
#if defined(__ANDROID__)
|
||||||
use_error_handler = true;
|
use_error_handler = true;
|
||||||
#endif
|
#endif
|
||||||
if (use_error_handler)
|
if (use_error_handler)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
signal(SIGSYS, _error_handler) == SIG_ERR ||
|
signal(SIGSYS, _error_handler) == SIG_ERR || signal(SIGABRT, _error_handler) == SIG_ERR ||
|
||||||
#endif
|
#endif
|
||||||
signal(SIGABRT, _error_handler) == SIG_ERR || signal(SIGSEGV, _error_handler) == SIG_ERR)
|
signal(SIGSEGV, _error_handler) == SIG_ERR)
|
||||||
{
|
{
|
||||||
perror("signal");
|
perror("signal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
AddVectoredExceptionHandler(0, _win32_exception_handler);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
184
src/ssb.c
184
src/ssb.c
@ -4,7 +4,6 @@
|
|||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "ssb.connections.h"
|
#include "ssb.connections.h"
|
||||||
#include "ssb.db.h"
|
#include "ssb.db.h"
|
||||||
#include "ssb.ebt.h"
|
|
||||||
#include "ssb.rpc.h"
|
#include "ssb.rpc.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "util.js.h"
|
#include "util.js.h"
|
||||||
@ -74,7 +73,6 @@ enum
|
|||||||
k_udp_discovery_expires_seconds = 10,
|
k_udp_discovery_expires_seconds = 10,
|
||||||
k_handshake_timeout_ms = 15000,
|
k_handshake_timeout_ms = 15000,
|
||||||
k_rpc_active_ms = 3000,
|
k_rpc_active_ms = 3000,
|
||||||
k_activity_timeout_ms = 15000,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t;
|
typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t;
|
||||||
@ -274,15 +272,14 @@ typedef struct _tf_ssb_connection_t
|
|||||||
uv_async_t scheduled_async;
|
uv_async_t scheduled_async;
|
||||||
uv_timer_t handshake_timer;
|
uv_timer_t handshake_timer;
|
||||||
uv_timer_t linger_timer;
|
uv_timer_t linger_timer;
|
||||||
uv_timer_t activity_timer;
|
bool closing;
|
||||||
bool is_closing;
|
|
||||||
|
|
||||||
tf_ssb_connection_t* tunnel_connection;
|
tf_ssb_connection_t* tunnel_connection;
|
||||||
int32_t tunnel_request_number;
|
int32_t tunnel_request_number;
|
||||||
|
|
||||||
tf_ssb_blob_wants_t blob_wants;
|
tf_ssb_blob_wants_t blob_wants;
|
||||||
|
bool sent_clock;
|
||||||
int32_t ebt_request_number;
|
int32_t ebt_request_number;
|
||||||
tf_ssb_ebt_t* ebt;
|
|
||||||
|
|
||||||
JSValue object;
|
JSValue object;
|
||||||
|
|
||||||
@ -603,7 +600,7 @@ static uint32_t _tf_ssb_connection_prng(tf_ssb_connection_t* connection)
|
|||||||
|
|
||||||
static void _tf_ssb_connection_dispatch_scheduled(tf_ssb_connection_t* connection)
|
static void _tf_ssb_connection_dispatch_scheduled(tf_ssb_connection_t* connection)
|
||||||
{
|
{
|
||||||
while (((connection->active_write_count == 0 && connection->read_back_pressure == 0) || connection->is_closing) && connection->scheduled_count && connection->scheduled)
|
while (((connection->active_write_count == 0 && connection->read_back_pressure == 0) || connection->closing) && connection->scheduled_count && connection->scheduled)
|
||||||
{
|
{
|
||||||
int index = _tf_ssb_connection_prng(connection) % connection->scheduled_count;
|
int index = _tf_ssb_connection_prng(connection) % connection->scheduled_count;
|
||||||
tf_ssb_connection_scheduled_t scheduled = connection->scheduled[index];
|
tf_ssb_connection_scheduled_t scheduled = connection->scheduled[index];
|
||||||
@ -631,9 +628,9 @@ static int _tf_ssb_connection_scheduled_compare(const void* a, const void* b)
|
|||||||
void tf_ssb_connection_schedule_idle(tf_ssb_connection_t* connection, const char* key, tf_ssb_scheduled_callback_t* callback, void* user_data)
|
void tf_ssb_connection_schedule_idle(tf_ssb_connection_t* connection, const char* key, tf_ssb_scheduled_callback_t* callback, void* user_data)
|
||||||
{
|
{
|
||||||
int index = tf_util_insert_index(key, connection->scheduled, connection->scheduled_count, sizeof(tf_ssb_connection_scheduled_t), _tf_ssb_connection_scheduled_compare);
|
int index = tf_util_insert_index(key, connection->scheduled, connection->scheduled_count, sizeof(tf_ssb_connection_scheduled_t), _tf_ssb_connection_scheduled_compare);
|
||||||
if (connection->is_closing || (index != connection->scheduled_count && strcmp(key, connection->scheduled[index].key) == 0))
|
if (index != connection->scheduled_count && strcmp(key, connection->scheduled[index].key) == 0)
|
||||||
{
|
{
|
||||||
/* Skip the new request. */
|
/* Keep the old request. Skip the new request. */
|
||||||
tf_trace_begin(connection->ssb->trace, "scheduled callback (skip)");
|
tf_trace_begin(connection->ssb->trace, "scheduled callback (skip)");
|
||||||
PRE_CALLBACK(connection->ssb, callback);
|
PRE_CALLBACK(connection->ssb, callback);
|
||||||
callback(connection, true, user_data);
|
callback(connection, true, user_data);
|
||||||
@ -650,10 +647,10 @@ void tf_ssb_connection_schedule_idle(tf_ssb_connection_t* connection, const char
|
|||||||
};
|
};
|
||||||
snprintf(connection->scheduled[index].key, sizeof(connection->scheduled[index].key), "%s", key);
|
snprintf(connection->scheduled[index].key, sizeof(connection->scheduled[index].key), "%s", key);
|
||||||
connection->scheduled_count++;
|
connection->scheduled_count++;
|
||||||
|
}
|
||||||
|
|
||||||
uv_async_send(&connection->scheduled_async);
|
uv_async_send(&connection->scheduled_async);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static int _request_compare(const void* a, const void* b)
|
static int _request_compare(const void* a, const void* b)
|
||||||
{
|
{
|
||||||
@ -696,11 +693,6 @@ static void _tf_ssb_request_activity_timer(uv_timer_t* timer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_connection_activity_timer(uv_timer_t* timer)
|
|
||||||
{
|
|
||||||
tf_ssb_connection_close(timer->data, "Inactivity");
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool _tf_ssb_connection_get_request_callback(
|
static bool _tf_ssb_connection_get_request_callback(
|
||||||
tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t** out_callback, void** out_user_data, const char** out_name)
|
tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t** out_callback, void** out_user_data, const char** out_name)
|
||||||
{
|
{
|
||||||
@ -724,10 +716,6 @@ static bool _tf_ssb_connection_get_request_callback(
|
|||||||
*out_name = request->name;
|
*out_name = request->name;
|
||||||
}
|
}
|
||||||
request->last_active = uv_now(connection->ssb->loop);
|
request->last_active = uv_now(connection->ssb->loop);
|
||||||
if (connection->flags & k_tf_ssb_connect_flag_one_shot)
|
|
||||||
{
|
|
||||||
uv_timer_start(&connection->activity_timer, _tf_ssb_connection_activity_timer, k_activity_timeout_ms, 0);
|
|
||||||
}
|
|
||||||
if (uv_timer_get_due_in(&connection->ssb->request_activity_timer) == 0)
|
if (uv_timer_get_due_in(&connection->ssb->request_activity_timer) == 0)
|
||||||
{
|
{
|
||||||
uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
||||||
@ -777,10 +765,6 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ
|
|||||||
connection->requests_count++;
|
connection->requests_count++;
|
||||||
connection->ssb->request_count++;
|
connection->ssb->request_count++;
|
||||||
}
|
}
|
||||||
if (connection->flags & k_tf_ssb_connect_flag_one_shot)
|
|
||||||
{
|
|
||||||
uv_timer_start(&connection->activity_timer, _tf_ssb_connection_activity_timer, k_activity_timeout_ms, 0);
|
|
||||||
}
|
|
||||||
if (uv_timer_get_due_in(&connection->ssb->request_activity_timer) == 0)
|
if (uv_timer_get_due_in(&connection->ssb->request_activity_timer) == 0)
|
||||||
{
|
{
|
||||||
uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
||||||
@ -1356,11 +1340,6 @@ bool tf_ssb_connection_is_connected(tf_ssb_connection_t* connection)
|
|||||||
return connection->state == k_tf_ssb_state_verified || connection->state == k_tf_ssb_state_server_verified;
|
return connection->state == k_tf_ssb_state_verified || connection->state == k_tf_ssb_state_server_verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tf_ssb_connection_is_closing(tf_ssb_connection_t* connection)
|
|
||||||
{
|
|
||||||
return connection && connection->is_closing;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection)
|
const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection)
|
||||||
{
|
{
|
||||||
return connection->host;
|
return connection->host;
|
||||||
@ -1588,7 +1567,7 @@ static bool _tf_ssb_connection_recv_pop(tf_ssb_connection_t* connection, uint8_t
|
|||||||
if (size >= sizeof(connection->recv_buffer))
|
if (size >= sizeof(connection->recv_buffer))
|
||||||
{
|
{
|
||||||
char message[256];
|
char message[256];
|
||||||
snprintf(message, sizeof(message), "Message (%zd) larger than the connection's receive buffer (%zd)", size, sizeof(connection->recv_buffer));
|
snprintf(message, sizeof(message), "Trying to pop a message (%zd) larger than the connection's receive buffer (%zd).", size, sizeof(connection->recv_buffer));
|
||||||
tf_ssb_connection_close(connection, message);
|
tf_ssb_connection_close(connection, message);
|
||||||
}
|
}
|
||||||
if (connection->recv_size < size)
|
if (connection->recv_size < size)
|
||||||
@ -1907,9 +1886,9 @@ static void _tf_ssb_connection_linger_timer(uv_timer_t* timer)
|
|||||||
static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* reason)
|
static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* reason)
|
||||||
{
|
{
|
||||||
tf_ssb_t* ssb = connection->ssb;
|
tf_ssb_t* ssb = connection->ssb;
|
||||||
if (!connection->is_closing)
|
if (!connection->closing)
|
||||||
{
|
{
|
||||||
connection->is_closing = true;
|
connection->closing = true;
|
||||||
uv_timer_start(&connection->linger_timer, _tf_ssb_connection_linger_timer, 5000, 0);
|
uv_timer_start(&connection->linger_timer, _tf_ssb_connection_linger_timer, 5000, 0);
|
||||||
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_update, connection);
|
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_update, connection);
|
||||||
}
|
}
|
||||||
@ -1959,7 +1938,7 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
|
|||||||
if (it->tunnel_connection == connection)
|
if (it->tunnel_connection == connection)
|
||||||
{
|
{
|
||||||
it->tunnel_connection = NULL;
|
it->tunnel_connection = NULL;
|
||||||
tf_ssb_connection_close(it, "Tunnel closed");
|
tf_ssb_connection_close(it, "tunnel closed");
|
||||||
again = true;
|
again = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1994,21 +1973,14 @@ static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const ch
|
|||||||
{
|
{
|
||||||
uv_close((uv_handle_t*)&connection->handshake_timer, _tf_ssb_connection_on_close);
|
uv_close((uv_handle_t*)&connection->handshake_timer, _tf_ssb_connection_on_close);
|
||||||
}
|
}
|
||||||
if (connection->activity_timer.data && !uv_is_closing((uv_handle_t*)&connection->activity_timer))
|
|
||||||
{
|
|
||||||
uv_close((uv_handle_t*)&connection->activity_timer, _tf_ssb_connection_on_close);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JS_IsUndefined(connection->object) && !connection->async.data && !connection->scheduled_async.data && !connection->tcp.data && !connection->connect.data &&
|
if (JS_IsUndefined(connection->object) && !connection->async.data && !connection->scheduled_async.data && !connection->tcp.data && !connection->connect.data &&
|
||||||
!connection->handshake_timer.data && !connection->linger_timer.data && !connection->activity_timer.data && connection->ref_count == 0)
|
!connection->handshake_timer.data && !connection->linger_timer.data && connection->ref_count == 0)
|
||||||
{
|
{
|
||||||
tf_free(connection->message_requests);
|
tf_free(connection->message_requests);
|
||||||
connection->message_requests = NULL;
|
connection->message_requests = NULL;
|
||||||
connection->message_requests_count = 0;
|
connection->message_requests_count = 0;
|
||||||
|
|
||||||
tf_ssb_ebt_destroy(connection->ebt);
|
|
||||||
connection->ebt = NULL;
|
|
||||||
|
|
||||||
for (tf_ssb_connection_t** it = &connection->ssb->connections; *it; it = &(*it)->next)
|
for (tf_ssb_connection_t** it = &connection->ssb->connections; *it; it = &(*it)->next)
|
||||||
{
|
{
|
||||||
if (*it == connection)
|
if (*it == connection)
|
||||||
@ -2034,7 +2006,7 @@ static void _tf_ssb_connection_on_close(uv_handle_t* handle)
|
|||||||
{
|
{
|
||||||
tf_ssb_connection_t* connection = handle->data;
|
tf_ssb_connection_t* connection = handle->data;
|
||||||
handle->data = NULL;
|
handle->data = NULL;
|
||||||
if (connection && connection->is_closing)
|
if (connection && connection->closing)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_destroy(connection, "handle closed");
|
_tf_ssb_connection_destroy(connection, "handle closed");
|
||||||
}
|
}
|
||||||
@ -2042,11 +2014,6 @@ static void _tf_ssb_connection_on_close(uv_handle_t* handle)
|
|||||||
|
|
||||||
static void _tf_ssb_connection_on_tcp_recv_internal(tf_ssb_connection_t* connection, const void* data, ssize_t nread)
|
static void _tf_ssb_connection_on_tcp_recv_internal(tf_ssb_connection_t* connection, const void* data, ssize_t nread)
|
||||||
{
|
{
|
||||||
if (connection->is_closing)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nread >= 0)
|
if (nread >= 0)
|
||||||
{
|
{
|
||||||
if (connection->recv_size + nread > sizeof(connection->recv_buffer))
|
if (connection->recv_size + nread > sizeof(connection->recv_buffer))
|
||||||
@ -2645,7 +2612,7 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
|||||||
while (connection)
|
while (connection)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_t* next = connection->next;
|
tf_ssb_connection_t* next = connection->next;
|
||||||
tf_ssb_connection_close(connection, "Shutting down");
|
tf_ssb_connection_close(connection, "Shutting down.");
|
||||||
connection = next;
|
connection = next;
|
||||||
}
|
}
|
||||||
uv_run(ssb->loop, UV_RUN_NOWAIT);
|
uv_run(ssb->loop, UV_RUN_NOWAIT);
|
||||||
@ -2742,8 +2709,7 @@ static void _tf_ssb_connection_finalizer(JSRuntime* runtime, JSValue value)
|
|||||||
static void _tf_ssb_connection_process_message_async(uv_async_t* async)
|
static void _tf_ssb_connection_process_message_async(uv_async_t* async)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_t* connection = async->data;
|
tf_ssb_connection_t* connection = async->data;
|
||||||
/* The receive may initiate a close, so this order is important. */
|
if (_tf_ssb_connection_box_stream_recv(connection))
|
||||||
if (_tf_ssb_connection_box_stream_recv(connection) && !connection->is_closing)
|
|
||||||
{
|
{
|
||||||
uv_async_send(&connection->async);
|
uv_async_send(&connection->async);
|
||||||
}
|
}
|
||||||
@ -2767,7 +2733,6 @@ static tf_ssb_connection_t* _tf_ssb_connection_create_internal(tf_ssb_t* ssb, co
|
|||||||
connection->ssb = ssb;
|
connection->ssb = ssb;
|
||||||
connection->send_request_number = 1;
|
connection->send_request_number = 1;
|
||||||
randombytes_buf(&connection->prng, sizeof(connection->prng));
|
randombytes_buf(&connection->prng, sizeof(connection->prng));
|
||||||
connection->ebt = tf_ssb_ebt_create(connection);
|
|
||||||
|
|
||||||
connection->async.data = connection;
|
connection->async.data = connection;
|
||||||
uv_async_init(ssb->loop, &connection->async, _tf_ssb_connection_process_message_async);
|
uv_async_init(ssb->loop, &connection->async, _tf_ssb_connection_process_message_async);
|
||||||
@ -2778,13 +2743,6 @@ static tf_ssb_connection_t* _tf_ssb_connection_create_internal(tf_ssb_t* ssb, co
|
|||||||
uv_timer_start(&connection->handshake_timer, _tf_ssb_connection_handshake_timer_callback, k_handshake_timeout_ms, 0);
|
uv_timer_start(&connection->handshake_timer, _tf_ssb_connection_handshake_timer_callback, k_handshake_timeout_ms, 0);
|
||||||
connection->linger_timer.data = connection;
|
connection->linger_timer.data = connection;
|
||||||
uv_timer_init(ssb->loop, &connection->linger_timer);
|
uv_timer_init(ssb->loop, &connection->linger_timer);
|
||||||
connection->activity_timer.data = connection;
|
|
||||||
uv_timer_init(ssb->loop, &connection->activity_timer);
|
|
||||||
|
|
||||||
if (connection->flags & k_tf_ssb_connect_flag_one_shot)
|
|
||||||
{
|
|
||||||
uv_timer_start(&connection->activity_timer, _tf_ssb_connection_activity_timer, k_activity_timeout_ms, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
connection->object = JS_NewObjectClass(ssb->context, _connection_class_id);
|
connection->object = JS_NewObjectClass(ssb->context, _connection_class_id);
|
||||||
JS_SetOpaque(connection->object, connection);
|
JS_SetOpaque(connection->object, connection);
|
||||||
@ -2867,27 +2825,8 @@ static void _tf_ssb_connection_tunnel_callback(
|
|||||||
tf_ssb_connection_remove_request(connection, -request_number);
|
tf_ssb_connection_remove_request(connection, -request_number);
|
||||||
tf_ssb_connection_rpc_send(connection, flags, -request_number, NULL, (const uint8_t*)"false", strlen("false"), NULL, NULL, NULL);
|
tf_ssb_connection_rpc_send(connection, flags, -request_number, NULL, (const uint8_t*)"false", strlen("false"), NULL, NULL, NULL);
|
||||||
|
|
||||||
JSContext* context = tf_ssb_connection_get_context(connection);
|
|
||||||
JSValue message_val = JS_GetPropertyStr(context, args, "message");
|
|
||||||
JSValue stack_val = JS_GetPropertyStr(context, args, "stack");
|
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
if (!JS_IsUndefined(message_val))
|
snprintf(buffer, sizeof(buffer), "tunnel error: %.*s", (int)size, message);
|
||||||
{
|
|
||||||
const char* message_string = JS_ToCString(context, message_val);
|
|
||||||
const char* stack_string = JS_ToCString(context, stack_val);
|
|
||||||
snprintf(buffer, sizeof(buffer), "Tunnel error: %s\n%s", message_string, stack_string);
|
|
||||||
JS_FreeCString(context, message_string);
|
|
||||||
JS_FreeCString(context, stack_string);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(buffer, sizeof(buffer), "Tunnel error: %.*s", (int)size, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_FreeValue(context, stack_val);
|
|
||||||
JS_FreeValue(context, message_val);
|
|
||||||
|
|
||||||
tf_ssb_connection_close(tunnel, buffer);
|
tf_ssb_connection_close(tunnel, buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2993,10 +2932,7 @@ void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* ke
|
|||||||
};
|
};
|
||||||
char id[k_id_base64_len] = { 0 };
|
char id[k_id_base64_len] = { 0 };
|
||||||
tf_ssb_id_bin_to_str(id, sizeof(id), key);
|
tf_ssb_id_bin_to_str(id, sizeof(id), key);
|
||||||
if ((connect_flags & k_tf_ssb_connect_flag_do_not_store) == 0)
|
|
||||||
{
|
|
||||||
tf_ssb_connections_store(ssb->connections_tracker, host, port, id);
|
tf_ssb_connections_store(ssb->connections_tracker, host, port, id);
|
||||||
}
|
|
||||||
snprintf(connect->host, sizeof(connect->host), "%s", host);
|
snprintf(connect->host, sizeof(connect->host), "%s", host);
|
||||||
memcpy(connect->key, key, k_id_bin_len);
|
memcpy(connect->key, key, k_id_bin_len);
|
||||||
tf_ssb_ref(ssb);
|
tf_ssb_ref(ssb);
|
||||||
@ -3935,6 +3871,16 @@ void tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, tf_ssb_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tf_ssb_connection_get_sent_clock(tf_ssb_connection_t* connection)
|
||||||
|
{
|
||||||
|
return connection->sent_clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tf_ssb_connection_set_sent_clock(tf_ssb_connection_t* connection, bool sent_clock)
|
||||||
|
{
|
||||||
|
connection->sent_clock = sent_clock;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tf_ssb_connection_get_ebt_request_number(tf_ssb_connection_t* connection)
|
int32_t tf_ssb_connection_get_ebt_request_number(tf_ssb_connection_t* connection)
|
||||||
{
|
{
|
||||||
return connection->ebt_request_number;
|
return connection->ebt_request_number;
|
||||||
@ -4032,7 +3978,7 @@ static void _tf_ssb_connection_after_work_callback(uv_work_t* work, int status)
|
|||||||
tf_trace_end(data->connection->ssb->trace);
|
tf_trace_end(data->connection->ssb->trace);
|
||||||
}
|
}
|
||||||
data->connection->ref_count--;
|
data->connection->ref_count--;
|
||||||
if (data->connection->ref_count == 0 && data->connection->is_closing)
|
if (data->connection->ref_count == 0 && data->connection->closing)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_destroy(data->connection, "work completed");
|
_tf_ssb_connection_destroy(data->connection, "work completed");
|
||||||
}
|
}
|
||||||
@ -4315,9 +4261,9 @@ void tf_ssb_connection_adjust_read_backpressure(tf_ssb_connection_t* connection,
|
|||||||
const int k_threshold = 256;
|
const int k_threshold = 256;
|
||||||
int old_pressure = connection->read_back_pressure;
|
int old_pressure = connection->read_back_pressure;
|
||||||
connection->read_back_pressure += delta;
|
connection->read_back_pressure += delta;
|
||||||
if (!connection->is_closing)
|
|
||||||
{
|
|
||||||
uv_async_send(&connection->scheduled_async);
|
uv_async_send(&connection->scheduled_async);
|
||||||
|
if (!connection->closing)
|
||||||
|
{
|
||||||
if (old_pressure < k_threshold && connection->read_back_pressure >= k_threshold)
|
if (old_pressure < k_threshold && connection->read_back_pressure >= k_threshold)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_read_stop(connection);
|
_tf_ssb_connection_read_stop(connection);
|
||||||
@ -4328,7 +4274,7 @@ void tf_ssb_connection_adjust_read_backpressure(tf_ssb_connection_t* connection,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection->ref_count += delta;
|
connection->ref_count += delta;
|
||||||
if (connection->ref_count == 0 && connection->is_closing)
|
if (connection->ref_count == 0 && connection->closing)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_destroy(connection, "backpressure released");
|
_tf_ssb_connection_destroy(connection, "backpressure released");
|
||||||
}
|
}
|
||||||
@ -4337,11 +4283,8 @@ void tf_ssb_connection_adjust_read_backpressure(tf_ssb_connection_t* connection,
|
|||||||
void tf_ssb_connection_adjust_write_count(tf_ssb_connection_t* connection, int delta)
|
void tf_ssb_connection_adjust_write_count(tf_ssb_connection_t* connection, int delta)
|
||||||
{
|
{
|
||||||
connection->active_write_count += delta;
|
connection->active_write_count += delta;
|
||||||
if (!connection->is_closing)
|
|
||||||
{
|
|
||||||
uv_async_send(&connection->scheduled_async);
|
uv_async_send(&connection->scheduled_async);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const char* tf_ssb_connection_get_destroy_reason(tf_ssb_connection_t* connection)
|
const char* tf_ssb_connection_get_destroy_reason(tf_ssb_connection_t* connection)
|
||||||
{
|
{
|
||||||
@ -4384,72 +4327,3 @@ int tf_ssb_connection_get_flags(tf_ssb_connection_t* connection)
|
|||||||
{
|
{
|
||||||
return connection->flags;
|
return connection->flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
tf_ssb_ebt_t* tf_ssb_connection_get_ebt(tf_ssb_connection_t* connection)
|
|
||||||
{
|
|
||||||
return connection ? connection->ebt : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* tf_ssb_private_message_encrypt(uint8_t* private_key, const char** recipients, int recipients_count, const char* message, size_t message_size)
|
|
||||||
{
|
|
||||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES] = { 0 };
|
|
||||||
uint8_t secret_key[crypto_box_SECRETKEYBYTES] = { 0 };
|
|
||||||
uint8_t nonce[crypto_box_NONCEBYTES] = { 0 };
|
|
||||||
uint8_t body_key[crypto_box_SECRETKEYBYTES] = { 0 };
|
|
||||||
crypto_box_keypair(public_key, secret_key);
|
|
||||||
randombytes_buf(nonce, sizeof(nonce));
|
|
||||||
randombytes_buf(body_key, sizeof(body_key));
|
|
||||||
|
|
||||||
uint8_t length_and_key[1 + sizeof(body_key)];
|
|
||||||
length_and_key[0] = (uint8_t)recipients_count;
|
|
||||||
memcpy(length_and_key + 1, body_key, sizeof(body_key));
|
|
||||||
|
|
||||||
size_t payload_size = sizeof(nonce) + sizeof(public_key) + (crypto_secretbox_MACBYTES + sizeof(length_and_key)) * recipients_count + crypto_secretbox_MACBYTES + message_size;
|
|
||||||
|
|
||||||
uint8_t* payload = tf_malloc(payload_size);
|
|
||||||
|
|
||||||
uint8_t* p = payload;
|
|
||||||
memcpy(p, nonce, sizeof(nonce));
|
|
||||||
p += sizeof(nonce);
|
|
||||||
|
|
||||||
memcpy(p, public_key, sizeof(public_key));
|
|
||||||
p += sizeof(public_key);
|
|
||||||
|
|
||||||
for (int i = 0; i < recipients_count; i++)
|
|
||||||
{
|
|
||||||
uint8_t recipient[crypto_scalarmult_curve25519_SCALARBYTES] = { 0 };
|
|
||||||
uint8_t key[crypto_box_PUBLICKEYBYTES] = { 0 };
|
|
||||||
tf_ssb_id_str_to_bin(key, recipients[i]);
|
|
||||||
if (crypto_sign_ed25519_pk_to_curve25519(recipient, key) != 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t shared_secret[crypto_secretbox_KEYBYTES] = { 0 };
|
|
||||||
if (crypto_scalarmult(shared_secret, secret_key, recipient) != 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (crypto_secretbox_easy(p, length_and_key, sizeof(length_and_key), nonce, shared_secret) != 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
p += crypto_secretbox_MACBYTES + sizeof(length_and_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (crypto_secretbox_easy(p, (const uint8_t*)message, message_size, nonce, body_key) != 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
p += crypto_secretbox_MACBYTES + message_size;
|
|
||||||
assert((size_t)(p - payload) == payload_size);
|
|
||||||
|
|
||||||
char* encoded = tf_malloc(payload_size * 2 + 5);
|
|
||||||
size_t encoded_length = tf_base64_encode(payload, payload_size, encoded, payload_size * 2 + 5);
|
|
||||||
memcpy(encoded + encoded_length, ".box", 5);
|
|
||||||
|
|
||||||
tf_free(payload);
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
|
@ -103,7 +103,7 @@ static void _tf_ssb_connections_get_next_after_work(tf_ssb_t* ssb, int status, v
|
|||||||
uint8_t key_bin[k_id_bin_len];
|
uint8_t key_bin[k_id_bin_len];
|
||||||
if (tf_ssb_id_str_to_bin(key_bin, next->key))
|
if (tf_ssb_id_str_to_bin(key_bin, next->key))
|
||||||
{
|
{
|
||||||
tf_ssb_connect(ssb, next->host, next->port, key_bin, k_tf_ssb_connect_flag_do_not_store, NULL, NULL);
|
tf_ssb_connect(ssb, next->host, next->port, key_bin, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tf_free(next);
|
tf_free(next);
|
||||||
@ -287,7 +287,7 @@ static void _tf_ssb_connections_sync_broadcast_visit(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tf_ssb_connect(ssb, host, ntohs(addr->sin_port), pub, k_tf_ssb_connect_flag_one_shot | k_tf_ssb_connect_flag_do_not_store, NULL, NULL);
|
tf_ssb_connect(ssb, host, ntohs(addr->sin_port), pub, k_tf_ssb_connect_flag_one_shot, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
src/ssb.db.c
36
src/ssb.db.c
@ -603,10 +603,11 @@ bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tf_ssb_db_blob_has(sqlite3* db, const char* id)
|
bool tf_ssb_db_blob_has(tf_ssb_t* ssb, const char* id)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
sqlite3_stmt* statement;
|
sqlite3_stmt* statement;
|
||||||
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
const char* query = "SELECT COUNT(*) FROM blobs WHERE id = ?1";
|
const char* query = "SELECT COUNT(*) FROM blobs WHERE id = ?1";
|
||||||
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
||||||
{
|
{
|
||||||
@ -616,6 +617,7 @@ bool tf_ssb_db_blob_has(sqlite3* db, const char* id)
|
|||||||
}
|
}
|
||||||
sqlite3_finalize(statement);
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1900,12 +1902,6 @@ static void _tf_ssb_db_resolve_index_work(tf_ssb_t* ssb, void* user_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
|
|
||||||
if (!request->path)
|
|
||||||
{
|
|
||||||
/* From default global settings. */
|
|
||||||
request->path = tf_strdup("/~core/ssb/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_db_resolve_index_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
static void _tf_ssb_db_resolve_index_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||||
@ -2082,29 +2078,3 @@ bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* ou
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* tf_ssb_db_get_profile(sqlite3* db, const char* id)
|
|
||||||
{
|
|
||||||
const char* result = NULL;
|
|
||||||
sqlite3_stmt* statement;
|
|
||||||
if (sqlite3_prepare(db,
|
|
||||||
"SELECT json(json_group_object(key, value)) FROM (SELECT fields.key, RANK() OVER (PARTITION BY fields.key ORDER BY messages.sequence DESC) AS rank, fields.value FROM "
|
|
||||||
"messages, json_each(messages.content) AS fields WHERE messages.author = ? AND messages.content ->> '$.type' = 'about' AND messages.content ->> '$.about' = "
|
|
||||||
"messages.author AND NOT fields.key IN ('about', 'type')) WHERE rank = 1",
|
|
||||||
-1, &statement, NULL) == SQLITE_OK)
|
|
||||||
{
|
|
||||||
if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK)
|
|
||||||
{
|
|
||||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
|
||||||
{
|
|
||||||
result = tf_strdup((const char*)sqlite3_column_text(statement, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sqlite3_finalize(statement);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tf_printf("prepare failed: %s\n", sqlite3_errmsg(db));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
12
src/ssb.db.h
12
src/ssb.db.h
@ -39,11 +39,11 @@ bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
** Determine whether a blob is in the database by ID.
|
** Determine whether a blob is in the database by ID.
|
||||||
** @param db The SQLite database instance to use.
|
** @param ssb The SSB instasnce.
|
||||||
** @param id The blob identifier.
|
** @param id The blob identifier.
|
||||||
** @return true If the blob is in the database.
|
** @return true If the blob is in the database.
|
||||||
*/
|
*/
|
||||||
bool tf_ssb_db_blob_has(sqlite3* db, const char* id);
|
bool tf_ssb_db_blob_has(tf_ssb_t* ssb, const char* id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Retrieve a blob from the database.
|
** Retrieve a blob from the database.
|
||||||
@ -483,14 +483,6 @@ bool tf_ssb_db_get_global_setting_int64(sqlite3* db, const char* name, int64_t*
|
|||||||
*/
|
*/
|
||||||
bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* out_value, size_t size);
|
bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* out_value, size_t size);
|
||||||
|
|
||||||
/**
|
|
||||||
** Get the latest profile information for the given identity.
|
|
||||||
** @param db The database.
|
|
||||||
** @param id The identity.
|
|
||||||
** @return A JSON representation of the latest profile information set for the account. Free with tf_free().
|
|
||||||
*/
|
|
||||||
const char* tf_ssb_db_get_profile(sqlite3* db, const char* id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** An SQLite authorizer callback. See https://www.sqlite.org/c3ref/set_authorizer.html for use.
|
** An SQLite authorizer callback. See https://www.sqlite.org/c3ref/set_authorizer.html for use.
|
||||||
** @param user_data User data registered with the authorizer.
|
** @param user_data User data registered with the authorizer.
|
||||||
|
322
src/ssb.ebt.c
322
src/ssb.ebt.c
@ -1,322 +0,0 @@
|
|||||||
#include "ssb.ebt.h"
|
|
||||||
|
|
||||||
#include "mem.h"
|
|
||||||
#include "ssb.db.h"
|
|
||||||
#include "ssb.h"
|
|
||||||
#include "util.js.h"
|
|
||||||
|
|
||||||
#include "uv.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef struct _ebt_entry_t
|
|
||||||
{
|
|
||||||
char id[k_id_base64_len];
|
|
||||||
int64_t out;
|
|
||||||
int64_t in;
|
|
||||||
bool out_replicate;
|
|
||||||
bool out_receive;
|
|
||||||
bool in_replicate;
|
|
||||||
bool in_receive;
|
|
||||||
} ebt_entry_t;
|
|
||||||
|
|
||||||
typedef struct _tf_ssb_ebt_t
|
|
||||||
{
|
|
||||||
tf_ssb_connection_t* connection;
|
|
||||||
uv_mutex_t mutex;
|
|
||||||
|
|
||||||
ebt_entry_t* entries;
|
|
||||||
int entries_count;
|
|
||||||
|
|
||||||
int send_clock_pending;
|
|
||||||
} tf_ssb_ebt_t;
|
|
||||||
|
|
||||||
tf_ssb_ebt_t* tf_ssb_ebt_create(tf_ssb_connection_t* connection)
|
|
||||||
{
|
|
||||||
tf_ssb_ebt_t* ebt = tf_malloc(sizeof(tf_ssb_ebt_t));
|
|
||||||
*ebt = (tf_ssb_ebt_t) {
|
|
||||||
.connection = connection,
|
|
||||||
};
|
|
||||||
uv_mutex_init(&ebt->mutex);
|
|
||||||
return ebt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_ebt_destroy(tf_ssb_ebt_t* ebt)
|
|
||||||
{
|
|
||||||
uv_mutex_destroy(&ebt->mutex);
|
|
||||||
tf_free(ebt->entries);
|
|
||||||
tf_free(ebt);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _ebt_entry_compare(const void* a, const void* b)
|
|
||||||
{
|
|
||||||
const char* id = a;
|
|
||||||
const ebt_entry_t* entry = b;
|
|
||||||
return strcmp(id, entry->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ebt_entry_t* _ebt_get_entry(tf_ssb_ebt_t* ebt, const char* id)
|
|
||||||
{
|
|
||||||
int index = tf_util_insert_index(id, ebt->entries, ebt->entries_count, sizeof(ebt_entry_t), _ebt_entry_compare);
|
|
||||||
if (index < ebt->entries_count && strcmp(id, ebt->entries[index].id) == 0)
|
|
||||||
{
|
|
||||||
return &ebt->entries[index];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ebt->entries = tf_resize_vec(ebt->entries, (ebt->entries_count + 1) * sizeof(ebt_entry_t));
|
|
||||||
if (index < ebt->entries_count)
|
|
||||||
{
|
|
||||||
memmove(ebt->entries + index + 1, ebt->entries + index, (ebt->entries_count - index) * sizeof(ebt_entry_t));
|
|
||||||
}
|
|
||||||
ebt->entries[index] = (ebt_entry_t) {
|
|
||||||
.in = -1,
|
|
||||||
.out = -1,
|
|
||||||
};
|
|
||||||
snprintf(ebt->entries[index].id, sizeof(ebt->entries[index].id), "%s", id);
|
|
||||||
ebt->entries_count++;
|
|
||||||
return &ebt->entries[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_ebt_receive_clock(tf_ssb_ebt_t* ebt, JSContext* context, JSValue clock)
|
|
||||||
{
|
|
||||||
JSPropertyEnum* ptab = NULL;
|
|
||||||
uint32_t plen = 0;
|
|
||||||
if (JS_GetOwnPropertyNames(context, &ptab, &plen, clock, JS_GPN_STRING_MASK) == 0)
|
|
||||||
{
|
|
||||||
uv_mutex_lock(&ebt->mutex);
|
|
||||||
for (uint32_t i = 0; i < plen; ++i)
|
|
||||||
{
|
|
||||||
JSValue in_clock = JS_UNDEFINED;
|
|
||||||
JSPropertyDescriptor desc = { 0 };
|
|
||||||
if (JS_GetOwnProperty(context, &desc, clock, ptab[i].atom) == 1)
|
|
||||||
{
|
|
||||||
in_clock = desc.value;
|
|
||||||
JS_FreeValue(context, desc.setter);
|
|
||||||
JS_FreeValue(context, desc.getter);
|
|
||||||
}
|
|
||||||
if (!JS_IsUndefined(in_clock))
|
|
||||||
{
|
|
||||||
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
|
||||||
const char* author = JS_ToCString(context, key);
|
|
||||||
int64_t sequence = -1;
|
|
||||||
JS_ToInt64(context, &sequence, in_clock);
|
|
||||||
|
|
||||||
ebt_entry_t* entry = _ebt_get_entry(ebt, author);
|
|
||||||
if (sequence < 0)
|
|
||||||
{
|
|
||||||
entry->in = -1;
|
|
||||||
entry->in_replicate = false;
|
|
||||||
entry->in_receive = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry->in = sequence >> 1;
|
|
||||||
entry->in_replicate = true;
|
|
||||||
entry->in_receive = (sequence & 1) == 0;
|
|
||||||
}
|
|
||||||
if (!entry->in_receive)
|
|
||||||
{
|
|
||||||
tf_ssb_connection_remove_new_message_request(ebt->connection, author);
|
|
||||||
}
|
|
||||||
JS_FreeCString(context, author);
|
|
||||||
JS_FreeValue(context, key);
|
|
||||||
}
|
|
||||||
JS_FreeValue(context, in_clock);
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&ebt->mutex);
|
|
||||||
for (uint32_t i = 0; i < plen; ++i)
|
|
||||||
{
|
|
||||||
JS_FreeAtom(context, ptab[i].atom);
|
|
||||||
}
|
|
||||||
js_free(context, ptab);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct _ebt_get_clock_t
|
|
||||||
{
|
|
||||||
tf_ssb_ebt_t* ebt;
|
|
||||||
int32_t request_number;
|
|
||||||
tf_ssb_ebt_clock_callback_t* callback;
|
|
||||||
tf_ssb_ebt_clock_t* clock;
|
|
||||||
void* user_data;
|
|
||||||
} ebt_get_clock_t;
|
|
||||||
|
|
||||||
static int _ebt_compare_entry(const void* a, const void* b)
|
|
||||||
{
|
|
||||||
const char* id = a;
|
|
||||||
const tf_ssb_ebt_clock_entry_t* entry = b;
|
|
||||||
return strcmp(id, entry->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _ebt_add_to_clock(ebt_get_clock_t* work, const char* id, int64_t value, bool replicate, bool receive)
|
|
||||||
{
|
|
||||||
int count = work->clock ? work->clock->count : 0;
|
|
||||||
ebt_entry_t* entry = _ebt_get_entry(work->ebt, id);
|
|
||||||
if ((replicate && !entry->out_replicate) || (receive && !entry->out_receive) || ((replicate || receive || entry->out_replicate || entry->out_receive) && entry->out != value))
|
|
||||||
{
|
|
||||||
entry->out = value;
|
|
||||||
entry->out_replicate = entry->out_replicate || replicate;
|
|
||||||
entry->out_receive = entry->out_receive || receive;
|
|
||||||
|
|
||||||
int index = tf_util_insert_index(id, count ? work->clock->entries : NULL, count, sizeof(tf_ssb_ebt_clock_entry_t), _ebt_compare_entry);
|
|
||||||
int64_t out_value = entry->out_replicate ? ((value << 1) | (entry->out_receive ? 0 : 1)) : -1;
|
|
||||||
if (index < count && strcmp(id, work->clock->entries[index].id) == 0)
|
|
||||||
{
|
|
||||||
work->clock->entries[index].value = out_value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
work->clock = tf_resize_vec(work->clock, sizeof(tf_ssb_ebt_clock_t) + (count + 1) * sizeof(tf_ssb_ebt_clock_entry_t));
|
|
||||||
if (index < count)
|
|
||||||
{
|
|
||||||
memmove(work->clock->entries + index + 1, work->clock->entries + index, (count - index) * sizeof(tf_ssb_ebt_clock_entry_t));
|
|
||||||
}
|
|
||||||
work->clock->entries[index] = (tf_ssb_ebt_clock_entry_t) { .value = out_value };
|
|
||||||
snprintf(work->clock->entries[index].id, sizeof(work->clock->entries[index].id), "%s", id);
|
|
||||||
work->clock->count = count + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _tf_ssb_ebt_get_send_clock_work(tf_ssb_connection_t* connection, void* user_data)
|
|
||||||
{
|
|
||||||
ebt_get_clock_t* work = user_data;
|
|
||||||
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(work->ebt->connection);
|
|
||||||
|
|
||||||
int64_t depth = 2;
|
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
|
||||||
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &depth);
|
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
|
||||||
|
|
||||||
/* Ask for every identity we know is being followed from local accounts. */
|
|
||||||
const char** visible = tf_ssb_db_get_all_visible_identities(ssb, depth);
|
|
||||||
if (visible)
|
|
||||||
{
|
|
||||||
int64_t* sequences = NULL;
|
|
||||||
for (int i = 0; visible[i]; i++)
|
|
||||||
{
|
|
||||||
int64_t sequence = 0;
|
|
||||||
tf_ssb_db_get_latest_message_by_author(ssb, visible[i], &sequence, NULL, 0);
|
|
||||||
sequences = tf_resize_vec(sequences, (i + 1) * sizeof(int64_t));
|
|
||||||
sequences[i] = sequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
uv_mutex_lock(&work->ebt->mutex);
|
|
||||||
for (int i = 0; visible[i]; i++)
|
|
||||||
{
|
|
||||||
_ebt_add_to_clock(work, visible[i], sequences[i], true, true);
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&work->ebt->mutex);
|
|
||||||
|
|
||||||
tf_free(visible);
|
|
||||||
tf_free(sequences);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ask about the incoming connection, too. */
|
|
||||||
char id[k_id_base64_len] = "";
|
|
||||||
if (tf_ssb_connection_get_id(connection, id, sizeof(id)))
|
|
||||||
{
|
|
||||||
int64_t sequence = 0;
|
|
||||||
tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0);
|
|
||||||
uv_mutex_lock(&work->ebt->mutex);
|
|
||||||
_ebt_add_to_clock(work, id, sequence, true, true);
|
|
||||||
uv_mutex_unlock(&work->ebt->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Also respond with what we know about all requested identities. */
|
|
||||||
tf_ssb_ebt_clock_entry_t* requested = NULL;
|
|
||||||
int requested_count = 0;
|
|
||||||
uv_mutex_lock(&work->ebt->mutex);
|
|
||||||
for (int i = 0; i < work->ebt->entries_count; i++)
|
|
||||||
{
|
|
||||||
ebt_entry_t* entry = &work->ebt->entries[i];
|
|
||||||
if (entry->in_replicate && !entry->out_replicate)
|
|
||||||
{
|
|
||||||
requested = tf_resize_vec(requested, (requested_count + 1) * sizeof(tf_ssb_ebt_clock_entry_t));
|
|
||||||
requested[requested_count] = (tf_ssb_ebt_clock_entry_t) { .value = -1 };
|
|
||||||
snprintf(requested[requested_count].id, sizeof(requested[requested_count].id), "%s", entry->id);
|
|
||||||
requested_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&work->ebt->mutex);
|
|
||||||
|
|
||||||
if (requested_count)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < requested_count; i++)
|
|
||||||
{
|
|
||||||
tf_ssb_db_get_latest_message_by_author(ssb, requested[i].id, &requested[i].value, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
uv_mutex_lock(&work->ebt->mutex);
|
|
||||||
for (int i = 0; i < requested_count; i++)
|
|
||||||
{
|
|
||||||
_ebt_add_to_clock(work, requested[i].id, requested[i].value, requested[i].value >= 0, false);
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&work->ebt->mutex);
|
|
||||||
tf_free(requested);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _tf_ssb_ebt_get_send_clock_after_work(tf_ssb_connection_t* connection, int status, void* user_data)
|
|
||||||
{
|
|
||||||
ebt_get_clock_t* work = user_data;
|
|
||||||
work->callback(work->clock, work->request_number, work->user_data);
|
|
||||||
tf_free(work->clock);
|
|
||||||
tf_free(work);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_ebt_get_send_clock(tf_ssb_ebt_t* ebt, int32_t request_number, tf_ssb_ebt_clock_callback_t* callback, void* user_data)
|
|
||||||
{
|
|
||||||
ebt_get_clock_t* work = tf_malloc(sizeof(ebt_get_clock_t));
|
|
||||||
*work = (ebt_get_clock_t) {
|
|
||||||
.ebt = ebt,
|
|
||||||
.request_number = request_number,
|
|
||||||
.callback = callback,
|
|
||||||
.user_data = user_data,
|
|
||||||
};
|
|
||||||
tf_ssb_connection_run_work(ebt->connection, _tf_ssb_ebt_get_send_clock_work, _tf_ssb_ebt_get_send_clock_after_work, work);
|
|
||||||
}
|
|
||||||
|
|
||||||
tf_ssb_ebt_clock_t* tf_ssb_ebt_get_messages_to_send(tf_ssb_ebt_t* ebt)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
tf_ssb_ebt_clock_t* clock = NULL;
|
|
||||||
uv_mutex_lock(&ebt->mutex);
|
|
||||||
for (int i = 0; i < ebt->entries_count; i++)
|
|
||||||
{
|
|
||||||
ebt_entry_t* entry = &ebt->entries[i];
|
|
||||||
if (entry->in_replicate && entry->in_receive && entry->out > entry->in)
|
|
||||||
{
|
|
||||||
clock = tf_resize_vec(clock, sizeof(tf_ssb_ebt_clock_t) + (count + 1) * sizeof(tf_ssb_ebt_clock_entry_t));
|
|
||||||
clock->entries[count] = (tf_ssb_ebt_clock_entry_t) { .value = entry->in };
|
|
||||||
snprintf(clock->entries[count].id, sizeof(clock->entries[count].id), "%s", entry->id);
|
|
||||||
clock->count = ++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&ebt->mutex);
|
|
||||||
return clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_ebt_set_messages_sent(tf_ssb_ebt_t* ebt, const char* id, int64_t sequence)
|
|
||||||
{
|
|
||||||
uv_mutex_lock(&ebt->mutex);
|
|
||||||
ebt_entry_t* entry = _ebt_get_entry(ebt, id);
|
|
||||||
entry->in = tf_max(entry->in, sequence);
|
|
||||||
if (entry->in == entry->out && (tf_ssb_connection_get_flags(ebt->connection) & k_tf_ssb_connect_flag_one_shot) == 0)
|
|
||||||
{
|
|
||||||
tf_ssb_connection_add_new_message_request(ebt->connection, id, tf_ssb_connection_get_ebt_request_number(ebt->connection), false);
|
|
||||||
}
|
|
||||||
uv_mutex_unlock(&ebt->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int tf_ssb_ebt_get_send_clock_pending(tf_ssb_ebt_t* ebt)
|
|
||||||
{
|
|
||||||
return ebt->send_clock_pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tf_ssb_ebt_set_send_clock_pending(tf_ssb_ebt_t* ebt, int pending)
|
|
||||||
{
|
|
||||||
ebt->send_clock_pending = pending;
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ssb.h"
|
|
||||||
|
|
||||||
#include "quickjs.h"
|
|
||||||
|
|
||||||
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
** SSB EBT state.
|
|
||||||
*/
|
|
||||||
typedef struct _tf_ssb_ebt_t tf_ssb_ebt_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
** An EBT clock entry (identity + sequence pair).
|
|
||||||
*/
|
|
||||||
typedef struct _tf_ssb_ebt_clock_entry_t
|
|
||||||
{
|
|
||||||
/** The identity. */
|
|
||||||
char id[k_id_base64_len];
|
|
||||||
/** The sequence number. */
|
|
||||||
int64_t value;
|
|
||||||
} tf_ssb_ebt_clock_entry_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
** A set of IDs and sequence values.
|
|
||||||
*/
|
|
||||||
typedef struct _tf_ssb_ebt_clock_t
|
|
||||||
{
|
|
||||||
/** Number of entries. */
|
|
||||||
int count;
|
|
||||||
/** Clock entries. */
|
|
||||||
tf_ssb_ebt_clock_entry_t entries[];
|
|
||||||
} tf_ssb_ebt_clock_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
** A callback with EBT clock state.
|
|
||||||
*/
|
|
||||||
typedef void(tf_ssb_ebt_clock_callback_t)(const tf_ssb_ebt_clock_t* clock, int32_t request_number, void* user_data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Create an EBT instance.
|
|
||||||
** @param connection The SSB connection to which this EBT state applies.
|
|
||||||
** @return The EBT instance.
|
|
||||||
*/
|
|
||||||
tf_ssb_ebt_t* tf_ssb_ebt_create(tf_ssb_connection_t* connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Update the EBT state with a received clock.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @param context The JS context.
|
|
||||||
** @param clock The received clock.
|
|
||||||
*/
|
|
||||||
void tf_ssb_ebt_receive_clock(tf_ssb_ebt_t* ebt, JSContext* context, JSValue clock);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Get the EBT clock state to send.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @param request_number The request number for which the clock will be sent.
|
|
||||||
** @param callback Called with the clock when determined.
|
|
||||||
** @param user_data User data passed to the callback.
|
|
||||||
*/
|
|
||||||
void tf_ssb_ebt_get_send_clock(tf_ssb_ebt_t* ebt, int32_t request_number, tf_ssb_ebt_clock_callback_t* callback, void* user_data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Get the set of messages requested to be sent.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @return A clock of identities and sequence numbers indicating which messages
|
|
||||||
** are due to be sent. The caller must free with tf_free().
|
|
||||||
*/
|
|
||||||
tf_ssb_ebt_clock_t* tf_ssb_ebt_get_messages_to_send(tf_ssb_ebt_t* ebt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Update the clock state indicating the messages that have been sent for an account.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @param id The identity to update.
|
|
||||||
** @param sequence The maximum sequence number sent.
|
|
||||||
*/
|
|
||||||
void tf_ssb_ebt_set_messages_sent(tf_ssb_ebt_t* ebt, const char* id, int64_t sequence);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Destroy an EBT instance.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
*/
|
|
||||||
void tf_ssb_ebt_destroy(tf_ssb_ebt_t* ebt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Get whether sending the clock is pending.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @return The last value set by tf_ssb_ebt_set_send_clock_pending().
|
|
||||||
*/
|
|
||||||
int tf_ssb_ebt_get_send_clock_pending(tf_ssb_ebt_t* ebt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Set whether sending the clock is pending.
|
|
||||||
** @param ebt The EBT instance.
|
|
||||||
** @param pending A value representing the pending status.
|
|
||||||
*/
|
|
||||||
void tf_ssb_ebt_set_send_clock_pending(tf_ssb_ebt_t* ebt, int pending);
|
|
44
src/ssb.h
44
src/ssb.h
@ -30,8 +30,6 @@ enum
|
|||||||
k_ssb_blob_bytes_max = 5 * 1024 * 1024,
|
k_ssb_blob_bytes_max = 5 * 1024 * 1024,
|
||||||
|
|
||||||
k_ssb_peer_exchange_expires_seconds = 60 * 60,
|
k_ssb_peer_exchange_expires_seconds = 60 * 60,
|
||||||
|
|
||||||
k_max_private_message_recipients = 8,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,15 +71,12 @@ typedef enum _tf_ssb_message_flags_t
|
|||||||
typedef enum _tf_ssb_connect_flags_t
|
typedef enum _tf_ssb_connect_flags_t
|
||||||
{
|
{
|
||||||
k_tf_ssb_connect_flag_one_shot = 0x1,
|
k_tf_ssb_connect_flag_one_shot = 0x1,
|
||||||
k_tf_ssb_connect_flag_do_not_store = 0x2,
|
|
||||||
} tf_ssb_connect_flags_t;
|
} tf_ssb_connect_flags_t;
|
||||||
|
|
||||||
/** An SSB instance. */
|
/** An SSB instance. */
|
||||||
typedef struct _tf_ssb_t tf_ssb_t;
|
typedef struct _tf_ssb_t tf_ssb_t;
|
||||||
/** An SSB connection. */
|
/** An SSB connection. */
|
||||||
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
typedef struct _tf_ssb_connection_t tf_ssb_connection_t;
|
||||||
/** A connection's EBT state. */
|
|
||||||
typedef struct _tf_ssb_ebt_t tf_ssb_ebt_t;
|
|
||||||
/** A trace instance. */
|
/** A trace instance. */
|
||||||
typedef struct _tf_trace_t tf_trace_t;
|
typedef struct _tf_trace_t tf_trace_t;
|
||||||
/** An SQLite database handle. */
|
/** An SQLite database handle. */
|
||||||
@ -530,13 +525,6 @@ void tf_ssb_connection_close(tf_ssb_connection_t* connection, const char* reason
|
|||||||
*/
|
*/
|
||||||
bool tf_ssb_connection_is_connected(tf_ssb_connection_t* connection);
|
bool tf_ssb_connection_is_connected(tf_ssb_connection_t* connection);
|
||||||
|
|
||||||
/**
|
|
||||||
** Check whether a connection is in the process of closing.
|
|
||||||
** @param connection The connection.
|
|
||||||
** @return True if the connection is closing.
|
|
||||||
*/
|
|
||||||
bool tf_ssb_connection_is_closing(tf_ssb_connection_t* connection);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Get the next outgoing request number for a connection.
|
** Get the next outgoing request number for a connection.
|
||||||
** @param connection The connection.
|
** @param connection The connection.
|
||||||
@ -928,6 +916,20 @@ int32_t tf_ssb_connection_get_ebt_request_number(tf_ssb_connection_t* connection
|
|||||||
*/
|
*/
|
||||||
void tf_ssb_connection_set_ebt_request_number(tf_ssb_connection_t* connection, int32_t request_number);
|
void tf_ssb_connection_set_ebt_request_number(tf_ssb_connection_t* connection, int32_t request_number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Get whether the EBT clock has been sent for a connection.
|
||||||
|
** @param connection An SHS connection.
|
||||||
|
** @return True if the clock has been sent.
|
||||||
|
*/
|
||||||
|
bool tf_ssb_connection_get_sent_clock(tf_ssb_connection_t* connection);
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Set the EBT clock sent state for a connection.
|
||||||
|
** @param connection An SHS connection.
|
||||||
|
** @param sent_clock Whether the clock has been sent.
|
||||||
|
*/
|
||||||
|
void tf_ssb_connection_set_sent_clock(tf_ssb_connection_t* connection, bool sent_clock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Get the JS class ID of the SSB connection class.
|
** Get the JS class ID of the SSB connection class.
|
||||||
** @return The class ID
|
** @return The class ID
|
||||||
@ -1123,22 +1125,4 @@ void tf_ssb_sync_start(tf_ssb_t* ssb);
|
|||||||
*/
|
*/
|
||||||
int tf_ssb_connection_get_flags(tf_ssb_connection_t* connection);
|
int tf_ssb_connection_get_flags(tf_ssb_connection_t* connection);
|
||||||
|
|
||||||
/**
|
|
||||||
** Get a connection's EBT state.
|
|
||||||
** @param connection The connection.
|
|
||||||
** @return the EBT state for the connection.
|
|
||||||
*/
|
|
||||||
tf_ssb_ebt_t* tf_ssb_connection_get_ebt(tf_ssb_connection_t* connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
** Encrypt a private message to a set of recipients.
|
|
||||||
** @param private_key The private key of the author.
|
|
||||||
** @param recipients A list of recipient identities.
|
|
||||||
** @param recipients_count The number of recipients in recipients.
|
|
||||||
** @param message The plain text to post.
|
|
||||||
** @param message_size The length in bytes of message.
|
|
||||||
** @return A secret box string. Free with tf_free().
|
|
||||||
*/
|
|
||||||
char* tf_ssb_private_message_encrypt(uint8_t* private_key, const char** recipients, int recipients_count, const char* message, size_t message_size);
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
228
src/ssb.js.c
228
src/ssb.js.c
@ -251,6 +251,111 @@ static JSValue _tf_ssb_deleteIdentity(JSContext* context, JSValueConst this_val,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue _set_server_following_internal(tf_ssb_t* ssb, JSValueConst this_val, const char* id, bool follow)
|
||||||
|
{
|
||||||
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
|
JSValue message = JS_NewObject(context);
|
||||||
|
JSValue server_user = JS_NewString(context, ":admin");
|
||||||
|
char server_id_buffer[k_id_base64_len] = { 0 };
|
||||||
|
tf_ssb_whoami(ssb, server_id_buffer, sizeof(server_id_buffer));
|
||||||
|
JSValue server_id = JS_NewString(context, server_id_buffer);
|
||||||
|
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "contact"));
|
||||||
|
JS_SetPropertyStr(context, message, "contact", JS_NewString(context, id));
|
||||||
|
JS_SetPropertyStr(context, message, "following", JS_NewBool(context, follow));
|
||||||
|
JSValue args[] = {
|
||||||
|
server_user,
|
||||||
|
server_id,
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
JSValue result = _tf_ssb_appendMessageWithIdentity(context, this_val, tf_countof(args), args);
|
||||||
|
JS_FreeValue(context, server_id);
|
||||||
|
JS_FreeValue(context, server_user);
|
||||||
|
JS_FreeValue(context, message);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct _set_server_following_me_t
|
||||||
|
{
|
||||||
|
const char* user;
|
||||||
|
const char* key;
|
||||||
|
bool follow;
|
||||||
|
JSValue this_val;
|
||||||
|
JSValue promise[2];
|
||||||
|
bool error_does_not_own_key;
|
||||||
|
bool append_message;
|
||||||
|
} set_server_following_me_t;
|
||||||
|
|
||||||
|
static void _tf_ssb_set_server_following_me_work(tf_ssb_t* ssb, void* user_data)
|
||||||
|
{
|
||||||
|
set_server_following_me_t* work = user_data;
|
||||||
|
if (!tf_ssb_db_identity_get_private_key(ssb, work->user, work->key, NULL, 0))
|
||||||
|
{
|
||||||
|
work->error_does_not_own_key = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char server_id[k_id_base64_len] = { 0 };
|
||||||
|
tf_ssb_whoami(ssb, server_id, sizeof(server_id));
|
||||||
|
const char* server_id_ptr = server_id;
|
||||||
|
const char** current_following = tf_ssb_db_following_deep_ids(ssb, &server_id_ptr, 1, 1);
|
||||||
|
bool is_following = false;
|
||||||
|
for (const char** it = current_following; *it; it++)
|
||||||
|
{
|
||||||
|
if (strcmp(work->key, *it) == 0)
|
||||||
|
{
|
||||||
|
is_following = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tf_free(current_following);
|
||||||
|
work->append_message = (work->follow && !is_following) || (!work->follow && is_following);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _tf_ssb_set_server_following_me_after_work(tf_ssb_t* ssb, int status, void* user_data)
|
||||||
|
{
|
||||||
|
set_server_following_me_t* work = user_data;
|
||||||
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
|
JSValue result = JS_UNDEFINED;
|
||||||
|
if (work->error_does_not_own_key)
|
||||||
|
{
|
||||||
|
result = JS_ThrowInternalError(context, "User %s does not own key %s.", work->user, work->key);
|
||||||
|
}
|
||||||
|
else if (work->append_message)
|
||||||
|
{
|
||||||
|
result = _set_server_following_internal(ssb, work->this_val, work->key, work->follow);
|
||||||
|
}
|
||||||
|
JS_FreeCString(context, work->key);
|
||||||
|
JS_FreeCString(context, work->user);
|
||||||
|
JSValue error = JS_Call(context, work->promise[0], JS_UNDEFINED, 1, &result);
|
||||||
|
JS_FreeValue(context, result);
|
||||||
|
tf_util_report_error(context, error);
|
||||||
|
JS_FreeValue(context, error);
|
||||||
|
JS_FreeValue(context, work->promise[0]);
|
||||||
|
JS_FreeValue(context, work->promise[1]);
|
||||||
|
JS_FreeValue(context, work->this_val);
|
||||||
|
tf_free(work);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue _tf_ssb_set_server_following_me(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||||
|
{
|
||||||
|
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||||
|
JSValue result = JS_UNDEFINED;
|
||||||
|
if (ssb)
|
||||||
|
{
|
||||||
|
set_server_following_me_t* work = tf_malloc(sizeof(set_server_following_me_t));
|
||||||
|
*work = (set_server_following_me_t) {
|
||||||
|
.user = JS_ToCString(context, argv[0]),
|
||||||
|
.key = JS_ToCString(context, argv[1]),
|
||||||
|
.follow = JS_ToBool(context, argv[2]),
|
||||||
|
.this_val = JS_DupValue(context, this_val),
|
||||||
|
};
|
||||||
|
result = JS_NewPromiseCapability(context, work->promise);
|
||||||
|
tf_ssb_run_work(ssb, _tf_ssb_set_server_following_me_work, _tf_ssb_set_server_following_me_after_work, work);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct _swap_with_server_identity_t
|
typedef struct _swap_with_server_identity_t
|
||||||
{
|
{
|
||||||
char server_id[k_id_base64_len];
|
char server_id[k_id_base64_len];
|
||||||
@ -1093,7 +1198,7 @@ static JSValue _tf_ssb_closeConnection(JSContext* context, JSValueConst this_val
|
|||||||
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, id);
|
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, id);
|
||||||
if (connection)
|
if (connection)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_close(connection, "Closed by user");
|
tf_ssb_connection_close(connection, "Close requested by user.");
|
||||||
}
|
}
|
||||||
JS_FreeCString(context, id);
|
JS_FreeCString(context, id);
|
||||||
return connection ? JS_TRUE : JS_FALSE;
|
return connection ? JS_TRUE : JS_FALSE;
|
||||||
@ -1390,10 +1495,10 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
uv_mutex_init(&work->lock);
|
uv_mutex_init(&work->lock);
|
||||||
uv_async_init(tf_ssb_get_loop(ssb), &work->async, _tf_ssb_sqlAsync_start_timer);
|
uv_async_init(tf_ssb_get_loop(ssb), &work->async, _tf_ssb_sqlAsync_start_timer);
|
||||||
uv_timer_init(tf_ssb_get_loop(ssb), &work->timeout);
|
uv_timer_init(tf_ssb_get_loop(ssb), &work->timeout);
|
||||||
JSValue result = JS_UNDEFINED;
|
JSValue result = JS_NewPromiseCapability(context, work->promise);
|
||||||
|
JSValue error_value = JS_UNDEFINED;
|
||||||
if (ssb)
|
if (ssb)
|
||||||
{
|
{
|
||||||
result = JS_NewPromiseCapability(context, work->promise);
|
|
||||||
int32_t length = tf_util_get_length(context, argv[1]);
|
int32_t length = tf_util_get_length(context, argv[1]);
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
@ -1436,6 +1541,18 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a
|
|||||||
}
|
}
|
||||||
tf_ssb_run_work(ssb, _tf_ssb_sqlAsync_work, _tf_ssb_sqlAsync_after_work, work);
|
tf_ssb_run_work(ssb, _tf_ssb_sqlAsync_work, _tf_ssb_sqlAsync_after_work, work);
|
||||||
}
|
}
|
||||||
|
if (!JS_IsUndefined(error_value))
|
||||||
|
{
|
||||||
|
JSValue call_result = JS_Call(context, work->promise[1], JS_UNDEFINED, 1, &error_value);
|
||||||
|
tf_util_report_error(context, call_result);
|
||||||
|
JS_FreeValue(context, call_result);
|
||||||
|
JS_FreeValue(context, error_value);
|
||||||
|
JS_FreeCString(context, query);
|
||||||
|
JS_FreeValue(context, work->promise[0]);
|
||||||
|
JS_FreeValue(context, work->promise[1]);
|
||||||
|
JS_FreeValue(context, work->callback);
|
||||||
|
_tf_ssb_sqlAsync_destroy(work);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1857,6 +1974,11 @@ static JSValue _tf_ssb_createTunnel(JSContext* context, JSValueConst this_val, i
|
|||||||
return result ? JS_TRUE : JS_FALSE;
|
return result ? JS_TRUE : JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
k_max_private_message_recipients = 8
|
||||||
|
};
|
||||||
|
|
||||||
static bool _tf_ssb_get_private_key_curve25519_internal(sqlite3* db, const char* user, const char* identity, uint8_t out_private_key[static crypto_sign_SECRETKEYBYTES])
|
static bool _tf_ssb_get_private_key_curve25519_internal(sqlite3* db, const char* user, const char* identity, uint8_t out_private_key[static crypto_sign_SECRETKEYBYTES])
|
||||||
{
|
{
|
||||||
if (!user || !identity)
|
if (!user || !identity)
|
||||||
@ -1905,12 +2027,14 @@ typedef struct _private_message_encrypt_t
|
|||||||
{
|
{
|
||||||
const char* signer_user;
|
const char* signer_user;
|
||||||
const char* signer_identity;
|
const char* signer_identity;
|
||||||
const char* recipients[k_max_private_message_recipients];
|
uint8_t recipients[k_max_private_message_recipients][crypto_scalarmult_curve25519_SCALARBYTES];
|
||||||
int recipient_count;
|
int recipient_count;
|
||||||
const char* message;
|
const char* message;
|
||||||
size_t message_size;
|
size_t message_size;
|
||||||
JSValue promise[2];
|
JSValue promise[2];
|
||||||
bool error_id_not_found;
|
bool error_id_not_found;
|
||||||
|
bool error_secretbox_failed;
|
||||||
|
bool error_scalarmult_failed;
|
||||||
char* encrypted;
|
char* encrypted;
|
||||||
size_t encrypted_length;
|
size_t encrypted_length;
|
||||||
} private_message_encrypt_t;
|
} private_message_encrypt_t;
|
||||||
@ -1926,8 +2050,73 @@ static void _tf_ssb_private_message_encrypt_work(tf_ssb_t* ssb, void* user_data)
|
|||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
work->encrypted = tf_ssb_private_message_encrypt(private_key, work->recipients, work->recipient_count, work->message, work->message_size);
|
uint8_t public_key[crypto_box_PUBLICKEYBYTES] = { 0 };
|
||||||
work->encrypted_length = work->encrypted ? strlen(work->encrypted) : 0;
|
uint8_t secret_key[crypto_box_SECRETKEYBYTES] = { 0 };
|
||||||
|
uint8_t nonce[crypto_box_NONCEBYTES] = { 0 };
|
||||||
|
uint8_t body_key[crypto_box_SECRETKEYBYTES] = { 0 };
|
||||||
|
crypto_box_keypair(public_key, secret_key);
|
||||||
|
randombytes_buf(nonce, sizeof(nonce));
|
||||||
|
randombytes_buf(body_key, sizeof(body_key));
|
||||||
|
|
||||||
|
uint8_t length_and_key[1 + sizeof(body_key)];
|
||||||
|
length_and_key[0] = (uint8_t)work->recipient_count;
|
||||||
|
memcpy(length_and_key + 1, body_key, sizeof(body_key));
|
||||||
|
|
||||||
|
size_t payload_size =
|
||||||
|
sizeof(nonce) + sizeof(public_key) + (crypto_secretbox_MACBYTES + sizeof(length_and_key)) * work->recipient_count + crypto_secretbox_MACBYTES + work->message_size;
|
||||||
|
|
||||||
|
uint8_t* payload = tf_malloc(payload_size);
|
||||||
|
|
||||||
|
uint8_t* p = payload;
|
||||||
|
memcpy(p, nonce, sizeof(nonce));
|
||||||
|
p += sizeof(nonce);
|
||||||
|
|
||||||
|
memcpy(p, public_key, sizeof(public_key));
|
||||||
|
p += sizeof(public_key);
|
||||||
|
|
||||||
|
for (int i = 0; i < work->recipient_count; i++)
|
||||||
|
{
|
||||||
|
uint8_t shared_secret[crypto_secretbox_KEYBYTES] = { 0 };
|
||||||
|
if (crypto_scalarmult(shared_secret, secret_key, work->recipients[i]) == 0)
|
||||||
|
{
|
||||||
|
if (crypto_secretbox_easy(p, length_and_key, sizeof(length_and_key), nonce, shared_secret) != 0)
|
||||||
|
{
|
||||||
|
work->error_secretbox_failed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p += crypto_secretbox_MACBYTES + sizeof(length_and_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
work->error_scalarmult_failed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!work->error_secretbox_failed && !work->error_scalarmult_failed)
|
||||||
|
{
|
||||||
|
if (crypto_secretbox_easy(p, (const uint8_t*)work->message, work->message_size, nonce, body_key) != 0)
|
||||||
|
{
|
||||||
|
work->error_scalarmult_failed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p += crypto_secretbox_MACBYTES + work->message_size;
|
||||||
|
assert((size_t)(p - payload) == payload_size);
|
||||||
|
|
||||||
|
char* encoded = tf_malloc(payload_size * 2 + 5);
|
||||||
|
size_t encoded_length = tf_base64_encode(payload, payload_size, encoded, payload_size * 2 + 5);
|
||||||
|
memcpy(encoded + encoded_length, ".box", 5);
|
||||||
|
encoded_length += 4;
|
||||||
|
|
||||||
|
work->encrypted = encoded;
|
||||||
|
work->encrypted_length = encoded_length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tf_free(payload);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1940,9 +2129,13 @@ static void _tf_ssb_private_message_encrypt_after_work(tf_ssb_t* ssb, int status
|
|||||||
private_message_encrypt_t* work = user_data;
|
private_message_encrypt_t* work = user_data;
|
||||||
JSContext* context = tf_ssb_get_context(ssb);
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
JSValue result = JS_UNDEFINED;
|
JSValue result = JS_UNDEFINED;
|
||||||
if (!work->encrypted)
|
if (work->error_secretbox_failed)
|
||||||
{
|
{
|
||||||
result = JS_ThrowInternalError(context, "Encrypt failed.");
|
result = JS_ThrowInternalError(context, "crypto_secretbox_easy failed");
|
||||||
|
}
|
||||||
|
else if (work->error_scalarmult_failed)
|
||||||
|
{
|
||||||
|
result = JS_ThrowInternalError(context, "crypto_scalarmult failed");
|
||||||
}
|
}
|
||||||
else if (work->error_id_not_found)
|
else if (work->error_id_not_found)
|
||||||
{
|
{
|
||||||
@ -1954,10 +2147,6 @@ static void _tf_ssb_private_message_encrypt_after_work(tf_ssb_t* ssb, int status
|
|||||||
tf_free((void*)work->encrypted);
|
tf_free((void*)work->encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < work->recipient_count; i++)
|
|
||||||
{
|
|
||||||
tf_free((void*)work->recipients[i]);
|
|
||||||
}
|
|
||||||
JSValue error = JS_Call(context, work->promise[0], JS_UNDEFINED, 1, &result);
|
JSValue error = JS_Call(context, work->promise[0], JS_UNDEFINED, 1, &result);
|
||||||
JS_FreeValue(context, result);
|
JS_FreeValue(context, result);
|
||||||
tf_util_report_error(context, error);
|
tf_util_report_error(context, error);
|
||||||
@ -1979,14 +2168,24 @@ static JSValue _tf_ssb_private_message_encrypt(JSContext* context, JSValueConst
|
|||||||
return JS_ThrowRangeError(context, "Number of recipients must be between 1 and %d.", k_max_private_message_recipients);
|
return JS_ThrowRangeError(context, "Number of recipients must be between 1 and %d.", k_max_private_message_recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* recipients[k_max_private_message_recipients] = { 0 };
|
uint8_t recipients[k_max_private_message_recipients][crypto_scalarmult_curve25519_SCALARBYTES] = { 0 };
|
||||||
for (int i = 0; i < recipient_count && JS_IsUndefined(result); i++)
|
for (int i = 0; i < recipient_count && JS_IsUndefined(result); i++)
|
||||||
{
|
{
|
||||||
JSValue recipient = JS_GetPropertyUint32(context, argv[2], i);
|
JSValue recipient = JS_GetPropertyUint32(context, argv[2], i);
|
||||||
const char* id = JS_ToCString(context, recipient);
|
const char* id = JS_ToCString(context, recipient);
|
||||||
if (id)
|
if (id)
|
||||||
{
|
{
|
||||||
recipients[i] = tf_strdup(id);
|
const char* type = strstr(id, ".ed25519");
|
||||||
|
const char* id_start = *id == '@' ? id + 1 : id;
|
||||||
|
uint8_t key[crypto_box_PUBLICKEYBYTES] = { 0 };
|
||||||
|
if (tf_base64_decode(id_start, type ? (size_t)(type - id_start) : strlen(id_start), key, sizeof(key)) != sizeof(key))
|
||||||
|
{
|
||||||
|
result = JS_ThrowInternalError(context, "Invalid recipient: %s.\n", id);
|
||||||
|
}
|
||||||
|
else if (crypto_sign_ed25519_pk_to_curve25519(recipients[i], key) != 0)
|
||||||
|
{
|
||||||
|
result = JS_ThrowInternalError(context, "Failed to convert recipient ID.\n");
|
||||||
|
}
|
||||||
JS_FreeCString(context, id);
|
JS_FreeCString(context, id);
|
||||||
}
|
}
|
||||||
JS_FreeValue(context, recipient);
|
JS_FreeValue(context, recipient);
|
||||||
@ -2375,6 +2574,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
|
|||||||
JS_SetPropertyStr(context, object, "createIdentity", JS_NewCFunction(context, _tf_ssb_createIdentity, "createIdentity", 1));
|
JS_SetPropertyStr(context, object, "createIdentity", JS_NewCFunction(context, _tf_ssb_createIdentity, "createIdentity", 1));
|
||||||
JS_SetPropertyStr(context, object, "addIdentity", JS_NewCFunction(context, _tf_ssb_addIdentity, "addIdentity", 2));
|
JS_SetPropertyStr(context, object, "addIdentity", JS_NewCFunction(context, _tf_ssb_addIdentity, "addIdentity", 2));
|
||||||
JS_SetPropertyStr(context, object, "deleteIdentity", JS_NewCFunction(context, _tf_ssb_deleteIdentity, "deleteIdentity", 2));
|
JS_SetPropertyStr(context, object, "deleteIdentity", JS_NewCFunction(context, _tf_ssb_deleteIdentity, "deleteIdentity", 2));
|
||||||
|
JS_SetPropertyStr(context, object, "setServerFollowingMe", JS_NewCFunction(context, _tf_ssb_set_server_following_me, "setServerFollowingMe", 3));
|
||||||
JS_SetPropertyStr(context, object, "swapWithServerIdentity", JS_NewCFunction(context, _tf_ssb_swap_with_server_identity, "swapWithServerIdentity", 2));
|
JS_SetPropertyStr(context, object, "swapWithServerIdentity", JS_NewCFunction(context, _tf_ssb_swap_with_server_identity, "swapWithServerIdentity", 2));
|
||||||
JS_SetPropertyStr(context, object, "getIdentities", JS_NewCFunction(context, _tf_ssb_getIdentities, "getIdentities", 1));
|
JS_SetPropertyStr(context, object, "getIdentities", JS_NewCFunction(context, _tf_ssb_getIdentities, "getIdentities", 1));
|
||||||
JS_SetPropertyStr(context, object, "getPrivateKey", JS_NewCFunction(context, _tf_ssb_getPrivateKey, "getPrivateKey", 2));
|
JS_SetPropertyStr(context, object, "getPrivateKey", JS_NewCFunction(context, _tf_ssb_getPrivateKey, "getPrivateKey", 2));
|
||||||
|
327
src/ssb.rpc.c
327
src/ssb.rpc.c
@ -3,7 +3,6 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "ssb.db.h"
|
#include "ssb.db.h"
|
||||||
#include "ssb.ebt.h"
|
|
||||||
#include "ssb.h"
|
#include "ssb.h"
|
||||||
#include "util.js.h"
|
#include "util.js.h"
|
||||||
|
|
||||||
@ -20,7 +19,30 @@ static void _tf_ssb_connection_send_history_stream(
|
|||||||
static void _tf_ssb_rpc_send_peers_exchange(tf_ssb_connection_t* connection);
|
static void _tf_ssb_rpc_send_peers_exchange(tf_ssb_connection_t* connection);
|
||||||
static void _tf_ssb_rpc_start_delete_blobs(tf_ssb_t* ssb, int delay_ms);
|
static void _tf_ssb_rpc_start_delete_blobs(tf_ssb_t* ssb, int delay_ms);
|
||||||
static void _tf_ssb_rpc_start_delete_feeds(tf_ssb_t* ssb, int delay_ms);
|
static void _tf_ssb_rpc_start_delete_feeds(tf_ssb_t* ssb, int delay_ms);
|
||||||
static void _tf_ssb_rpc_ebt_replicate_resend_clock(tf_ssb_connection_t* connection, bool skip, void* user_data);
|
|
||||||
|
static bool _get_global_setting_bool(tf_ssb_t* ssb, const char* name, bool default_value)
|
||||||
|
{
|
||||||
|
bool result = default_value;
|
||||||
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
|
sqlite3_stmt* statement;
|
||||||
|
if (sqlite3_prepare(db, "SELECT json_extract(value, '$.' || ?) FROM properties WHERE id = 'core' AND key = 'settings'", -1, &statement, NULL) == SQLITE_OK)
|
||||||
|
{
|
||||||
|
if (sqlite3_bind_text(statement, 1, name, -1, NULL) == SQLITE_OK)
|
||||||
|
{
|
||||||
|
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||||
|
{
|
||||||
|
result = sqlite3_column_int(statement, 0) != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tf_printf("prepare failed: %s\n", sqlite3_errmsg(db));
|
||||||
|
}
|
||||||
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void _tf_ssb_rpc_gossip_ping_callback(
|
static void _tf_ssb_rpc_gossip_ping_callback(
|
||||||
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
||||||
@ -139,9 +161,7 @@ static void _tf_ssb_rpc_blobs_has_work(tf_ssb_connection_t* connection, void* us
|
|||||||
{
|
{
|
||||||
blobs_has_work_t* work = user_data;
|
blobs_has_work_t* work = user_data;
|
||||||
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
work->found = tf_ssb_db_blob_has(ssb, work->id);
|
||||||
work->found = tf_ssb_db_blob_has(db, work->id);
|
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_rpc_blobs_has_after_work(tf_ssb_connection_t* connection, int status, void* user_data)
|
static void _tf_ssb_rpc_blobs_has_after_work(tf_ssb_connection_t* connection, int status, void* user_data)
|
||||||
@ -295,28 +315,8 @@ static void _tf_ssb_rpc_tunnel_callback(tf_ssb_connection_t* connection, uint8_t
|
|||||||
if (flags & k_ssb_rpc_flag_end_error)
|
if (flags & k_ssb_rpc_flag_end_error)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_remove_request(connection, request_number);
|
tf_ssb_connection_remove_request(connection, request_number);
|
||||||
|
|
||||||
JSContext* context = tf_ssb_connection_get_context(connection);
|
|
||||||
JSValue message_val = JS_GetPropertyStr(context, args, "message");
|
|
||||||
JSValue stack_val = JS_GetPropertyStr(context, args, "stack");
|
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
if (!JS_IsUndefined(message_val))
|
snprintf(buffer, sizeof(buffer), "error from tunnel: %.*s", (int)size, message);
|
||||||
{
|
|
||||||
const char* message_string = JS_ToCString(context, message_val);
|
|
||||||
const char* stack_string = JS_ToCString(context, stack_val);
|
|
||||||
snprintf(buffer, sizeof(buffer), "Error from tunnel: %s\n%s", message_string, stack_string);
|
|
||||||
JS_FreeCString(context, message_string);
|
|
||||||
JS_FreeCString(context, stack_string);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(buffer, sizeof(buffer), "Error from tunnel: %.*s", (int)size, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_FreeValue(context, stack_val);
|
|
||||||
JS_FreeValue(context, message_val);
|
|
||||||
|
|
||||||
tf_ssb_connection_close(tun->connection, buffer);
|
tf_ssb_connection_close(tun->connection, buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -879,7 +879,6 @@ static void _tf_ssb_connection_send_history_stream_after_work(tf_ssb_connection_
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tf_ssb_ebt_set_messages_sent(tf_ssb_connection_get_ebt(connection), request->author, request->out_max_sequence_seen);
|
|
||||||
if (!request->out_finished)
|
if (!request->out_finished)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_send_history_stream(
|
_tf_ssb_connection_send_history_stream(
|
||||||
@ -909,7 +908,7 @@ static void _tf_ssb_connection_send_history_stream_callback(tf_ssb_connection_t*
|
|||||||
static void _tf_ssb_connection_send_history_stream(
|
static void _tf_ssb_connection_send_history_stream(
|
||||||
tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live, bool end_request)
|
tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live, bool end_request)
|
||||||
{
|
{
|
||||||
if (tf_ssb_connection_is_connected(connection) && !tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(connection)) && !tf_ssb_connection_is_closing(connection))
|
if (tf_ssb_connection_is_connected(connection) && !tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(connection)))
|
||||||
{
|
{
|
||||||
tf_ssb_connection_send_history_stream_t* async = tf_malloc(sizeof(tf_ssb_connection_send_history_stream_t));
|
tf_ssb_connection_send_history_stream_t* async = tf_malloc(sizeof(tf_ssb_connection_send_history_stream_t));
|
||||||
*async = (tf_ssb_connection_send_history_stream_t) {
|
*async = (tf_ssb_connection_send_history_stream_t) {
|
||||||
@ -968,20 +967,197 @@ static void _tf_ssb_rpc_createHistoryStream(
|
|||||||
JS_FreeValue(context, arg_array);
|
JS_FreeValue(context, arg_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_rpc_ebt_replicate_send_messages(tf_ssb_connection_t* connection)
|
typedef struct _ebt_clock_row_t
|
||||||
{
|
{
|
||||||
tf_ssb_ebt_t* ebt = tf_ssb_connection_get_ebt(connection);
|
char id[k_id_base64_len];
|
||||||
tf_ssb_ebt_clock_t* clock = tf_ssb_ebt_get_messages_to_send(ebt);
|
int64_t value;
|
||||||
if (clock)
|
} ebt_clock_row_t;
|
||||||
|
|
||||||
|
typedef struct _ebt_replicate_send_clock_t
|
||||||
{
|
{
|
||||||
for (int i = 0; i < clock->count; i++)
|
int64_t request_number;
|
||||||
|
ebt_clock_row_t* clock;
|
||||||
|
int clock_count;
|
||||||
|
|
||||||
|
char* out_clock;
|
||||||
|
} ebt_replicate_send_clock_t;
|
||||||
|
|
||||||
|
static void _tf_ssb_rpc_ebt_replicate_send_clock_work(tf_ssb_connection_t* connection, void* user_data)
|
||||||
|
{
|
||||||
|
ebt_replicate_send_clock_t* work = user_data;
|
||||||
|
|
||||||
|
JSMallocFunctions funcs = { 0 };
|
||||||
|
tf_get_js_malloc_functions(&funcs);
|
||||||
|
JSRuntime* runtime = JS_NewRuntime2(&funcs, NULL);
|
||||||
|
JSContext* context = JS_NewContext(runtime);
|
||||||
|
|
||||||
|
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
||||||
|
JSValue full_clock = JS_NewObject(context);
|
||||||
|
|
||||||
|
int64_t depth = 2;
|
||||||
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
|
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &depth);
|
||||||
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
|
|
||||||
|
/* Ask for every identity we know is being followed from local accounts. */
|
||||||
|
const char** visible = tf_ssb_db_get_all_visible_identities(ssb, depth);
|
||||||
|
for (int i = 0; visible[i]; i++)
|
||||||
|
{
|
||||||
|
int64_t sequence = 0;
|
||||||
|
tf_ssb_db_get_latest_message_by_author(ssb, visible[i], &sequence, NULL, 0);
|
||||||
|
JS_SetPropertyStr(context, full_clock, visible[i], JS_NewInt64(context, sequence == -1 ? -1 : (sequence << 1)));
|
||||||
|
}
|
||||||
|
tf_free(visible);
|
||||||
|
|
||||||
|
/* Ask about the incoming connection, too. */
|
||||||
|
char id[k_id_base64_len] = "";
|
||||||
|
if (tf_ssb_connection_get_id(connection, id, sizeof(id)))
|
||||||
|
{
|
||||||
|
JSValue in_clock = JS_GetPropertyStr(context, full_clock, id);
|
||||||
|
if (JS_IsUndefined(in_clock))
|
||||||
|
{
|
||||||
|
int64_t sequence = 0;
|
||||||
|
tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0);
|
||||||
|
JS_SetPropertyStr(context, full_clock, id, JS_NewInt64(context, sequence == -1 ? -1 : (sequence << 1)));
|
||||||
|
}
|
||||||
|
JS_FreeValue(context, in_clock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Also respond with what we know about all requested identities. */
|
||||||
|
for (int i = 0; i < work->clock_count; i++)
|
||||||
|
{
|
||||||
|
JSValue in_clock = JS_GetPropertyStr(context, full_clock, work->clock[i].id);
|
||||||
|
if (JS_IsUndefined(in_clock))
|
||||||
|
{
|
||||||
|
int64_t sequence = -1;
|
||||||
|
tf_ssb_db_get_latest_message_by_author(ssb, work->clock[i].id, &sequence, NULL, 0);
|
||||||
|
JS_SetPropertyStr(context, full_clock, work->clock[i].id, JS_NewInt64(context, sequence == -1 ? -1 : (sequence << 1)));
|
||||||
|
}
|
||||||
|
JS_FreeValue(context, in_clock);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSValue json = JS_JSONStringify(context, full_clock, JS_NULL, JS_NULL);
|
||||||
|
size_t size = 0;
|
||||||
|
const char* string = JS_ToCStringLen(context, &size, json);
|
||||||
|
char* copy = tf_malloc(size + 1);
|
||||||
|
memcpy(copy, string, size + 1);
|
||||||
|
work->out_clock = copy;
|
||||||
|
JS_FreeCString(context, string);
|
||||||
|
JS_FreeValue(context, json);
|
||||||
|
JS_FreeValue(context, full_clock);
|
||||||
|
|
||||||
|
JS_FreeContext(context);
|
||||||
|
JS_FreeRuntime(runtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _tf_ssb_rpc_ebt_replicate_send_clock_after_work(tf_ssb_connection_t* connection, int result, void* user_data)
|
||||||
|
{
|
||||||
|
ebt_replicate_send_clock_t* work = user_data;
|
||||||
|
tf_free(work->clock);
|
||||||
|
if (work->out_clock)
|
||||||
|
{
|
||||||
|
tf_ssb_connection_rpc_send(
|
||||||
|
connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, -work->request_number, NULL, (const uint8_t*)work->out_clock, strlen(work->out_clock), NULL, NULL, NULL);
|
||||||
|
tf_free(work->out_clock);
|
||||||
|
}
|
||||||
|
tf_free(work);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _tf_ssb_rpc_ebt_replicate_send_clock(tf_ssb_connection_t* connection, int32_t request_number, JSValue message)
|
||||||
|
{
|
||||||
|
ebt_replicate_send_clock_t* work = tf_malloc(sizeof(ebt_replicate_send_clock_t));
|
||||||
|
*work = (ebt_replicate_send_clock_t) {
|
||||||
|
.request_number = request_number,
|
||||||
|
};
|
||||||
|
JSContext* context = tf_ssb_connection_get_context(connection);
|
||||||
|
|
||||||
|
if (!JS_IsUndefined(message))
|
||||||
|
{
|
||||||
|
JSPropertyEnum* ptab = NULL;
|
||||||
|
uint32_t plen = 0;
|
||||||
|
if (JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK) == 0)
|
||||||
|
{
|
||||||
|
work->clock_count = (int)plen;
|
||||||
|
work->clock = tf_malloc(sizeof(ebt_clock_row_t) * plen);
|
||||||
|
memset(work->clock, 0, sizeof(ebt_clock_row_t) * plen);
|
||||||
|
for (uint32_t i = 0; i < plen; ++i)
|
||||||
|
{
|
||||||
|
const char* id = JS_AtomToCString(context, ptab[i].atom);
|
||||||
|
snprintf(work->clock[i].id, sizeof(work->clock[i].id), "%s", id);
|
||||||
|
JS_FreeCString(context, id);
|
||||||
|
|
||||||
|
JSPropertyDescriptor desc = { 0 };
|
||||||
|
JSValue key_value = JS_UNDEFINED;
|
||||||
|
if (JS_GetOwnProperty(context, &desc, message, ptab[i].atom) == 1)
|
||||||
|
{
|
||||||
|
key_value = desc.value;
|
||||||
|
JS_FreeValue(context, desc.setter);
|
||||||
|
JS_FreeValue(context, desc.getter);
|
||||||
|
}
|
||||||
|
JS_ToInt64(context, &work->clock[i].value, key_value);
|
||||||
|
JS_FreeValue(context, key_value);
|
||||||
|
JS_FreeAtom(context, ptab[i].atom);
|
||||||
|
}
|
||||||
|
js_free(context, ptab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tf_ssb_connection_run_work(connection, _tf_ssb_rpc_ebt_replicate_send_clock_work, _tf_ssb_rpc_ebt_replicate_send_clock_after_work, work);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _tf_ssb_rpc_ebt_replicate_send_messages(tf_ssb_connection_t* connection, JSValue message)
|
||||||
|
{
|
||||||
|
if (JS_IsUndefined(message))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
||||||
|
JSContext* context = tf_ssb_get_context(ssb);
|
||||||
|
JSPropertyEnum* ptab = NULL;
|
||||||
|
uint32_t plen = 0;
|
||||||
|
if (JS_GetOwnPropertyNames(context, &ptab, &plen, message, JS_GPN_STRING_MASK) == 0)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < plen; ++i)
|
||||||
|
{
|
||||||
|
JSValue in_clock = JS_UNDEFINED;
|
||||||
|
JSPropertyDescriptor desc = { 0 };
|
||||||
|
if (JS_GetOwnProperty(context, &desc, message, ptab[i].atom) == 1)
|
||||||
|
{
|
||||||
|
in_clock = desc.value;
|
||||||
|
JS_FreeValue(context, desc.setter);
|
||||||
|
JS_FreeValue(context, desc.getter);
|
||||||
|
}
|
||||||
|
if (!JS_IsUndefined(in_clock))
|
||||||
|
{
|
||||||
|
JSValue key = JS_AtomToString(context, ptab[i].atom);
|
||||||
|
int64_t sequence = -1;
|
||||||
|
JS_ToInt64(context, &sequence, in_clock);
|
||||||
|
const char* author = JS_ToCString(context, key);
|
||||||
|
if (sequence >= 0 && (sequence & 1) == 0)
|
||||||
{
|
{
|
||||||
tf_ssb_ebt_clock_entry_t* entry = &clock->entries[i];
|
|
||||||
int32_t request_number = tf_ssb_connection_get_ebt_request_number(connection);
|
int32_t request_number = tf_ssb_connection_get_ebt_request_number(connection);
|
||||||
bool live = (tf_ssb_connection_get_flags(connection) & k_tf_ssb_connect_flag_one_shot) == 0;
|
bool live = (tf_ssb_connection_get_flags(connection) & k_tf_ssb_connect_flag_one_shot) == 0;
|
||||||
_tf_ssb_connection_send_history_stream(connection, request_number, entry->id, entry->value, false, live, false);
|
_tf_ssb_connection_send_history_stream(connection, request_number, author, sequence >> 1, false, live, false);
|
||||||
|
if (live)
|
||||||
|
{
|
||||||
|
tf_ssb_connection_add_new_message_request(connection, author, request_number, false);
|
||||||
}
|
}
|
||||||
tf_free(clock);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tf_ssb_connection_remove_new_message_request(connection, author);
|
||||||
|
}
|
||||||
|
JS_FreeCString(context, author);
|
||||||
|
JS_FreeValue(context, key);
|
||||||
|
}
|
||||||
|
JS_FreeValue(context, in_clock);
|
||||||
|
}
|
||||||
|
for (uint32_t i = 0; i < plen; ++i)
|
||||||
|
{
|
||||||
|
JS_FreeAtom(context, ptab[i].atom);
|
||||||
|
}
|
||||||
|
js_free(context, ptab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,54 +1171,17 @@ typedef struct _resend_clock_t
|
|||||||
{
|
{
|
||||||
tf_ssb_connection_t* connection;
|
tf_ssb_connection_t* connection;
|
||||||
int32_t request_number;
|
int32_t request_number;
|
||||||
int pending;
|
|
||||||
} resend_clock_t;
|
} resend_clock_t;
|
||||||
|
|
||||||
static void _tf_ssb_rpc_ebt_send_clock_callback(const tf_ssb_ebt_clock_t* clock, int32_t request_number, void* user_data)
|
|
||||||
{
|
|
||||||
resend_clock_t* resend = user_data;
|
|
||||||
tf_ssb_connection_t* connection = resend->connection;
|
|
||||||
|
|
||||||
if (clock && clock->count)
|
|
||||||
{
|
|
||||||
JSContext* context = tf_ssb_connection_get_context(connection);
|
|
||||||
JSValue message = JS_NewObject(context);
|
|
||||||
for (int i = 0; i < clock->count; i++)
|
|
||||||
{
|
|
||||||
JS_SetPropertyStr(context, message, clock->entries[i].id, JS_NewInt64(context, clock->entries[i].value));
|
|
||||||
}
|
|
||||||
tf_ssb_connection_rpc_send_json(connection, k_ssb_rpc_flag_stream | k_ssb_rpc_flag_json, -request_number, NULL, message, NULL, NULL, NULL);
|
|
||||||
JS_FreeValue(context, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
tf_ssb_ebt_t* ebt = tf_ssb_connection_get_ebt(connection);
|
|
||||||
if (resend->pending != tf_ssb_ebt_get_send_clock_pending(ebt) && tf_ssb_connection_is_connected(connection) &&
|
|
||||||
!tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(connection)) && !tf_ssb_connection_is_closing(connection))
|
|
||||||
{
|
|
||||||
resend->pending = tf_ssb_ebt_get_send_clock_pending(ebt);
|
|
||||||
tf_ssb_connection_schedule_idle(connection, "ebt.clock", _tf_ssb_rpc_ebt_replicate_resend_clock, resend);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tf_ssb_ebt_set_send_clock_pending(ebt, 0);
|
|
||||||
tf_free(resend);
|
|
||||||
}
|
|
||||||
|
|
||||||
_tf_ssb_rpc_ebt_replicate_send_messages(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _tf_ssb_rpc_ebt_replicate_resend_clock(tf_ssb_connection_t* connection, bool skip, void* user_data)
|
static void _tf_ssb_rpc_ebt_replicate_resend_clock(tf_ssb_connection_t* connection, bool skip, void* user_data)
|
||||||
{
|
{
|
||||||
resend_clock_t* resend = user_data;
|
resend_clock_t* resend = user_data;
|
||||||
if (!skip)
|
if (!skip)
|
||||||
{
|
{
|
||||||
tf_ssb_ebt_t* ebt = tf_ssb_connection_get_ebt(connection);
|
_tf_ssb_rpc_ebt_replicate_send_clock(resend->connection, resend->request_number, JS_UNDEFINED);
|
||||||
tf_ssb_ebt_get_send_clock(ebt, resend->request_number, _tf_ssb_rpc_ebt_send_clock_callback, resend);
|
tf_ssb_connection_set_sent_clock(resend->connection, true);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tf_free(resend);
|
|
||||||
}
|
}
|
||||||
|
tf_free(user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data)
|
||||||
@ -1065,38 +1204,33 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f
|
|||||||
JSValue name = JS_GetPropertyStr(context, args, "name");
|
JSValue name = JS_GetPropertyStr(context, args, "name");
|
||||||
JSValue in_clock = JS_IsUndefined(name) ? args : JS_UNDEFINED;
|
JSValue in_clock = JS_IsUndefined(name) ? args : JS_UNDEFINED;
|
||||||
|
|
||||||
bool resend_clock = false;
|
|
||||||
|
|
||||||
tf_ssb_ebt_t* ebt = tf_ssb_connection_get_ebt(connection);
|
|
||||||
if (!JS_IsUndefined(author))
|
if (!JS_IsUndefined(author))
|
||||||
{
|
{
|
||||||
/* Looks like a message. */
|
/* Looks like a message. */
|
||||||
tf_ssb_connection_adjust_read_backpressure(connection, 1);
|
tf_ssb_connection_adjust_read_backpressure(connection, 1);
|
||||||
tf_ssb_verify_strip_and_store_message(ssb, args, _tf_ssb_rpc_ebt_replicate_store_callback, connection);
|
tf_ssb_verify_strip_and_store_message(ssb, args, _tf_ssb_rpc_ebt_replicate_store_callback, connection);
|
||||||
|
|
||||||
resend_clock = !tf_ssb_is_shutting_down(ssb) && !tf_ssb_connection_is_closing(connection);
|
if (tf_ssb_connection_get_sent_clock(connection) && !tf_ssb_is_shutting_down(ssb))
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tf_ssb_ebt_receive_clock(ebt, context, in_clock);
|
|
||||||
resend_clock = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resend_clock && tf_ssb_connection_is_connected(connection) && !tf_ssb_is_shutting_down(tf_ssb_connection_get_ssb(connection)) && !tf_ssb_connection_is_closing(connection))
|
|
||||||
{
|
|
||||||
int pending = tf_ssb_ebt_get_send_clock_pending(ebt) + 1;
|
|
||||||
tf_ssb_ebt_set_send_clock_pending(ebt, pending);
|
|
||||||
if (pending == 1)
|
|
||||||
{
|
{
|
||||||
|
tf_ssb_connection_set_sent_clock(connection, false);
|
||||||
resend_clock_t* resend = tf_malloc(sizeof(resend_clock_t));
|
resend_clock_t* resend = tf_malloc(sizeof(resend_clock_t));
|
||||||
*resend = (resend_clock_t) {
|
*resend = (resend_clock_t) {
|
||||||
.connection = connection,
|
.connection = connection,
|
||||||
.request_number = request_number,
|
.request_number = request_number,
|
||||||
.pending = pending,
|
|
||||||
};
|
};
|
||||||
tf_ssb_connection_schedule_idle(connection, "ebt.clock", _tf_ssb_rpc_ebt_replicate_resend_clock, resend);
|
tf_ssb_connection_schedule_idle(connection, "ebt.clock", _tf_ssb_rpc_ebt_replicate_resend_clock, resend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* EBT clock. */
|
||||||
|
if (!tf_ssb_connection_get_sent_clock(connection))
|
||||||
|
{
|
||||||
|
_tf_ssb_rpc_ebt_replicate_send_clock(connection, request_number, in_clock);
|
||||||
|
tf_ssb_connection_set_sent_clock(connection, true);
|
||||||
|
}
|
||||||
|
_tf_ssb_rpc_ebt_replicate_send_messages(connection, in_clock);
|
||||||
|
}
|
||||||
JS_FreeValue(context, name);
|
JS_FreeValue(context, name);
|
||||||
JS_FreeValue(context, author);
|
JS_FreeValue(context, author);
|
||||||
}
|
}
|
||||||
@ -1335,16 +1469,13 @@ static void _tf_ssb_rpc_start_delete_blobs(tf_ssb_t* ssb, int delay_ms)
|
|||||||
static void _tf_ssb_rpc_delete_feeds_work(tf_ssb_t* ssb, void* user_data)
|
static void _tf_ssb_rpc_delete_feeds_work(tf_ssb_t* ssb, void* user_data)
|
||||||
{
|
{
|
||||||
delete_t* delete = user_data;
|
delete_t* delete = user_data;
|
||||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
if (!_get_global_setting_bool(ssb, "delete_stale_feeds", false))
|
||||||
bool delete_stale_feeds = false;
|
|
||||||
tf_ssb_db_get_global_setting_bool(db, "delete_stale_feeds", &delete_stale_feeds);
|
|
||||||
if (!delete_stale_feeds)
|
|
||||||
{
|
{
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int64_t start_ns = uv_hrtime();
|
int64_t start_ns = uv_hrtime();
|
||||||
int64_t replication_hops = 2;
|
int64_t replication_hops = 2;
|
||||||
|
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||||
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &replication_hops);
|
tf_ssb_db_get_global_setting_int64(db, "replication_hops", &replication_hops);
|
||||||
tf_ssb_release_db_reader(ssb, db);
|
tf_ssb_release_db_reader(ssb, db);
|
||||||
const char** identities = tf_ssb_db_get_all_visible_identities(ssb, replication_hops);
|
const char** identities = tf_ssb_db_get_all_visible_identities(ssb, replication_hops);
|
||||||
|
@ -339,7 +339,7 @@ static JSValue _util_defaultGlobalSettings(JSContext* context, JSValueConst this
|
|||||||
.default_value = _is_mobile() ? JS_NewInt32(context, (int)(1.0f * 365 * 24 * 60 * 60)) : JS_UNDEFINED },
|
.default_value = _is_mobile() ? JS_NewInt32(context, (int)(1.0f * 365 * 24 * 60 * 60)) : JS_UNDEFINED },
|
||||||
{ .name = "fetch_hosts", .type = "string", .description = "Comma-separated list of host names to which HTTP fetch requests are allowed. None if empty." },
|
{ .name = "fetch_hosts", .type = "string", .description = "Comma-separated list of host names to which HTTP fetch requests are allowed. None if empty." },
|
||||||
{ .name = "http_redirect", .type = "string", .description = "If connecting by HTTP and HTTPS is configured, Location header prefix (ie, \"http://example.com\")" },
|
{ .name = "http_redirect", .type = "string", .description = "If connecting by HTTP and HTTPS is configured, Location header prefix (ie, \"http://example.com\")" },
|
||||||
{ .name = "index", .type = "string", .description = "Default path.", .default_value = JS_NewString(context, "/~core/ssb/") },
|
{ .name = "index", .type = "string", .description = "Default path.", .default_value = JS_NewString(context, "/~core/apps") },
|
||||||
{ .name = "index_map", .type = "textarea", .description = "Mappings from hostname to redirect path, one per line, as in: \"www.tildefriends.net=/~core/index/\"" },
|
{ .name = "index_map", .type = "textarea", .description = "Mappings from hostname to redirect path, one per line, as in: \"www.tildefriends.net=/~core/index/\"" },
|
||||||
{ .name = "peer_exchange",
|
{ .name = "peer_exchange",
|
||||||
.type = "boolean",
|
.type = "boolean",
|
||||||
@ -356,7 +356,7 @@ static JSValue _util_defaultGlobalSettings(JSContext* context, JSValueConst this
|
|||||||
.default_value = JS_NewInt32(context, 2) },
|
.default_value = JS_NewInt32(context, 2) },
|
||||||
{ .name = "delete_stale_feeds",
|
{ .name = "delete_stale_feeds",
|
||||||
.type = "boolean",
|
.type = "boolean",
|
||||||
.description = "Periodically delete feeds that aren't visible from local accounts or related follows.",
|
.description = "Periodically delete feeds that visible from local accounts and related follows.",
|
||||||
.default_value = JS_FALSE },
|
.default_value = JS_FALSE },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,19 +150,6 @@ const char* tf_util_function_to_string(void* function);
|
|||||||
_a > _b ? _b : _a; \
|
_a > _b ? _b : _a; \
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
** Get the maximum of two values.
|
|
||||||
** @param a The first value.
|
|
||||||
** @param b The second value.
|
|
||||||
** @return The maximum of a and b.
|
|
||||||
*/
|
|
||||||
#define tf_max(a, b) \
|
|
||||||
({ \
|
|
||||||
__typeof__(a) _a = (a); \
|
|
||||||
__typeof__(b) _b = (b); \
|
|
||||||
_a > _b ? _a : _b; \
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Get the number of elements in an array.
|
** Get the number of elements in an array.
|
||||||
** @param a The array.
|
** @param a The array.
|
||||||
|
@ -71,7 +71,7 @@ try:
|
|||||||
driver = webdriver.Firefox(options = options, service = service)
|
driver = webdriver.Firefox(options = options, service = service)
|
||||||
wait = WebDriverWait(driver, 10)
|
wait = WebDriverWait(driver, 10)
|
||||||
|
|
||||||
driver.get('http://localhost:8888/~core/apps/')
|
driver.get('http://localhost:8888')
|
||||||
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
||||||
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
||||||
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'adminuser'))
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'adminuser'))
|
||||||
@ -89,7 +89,7 @@ try:
|
|||||||
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '#identity'], ('click',))
|
||||||
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '#logout'], ('click',))
|
||||||
|
|
||||||
driver.get('http://localhost:8888/~core/apps/')
|
driver.get('http://localhost:8888')
|
||||||
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '=login'], ('click',))
|
||||||
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
select(driver, ['tf-auth', 'shadow_root', '#register_label'], ('click',))
|
||||||
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
select(driver, ['tf-auth', 'shadow_root', '#name'], ('send_keys', 'testuser'))
|
||||||
@ -140,7 +140,7 @@ try:
|
|||||||
select(driver, ['tf-navigation', 'shadow_root', '#close_error'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '#close_error'], ('click',))
|
||||||
select(driver, ['tf-navigation', 'shadow_root', '=edit'], ('click',))
|
select(driver, ['tf-navigation', 'shadow_root', '=edit'], ('click',))
|
||||||
|
|
||||||
driver.get('http://localhost:8888/~core/apps/')
|
driver.get('http://localhost:8888')
|
||||||
|
|
||||||
select(driver, ['#document', 'frame', '=identity'])
|
select(driver, ['#document', 'frame', '=identity'])
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ try:
|
|||||||
id1 = select(driver, ['#document', 'frame', 'li']).text.split(' ')[-1]
|
id1 = select(driver, ['#document', 'frame', 'li']).text.split(' ')[-1]
|
||||||
assert id0 == id1
|
assert id0 == id1
|
||||||
|
|
||||||
driver.get('http://localhost:8888/~core/apps/')
|
driver.get('http://localhost:8888')
|
||||||
select(driver, ['#document', 'frame', '=ssb'], ('click',))
|
select(driver, ['#document', 'frame', '=ssb'], ('click',))
|
||||||
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#edit'], ('send_keys', 'Hello, world!'))
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#edit'], ('send_keys', 'Hello, world!'))
|
||||||
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#submit'], ('click',))
|
select(driver, ['#document', 'frame', 'tf-app', 'shadow_root', '#tf-tab-news', 'shadow_root', '#tf-compose', 'shadow_root', '#submit'], ('click',))
|
||||||
|
@ -12,7 +12,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf $WORK_DIR
|
rm -rf $WORK_DIR
|
||||||
mkdir -p out/
|
|
||||||
cp -aRf deps/openssl_src/ $WORK_DIR
|
cp -aRf deps/openssl_src/ $WORK_DIR
|
||||||
|
|
||||||
echo "Building"
|
echo "Building"
|
||||||
@ -74,7 +73,6 @@ no-weak-ssl-ciphers
|
|||||||
no-zlib
|
no-zlib
|
||||||
-Os
|
-Os
|
||||||
-DOPENSSL_SMALL_FOOTPRINT
|
-DOPENSSL_SMALL_FOOTPRINT
|
||||||
-Wno-error
|
|
||||||
-ffunction-sections
|
-ffunction-sections
|
||||||
-fdata-sections"
|
-fdata-sections"
|
||||||
pwd
|
pwd
|
||||||
|
Loading…
x
Reference in New Issue
Block a user