3 Commits

20 changed files with 180 additions and 91 deletions

View File

@@ -6,7 +6,7 @@
user_data_dir="${1:-./profile}"
user_id="${2:-b38b623c-c3fa-4351-9cab-50233c99fa4e}"
chromium-browser \
chromium \
--disable-setuid-sandbox \
--disable-infobars \
--no-first-run \

View File

@@ -361,7 +361,8 @@ async function main() {
messageDispatch.set('peer_message', peerMessageHandler);
Deno.serve({
port: 6789,
hostname: "[::]",
port: 443,
cert: Deno.readTextFileSync("/etc/letsencrypt/live/ddln.app/fullchain.pem"),
key: Deno.readTextFileSync("/etc/letsencrypt/live/ddln.app/privkey.pem"),
}, handler);

26
package-lock.json generated
View File

@@ -1,26 +0,0 @@
{
"name": "dandelion",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"devDependencies": {
"typescript": "^5.5.4"
}
},
"node_modules/typescript": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
}
}
}

View File

@@ -1,5 +1,5 @@
{
"devDependencies": {
"typescript": "^5.5.4"
"typescript": "5.8.3"
}
}

View File

@@ -1,7 +1,7 @@
import { generateID } from "IDUtils";
import { PeerManager, PeerEventTypes } from "PeerManager";
import { Sync } from "Sync";
import { openDatabase, getData, addData, addDataArray, clearData, deleteData, mergeDataArray, getAllData, checkPostIds, getAllIds, getPostsByIds } from "db";
import { openDatabase, getData, addData, addDataArray, clearData, deleteData, mergeDataArray, getAllData, checkPostIds, getAllIds, getPostsByIds, getPostForUser } from "db";
import { arrayBufferToBase64, compressString } from "dataUtils";
import { log, logID, renderLog, setLogVisibility } from "log"
@@ -189,7 +189,7 @@ export class App {
let neededPostCount = neededPostIDs.length;
this.statusBar.updatePeerStatus(peerID, `need(${logID(userID)} | ${neededPostCount})`, { havePostCount: 0, neededPostCount: neededPostCount });
let neededPosts = await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
}
else {
console.log.apply(null, log(`[app] Don't need any posts for user ${logID(userID)} from peer ${logID(peerID)}`));
@@ -236,15 +236,34 @@ export class App {
for (let userID of userIDs) {
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
this.sync.addUserPeer(userID, sendingPeerID);
if (!(this.sync.shouldSyncUserID(userID) || (this.router.route === App.Route.USER && userID === this.router.userID))) {
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
continue;
const isUserOrPostRoute = (this.router.route & (App.Route.USER | App.Route.POST)) !== 0;
if (isUserOrPostRoute) {
if (userID !== this.router.userID) {
continue;
}
} else {
if (!this.sync.shouldSyncUserID(userID)) {
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
continue;
}
}
console.log.apply(null, log(`[app] calling getPostIDsForUser for user [${logID(userID)}] on peer [${logID(sendingPeerID)}]`));
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
let postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
let postIDs = null;
if (this.router.route === App.Route.POST && this.router.userID == userID) {
postIDs = [this.router.postID];
} else {
postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
}
if (!postIDs) {
continue;
}
this.statusBar.updatePeerStatus(sendingPeerID, `syncing(${logID(userID)} ${postIDs.length})`);
@@ -306,6 +325,8 @@ export class App {
if (postIDs) {
return postIDs;
}
return [];
});
this.peerManager.registerRPC('getPostsForUser', async (requestingPeerID: string, userID: string, postIDs: string[]) => {
@@ -1078,17 +1099,23 @@ export class App {
this.timerStart();
let posts: StoragePost[] = [];
// if (postID) {
// posts = await gePostForUser(userID, postID);
// }
if (postID) {
const post = await getPostForUser(userID, postID);
posts = await getData(userID, new Date(2022, 8), new Date());
posts = post ? [post] : [];
if (posts.length > 0) {
} else {
posts = await getData(userID, new Date(2022, 8), new Date());
}
if (posts?.length) {
console.log.apply(null, log(`Loaded ${posts.length} posts in ${this.timerDelta().toFixed(2)}ms`));;
return posts;
}
console.log.apply(null, log(`No posts found for userID:${userID}, postID:${postID}`));;
// posts = await createTestData2(userID);
// log("Adding test data...");
@@ -1602,11 +1629,11 @@ export class App {
export namespace App {
export enum Route {
USER,
POST,
MEDIA,
GROUP,
HOME,
CONNECT,
USER = 1,
POST = 2,
MEDIA = 4,
GROUP = 8,
HOME = 16,
CONNECT = 32,
}
};

View File

@@ -553,12 +553,7 @@ class PeerConnection {
static config = {
iceServers: [
{ urls: "stun:ddln.app" },
// { urls: "turn:ddln.app", username: "a", credential: "b" },
{ urls: "stun:stun.l.google.com" }, // keeping this for now as my STUN server is not returning ipv6
{ urls: "stun:stun1.l.google.com" },
{ urls: "stun:stun2.l.google.com" },
{ urls: "stun:stun3.l.google.com" },
{ urls: "stun:stun4.l.google.com" },
{ urls: "turn:ddln.app", username: "ddln1", credential: "ddln1" },
],
};
// longMessageQueue: string[] = [];

View File

@@ -122,7 +122,8 @@ export class Sync {
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
'194696a2-d850-4bb0-98f7-47416b3d1662',
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
'dd1d92aa-aa24-4166-a925-94ba072a9048'
'dd1d92aa-aa24-4166-a925-94ba072a9048',
'290dbb4f-6ce1-491a-b90d-51d8efcd3d60'
]);
getFollowing(userID: string): string[] {

View File

@@ -36,7 +36,7 @@ export async function compressString(input: string) {
const compressedArray = await new Response(compressionStream.readable).arrayBuffer();
// Convert the compressed data to a Uint8Array
return new Uint8Array(compressedArray);
return compressedArray;
}
// Base58 character set

View File

@@ -198,15 +198,28 @@ export async function clearData(userID: string) {
}
}
// TODO - this function can return before the data is stored!
export async function addDataArray(userID: string, array: any[]): Promise<void> {
try {
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
transaction.onerror = (event: Event) => {
console.error('Error in adding data:', event);
}
let completionPromise = new Promise<void>((resolve, reject) => {
transaction.oncomplete = (event: Event) => {
resolve();
};
transaction.onerror = (event: Event) => {
console.error('Error in adding data:', event);
reject();
}
});
// let count = 0;
array.reverse();
@@ -230,6 +243,8 @@ export async function addDataArray(userID: string, array: any[]): Promise<void>
// }
}
return completionPromise;
} catch (error) {
console.error('Error in opening database:', error);
@@ -342,7 +357,21 @@ export async function mergeDataArray(userID: string, array: any[]): Promise<void
}
export async function getPostForUser(userID: string, postID: string): Promise<any | undefined> {
const { store } = await getDBTransactionStore(userID);
const index = store.index("postIDIndex");
return new Promise((resolve, reject) => {
const getPostRequest = index.get(postID);
getPostRequest.onsuccess = () => {
resolve(getPostRequest.result);
};
getPostRequest.onerror = () => {
console.error('Transaction failed:', getPostRequest.error?.message);
reject(getPostRequest.error);
};
});
}

View File

@@ -1,7 +1,7 @@
import { generateID } from "IDUtils";
import { PeerManager, PeerEventTypes } from "PeerManager";
import { Sync } from "Sync";
import { openDatabase, getData, addData, deleteData, getAllData } from "db";
import { openDatabase, getData, addData, deleteData, getAllData, getPostForUser } from "db";
import { arrayBufferToBase64, compressString } from "dataUtils";
import { log, logID, renderLog, setLogVisibility } from "log";
class Post {
@@ -139,7 +139,7 @@ export class App {
console.log.apply(null, log(`[app] Need (${neededPostIDs.length}) posts for user ${logID(userID)} from peer ${logID(peerID)}`));
let neededPostCount = neededPostIDs.length;
this.statusBar.updatePeerStatus(peerID, `need(${logID(userID)} | ${neededPostCount})`, { havePostCount: 0, neededPostCount: neededPostCount });
let neededPosts = await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
}
else {
console.log.apply(null, log(`[app] Don't need any posts for user ${logID(userID)} from peer ${logID(peerID)}`));
@@ -172,13 +172,30 @@ export class App {
for (let userID of userIDs) {
// console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
this.sync.addUserPeer(userID, sendingPeerID);
if (!(this.sync.shouldSyncUserID(userID) || (this.router.route === App.Route.USER && userID === this.router.userID))) {
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
continue;
const isUserOrPostRoute = (this.router.route & (App.Route.USER | App.Route.POST)) !== 0;
if (isUserOrPostRoute) {
if (userID !== this.router.userID) {
continue;
}
}
else {
if (!this.sync.shouldSyncUserID(userID)) {
console.log.apply(null, log(`[app] announceUser_rpc_response skipping user[${logID(userID)}] from[${logID(sendingPeerID)}]`));
continue;
}
}
console.log.apply(null, log(`[app] calling getPostIDsForUser for user [${logID(userID)}] on peer [${logID(sendingPeerID)}]`));
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
let postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
let postIDs = null;
if (this.router.route === App.Route.POST && this.router.userID == userID) {
postIDs = [this.router.postID];
}
else {
postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
}
if (!postIDs) {
continue;
}
this.statusBar.updatePeerStatus(sendingPeerID, `syncing(${logID(userID)} ${postIDs.length})`);
console.log.apply(null, log(`[app] Got (${postIDs.length}) post IDs for user [${logID(userID)}] from peer [${logID(sendingPeerID)}]`));
this.addPostIDsToSyncQueue(userID, sendingPeerID, postIDs);
@@ -223,6 +240,7 @@ export class App {
if (postIDs) {
return postIDs;
}
return [];
});
this.peerManager.registerRPC('getPostsForUser', async (requestingPeerID, userID, postIDs) => {
let posts = await this.sync.getPostsForUser(userID, postIDs);
@@ -798,15 +816,20 @@ export class App {
async loadPostsFromStorage(userID, postID) {
this.timerStart();
let posts = [];
// if (postID) {
// posts = await gePostForUser(userID, postID);
// }
posts = await getData(userID, new Date(2022, 8), new Date());
if (posts.length > 0) {
if (postID) {
const post = await getPostForUser(userID, postID);
posts = post ? [post] : [];
}
else {
posts = await getData(userID, new Date(2022, 8), new Date());
}
if (posts?.length) {
console.log.apply(null, log(`Loaded ${posts.length} posts in ${this.timerDelta().toFixed(2)}ms`));
;
return posts;
}
console.log.apply(null, log(`No posts found for userID:${userID}, postID:${postID}`));
;
// posts = await createTestData2(userID);
// log("Adding test data...");
// addDataArray(userID, posts);
@@ -1174,12 +1197,12 @@ export class App {
(function (App) {
let Route;
(function (Route) {
Route[Route["USER"] = 0] = "USER";
Route[Route["POST"] = 1] = "POST";
Route[Route["MEDIA"] = 2] = "MEDIA";
Route[Route["GROUP"] = 3] = "GROUP";
Route[Route["HOME"] = 4] = "HOME";
Route[Route["CONNECT"] = 5] = "CONNECT";
Route[Route["USER"] = 1] = "USER";
Route[Route["POST"] = 2] = "POST";
Route[Route["MEDIA"] = 4] = "MEDIA";
Route[Route["GROUP"] = 8] = "GROUP";
Route[Route["HOME"] = 16] = "HOME";
Route[Route["CONNECT"] = 32] = "CONNECT";
})(Route = App.Route || (App.Route = {}));
})(App || (App = {}));
;

File diff suppressed because one or more lines are too long

View File

@@ -727,12 +727,7 @@ class PeerConnection {
PeerConnection.config = {
iceServers: [
{ urls: "stun:ddln.app" },
// { urls: "turn:ddln.app", username: "a", credential: "b" },
{ urls: "stun:stun.l.google.com" }, // keeping this for now as my STUN server is not returning ipv6
{ urls: "stun:stun1.l.google.com" },
{ urls: "stun:stun2.l.google.com" },
{ urls: "stun:stun3.l.google.com" },
{ urls: "stun:stun4.l.google.com" },
{ urls: "turn:ddln.app", username: "ddln1", credential: "ddln1" },
],
};
//# sourceMappingURL=PeerManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -44,7 +44,8 @@ export class Sync {
'e01eff89-5100-4b35-af4c-1c1bcb007dd0',
'194696a2-d850-4bb0-98f7-47416b3d1662',
'f6b21eb1-a0ff-435b-8efc-6a3dd70c0dca',
'dd1d92aa-aa24-4166-a925-94ba072a9048'
'dd1d92aa-aa24-4166-a925-94ba072a9048',
'290dbb4f-6ce1-491a-b90d-51d8efcd3d60'
]);
// async getPostIdsForUserHandler(data: any) {
// let message = data.message;

File diff suppressed because one or more lines are too long

View File

@@ -34,5 +34,28 @@
"protocol": "web+ddln",
"url": "/%s"
}
]
],
"share_target": {
"action": "/share-target",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"title": "name",
"text": "text",
"url": "link",
"files": [
{
"name": "photos",
"accept": [
"image/svg+xml",
".svg",
".jpg",
".jpeg",
".png",
".gif"
]
}
]
}
}
}

View File

@@ -29,7 +29,7 @@ export async function compressString(input) {
// Read the compressed data from the stream
const compressedArray = await new Response(compressionStream.readable).arrayBuffer();
// Convert the compressed data to a Uint8Array
return new Uint8Array(compressedArray);
return compressedArray;
}
// Base58 character set
// const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';

View File

@@ -1 +1 @@
{"version":3,"file":"dataUtils.js","sourceRoot":"","sources":["../src/dataUtils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,KAAiB,EAAE,IAAI,GAAG,0BAA0B;IAC7F,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,EAAE,EAAE;YAC7C,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YACpC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;SACpC,CAAC,CAAC;QACH,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,C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CAAqC;IACrC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE7C,6BAA6B;IAC7B,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;IAEtD,sCAAsC;IACtC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,2CAA2C;IAC3C,MAAM,eAAe,GAAG,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAErF,8CAA8C;IAC9C,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,uBAAuB;AACvB,wFAAwF;AACxF,kBAAkB;AAClB,kBAAkB;AAClB,sDAAsD;AACtD,eAAe;AACf,wBAAwB;AAExB,iCAAiC;AACjC,oBAAoB;AACpB,gDAAgD;AAChD,iCAAiC;AACjC,gCAAgC;AAChC,wCAAwC;AACxC,QAAQ;AACR,0BAA0B;AAC1B,iCAAiC;AACjC,wCAAwC;AACxC,QAAQ;AACR,MAAM;AAEN,qBAAqB;AACrB,4CAA4C;AAC5C,wCAAwC;AACxC,MAAM;AAEN,iCAAiC;AACjC,iCAAiC;AACjC,2BAA2B;AAC3B,8CAA8C;AAC9C,eAAe;AACf,eAAe;AACf,QAAQ;AACR,MAAM;AAEN,mBAAmB;AACnB,IAAI;AAEJ,4BAA4B;AAC5B,gDAAgD;AAChD,qCAAqC;AACrC,gCAAgC;AAChC,IAAI"}

View File

@@ -147,12 +147,19 @@ export async function clearData(userID) {
console.error('Error in opening database:', error);
}
}
// TODO - this function can return before the data is stored!
export async function addDataArray(userID, array) {
try {
const { db, transaction, store } = await getDBTransactionStore(userID, "readwrite");
transaction.onerror = (event) => {
console.error('Error in adding data:', event);
};
let completionPromise = new Promise((resolve, reject) => {
transaction.oncomplete = (event) => {
resolve();
};
transaction.onerror = (event) => {
console.error('Error in adding data:', event);
reject();
};
});
// let count = 0;
array.reverse();
for (let data of array) {
@@ -170,6 +177,7 @@ export async function addDataArray(userID, array) {
// console.log(`Added ${count} posts...`);
// }
}
return completionPromise;
}
catch (error) {
console.error('Error in opening database:', error);
@@ -260,6 +268,18 @@ export async function mergeDataArray(userID, array) {
}
}
export async function getPostForUser(userID, postID) {
const { store } = await getDBTransactionStore(userID);
const index = store.index("postIDIndex");
return new Promise((resolve, reject) => {
const getPostRequest = index.get(postID);
getPostRequest.onsuccess = () => {
resolve(getPostRequest.result);
};
getPostRequest.onerror = () => {
console.error('Transaction failed:', getPostRequest.error?.message);
reject(getPostRequest.error);
};
});
}
export async function getData(userID, lowerID, upperID) {
const { store } = await getDBTransactionStore(userID);

File diff suppressed because one or more lines are too long