forked from cory/tildefriends
Compare commits
1 Commits
tasiaiso-d
...
tasiaiso-s
Author | SHA1 | Date | |
---|---|---|---|
0b4ac2b355
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
name: 'Bug Report'
|
||||
---
|
@ -1,5 +0,0 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Documentation
|
||||
url: https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/index.md
|
||||
about: Read the documentation
|
@ -1,3 +0,0 @@
|
||||
---
|
||||
name: 'Feature Request'
|
||||
---
|
@ -1,9 +0,0 @@
|
||||
To Do List
|
||||
|
||||
- [ ] My changes are documented in the [documentation](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/index.md)
|
||||
- [ ] I have tested my changes
|
||||
- [ ] I agree to the contribution guidelines
|
||||
- [ ] [C](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/guidelines/c-guidelines.md)
|
||||
- [ ] [JavaScript](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/guidelines/javascript-guidelines.md)
|
||||
- [ ] [documentation](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/guidelines/documentation-guidelines.md)
|
||||
<!-- - [ ] I agree to the [Code of Conduct]() -->
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,5 +8,4 @@ out
|
||||
*.swo
|
||||
*.swp
|
||||
.zsign_cache/
|
||||
result
|
||||
NOTES.md
|
||||
|
@ -2,4 +2,4 @@ default: true
|
||||
MD010: false # Ignore tabs in code blocks
|
||||
MD013: false # Don't wrap lines by default
|
||||
MD046:
|
||||
style: 'fenced' # Force fenced code blocks
|
||||
style: "fenced" # Force fenced code blocks
|
||||
|
@ -2,7 +2,6 @@ node_modules
|
||||
src
|
||||
deps
|
||||
.clang-format
|
||||
flake.lock
|
||||
|
||||
# Minified files
|
||||
**/*.min.css
|
||||
|
@ -616,7 +616,7 @@ $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \
|
||||
|
||||
unix: debug release
|
||||
win: windebug winrelease
|
||||
all: $(BUILD_TYPES) default.nix
|
||||
all: $(BUILD_TYPES)
|
||||
.PHONY: all win unix
|
||||
|
||||
ALL_APP_OBJS := \
|
||||
@ -673,10 +673,6 @@ src/android/AndroidManifest.xml : $(firstword $(MAKEFILE_LIST))
|
||||
-e 's/android:targetSdkVersion="[[:digit:]]*"/android:targetSdkVersion="$(ANDROID_TARGET_SDK_VERSION)"/' \
|
||||
$@
|
||||
|
||||
default.nix : $(firstword $(MAKEFILE_LIST))
|
||||
@echo "[version] $@"
|
||||
@sed -i -e 's/version = ".*";/version = "$(VERSION_NUMBER)";/' $@
|
||||
|
||||
# Android support.
|
||||
out/res/layout_activity_main.xml.flat: src/android/res/layout/activity_main.xml
|
||||
@mkdir -p $(dir $@)
|
||||
@ -862,7 +858,7 @@ clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
.PHONY: clean
|
||||
|
||||
dist: release-apk iosrelease-ipa $(if $(HAVE_WIN), out/winrelease/tildefriends.standalone.exe) default.nix
|
||||
dist: release-apk iosrelease-ipa $(if $(HAVE_WIN), out/winrelease/tildefriends.standalone.exe)
|
||||
@echo [archive] dist/tildefriends-$(VERSION_NUMBER).tar.xz
|
||||
@rm -rf out/tildefriends-$(VERSION_NUMBER)
|
||||
@mkdir -p dist/ out/tildefriends-$(VERSION_NUMBER)
|
||||
|
@ -14,7 +14,7 @@ It is both a peer-to-peer social network client, participating in Secure Scuttle
|
||||
|
||||
## Documentation
|
||||
|
||||
Docs are a work in progress: [documentation](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/index.md), or alternatively in Tilde Friends: <https://www.tildefriends.net/~cory/wiki/#test-wiki/tf-app-quick-reference>.
|
||||
Docs are a work in progress in the `docs` folder, or alternatively in Tilde Friends: <https://www.tildefriends.net/~cory/wiki/#test-wiki/tf-app-quick-reference>.
|
||||
|
||||
## License
|
||||
|
||||
|
@ -4,8 +4,7 @@
|
||||
<script>
|
||||
const g_data = $data;
|
||||
</script>
|
||||
<link rel="stylesheet" href="w3.css" />
|
||||
<!-- prettier-ignore -->
|
||||
<link rel="stylesheet" href="w3.css"></link>
|
||||
<style>
|
||||
/* 2018 Valiant Poppy */
|
||||
.w3-theme-l5 {color:#000 !important; background-color:#fbf3f3 !important}
|
||||
|
@ -42,27 +42,10 @@ window.addEventListener('load', function () {
|
||||
} else if (description.type === 'textarea') {
|
||||
return html`
|
||||
<li class="w3-row">
|
||||
<label class="w3-quarter" for=${'gs_' + key} style="font-weight: bold"
|
||||
>${key}</label
|
||||
>
|
||||
<label class="w3-quarter" for=${'gs_' + key} style="font-weight: bold">${key}</label>
|
||||
<div class="w3-rest w3-padding">${description.description}</div>
|
||||
<textarea
|
||||
class="w3-input"
|
||||
style="vertical-align: top; resize: vertical"
|
||||
id=${'gs_' + key}
|
||||
>
|
||||
${description.value}</textarea
|
||||
>
|
||||
<button
|
||||
class="w3-button w3-right w3-quarter w3-theme-action"
|
||||
@click=${(e) =>
|
||||
global_settings_set(
|
||||
key,
|
||||
e.srcElement.previousElementSibling.value
|
||||
)}
|
||||
>
|
||||
Set
|
||||
</button>
|
||||
<textarea class="w3-input" style="vertical-align: top; resize: vertical" id=${'gs_' + key}>${description.value}</textarea>
|
||||
<button class="w3-button w3-right w3-quarter w3-theme-action" @click=${(e) => global_settings_set(key, e.srcElement.previousElementSibling.value)}>Set</button>
|
||||
</li>
|
||||
`;
|
||||
} else {
|
||||
@ -78,17 +61,13 @@ ${description.value}</textarea
|
||||
}
|
||||
const user_template = (user, permissions) => html`
|
||||
<li class="w3-card w3-margin">
|
||||
<button
|
||||
class="w3-button w3-theme-action"
|
||||
@click=${(e) => delete_user(user)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
<button class="w3-button w3-theme-action" @click=${(e) => delete_user(user)}>Delete</button>
|
||||
${user}: ${permissions.map((x) => permission_template(x))}
|
||||
</li>
|
||||
`;
|
||||
const users_template = (users) =>
|
||||
html` <header class="w3-container w3-theme-l2"><h2>Users</h2></header>
|
||||
html`
|
||||
<header class="w3-container w3-theme-l2"><h2>Users</h2></header>
|
||||
<ul class="w3-ul">
|
||||
${Object.entries(users).map((u) => user_template(u[0], u[1]))}
|
||||
</ul>`;
|
||||
|
@ -78,7 +78,7 @@ async function main() {
|
||||
alert('Successfully created: ' + id);
|
||||
await tfrpc.rpc.reload();
|
||||
} catch (e) {
|
||||
alert('Error creating identity: ' + e.message);
|
||||
alert('Error creating identity: ' + e);
|
||||
}
|
||||
}
|
||||
handler.hide_id = function hide_id(event, element) {
|
||||
@ -116,18 +116,16 @@ async function main() {
|
||||
<div class="w3-card-4 w3-margin">
|
||||
<header class="w3-container w3-theme-l2"><h2>Identities</h2></header>
|
||||
<ul class="w3-ul">` +
|
||||
ids
|
||||
.map(
|
||||
(
|
||||
id
|
||||
) => `<li style="overflow: hidden; text-wrap: nowrap; text-overflow: ellipsis">
|
||||
ids
|
||||
.map(
|
||||
(id) => `<li style="overflow: hidden; text-wrap: nowrap; text-overflow: ellipsis">
|
||||
<button onclick="handler.export_id(event)" data-id="${id}" class="w3-button w3-theme">Export Identity</button>
|
||||
<button onclick="handler.delete_id(event)" data-id="${id}" class="w3-button w3-theme">Delete Identity</button>
|
||||
${id}
|
||||
</li>`
|
||||
)
|
||||
.join('\n') +
|
||||
` </ul>
|
||||
)
|
||||
.join('\n') +
|
||||
` </ul>
|
||||
</div>
|
||||
</body>`
|
||||
);
|
||||
|
@ -67,6 +67,9 @@ tfrpc.register(function getHash(id, message) {
|
||||
tfrpc.register(function setHash(hash) {
|
||||
return app.setHash(hash);
|
||||
});
|
||||
ssb.addEventListener('message', async function (id) {
|
||||
await tfrpc.rpc.notifyNewMessage(id);
|
||||
});
|
||||
tfrpc.register(async function store_blob(blob) {
|
||||
if (Array.isArray(blob)) {
|
||||
blob = Uint8Array.from(blob);
|
||||
@ -88,12 +91,10 @@ tfrpc.register(function getActiveIdentity() {
|
||||
tfrpc.register(async function try_decrypt(id, content) {
|
||||
return await ssb.privateMessageDecrypt(id, content);
|
||||
});
|
||||
core.register('onMessage', async function (id) {
|
||||
await tfrpc.rpc.notifyNewMessage(id);
|
||||
});
|
||||
core.register('onBroadcastsChanged', async function () {
|
||||
ssb.addEventListener('broadcasts', async function () {
|
||||
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
||||
});
|
||||
|
||||
core.register('onConnectionsChanged', async function () {
|
||||
await tfrpc.rpc.set('connections', await ssb.connections());
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ function new_message() {
|
||||
return g_new_message_promise;
|
||||
}
|
||||
|
||||
core.register('onMessage', function (id) {
|
||||
ssb.addEventListener('message', function (id) {
|
||||
let resolve = g_new_message_resolve;
|
||||
g_new_message_promise = new Promise(function (resolve, reject) {
|
||||
g_new_message_resolve = resolve;
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"type": "tildefriends-app",
|
||||
"emoji": "🐌",
|
||||
"previous": "&h0sTvkhc3zEJw/sH612fy5i554Gr1AKzCBbLkm0KH28=.sha256"
|
||||
"previous": "&vEaOZjrNb0u9rhNqrQ8eU9TlOFlo4HsgW6hbI7VdIT0=.sha256"
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ tfrpc.register(function getHash(id, message) {
|
||||
tfrpc.register(function setHash(hash) {
|
||||
return app.setHash(hash);
|
||||
});
|
||||
core.register('onMessage', async function (id) {
|
||||
ssb.addEventListener('message', async function (id) {
|
||||
await tfrpc.rpc.notifyNewMessage(id);
|
||||
});
|
||||
tfrpc.register(async function store_blob(blob) {
|
||||
@ -103,7 +103,7 @@ tfrpc.register(async function encrypt(id, recipients, content) {
|
||||
tfrpc.register(async function getActiveIdentity() {
|
||||
return await ssb.getActiveIdentity();
|
||||
});
|
||||
core.register('onBroadcastsChanged', async function () {
|
||||
ssb.addEventListener('broadcasts', async function () {
|
||||
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
||||
});
|
||||
|
||||
|
@ -264,7 +264,6 @@ class TfElement extends LitElement {
|
||||
hash=${this.hash}
|
||||
.unread=${this.unread}
|
||||
@refresh=${() => (this.unread = [])}
|
||||
?loading=${this.loading}
|
||||
></tf-tab-news>
|
||||
`;
|
||||
} else if (this.tab === 'connections') {
|
||||
@ -340,20 +339,26 @@ class TfElement extends LitElement {
|
||||
};
|
||||
|
||||
let tabs = html`
|
||||
<style>
|
||||
@media only screen and (max-width: 650px) {
|
||||
.hide-on-small-screens {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="w3-bar w3-theme-l1">
|
||||
${Object.entries(k_tabs).map(
|
||||
([k, v]) => html`
|
||||
<button
|
||||
title=${v}
|
||||
class="w3-bar-item w3-padding w3-hover-theme tab ${self.tab == v
|
||||
class="w3-bar-item w3-padding-large w3-hover-theme tab ${self.tab ==
|
||||
v
|
||||
? 'w3-theme-l2'
|
||||
: 'w3-theme-l1'}"
|
||||
@click=${() => self.set_tab(v)}
|
||||
>
|
||||
${k}
|
||||
<span class=${self.tab == v ? '' : 'w3-hide-small'}
|
||||
>${v.charAt(0).toUpperCase() + v.substring(1)}</span
|
||||
>
|
||||
<span class="hide-on-small-screens">${v}</span>
|
||||
</button>
|
||||
`
|
||||
)}
|
||||
@ -361,12 +366,10 @@ class TfElement extends LitElement {
|
||||
`;
|
||||
let contents = !this.loaded
|
||||
? this.loading
|
||||
? html`<div
|
||||
class="w3-panel w3-theme-l5 w3-card-4 w3-padding-large w3-round-xlarge"
|
||||
>
|
||||
Loading...
|
||||
</div>
|
||||
${this.render_tab()}`
|
||||
? html`<div class="w3-panel w3-theme-l5 w3-card-4 w3-padding-large w3-round-xlarge">
|
||||
Loading...
|
||||
</div>
|
||||
${this.render_tab()}`
|
||||
: html`<div>Select or create an identity.</div>`
|
||||
: this.render_tab();
|
||||
return html`
|
||||
|
@ -295,18 +295,14 @@ class TfComposeElement extends LitElement {
|
||||
{
|
||||
values: values,
|
||||
selectTemplate: function (item) {
|
||||
return item
|
||||
? `[@${item.original.key}](${item.original.value})`
|
||||
: undefined;
|
||||
return item ? `[@${item.original.key}](${item.original.value})` : undefined;
|
||||
},
|
||||
},
|
||||
{
|
||||
trigger: '&',
|
||||
values: this.autocomplete,
|
||||
selectTemplate: function (item) {
|
||||
return item
|
||||
? ``
|
||||
: undefined;
|
||||
return item ? `` : undefined;
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -548,7 +544,7 @@ class TfComposeElement extends LitElement {
|
||||
@paste=${this.paste}
|
||||
contenteditable
|
||||
.innerText=${live(draft.text ?? '')}
|
||||
></span>
|
||||
></span>
|
||||
</div>
|
||||
<div class="w3-half w3-padding">
|
||||
${content_warning}
|
||||
|
@ -247,7 +247,9 @@ ${JSON.stringify(mention, null, 2)}</pre
|
||||
if (mentions.length) {
|
||||
let self = this;
|
||||
return html`
|
||||
<fieldset style="padding: 0.5em; border: 1px solid black">
|
||||
<fieldset
|
||||
style="padding: 0.5em; border: 1px solid black"
|
||||
>
|
||||
<legend>Mentions</legend>
|
||||
${mentions.map((x) => self.render_mention(x))}
|
||||
</fieldset>
|
||||
|
@ -7,11 +7,9 @@ class TfTabConnectionsElement extends LitElement {
|
||||
return {
|
||||
broadcasts: {type: Array},
|
||||
identities: {type: Array},
|
||||
my_identities: {type: Array},
|
||||
connections: {type: Array},
|
||||
stored_connections: {type: Array},
|
||||
users: {type: Object},
|
||||
server_identity: {type: String},
|
||||
};
|
||||
}
|
||||
|
||||
@ -22,22 +20,15 @@ class TfTabConnectionsElement extends LitElement {
|
||||
let self = this;
|
||||
this.broadcasts = [];
|
||||
this.identities = [];
|
||||
this.my_identities = [];
|
||||
this.connections = [];
|
||||
this.stored_connections = [];
|
||||
this.users = {};
|
||||
tfrpc.rpc.getIdentities().then(function (identities) {
|
||||
self.my_identities = identities || [];
|
||||
});
|
||||
tfrpc.rpc.getAllIdentities().then(function (identities) {
|
||||
self.identities = identities || [];
|
||||
});
|
||||
tfrpc.rpc.getStoredConnections().then(function (connections) {
|
||||
self.stored_connections = connections || [];
|
||||
});
|
||||
tfrpc.rpc.getServerIdentity().then(function (identity) {
|
||||
self.server_identity = identity;
|
||||
});
|
||||
}
|
||||
|
||||
render_connection_summary(connection) {
|
||||
@ -105,16 +96,6 @@ class TfTabConnectionsElement extends LitElement {
|
||||
}
|
||||
|
||||
render_connection(connection) {
|
||||
let requests = Object.values(
|
||||
connection.requests.reduce(function (accumulator, value) {
|
||||
let key = `${value.name}:${Math.sign(value.request_number)}`;
|
||||
if (!accumulator[key]) {
|
||||
accumulator[key] = Object.assign({count: 0}, value);
|
||||
}
|
||||
accumulator[key].count++;
|
||||
return accumulator;
|
||||
}, {})
|
||||
);
|
||||
return html`
|
||||
<button
|
||||
class="w3-button w3-theme-d1"
|
||||
@ -126,20 +107,9 @@ class TfTabConnectionsElement extends LitElement {
|
||||
${connection.tunnel !== undefined
|
||||
? '🚇'
|
||||
: html`(${connection.host}:${connection.port})`}
|
||||
<div>
|
||||
${requests.map(
|
||||
(x) => html`
|
||||
<span class="w3-tag w3-small"
|
||||
>${x.request_number > 0 ? '🟩' : '🟥'} ${x.name}
|
||||
<span
|
||||
class="w3-badge w3-white"
|
||||
style=${x.count > 1 ? undefined : 'display: none'}
|
||||
>${x.count}</span
|
||||
></span
|
||||
>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
<div>${connection.requests.map(x => html`
|
||||
<span class="w3-tag w3-small">${x.request_number > 0 ? '🟩' : '🟥'} ${x.name}</span>
|
||||
`)}</div>
|
||||
<ul>
|
||||
${this.connections
|
||||
.filter((x) => x.tunnel === this.connections.indexOf(connection))
|
||||
@ -208,16 +178,6 @@ class TfTabConnectionsElement extends LitElement {
|
||||
${this.identities.map(
|
||||
(x) =>
|
||||
html`<li class="w3-bar">
|
||||
${x == this.server_identity
|
||||
? html`<span class="w3-tag w3-medium w3-round w3-theme-l1"
|
||||
>🖥 local server</span
|
||||
>`
|
||||
: undefined}
|
||||
${this.my_identities.indexOf(x) != -1
|
||||
? html`<span class="w3-tag w3-medium w3-round w3-theme-d1"
|
||||
>😎 you</span
|
||||
>`
|
||||
: undefined}
|
||||
<tf-user id=${x} .users=${this.users}></tf-user>
|
||||
</li>`
|
||||
)}
|
||||
|
@ -12,7 +12,6 @@ class TfTabNewsElement extends LitElement {
|
||||
following: {type: Array},
|
||||
drafts: {type: Object},
|
||||
expanded: {type: Object},
|
||||
loading: {type: Boolean},
|
||||
};
|
||||
}
|
||||
|
||||
@ -114,19 +113,6 @@ class TfTabNewsElement extends LitElement {
|
||||
.users=${this.users}
|
||||
></tf-profile>`
|
||||
: undefined;
|
||||
let edit_profile;
|
||||
if (
|
||||
!this.loading &&
|
||||
this.users[this.whoami]?.name === undefined &&
|
||||
this.hash.substring(1) != this.whoami
|
||||
) {
|
||||
edit_profile = html` <div
|
||||
class="w3-panel w3-padding w3-round w3-card-4 w3-theme-l3"
|
||||
>
|
||||
ℹ️ Follow your identity link ☝️ above to edit your profile and set your
|
||||
name.
|
||||
</div>`;
|
||||
}
|
||||
return html`
|
||||
<p class="w3-bar">
|
||||
<button
|
||||
@ -136,9 +122,8 @@ class TfTabNewsElement extends LitElement {
|
||||
${this.new_messages_text()}
|
||||
</button>
|
||||
</p>
|
||||
<div class="w3-bar">
|
||||
<div>
|
||||
Welcome, <tf-user id=${this.whoami} .users=${this.users}></tf-user>!
|
||||
${edit_profile}
|
||||
</div>
|
||||
<div>
|
||||
<tf-compose
|
||||
|
@ -19,11 +19,6 @@ class TfUserElement extends LitElement {
|
||||
}
|
||||
|
||||
render() {
|
||||
let image = html`<span
|
||||
class="w3-theme-light w3-circle"
|
||||
style="display: inline-block; width: 2em; height: 2em; text-align: center; line-height: 2em"
|
||||
>?</span
|
||||
>`;
|
||||
let name = this.users?.[this.id]?.name;
|
||||
name =
|
||||
name !== undefined
|
||||
@ -31,20 +26,21 @@ class TfUserElement extends LitElement {
|
||||
: html`<a target="_top" href=${'#' + this.id}>${this.id}</a>`;
|
||||
|
||||
if (this.users[this.id]) {
|
||||
let image_link = this.users[this.id].image;
|
||||
image_link =
|
||||
typeof image_link == 'string' ? image_link : image_link?.link;
|
||||
if (image_link !== undefined) {
|
||||
image = html`<img
|
||||
class="w3-circle"
|
||||
style="width: 2em; height: 2em; vertical-align: middle"
|
||||
src="/${image_link}/view"
|
||||
/>`;
|
||||
}
|
||||
let image = this.users[this.id].image;
|
||||
image = typeof image == 'string' ? image : image?.link;
|
||||
return html` <div style="display: inline-block; font-weight: bold">
|
||||
<img
|
||||
style="width: 2em; height: 2em; vertical-align: middle; border-radius: 50%"
|
||||
?hidden=${image === undefined}
|
||||
src="${image ? '/' + image + '/view' : undefined}"
|
||||
/>
|
||||
${name}
|
||||
</div>`;
|
||||
} else {
|
||||
return html` <div style="display: inline-block; font-weight: bold">
|
||||
${name}
|
||||
</div>`;
|
||||
}
|
||||
return html` <div style="display: inline-block; font-weight: bold">
|
||||
${image} ${name}
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ function new_message() {
|
||||
return g_new_message_promise;
|
||||
}
|
||||
|
||||
core.register('onMessage', function (id) {
|
||||
ssb.addEventListener('message', function (id) {
|
||||
let resolve = g_new_message_resolve;
|
||||
g_new_message_promise = new Promise(function (resolve, reject) {
|
||||
g_new_message_resolve = resolve;
|
||||
|
@ -208,10 +208,7 @@ class TfNavigationElement extends LitElement {
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else if (
|
||||
this.credentials?.session?.name &&
|
||||
this.credentials.session.name !== 'guest'
|
||||
) {
|
||||
} else {
|
||||
return html`
|
||||
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
|
||||
<button
|
||||
|
152
core/core.js
152
core/core.js
@ -8,6 +8,116 @@ let gStatsTimer = false;
|
||||
const k_content_security_policy =
|
||||
'sandbox allow-downloads allow-top-navigation-by-user-activation';
|
||||
|
||||
const k_mime_types = {
|
||||
css: 'text/css',
|
||||
html: 'text/html',
|
||||
js: 'text/javascript',
|
||||
json: 'text/json',
|
||||
map: 'application/json',
|
||||
svg: 'image/svg+xml',
|
||||
};
|
||||
|
||||
const k_magic_bytes = [
|
||||
{bytes: [0xff, 0xd8, 0xff, 0xdb], type: 'image/jpeg'},
|
||||
{
|
||||
bytes: [
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
|
||||
],
|
||||
type: 'image/jpeg',
|
||||
},
|
||||
{bytes: [0xff, 0xd8, 0xff, 0xee], type: 'image/jpeg'},
|
||||
{
|
||||
bytes: [
|
||||
0xff,
|
||||
0xd8,
|
||||
0xff,
|
||||
0xe1,
|
||||
null,
|
||||
null,
|
||||
0x45,
|
||||
0x78,
|
||||
0x69,
|
||||
0x66,
|
||||
0x00,
|
||||
0x00,
|
||||
],
|
||||
type: 'image/jpeg',
|
||||
},
|
||||
{bytes: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], type: 'image/png'},
|
||||
{bytes: [0x47, 0x49, 0x46, 0x38, 0x37, 0x61], type: 'image/gif'},
|
||||
{bytes: [0x47, 0x49, 0x46, 0x38, 0x39, 0x61], type: 'image/gif'},
|
||||
{
|
||||
bytes: [
|
||||
0x52,
|
||||
0x49,
|
||||
0x46,
|
||||
0x46,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
0x57,
|
||||
0x45,
|
||||
0x42,
|
||||
0x50,
|
||||
],
|
||||
type: 'image/webp',
|
||||
},
|
||||
{bytes: [0x3c, 0x73, 0x76, 0x67], type: 'image/svg+xml'},
|
||||
{
|
||||
bytes: [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
0x66,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x6d,
|
||||
0x70,
|
||||
0x34,
|
||||
0x32,
|
||||
],
|
||||
type: 'audio/mpeg',
|
||||
},
|
||||
{
|
||||
bytes: [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
0x66,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x69,
|
||||
0x73,
|
||||
0x6f,
|
||||
0x6d,
|
||||
],
|
||||
type: 'video/mp4',
|
||||
},
|
||||
{
|
||||
bytes: [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
0x66,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x6d,
|
||||
0x70,
|
||||
0x34,
|
||||
0x32,
|
||||
],
|
||||
type: 'video/mp4',
|
||||
},
|
||||
{bytes: [0x4d, 0x54, 0x68, 0x64], type: 'audio/midi'},
|
||||
];
|
||||
|
||||
let k_static_files = [
|
||||
{uri: '/', path: 'index.html', type: 'text/html; charset=UTF-8'},
|
||||
];
|
||||
@ -467,8 +577,7 @@ async function getProcessBlob(blobId, key, options) {
|
||||
if (
|
||||
process.credentials &&
|
||||
process.credentials.session &&
|
||||
process.credentials.session.name &&
|
||||
process.credentials.session.name !== 'guest'
|
||||
process.credentials.session.name
|
||||
) {
|
||||
let id = ssb.createIdentity(process.credentials.session.name);
|
||||
await process.sendIdentities();
|
||||
@ -486,8 +595,6 @@ async function getProcessBlob(blobId, key, options) {
|
||||
]
|
||||
);
|
||||
return id;
|
||||
} else {
|
||||
throw new Error('Must be signed-in to create an account.');
|
||||
}
|
||||
};
|
||||
if (process.credentials?.permissions?.administration) {
|
||||
@ -678,8 +785,6 @@ async function getProcessBlob(blobId, key, options) {
|
||||
);
|
||||
}
|
||||
};
|
||||
imports.ssb.addEventListener = undefined;
|
||||
imports.ssb.removeEventListener = undefined;
|
||||
imports.ssb.getIdentityInfo = undefined;
|
||||
imports.fetch = function (url, options) {
|
||||
return http.fetch(url, options, gGlobalSettings.fetch_hosts);
|
||||
@ -833,6 +938,29 @@ function startsWithBytes(data, bytes) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODOC
|
||||
* @param {*} path
|
||||
* @returns
|
||||
*/
|
||||
function guessTypeFromName(path) {
|
||||
let extension = path.split('.').pop();
|
||||
return k_mime_types[extension];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODOC
|
||||
* @param {*} data
|
||||
* @returns
|
||||
*/
|
||||
function guessTypeFromMagicBytes(data) {
|
||||
for (let magic of k_magic_bytes) {
|
||||
if (startsWithBytes(data, magic.bytes)) {
|
||||
return magic.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODOC
|
||||
* @param {*} response
|
||||
@ -848,9 +976,7 @@ function sendData(response, data, type, headers, status_code) {
|
||||
Object.assign(
|
||||
{
|
||||
'Content-Type':
|
||||
type ||
|
||||
httpd.mime_type_from_magic_bytes(data) ||
|
||||
'application/binary',
|
||||
type || guessTypeFromMagicBytes(data) || 'application/binary',
|
||||
'Content-Length': data.byteLength,
|
||||
},
|
||||
headers || {}
|
||||
@ -1219,9 +1345,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
'Content-Security-Policy': k_content_security_policy,
|
||||
};
|
||||
data = await getBlobOrContent(id);
|
||||
let type =
|
||||
httpd.mime_type_from_extension(uri) ||
|
||||
httpd.mime_type_from_magic_bytes(data);
|
||||
let type = guessTypeFromName(uri) || guessTypeFromMagicBytes(data);
|
||||
sendData(response, data, type, headers);
|
||||
}
|
||||
} else {
|
||||
@ -1230,10 +1354,6 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
}
|
||||
}
|
||||
|
||||
ssb.addEventListener('message', function () {
|
||||
broadcastEvent('onMessage', [...arguments]);
|
||||
});
|
||||
|
||||
ssb.addEventListener('broadcasts', function () {
|
||||
broadcastEvent('onBroadcastsChanged', []);
|
||||
});
|
||||
|
68
default.nix
68
default.nix
@ -1,68 +0,0 @@
|
||||
# How to upgrade to a newer version
|
||||
# - Comment `src.hash`
|
||||
# - Change `version`
|
||||
# - Run `$ nix build`
|
||||
# This will fetch the source code
|
||||
# Since `hash` is not provided, nix will stop building and throw an error:
|
||||
#
|
||||
# error: hash mismatch in fixed-output derivation '/nix/store/fghi3ljs6fhz8pwm3dh73j5fwjpq5wbz-source.drv':
|
||||
# specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
|
||||
# got: sha256-+uthA1w8CmZfW+WOK9wYGl2fUl/k10ufOc8W+Pwa9iQ=
|
||||
# error: 1 dependencies of derivation '/nix/store/imcwsw5r74vkd8r0qa2k7cys2xfgraaz-tildefriends-0.0.18.drv' failed to build
|
||||
#
|
||||
# - Change `src.hash` to the new one, ie `sha256-+uthA1w8CmZfW+WOK9wYGl2fUl/k10ufOc8W+Pwa9iQ=`
|
||||
# - Uncomment `src.hash`
|
||||
# - Build again, this time it should work.
|
||||
# - Check the release notes, if there's a new dependency or a change to `GNUMakefile`, this file might need to be changed too.
|
||||
# For more details, contact tasiaiso @ https://tilde.club/~tasiaiso/
|
||||
#
|
||||
# WARNING: currently it is pinned to `47838d5e482cb4aac40190fa0414f08b8cf94d40`. I couldn't get v0.0.18 to work for some reason.
|
||||
# I'll change this in the next release - tasiaiso
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? import <nixpkgs/lib>,
|
||||
}:
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pname = "tildefriends";
|
||||
version = "0.0.19-wip";
|
||||
|
||||
src = pkgs.fetchFromGitea {
|
||||
domain = "dev.tildefriends.net";
|
||||
owner = "cory";
|
||||
repo = "tildefriends";
|
||||
# rev = "v${version}";
|
||||
rev = "47838d5e482cb4aac40190fa0414f08b8cf94d40";
|
||||
hash = "sha256-mb5KYvWPIqgV64FOaXKHm2ownBJiiSRtdH8+YWiXwvE="; # 47838d5e482cb4aac40190fa0414f08b8cf94d40
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
gnumake
|
||||
openssl
|
||||
which
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
which
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
make -j $NIX_BUILD_CORES release
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp -r out/release/tildefriends $out/bin
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
|
||||
meta = with pkgs; {
|
||||
homepage = "https://tildefriends.net";
|
||||
description = "Make apps and friends from the comfort of your web browser.";
|
||||
mainProgram = "tildefriends";
|
||||
license = with lib.licenses; [mit];
|
||||
platforms = lib.platforms.all;
|
||||
};
|
||||
}
|
@ -1,4 +1,38 @@
|
||||
<!--
|
||||
# Tilde Friends
|
||||
|
||||
## Philosophy
|
||||
|
||||
Tilde Friends is a platform for making, running, and sharing web applications.
|
||||
|
||||
When you visit Tilde Friends in a web browser, you are presented with a
|
||||
terminal interface, typically with a big text output box covering most of the
|
||||
page and an input box at the bottom, into which text or commands can be
|
||||
entered. A script runs to produce text output and consume user input.
|
||||
|
||||
The script is a Tilde Friends application, and it runs on the server, which
|
||||
means that unlike client-side JavaScript, it can have the ability to read and
|
||||
write files on the server or create network connections to other machines.
|
||||
Unlike node.js or other server-side runtime environments, applications are
|
||||
limited for security reasons to not interfere with each other or bring the
|
||||
entire server down.
|
||||
|
||||
Above the terminal, an "Edit" link brings a visitor to the source code for the
|
||||
current Tilde Friends application, which they can then edit, save as their own,
|
||||
and run.
|
||||
|
||||
## Architecture
|
||||
|
||||
Tilde Friends is a C++ application with a JavaScript runtime that provides
|
||||
restricted access to filesystem, network, and other system resources. The core
|
||||
process runs a core set of scripts that implement a web server, typically
|
||||
starting a new process for each visitor's session which runs scripts for the
|
||||
active application and stopping it when the visitor leaves.
|
||||
|
||||
Only the core process has access to most system resources, but session
|
||||
processes can be given accesss through the core process.
|
||||
|
||||
Service processes are identical to session processes, but they are not tied to
|
||||
a user session.
|
||||
|
||||
## Communication
|
||||
|
||||
@ -177,5 +211,3 @@ Writes data to the connection.
|
||||
#### connection.close()
|
||||
|
||||
Closes the connection.
|
||||
|
||||
-->
|
@ -32,6 +32,7 @@ main();
|
||||
|
||||
Save the app, and you should now be seeing `Hello world!` on the screen.
|
||||
|
||||
|
||||
## Components
|
||||
|
||||
Once your app grows to a certain size, you'll want to introduce components.
|
||||
@ -46,8 +47,4 @@ TODO
|
||||
|
||||
TODO: tfrpc
|
||||
|
||||
Apps can interact with Tilde Friends using tfrpc.
|
||||
|
||||
Read [tfrpc.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/apps/tfrpc.md)
|
||||
|
||||
TODO: sharing apps
|
||||
|
@ -1,7 +0,0 @@
|
||||
# RPC documentation
|
||||
|
||||
Quick start
|
||||
|
||||
Complete documentation
|
||||
|
||||
TODO
|
@ -41,13 +41,12 @@ To build in docker, `docker build .`
|
||||
<!-- On NixOS: TODO -->
|
||||
<!-- Add shell.nix and nix derivs first -->
|
||||
|
||||
Now that you have a binary, head over to [running.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/running.md).
|
||||
Now that you have a binary, head over to <running.md>.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### The compiler throws a warning and I can't build the binary
|
||||
### The compiler throws an error and I can't build the binary
|
||||
|
||||
You can choose to tell the compiler to ignore warnings.
|
||||
Open `GNUMakefile` and edit the CFLAGS environment variable around line 50.
|
||||
|
||||
For example given this error:
|
||||
@ -75,4 +74,3 @@ CFLAGS += \
|
||||
```
|
||||
|
||||
Now the compiler will ignore this error and *should* continue building anyways.
|
||||
Note this is a dirty hack to get Tilde Friends to compile and you should not propose to keep this flag on. Instead, open a bug report.
|
||||
|
@ -1,30 +1,12 @@
|
||||
# How to contribute
|
||||
|
||||
## Philosophy
|
||||
|
||||
TODO
|
||||
|
||||
## Best practices
|
||||
|
||||
TODO
|
||||
|
||||
## How to get your changes merged
|
||||
|
||||
- Fork this repository
|
||||
|
||||
- Clone your repository
|
||||
|
||||
1. Alternatively, you can add a remote called `fork`:
|
||||
Alternatively, you can change the `origin` remote on your existing clone:
|
||||
|
||||
`$ git remote add fork https://dev.tildefriends.net/YOUR_USERNAME/tildefriends.git`
|
||||
|
||||
You'll need to set your branch's upstream to `fork`:
|
||||
|
||||
`$ git push --set-upstream fork my-branch`
|
||||
|
||||
2. or you can change the `origin` remote on your existing clone altogether:
|
||||
|
||||
`$ git remote set-url origin https://dev.tildefriends.net/YOUR_USERNAME/tildefriends.git`
|
||||
`git remote set-url origin https://dev.tildefriends.net/YOUR_USERNAME/tildefriends.git`
|
||||
|
||||
- Make your changes
|
||||
|
||||
@ -38,7 +20,7 @@ TODO
|
||||
|
||||
- I want to write documentation !
|
||||
|
||||
Great! Before you do, have a look at the [documentation guidelines](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/guidelines/documentation-guidelines.md) to learn how to write consistent documentation.
|
||||
Great! Before you do, have a look at the [documentation guidelines](guidelines/documentation-guidelines.md) to learn how to write consistent documentation.
|
||||
|
||||
In all cases:
|
||||
|
||||
|
@ -2,12 +2,18 @@
|
||||
|
||||
## Building
|
||||
|
||||
See [building.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/building.md).
|
||||
See <building.md>.
|
||||
|
||||
## Contibuting
|
||||
|
||||
See [contributing.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/contributing.md).
|
||||
See <contributing.md>.
|
||||
|
||||
## FAQ / Troubleshooting
|
||||
|
||||
See [faq.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/faq.md).
|
||||
See <faq.md>.
|
||||
|
||||
## Guide
|
||||
|
||||
This document will be phased out and integrated into the new documentation.
|
||||
|
||||
See <.guide.md>.
|
||||
|
@ -2,12 +2,8 @@
|
||||
|
||||
## I started tildefriends. Now what ?
|
||||
|
||||
See [running.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/running.md).
|
||||
See <running.md>.
|
||||
|
||||
### The compiler throws an error and I can't build the binary
|
||||
|
||||
See [building.md](https://dev.tildefriends.net/cory/tildefriends/src/branch/main/docs/building.md).
|
||||
|
||||
### Where is my database located ?
|
||||
|
||||
TODO
|
||||
See <building.md>.
|
||||
|
@ -1 +1 @@
|
||||
# TODO
|
||||
TODO
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Documentation guidelines
|
||||
|
||||
This document defines the rules used to write documentation in order to make it more consistent.
|
||||
|
||||
This documentation is a living document and so are it's rules; you are free to propose changes but in the meantime, please stick to them.
|
||||
|
||||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119/).
|
||||
@ -8,6 +9,7 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S
|
||||
## File naming
|
||||
|
||||
Files SHOULD be named using [kebab-case](https://www.freecodecamp.org/news/snake-case-vs-camel-case-vs-pascal-case-vs-kebab-case-whats-the-difference/#kebab-case).
|
||||
|
||||
Their names should be meaningful and SHOULD not conflict with other files in other directories:
|
||||
|
||||
> Example: this document is named `docs/guidelines/documentation-guidelines.md` instead of `docs/guidelines/documentation.md` because it could cause confusion with `docs/documentation.md`.
|
||||
@ -47,29 +49,16 @@ The documentation should therefore be acessible and usefule to most people inter
|
||||
|
||||
You MAY use one line per sentence.
|
||||
|
||||
2. Lines ending with an `inline code block` or hyperlinks SHOULD NOT end with a period to make copy-pasting easier.
|
||||
2. Lines ending with an `inline code block` SHOULD NOT end with a period.
|
||||
|
||||
> Example: To build in docker, `$ docker build .`
|
||||
> Example: To build in docker, `docker build .`
|
||||
|
||||
NB: this does not apply to file names or other text that are not meant to be copy-pasted.
|
||||
NB: this does not apply to file names or other text that are not meant to be copy-pasted.
|
||||
|
||||
> Example: this document is named `docs/guidelines/documentation-guidelines.md` instead of `docs/guidelines/documentation.md` because it could cause confusion with `docs/documentation.md`.
|
||||
|
||||
3. Commands SHOULD start with a caret: (is that the tehnical term ?)
|
||||
|
||||
- `$` if the command should be run as the current user
|
||||
- `#` if the command should be run as root
|
||||
|
||||
> Example: To build in docker, `$ docker build .`
|
||||
> Example: this document is named `docs/guidelines/documentation-guidelines.md` instead of `docs/guidelines/documentation.md` because it could cause confusion with `docs/documentation.md`.
|
||||
|
||||
More TODO
|
||||
|
||||
## License
|
||||
|
||||
As per the rest of the code in this repository, the documentation is shared under the [MIT](https://opensource.org/licenses/MIT/) license.
|
||||
|
||||
## Changelog
|
||||
|
||||
### v1 (2024-05-12)
|
||||
|
||||
First version; 3 new guidelines.
|
||||
|
@ -1 +1 @@
|
||||
# TODO
|
||||
TODO
|
||||
|
@ -1,37 +0,0 @@
|
||||
# Tilde Friends in depth
|
||||
|
||||
## Philosophy
|
||||
|
||||
Tilde Friends is a platform for making, running, and sharing web applications.
|
||||
|
||||
<!-- When you visit Tilde Friends in a web browser, you are presented with a
|
||||
terminal interface, typically with a big text output box covering most of the
|
||||
page and an input box at the bottom, into which text or commands can be
|
||||
entered. A script runs to produce text output and consume user input.
|
||||
|
||||
The script is a Tilde Friends application, and it runs on the server, which
|
||||
means that unlike client-side JavaScript, it can have the ability to read and
|
||||
write files on the server or create network connections to other machines.
|
||||
Unlike node.js or other server-side runtime environments, applications are
|
||||
limited for security reasons to not interfere with each other or bring the
|
||||
entire server down.
|
||||
|
||||
Above the terminal, an "Edit" link brings a visitor to the source code for the
|
||||
current Tilde Friends application, which they can then edit, save as their own,
|
||||
and run. -->
|
||||
|
||||
## Architecture
|
||||
|
||||
Tilde Friends is a C++ application with a JavaScript runtime that provides restricted access to filesystem, network, and other system resources.
|
||||
The core process runs a core set of scripts that implement a web server, typically starting a new process for each visitor's session which runs scripts for the active application and stopping it when the visitor leaves.
|
||||
|
||||
Only the core process has access to most system resources, but session processes can be given accesss through the core process.
|
||||
|
||||
Service processes are identical to session processes, but they are not tied to a user session.
|
||||
|
||||
```text
|
||||
/-------\ /-------------\ /--------------\
|
||||
| C app | <-----> | Server-side | <-----> | Client-side |
|
||||
| | tfrpc | JS runtime | | JS (Browser) |
|
||||
\-------/ \-------------/ \--------------/
|
||||
```
|
@ -6,10 +6,10 @@ The binaries should appear at `out/debug/tildefriends` and `out/release/tildefri
|
||||
|
||||
For Android, iOS and Windows: TODO
|
||||
|
||||
You can now start the server by running `$ ./out/debug/tildefriends` or `$ ./out/release/tildefriends`.
|
||||
You can now start the server by running `./out/debug/tildefriends` or `./out/release/tildefriends`.
|
||||
|
||||
By default, running the built `tildefriends` executable will start a web server
|
||||
at <http://localhost:12345/>. `$ tildefriends -h` lists further options.
|
||||
at <http://localhost:12345/>. `tildefriends -h` lists further options.
|
||||
|
||||
## How to use TF
|
||||
|
||||
|
61
flake.lock
generated
61
flake.lock
generated
@ -1,61 +0,0 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1715395895,
|
||||
"narHash": "sha256-DreMqi6+qa21ffLQqhMQL2XRUkAGt3N7iVB5FhJKie4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "71bae31b7dbc335528ca7e96f479ec93462323ff",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-23.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
37
flake.nix
37
flake.nix
@ -1,37 +0,0 @@
|
||||
{
|
||||
description = "Tilde Friends is a platform for making, running, and sharing web applications.";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in rec
|
||||
{
|
||||
# Nix formatter, run using `$ nix fmt`
|
||||
formatter = pkgs.alejandra;
|
||||
|
||||
# Exports the tildefriends package
|
||||
# Build with `$ nix build`
|
||||
packages.default = pkgs.callPackage ./default.nix {};
|
||||
|
||||
# Creates a shell with the necessary dependencies
|
||||
# Enter using `$ nix develop`
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
llvmPackages_17.clang-unwrapped
|
||||
unzip
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
214
src/httpd.js.c
214
src/httpd.js.c
@ -31,10 +31,6 @@
|
||||
|
||||
#define tf_countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
|
||||
|
||||
#define CYAN "\e[1;36m"
|
||||
#define MAGENTA "\e[1;35m"
|
||||
#define RESET "\e[0m"
|
||||
|
||||
const int64_t k_refresh_interval = 1ULL * 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
static JSValue _authenticate_jwt(JSContext* context, const char* jwt);
|
||||
@ -420,7 +416,6 @@ static JSValue _httpd_endpoint_start(JSContext* context, JSValueConst this_val,
|
||||
*listener = (httpd_listener_t) { .context = context, .tls = JS_DupValue(context, argv[1]) };
|
||||
tf_tls_context_t* tls = tf_tls_context_get(listener->tls);
|
||||
int assigned_port = tf_http_listen(http, port, tls, _httpd_listener_cleanup, listener);
|
||||
tf_printf(CYAN "~😎 Tilde Friends" RESET " is now up at " MAGENTA "http%s://127.0.0.1:%d/" RESET ".\n", tls ? "s" : "", assigned_port);
|
||||
return JS_NewInt32(context, assigned_port);
|
||||
}
|
||||
|
||||
@ -498,151 +493,6 @@ static JSValue _httpd_auth_query(JSContext* context, JSValueConst this_val, int
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct _magic_bytes_t
|
||||
{
|
||||
const char* type;
|
||||
uint8_t bytes[12];
|
||||
uint8_t ignore[12];
|
||||
} magic_bytes_t;
|
||||
|
||||
static bool _magic_bytes_match(const magic_bytes_t* magic, const uint8_t* actual, size_t size)
|
||||
{
|
||||
if (size < sizeof(magic->bytes))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int length = (int)tf_min(sizeof(magic->bytes), size);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if ((magic->bytes[i] & ~magic->ignore[i]) != (actual[i] & ~magic->ignore[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSValue _httpd_mime_type_from_magic_bytes(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_UNDEFINED;
|
||||
size_t size = 0;
|
||||
uint8_t* bytes = tf_util_try_get_array_buffer(context, &size, argv[0]);
|
||||
if (bytes)
|
||||
{
|
||||
|
||||
const magic_bytes_t k_magic_bytes[] = {
|
||||
{
|
||||
.type = "image/jpeg",
|
||||
.bytes = { 0xff, 0xd8, 0xff, 0xdb },
|
||||
},
|
||||
{
|
||||
.type = "image/jpeg",
|
||||
.bytes = { 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01 },
|
||||
},
|
||||
{
|
||||
.type = "image/jpeg",
|
||||
.bytes = { 0xff, 0xd8, 0xff, 0xee },
|
||||
},
|
||||
{
|
||||
.type = "image/jpeg",
|
||||
.bytes = { 0xff, 0xd8, 0xff, 0xe1, 0x00, 0x00, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 },
|
||||
.ignore = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
},
|
||||
{
|
||||
.type = "image/png",
|
||||
.bytes = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a },
|
||||
},
|
||||
{
|
||||
.type = "image/gif",
|
||||
.bytes = { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 },
|
||||
},
|
||||
{
|
||||
.type = "image/gif",
|
||||
.bytes = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 },
|
||||
},
|
||||
{
|
||||
.type = "image/webp",
|
||||
.bytes = { 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50 },
|
||||
.ignore = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
|
||||
},
|
||||
{
|
||||
.type = "image/svg+xml",
|
||||
.bytes = { 0x3c, 0x73, 0x76, 0x67 },
|
||||
},
|
||||
{
|
||||
.type = "audio/mpeg",
|
||||
.bytes = { 0x00, 0x00, 0x00, 0x00, 0x66, 0x74, 0x79, 0x70, 0x6d, 0x70, 0x34, 0x32 },
|
||||
.ignore = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
},
|
||||
{
|
||||
.type = "video/mp4",
|
||||
.bytes = { 0x00, 0x00, 0x00, 0x00, 0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6f, 0x6d },
|
||||
.ignore = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
},
|
||||
{
|
||||
.type = "video/mp4",
|
||||
.bytes = { 0x00, 0x00, 0x00, 0x00, 0x66, 0x74, 0x79, 0x70, 0x6d, 0x70, 0x34, 0x32 },
|
||||
.ignore = { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
},
|
||||
{
|
||||
.type = "audio/midi",
|
||||
.bytes = { 0x4d, 0x54, 0x68, 0x64 },
|
||||
},
|
||||
};
|
||||
|
||||
for (int i = 0; i < tf_countof(k_magic_bytes); i++)
|
||||
{
|
||||
if (_magic_bytes_match(&k_magic_bytes[i], bytes, size))
|
||||
{
|
||||
result = JS_NewString(context, k_magic_bytes[i].type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char* _ext_to_content_type(const char* ext, bool use_fallback)
|
||||
{
|
||||
if (ext)
|
||||
{
|
||||
typedef struct _ext_type_t
|
||||
{
|
||||
const char* ext;
|
||||
const char* type;
|
||||
} ext_type_t;
|
||||
|
||||
const ext_type_t k_types[] = {
|
||||
{ .ext = ".html", .type = "text/html; charset=UTF-8" },
|
||||
{ .ext = ".js", .type = "text/javascript; charset=UTF-8" },
|
||||
{ .ext = ".mjs", .type = "text/javascript; charset=UTF-8" },
|
||||
{ .ext = ".css", .type = "text/css; charset=UTF-8" },
|
||||
{ .ext = ".png", .type = "image/png" },
|
||||
{ .ext = ".json", .type = "application/json" },
|
||||
{ .ext = ".map", .type = "application/json" },
|
||||
{ .ext = ".svg", .type = "image/svg+xml" },
|
||||
};
|
||||
|
||||
for (int i = 0; i < tf_countof(k_types); i++)
|
||||
{
|
||||
if (strcmp(ext, k_types[i].ext) == 0)
|
||||
{
|
||||
return k_types[i].type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return use_fallback ? "application/binary" : NULL;
|
||||
}
|
||||
|
||||
static JSValue _httpd_mime_type_from_extension(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
const char* name = JS_ToCString(context, argv[0]);
|
||||
const char* type = _ext_to_content_type(strrchr(name, '.'), false);
|
||||
JS_FreeCString(context, name);
|
||||
return type ? JS_NewString(context, type) : JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static void _httpd_finalizer(JSRuntime* runtime, JSValue value)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(value, _httpd_class_id);
|
||||
@ -772,6 +622,30 @@ typedef struct _http_file_t
|
||||
char etag[512];
|
||||
} http_file_t;
|
||||
|
||||
static const char* _ext_to_content_type(const char* ext)
|
||||
{
|
||||
if (ext)
|
||||
{
|
||||
if (strcmp(ext, ".html") == 0)
|
||||
{
|
||||
return "text/html; charset=UTF-8";
|
||||
}
|
||||
else if (strcmp(ext, ".js") == 0 || strcmp(ext, ".mjs") == 0)
|
||||
{
|
||||
return "text/javascript; charset=UTF-8";
|
||||
}
|
||||
else if (strcmp(ext, ".css") == 0)
|
||||
{
|
||||
return "text/css; charset=UTF-8";
|
||||
}
|
||||
else if (strcmp(ext, ".png") == 0)
|
||||
{
|
||||
return "image/png";
|
||||
}
|
||||
}
|
||||
return "application/binary";
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_static_read(tf_task_t* task, const char* path, int result, const void* data, void* user_data)
|
||||
{
|
||||
http_file_t* file = user_data;
|
||||
@ -780,7 +654,7 @@ static void _httpd_endpoint_static_read(tf_task_t* task, const char* path, int r
|
||||
{
|
||||
if (strcmp(path, "core/tfrpc.js") == 0)
|
||||
{
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'), true);
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'));
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
content_type,
|
||||
@ -793,7 +667,7 @@ static void _httpd_endpoint_static_read(tf_task_t* task, const char* path, int r
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'), true);
|
||||
const char* content_type = _ext_to_content_type(strrchr(path, '.'));
|
||||
const char* headers[] = {
|
||||
"Content-Type",
|
||||
content_type,
|
||||
@ -1201,7 +1075,7 @@ static JSValue _authenticate_jwt(JSContext* context, const char* jwt)
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
char public_key_b64[k_id_base64_len] = { 0 };
|
||||
tf_ssb_db_identity_visit(ssb, ":admin", _public_key_visit, public_key_b64);
|
||||
tf_ssb_db_identity_visit(ssb, ":auth", _public_key_visit, public_key_b64);
|
||||
|
||||
const char* payload = jwt + dot[0] + 1;
|
||||
size_t payload_length = dot[1] - dot[0] - 1;
|
||||
@ -1271,12 +1145,15 @@ static void _visit_auth_identity(const char* identity, void* user_data)
|
||||
static bool _get_auth_private_key(tf_ssb_t* ssb, uint8_t* out_private_key)
|
||||
{
|
||||
char id[k_id_base64_len] = { 0 };
|
||||
tf_ssb_db_identity_visit(ssb, ":admin", _visit_auth_identity, id);
|
||||
tf_ssb_db_identity_visit(ssb, ":auth", _visit_auth_identity, id);
|
||||
if (*id)
|
||||
{
|
||||
return tf_ssb_db_identity_get_private_key(ssb, ":admin", id, out_private_key, crypto_sign_SECRETKEYBYTES);
|
||||
return tf_ssb_db_identity_get_private_key(ssb, ":auth", id, out_private_key, crypto_sign_SECRETKEYBYTES);
|
||||
}
|
||||
else
|
||||
{
|
||||
return tf_ssb_db_identity_create(ssb, ":auth", out_private_key + crypto_sign_PUBLICKEYBYTES, out_private_key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char* _make_session_jwt(tf_ssb_t* ssb, const char* name)
|
||||
@ -1285,15 +1162,21 @@ static const char* _make_session_jwt(tf_ssb_t* ssb, const char* name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
uint8_t private_key[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
if (!_get_auth_private_key(ssb, private_key))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uv_timespec64_t now = { 0 };
|
||||
uv_clock_gettime(UV_CLOCK_REALTIME, &now);
|
||||
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
|
||||
const char* header_json = "{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
|
||||
char header_base64[256];
|
||||
sodium_bin2base64(header_base64, sizeof(header_base64), (uint8_t*)header_json, strlen(header_json), sodium_base64_VARIANT_URLSAFE_NO_PADDING);
|
||||
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
JSValue payload = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, payload, "name", JS_NewString(context, name));
|
||||
JS_SetPropertyStr(context, payload, "exp", JS_NewInt64(context, now.tv_sec * 1000 + now.tv_nsec / 1000000LL + k_refresh_interval));
|
||||
@ -1308,17 +1191,12 @@ static const char* _make_session_jwt(tf_ssb_t* ssb, const char* name)
|
||||
unsigned long long signature_length = 0;
|
||||
char signature_base64[256] = { 0 };
|
||||
|
||||
uint8_t private_key[crypto_sign_SECRETKEYBYTES] = { 0 };
|
||||
if (_get_auth_private_key(ssb, private_key))
|
||||
if (crypto_sign_detached(signature, &signature_length, (const uint8_t*)payload_base64, strlen(payload_base64), private_key) == 0)
|
||||
{
|
||||
if (crypto_sign_detached(signature, &signature_length, (const uint8_t*)payload_base64, strlen(payload_base64), private_key) == 0)
|
||||
{
|
||||
sodium_bin2base64(signature_base64, sizeof(signature_base64), signature, sizeof(signature), sodium_base64_VARIANT_URLSAFE_NO_PADDING);
|
||||
size_t size = strlen(header_base64) + 1 + strlen(payload_base64) + 1 + strlen(signature_base64) + 1;
|
||||
result = tf_malloc(size);
|
||||
snprintf(result, size, "%s.%s.%s", header_base64, payload_base64, signature_base64);
|
||||
}
|
||||
sodium_memzero(private_key, sizeof(private_key));
|
||||
sodium_bin2base64(signature_base64, sizeof(signature_base64), signature, sizeof(signature), sodium_base64_VARIANT_URLSAFE_NO_PADDING);
|
||||
size_t size = strlen(header_base64) + 1 + strlen(payload_base64) + 1 + strlen(signature_base64) + 1;
|
||||
result = tf_malloc(size);
|
||||
snprintf(result, size, "%s.%s.%s", header_base64, payload_base64, signature_base64);
|
||||
}
|
||||
|
||||
JS_FreeCString(context, payload_string);
|
||||
@ -1640,8 +1518,6 @@ void tf_httpd_register(JSContext* context)
|
||||
JS_SetPropertyStr(context, httpd, "start", JS_NewCFunction(context, _httpd_endpoint_start, "start", 2));
|
||||
JS_SetPropertyStr(context, httpd, "set_http_redirect", JS_NewCFunction(context, _httpd_set_http_redirect, "set_http_redirect", 1));
|
||||
JS_SetPropertyStr(context, httpd, "auth_query", JS_NewCFunction(context, _httpd_auth_query, "auth_query", 1));
|
||||
JS_SetPropertyStr(context, httpd, "mime_type_from_magic_bytes", JS_NewCFunction(context, _httpd_mime_type_from_magic_bytes, "mime_type_from_magic_bytes", 1));
|
||||
JS_SetPropertyStr(context, httpd, "mime_type_from_extension", JS_NewCFunction(context, _httpd_mime_type_from_extension, "mime_type_from_extension", 1));
|
||||
JS_SetPropertyStr(context, global, "httpd", httpd);
|
||||
JS_FreeValue(context, global);
|
||||
}
|
||||
|
55
src/main.c
55
src/main.c
@ -48,7 +48,6 @@ static int _tf_command_import(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_export(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_verify(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_usage(const char* file);
|
||||
|
||||
typedef struct _command_t
|
||||
@ -63,7 +62,6 @@ const command_t k_commands[] = {
|
||||
{ "sandbox", _tf_command_sandbox, "Run a sandboxed tildefriends sandbox process (used internally)." },
|
||||
{ "import", _tf_command_import, "Import apps to SSB." },
|
||||
{ "export", _tf_command_export, "Export apps from SSB." },
|
||||
{ "verify", _tf_command_verify, "Verify a feed." },
|
||||
{ "test", _tf_command_test, "Test SSB." },
|
||||
};
|
||||
|
||||
@ -268,59 +266,6 @@ static int _tf_command_export(const char* file, int argc, char* argv[])
|
||||
tf_ssb_destroy(ssb);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int _tf_command_verify(const char* file, int argc, char* argv[])
|
||||
{
|
||||
const char* identity = NULL;
|
||||
const char* db_path = k_db_path_default;
|
||||
bool show_usage = false;
|
||||
|
||||
while (!show_usage)
|
||||
{
|
||||
static const struct option k_options[] = {
|
||||
{ "id", required_argument, NULL, 'u' },
|
||||
{ "db-path", required_argument, NULL, 'd' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ 0 },
|
||||
};
|
||||
int c = getopt_long(argc, argv, "i:d:h", k_options, NULL);
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
case 'h':
|
||||
default:
|
||||
show_usage = true;
|
||||
break;
|
||||
case 'i':
|
||||
identity = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
db_path = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (show_usage)
|
||||
{
|
||||
tf_printf("\n%s import [options] [paths...]\n\n", file);
|
||||
tf_printf("options:\n");
|
||||
tf_printf(" -i, --identity identity Identity to verify.\n");
|
||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", k_db_path_default);
|
||||
tf_printf(" -h, --help Show this usage information.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
tf_printf("Verifying %s...\n", identity);
|
||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
||||
bool verified = tf_ssb_db_verify(ssb, identity);
|
||||
tf_ssb_destroy(ssb);
|
||||
return verified ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct tf_run_args_t
|
||||
|
140
src/ssb.c
140
src/ssb.c
@ -342,8 +342,6 @@ typedef struct _tf_ssb_connection_t
|
||||
|
||||
tf_ssb_debug_message_t* debug_messages[k_debug_close_message_count];
|
||||
int ref_count;
|
||||
|
||||
int read_back_pressure;
|
||||
} tf_ssb_connection_t;
|
||||
|
||||
static JSClassID _connection_class_id;
|
||||
@ -1021,18 +1019,7 @@ static bool _tf_ssb_verify_and_strip_signature_internal(JSContext* context, JSVa
|
||||
|
||||
bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* out_id, size_t out_id_size, char* out_signature, size_t out_signature_size, int* out_flags)
|
||||
{
|
||||
JSValue reordered = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous"));
|
||||
JS_SetPropertyStr(context, reordered, "author", JS_GetPropertyStr(context, val, "author"));
|
||||
JS_SetPropertyStr(context, reordered, "sequence", JS_GetPropertyStr(context, val, "sequence"));
|
||||
JS_SetPropertyStr(context, reordered, "timestamp", JS_GetPropertyStr(context, val, "timestamp"));
|
||||
JS_SetPropertyStr(context, reordered, "hash", JS_GetPropertyStr(context, val, "hash"));
|
||||
JS_SetPropertyStr(context, reordered, "content", JS_GetPropertyStr(context, val, "content"));
|
||||
JS_SetPropertyStr(context, reordered, "signature", JS_GetPropertyStr(context, val, "signature"));
|
||||
bool result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_id, out_id_size, out_signature, out_signature_size);
|
||||
JS_FreeValue(context, reordered);
|
||||
|
||||
if (result)
|
||||
if (_tf_ssb_verify_and_strip_signature_internal(context, val, out_id, out_id_size, out_signature, out_signature_size))
|
||||
{
|
||||
if (out_flags)
|
||||
{
|
||||
@ -1040,26 +1027,27 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
reordered = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous"));
|
||||
JS_SetPropertyStr(context, reordered, "sequence", JS_GetPropertyStr(context, val, "sequence"));
|
||||
JS_SetPropertyStr(context, reordered, "author", JS_GetPropertyStr(context, val, "author"));
|
||||
JS_SetPropertyStr(context, reordered, "timestamp", JS_GetPropertyStr(context, val, "timestamp"));
|
||||
JS_SetPropertyStr(context, reordered, "hash", JS_GetPropertyStr(context, val, "hash"));
|
||||
JS_SetPropertyStr(context, reordered, "content", JS_GetPropertyStr(context, val, "content"));
|
||||
JS_SetPropertyStr(context, reordered, "signature", JS_GetPropertyStr(context, val, "signature"));
|
||||
result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_id, out_id_size, out_signature, out_signature_size);
|
||||
JS_FreeValue(context, reordered);
|
||||
if (result)
|
||||
else
|
||||
{
|
||||
if (out_flags)
|
||||
JSValue reordered = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous"));
|
||||
JS_SetPropertyStr(context, reordered, "sequence", JS_GetPropertyStr(context, val, "sequence"));
|
||||
JS_SetPropertyStr(context, reordered, "author", JS_GetPropertyStr(context, val, "author"));
|
||||
JS_SetPropertyStr(context, reordered, "timestamp", JS_GetPropertyStr(context, val, "timestamp"));
|
||||
JS_SetPropertyStr(context, reordered, "hash", JS_GetPropertyStr(context, val, "hash"));
|
||||
JS_SetPropertyStr(context, reordered, "content", JS_GetPropertyStr(context, val, "content"));
|
||||
JS_SetPropertyStr(context, reordered, "signature", JS_GetPropertyStr(context, val, "signature"));
|
||||
bool result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_id, out_id_size, out_signature, out_signature_size);
|
||||
JS_FreeValue(context, reordered);
|
||||
if (result)
|
||||
{
|
||||
*out_flags = k_tf_ssb_message_flag_sequence_before_author;
|
||||
if (out_flags)
|
||||
{
|
||||
*out_flags = k_tf_ssb_message_flag_sequence_before_author;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1620,7 +1608,6 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
||||
}
|
||||
if (!found && !_tf_ssb_name_equals(context, val, (const char*[]) { "Error", NULL }))
|
||||
{
|
||||
tf_ssb_connection_add_request(connection, -request_number, namebuf, NULL, NULL, NULL, NULL);
|
||||
char buffer[256];
|
||||
_tf_ssb_name_to_string(context, val, buffer, sizeof(buffer));
|
||||
tf_ssb_connection_rpc_send_error_method_not_allowed(connection, flags, -request_number, buffer);
|
||||
@ -2064,30 +2051,6 @@ static void _tf_ssb_connection_client_send_hello(tf_ssb_connection_t* connection
|
||||
connection->state = k_tf_ssb_state_sent_hello;
|
||||
}
|
||||
|
||||
static bool _tf_ssb_connection_read_start(tf_ssb_connection_t* connection)
|
||||
{
|
||||
int result = uv_read_start((uv_stream_t*)&connection->tcp, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
||||
if (result && result != UV_EALREADY)
|
||||
{
|
||||
tf_printf("uv_read_start => %s\n", uv_strerror(result));
|
||||
_tf_ssb_connection_close(connection, "uv_read_start failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _tf_ssb_connection_read_stop(tf_ssb_connection_t* connection)
|
||||
{
|
||||
int result = uv_read_stop((uv_stream_t*)&connection->tcp);
|
||||
if (result && result != UV_EALREADY)
|
||||
{
|
||||
tf_printf("uv_read_stop => %s\n", uv_strerror(result));
|
||||
_tf_ssb_connection_close(connection, "uv_read_stop failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _tf_ssb_connection_on_connect(uv_connect_t* connect, int status)
|
||||
{
|
||||
tf_ssb_connection_t* connection = connect->data;
|
||||
@ -2095,7 +2058,13 @@ static void _tf_ssb_connection_on_connect(uv_connect_t* connect, int status)
|
||||
if (status == 0)
|
||||
{
|
||||
connection->state = k_tf_ssb_state_connected;
|
||||
if (_tf_ssb_connection_read_start(connection))
|
||||
int result = uv_read_start(connect->handle, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
||||
if (result)
|
||||
{
|
||||
tf_printf("uv_read_start => %s\n", uv_strerror(status));
|
||||
_tf_ssb_connection_close(connection, "uv_read_start failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
_tf_ssb_connection_client_send_hello(connection);
|
||||
}
|
||||
@ -2586,11 +2555,6 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
||||
}
|
||||
}
|
||||
|
||||
bool tf_ssb_is_shutting_down(tf_ssb_t* ssb)
|
||||
{
|
||||
return ssb->shutting_down;
|
||||
}
|
||||
|
||||
void tf_ssb_run(tf_ssb_t* ssb)
|
||||
{
|
||||
uv_run(ssb->loop, UV_RUN_DEFAULT);
|
||||
@ -2748,30 +2712,22 @@ typedef struct _connect_t
|
||||
static void _tf_on_connect_getaddrinfo(uv_getaddrinfo_t* addrinfo, int result, struct addrinfo* info)
|
||||
{
|
||||
connect_t* connect = addrinfo->data;
|
||||
if (!connect->ssb->shutting_down)
|
||||
if (result == 0 && info)
|
||||
{
|
||||
if (result == 0 && info)
|
||||
{
|
||||
struct sockaddr_in addr = *(struct sockaddr_in*)info->ai_addr;
|
||||
addr.sin_port = htons(connect->port);
|
||||
tf_ssb_connection_create(connect->ssb, connect->host, &addr, connect->key);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("getaddrinfo(%s) => %s\n", connect->host, uv_strerror(result));
|
||||
}
|
||||
struct sockaddr_in addr = *(struct sockaddr_in*)info->ai_addr;
|
||||
addr.sin_port = htons(connect->port);
|
||||
tf_ssb_connection_create(connect->ssb, connect->host, &addr, connect->key);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("getaddrinfo(%s) => %s\n", connect->host, uv_strerror(result));
|
||||
}
|
||||
uv_freeaddrinfo(info);
|
||||
tf_ssb_unref(connect->ssb);
|
||||
tf_free(connect);
|
||||
uv_freeaddrinfo(info);
|
||||
}
|
||||
|
||||
void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* key)
|
||||
{
|
||||
if (ssb->shutting_down)
|
||||
{
|
||||
return;
|
||||
}
|
||||
connect_t* connect = tf_malloc(sizeof(connect_t));
|
||||
*connect = (connect_t) {
|
||||
.ssb = ssb,
|
||||
@ -2783,13 +2739,11 @@ void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* ke
|
||||
tf_ssb_connections_store(ssb->connections_tracker, host, port, id);
|
||||
snprintf(connect->host, sizeof(connect->host), "%s", host);
|
||||
memcpy(connect->key, key, k_id_bin_len);
|
||||
tf_ssb_ref(ssb);
|
||||
int r = uv_getaddrinfo(ssb->loop, &connect->req, _tf_on_connect_getaddrinfo, host, NULL, &(struct addrinfo) { .ai_family = AF_INET });
|
||||
if (r < 0)
|
||||
{
|
||||
tf_printf("uv_getaddrinfo: %s\n", uv_strerror(r));
|
||||
tf_free(connect);
|
||||
tf_ssb_unref(ssb);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2846,7 +2800,7 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
|
||||
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_create, connection);
|
||||
|
||||
connection->state = k_tf_ssb_state_server_wait_hello;
|
||||
_tf_ssb_connection_read_start(connection);
|
||||
uv_read_start((uv_stream_t*)&connection->tcp, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
||||
}
|
||||
|
||||
static void _tf_ssb_send_broadcast(tf_ssb_t* ssb, struct sockaddr_in* address, struct sockaddr_in* netmask)
|
||||
@ -3654,6 +3608,7 @@ void tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, tf_ssb_
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("nope\n");
|
||||
_tf_ssb_verify_strip_and_store_finish(async);
|
||||
}
|
||||
}
|
||||
@ -4085,26 +4040,3 @@ JSValue tf_ssb_connection_requests_to_object(tf_ssb_connection_t* connection)
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void tf_ssb_connection_adjust_read_backpressure(tf_ssb_connection_t* connection, int delta)
|
||||
{
|
||||
const int k_threshold = 256;
|
||||
int old_pressure = connection->read_back_pressure;
|
||||
connection->read_back_pressure += delta;
|
||||
if (!connection->closing)
|
||||
{
|
||||
if (old_pressure < k_threshold && connection->read_back_pressure >= k_threshold)
|
||||
{
|
||||
_tf_ssb_connection_read_stop(connection);
|
||||
}
|
||||
else if (old_pressure >= k_threshold && connection->read_back_pressure < k_threshold)
|
||||
{
|
||||
_tf_ssb_connection_read_start(connection);
|
||||
}
|
||||
}
|
||||
connection->ref_count += delta;
|
||||
if (connection->ref_count == 0 && connection->closing)
|
||||
{
|
||||
_tf_ssb_connection_destroy(connection, "backpressure released");
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,6 @@ typedef struct _tf_ssb_connections_get_next_t
|
||||
static void _tf_ssb_connections_get_next_work(tf_ssb_t* ssb, void* user_data)
|
||||
{
|
||||
tf_ssb_connections_get_next_t* next = user_data;
|
||||
if (tf_ssb_is_shutting_down(ssb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
next->ready = _tf_ssb_connections_get_next_connection(next->connections, next->host, sizeof(next->host), &next->port, next->key, sizeof(next->key));
|
||||
}
|
||||
|
||||
@ -163,10 +159,6 @@ typedef struct _tf_ssb_connections_update_t
|
||||
static void _tf_ssb_connections_update_work(tf_ssb_t* ssb, void* user_data)
|
||||
{
|
||||
tf_ssb_connections_update_t* update = user_data;
|
||||
if (tf_ssb_is_shutting_down(ssb))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sqlite3_stmt* statement;
|
||||
sqlite3* db = tf_ssb_acquire_db_writer(ssb);
|
||||
if (update->attempted)
|
||||
|
102
src/ssb.db.c
102
src/ssb.db.c
@ -163,7 +163,6 @@ void tf_ssb_db_init(tf_ssb_t* ssb)
|
||||
" private_key TEXT UNIQUE"
|
||||
")");
|
||||
_tf_ssb_db_exec(db, "CREATE INDEX IF NOT EXISTS identities_user ON identities (user, public_key)");
|
||||
_tf_ssb_db_exec(db, "DELETE FROM identities WHERE user = ':auth'");
|
||||
|
||||
bool populate_fts = false;
|
||||
if (!_tf_ssb_db_has_rows(db, "PRAGMA table_list('messages_fts')"))
|
||||
@ -736,12 +735,12 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char*
|
||||
return result;
|
||||
}
|
||||
|
||||
bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, char* out_previous,
|
||||
size_t out_previous_size, double* out_timestamp, char** out_content, char* out_hash, size_t out_hash_size, char* out_signature, size_t out_signature_size, int* out_flags)
|
||||
bool tf_ssb_db_get_message_by_author_and_sequence(
|
||||
tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, double* out_timestamp, char** out_content)
|
||||
{
|
||||
bool found = false;
|
||||
sqlite3_stmt* statement;
|
||||
const char* query = "SELECT id, previous, timestamp, json(content), hash, signature, flags FROM messages WHERE author = ?1 AND sequence = ?2";
|
||||
const char* query = "SELECT id, timestamp, json(content) FROM messages WHERE author = ?1 AND sequence = ?2";
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
@ -749,41 +748,15 @@ bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* aut
|
||||
{
|
||||
if (out_message_id)
|
||||
{
|
||||
snprintf(out_message_id, out_message_id_size, "%s", (const char*)sqlite3_column_text(statement, 0));
|
||||
}
|
||||
if (out_previous)
|
||||
{
|
||||
if (sqlite3_column_type(statement, 1) == SQLITE_NULL)
|
||||
{
|
||||
if (out_previous_size)
|
||||
{
|
||||
*out_previous = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(out_previous, out_previous_size, "%s", (const char*)sqlite3_column_text(statement, 1));
|
||||
}
|
||||
strncpy(out_message_id, (const char*)sqlite3_column_text(statement, 0), out_message_id_size - 1);
|
||||
}
|
||||
if (out_timestamp)
|
||||
{
|
||||
*out_timestamp = sqlite3_column_double(statement, 2);
|
||||
*out_timestamp = sqlite3_column_double(statement, 1);
|
||||
}
|
||||
if (out_content)
|
||||
{
|
||||
*out_content = tf_strdup((const char*)sqlite3_column_text(statement, 3));
|
||||
}
|
||||
if (out_hash)
|
||||
{
|
||||
snprintf(out_hash, out_hash_size, "%s", (const char*)sqlite3_column_text(statement, 4));
|
||||
}
|
||||
if (out_signature)
|
||||
{
|
||||
snprintf(out_signature, out_signature_size, "%s", (const char*)sqlite3_column_text(statement, 5));
|
||||
}
|
||||
if (out_flags)
|
||||
{
|
||||
*out_flags = sqlite3_column_int(statement, 6);
|
||||
*out_content = tf_strdup((const char*)sqlite3_column_text(statement, 2));
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
@ -1661,7 +1634,6 @@ bool tf_ssb_db_register_account(tf_ssb_t* ssb, const char* name, const char* pas
|
||||
{
|
||||
if (sqlite3_bind_text(statement, 1, value, value_length, NULL) == SQLITE_OK)
|
||||
{
|
||||
tf_printf("added user to properties\n");
|
||||
result = sqlite3_step(statement) == SQLITE_DONE;
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
@ -1812,65 +1784,3 @@ void tf_ssb_db_resolve_index_async(tf_ssb_t* ssb, const char* host, void (*callb
|
||||
};
|
||||
tf_ssb_run_work(ssb, _tf_ssb_db_resolve_index_work, _tf_ssb_db_resolve_index_after_work, request);
|
||||
}
|
||||
|
||||
bool tf_ssb_db_verify(tf_ssb_t* ssb, const char* id)
|
||||
{
|
||||
JSContext* context = tf_ssb_get_context(ssb);
|
||||
bool verified = true;
|
||||
int64_t sequence = -1;
|
||||
if (tf_ssb_db_get_latest_message_by_author(ssb, id, &sequence, NULL, 0))
|
||||
{
|
||||
for (int64_t i = 1; i <= sequence; i++)
|
||||
{
|
||||
char message_id[k_id_base64_len];
|
||||
char previous[256];
|
||||
double timestamp;
|
||||
char* content = NULL;
|
||||
char hash[32];
|
||||
char signature[256];
|
||||
int flags = 0;
|
||||
if (tf_ssb_db_get_message_by_author_and_sequence(
|
||||
ssb, id, i, message_id, sizeof(message_id), previous, sizeof(previous), ×tamp, &content, hash, sizeof(hash), signature, sizeof(signature), &flags))
|
||||
{
|
||||
JSValue message = tf_ssb_format_message(context, previous, id, i, timestamp, hash, content, signature, flags);
|
||||
char calculated_id[k_id_base64_len];
|
||||
char extracted_signature[256];
|
||||
int calculated_flags = 0;
|
||||
if (!tf_ssb_verify_and_strip_signature(context, message, calculated_id, sizeof(calculated_id), extracted_signature, sizeof(extracted_signature), &calculated_flags))
|
||||
{
|
||||
tf_printf("author=%s sequence=%" PRId64 " verify failed.\n", id, i);
|
||||
verified = false;
|
||||
}
|
||||
if (calculated_flags != flags)
|
||||
{
|
||||
tf_printf("author=%s sequence=%" PRId64 " flag mismatch %d => %d.\n", id, i, flags, calculated_flags);
|
||||
verified = false;
|
||||
}
|
||||
if (strcmp(message_id, calculated_id))
|
||||
{
|
||||
tf_printf("author=%s sequence=%" PRId64 " id mismatch %s => %s.\n", id, i, message_id, calculated_id);
|
||||
verified = false;
|
||||
}
|
||||
JS_FreeValue(context, message);
|
||||
tf_free(content);
|
||||
|
||||
if (!verified)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("Unable to find message with sequence=%" PRId64 " for author=%s.", i, id);
|
||||
verified = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("Unable to get latest message for author '%s'.\n", id);
|
||||
verified = false;
|
||||
}
|
||||
return verified;
|
||||
}
|
||||
|
19
src/ssb.db.h
19
src/ssb.db.h
@ -122,19 +122,12 @@ JSValue tf_ssb_db_get_message_by_id(tf_ssb_t* ssb, const char* id, bool is_keys)
|
||||
** @param sequence The message sequence number.
|
||||
** @param[out] out_message_id Populated with the message identifier.
|
||||
** @param out_message_id_size The size of the out_message_id buffer.
|
||||
** @param[out] out_previous Populated with the previous message identifier.
|
||||
** @param out_previous_size The size of the out_previous buffer.
|
||||
** @param[out] out_timestamp Populated with the timestamp.
|
||||
** @param[out] out_content Populated with the message content. Free with tf_free().
|
||||
** @param[out] out_hash Populated with the message hash format.
|
||||
** @param out_hash_size The size of the out_hash buffer.
|
||||
** @param[out] out_signature Populated with the message signature.
|
||||
** @param out_signature_size The size of the out_signature buffer.
|
||||
** @param[out] out_flags Populated with flags describing the format of the message.
|
||||
** @return True if the message was found and retrieved.
|
||||
*/
|
||||
bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, char* out_previous,
|
||||
size_t out_previous_size, double* out_timestamp, char** out_content, char* out_hash, size_t out_hash_size, char* out_signature, size_t out_signature_size, int* out_flags);
|
||||
bool tf_ssb_db_get_message_by_author_and_sequence(
|
||||
tf_ssb_t* ssb, const char* author, int64_t sequence, char* out_message_id, size_t out_message_id_size, double* out_timestamp, char** out_content);
|
||||
|
||||
/**
|
||||
** Get information about the last message from an author.
|
||||
@ -386,14 +379,6 @@ bool tf_ssb_db_set_property(tf_ssb_t* ssb, const char* id, const char* key, cons
|
||||
*/
|
||||
void tf_ssb_db_resolve_index_async(tf_ssb_t* ssb, const char* host, void (*callback)(const char* path, void* user_data), void* user_data);
|
||||
|
||||
/**
|
||||
** Verify an author's feed.
|
||||
** @param ssb The SSB instance.
|
||||
** @param id The author'd identity.
|
||||
** @return true If the feed verified successfully.
|
||||
*/
|
||||
bool tf_ssb_db_verify(tf_ssb_t* ssb, const char* id);
|
||||
|
||||
/**
|
||||
** An SQLite authorizer callback. See https://www.sqlite.org/c3ref/set_authorizer.html for use.
|
||||
** @param user_data User data registered with the authorizer.
|
||||
|
16
src/ssb.h
16
src/ssb.h
@ -144,13 +144,6 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path
|
||||
*/
|
||||
void tf_ssb_destroy(tf_ssb_t* ssb);
|
||||
|
||||
/**
|
||||
** Checking if the SSB instance is in the process of shutting down.
|
||||
** @param ssb The SSB instance.
|
||||
** @return true If the SSB instance is shutting down.
|
||||
*/
|
||||
bool tf_ssb_is_shutting_down(tf_ssb_t* ssb);
|
||||
|
||||
/**
|
||||
** Start optional periodic work.
|
||||
** @param ssb The SSB instance.
|
||||
@ -996,13 +989,4 @@ void tf_ssb_schedule_work(tf_ssb_t* ssb, int delay_ms, void (*callback)(tf_ssb_t
|
||||
*/
|
||||
bool tf_ssb_hmacsha256_verify(const char* public_key, const void* payload, size_t payload_length, const char* signature, bool signature_is_urlb64);
|
||||
|
||||
/**
|
||||
** Adjust read backpressure. If it gets too high, TCP receive will be paused
|
||||
** until it lowers.
|
||||
** @param connection The connection on which to affect backpressure.
|
||||
** @param delta The change in backpressure. Higher will eventually pause
|
||||
** receive. Lower will resume it.
|
||||
*/
|
||||
void tf_ssb_connection_adjust_read_backpressure(tf_ssb_connection_t* connection, int delta);
|
||||
|
||||
/** @} */
|
||||
|
49
src/ssb.js.c
49
src/ssb.js.c
@ -399,11 +399,10 @@ static void _tf_ssb_getIdentityInfo_visit(const char* identity, void* data)
|
||||
identity_info_work_t* request = data;
|
||||
request->identities = tf_resize_vec(request->identities, (request->count + 1) * sizeof(char*));
|
||||
request->names = tf_resize_vec(request->names, (request->count + 1) * sizeof(char*));
|
||||
char buffer[k_id_base64_len];
|
||||
snprintf(buffer, sizeof(buffer), "@%s", identity);
|
||||
request->identities[request->count] = tf_strdup(buffer);
|
||||
request->identities[request->count] = tf_strdup(identity);
|
||||
request->names[request->count] = NULL;
|
||||
request->count++;
|
||||
;
|
||||
}
|
||||
|
||||
static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data)
|
||||
@ -420,8 +419,8 @@ static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data)
|
||||
" RANK() OVER (PARTITION BY messages.author ORDER BY messages.sequence DESC) AS author_rank, "
|
||||
" messages.content ->> 'name' AS name "
|
||||
" FROM messages "
|
||||
" JOIN identities ON messages.author = ('@' || identities.public_key) "
|
||||
" WHERE identities.user = ? AND json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL) "
|
||||
" JOIN identities ON messages.author = ids.value "
|
||||
" WHERE WHERE identities.user = ? AND json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL) "
|
||||
"WHERE author_rank = 1 ",
|
||||
-1, &statement, NULL);
|
||||
if (request->result == SQLITE_OK)
|
||||
@ -429,26 +428,22 @@ static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data)
|
||||
if (sqlite3_bind_text(statement, 1, request->name, -1, NULL) == SQLITE_OK)
|
||||
{
|
||||
int r = SQLITE_OK;
|
||||
while ((r = sqlite3_step(statement)) == SQLITE_ROW)
|
||||
while ((r = sqlite3_step(statement)) == SQLITE_OK)
|
||||
{
|
||||
const char* identity = (const char*)sqlite3_column_text(statement, 0);
|
||||
const char* name = (const char*)sqlite3_column_text(statement, 1);
|
||||
for (int i = 0; i < request->count; i++)
|
||||
{
|
||||
if (!request->names[i] && strcmp(request->identities[i], identity) == 0)
|
||||
const char* identity = (const char*)sqlite3_column_text(statement, 0);
|
||||
const char* name = (const char*)sqlite3_column_text(statement, 1);
|
||||
if (strcmp(request->identities[i], identity) == 0 && !request->names[i])
|
||||
{
|
||||
request->names[i] = tf_strdup(name);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("prepare failed: %s.\n", sqlite3_errmsg(db));
|
||||
}
|
||||
|
||||
tf_ssb_db_identity_get_active(db, request->name, request->package_owner, request->package_name, request->active_identity, sizeof(request->active_identity));
|
||||
if (!*request->active_identity && request->count)
|
||||
@ -581,6 +576,29 @@ static JSValue _tf_ssb_appendMessageWithIdentity(JSContext* context, JSValueCons
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_getMessage(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_NULL;
|
||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||
if (ssb)
|
||||
{
|
||||
const char* id = JS_ToCString(context, argv[0]);
|
||||
int64_t sequence = 0;
|
||||
JS_ToInt64(context, &sequence, argv[1]);
|
||||
double timestamp = -1.0;
|
||||
char* contents = NULL;
|
||||
if (tf_ssb_db_get_message_by_author_and_sequence(ssb, id, sequence, NULL, 0, ×tamp, &contents))
|
||||
{
|
||||
result = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, result, "timestamp", JS_NewFloat64(context, timestamp));
|
||||
JS_SetPropertyStr(context, result, "content", JS_NewString(context, contents));
|
||||
tf_free(contents);
|
||||
}
|
||||
JS_FreeCString(context, id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_blobGet(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_NULL;
|
||||
@ -1873,6 +1891,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
|
||||
JS_SetPropertyStr(context, object, "getAllIdentities", JS_NewCFunction(context, _tf_ssb_getAllIdentities, "getAllIdentities", 0));
|
||||
JS_SetPropertyStr(context, object, "getActiveIdentity", JS_NewCFunction(context, _tf_ssb_getActiveIdentity, "getActiveIdentity", 3));
|
||||
JS_SetPropertyStr(context, object, "getIdentityInfo", JS_NewCFunction(context, _tf_ssb_getIdentityInfo, "getIdentityInfo", 3));
|
||||
JS_SetPropertyStr(context, object, "getMessage", JS_NewCFunction(context, _tf_ssb_getMessage, "getMessage", 2));
|
||||
JS_SetPropertyStr(context, object, "blobGet", JS_NewCFunction(context, _tf_ssb_blobGet, "blobGet", 1));
|
||||
JS_SetPropertyStr(context, object, "messageContentGet", JS_NewCFunction(context, _tf_ssb_messageContentGet, "messageContentGet", 1));
|
||||
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
|
||||
@ -1889,7 +1908,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
|
||||
JS_SetPropertyStr(context, object, "storeMessage", JS_NewCFunction(context, _tf_ssb_storeMessage, "storeMessage", 1));
|
||||
JS_SetPropertyStr(context, object, "blobStore", JS_NewCFunction(context, _tf_ssb_blobStore, "blobStore", 1));
|
||||
|
||||
/* Trusted only. */
|
||||
/* Should be trusted only. */
|
||||
JS_SetPropertyStr(context, object, "addEventListener", JS_NewCFunction(context, _tf_ssb_add_event_listener, "addEventListener", 2));
|
||||
JS_SetPropertyStr(context, object, "removeEventListener", JS_NewCFunction(context, _tf_ssb_remove_event_listener, "removeEventListener", 2));
|
||||
|
||||
|
@ -404,7 +404,6 @@ typedef struct _blobs_get_t
|
||||
bool done;
|
||||
bool storing;
|
||||
tf_ssb_t* ssb;
|
||||
tf_ssb_connection_t* connection;
|
||||
uint8_t buffer[];
|
||||
} blobs_get_t;
|
||||
|
||||
@ -412,7 +411,6 @@ static void _tf_ssb_rpc_blob_store_callback(const char* id, bool is_new, void* u
|
||||
{
|
||||
blobs_get_t* get = user_data;
|
||||
get->storing = false;
|
||||
tf_ssb_connection_adjust_read_backpressure(get->connection, -1);
|
||||
if (get->done)
|
||||
{
|
||||
tf_free(get);
|
||||
@ -435,7 +433,6 @@ static void _tf_ssb_rpc_connection_blobs_get_callback(
|
||||
if (JS_ToBool(context, args))
|
||||
{
|
||||
get->storing = true;
|
||||
tf_ssb_connection_adjust_read_backpressure(connection, 1);
|
||||
tf_ssb_db_blob_store_async(ssb, get->buffer, get->received, _tf_ssb_rpc_blob_store_callback, get);
|
||||
}
|
||||
/* TODO: Should we send the response in the callback? */
|
||||
@ -458,7 +455,7 @@ static void _tf_ssb_rpc_connection_blobs_get_cleanup(tf_ssb_t* ssb, void* user_d
|
||||
static void _tf_ssb_rpc_connection_blobs_get(tf_ssb_connection_t* connection, const char* blob_id, size_t size)
|
||||
{
|
||||
blobs_get_t* get = tf_malloc(sizeof(blobs_get_t) + size);
|
||||
*get = (blobs_get_t) { .ssb = tf_ssb_connection_get_ssb(connection), .connection = connection, .expected_size = size };
|
||||
*get = (blobs_get_t) { .ssb = tf_ssb_connection_get_ssb(connection), .expected_size = size };
|
||||
snprintf(get->id, sizeof(get->id), "%s", blob_id);
|
||||
memset(get->buffer, 0, size);
|
||||
|
||||
@ -1003,12 +1000,6 @@ static void _tf_ssb_rpc_ebt_replicate_send_messages(tf_ssb_connection_t* connect
|
||||
}
|
||||
}
|
||||
|
||||
static void _tf_ssb_rpc_ebt_replicate_store_callback(const char* id, bool verified, bool is_new, void* user_data)
|
||||
{
|
||||
tf_ssb_connection_t* connection = user_data;
|
||||
tf_ssb_connection_adjust_read_backpressure(connection, -1);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);
|
||||
@ -1031,8 +1022,7 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f
|
||||
if (!JS_IsUndefined(author))
|
||||
{
|
||||
/* Looks like a message. */
|
||||
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, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -83,13 +83,6 @@ try:
|
||||
driver.switch_to.frame(wait.until(expected_conditions.presence_of_element_located((By.ID, 'document'))))
|
||||
id1 = wait.until(expected_conditions.presence_of_element_located((By.TAG_NAME, 'li'))).text.split(' ')[-1]
|
||||
|
||||
driver.get('http://localhost:8888/~core/admin/')
|
||||
wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))
|
||||
driver.switch_to.frame(driver.find_element(By.ID, 'document'))
|
||||
wait.until(expected_conditions.presence_of_element_located((By.ID, 'gs_room_name'))).send_keys('test room')
|
||||
wait.until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="gs_room_name"]/following-sibling::button'))).click()
|
||||
driver.switch_to.alert.accept()
|
||||
|
||||
driver.get('http://localhost:8888')
|
||||
wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))
|
||||
driver.switch_to.frame(driver.find_element(By.ID, 'document'))
|
||||
@ -113,15 +106,9 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
# WebDriverException (shadow root is detached)
|
||||
while True:
|
||||
try:
|
||||
tf_tab_news = wait.until(exists_in_shadow_root(tf_app, By.ID, 'tf-tab-news')).shadow_root
|
||||
tf_tab_news.find_element(By.ID, 'tf-compose').shadow_root.find_element(By.ID, 'edit').send_keys('Hello, world!')
|
||||
tf_tab_news.find_element(By.ID, 'tf-compose').shadow_root.find_element(By.ID, 'submit').click()
|
||||
break
|
||||
except:
|
||||
pass
|
||||
tf_tab_news = wait.until(exists_in_shadow_root(tf_app, By.ID, 'tf-tab-news')).shadow_root
|
||||
tf_tab_news.find_element(By.ID, 'tf-compose').shadow_root.find_element(By.ID, 'edit').send_keys('Hello, world!')
|
||||
tf_tab_news.find_element(By.ID, 'tf-compose').shadow_root.find_element(By.ID, 'submit').click()
|
||||
|
||||
driver.switch_to.default_content()
|
||||
driver.find_element(By.ID, 'allow').click()
|
||||
|
Reference in New Issue
Block a user