request post ids for users that match users we follow when peers announce users they know about. Fix for RPCs being async on the remote end. Check returned postIDs to see if we need any posts from a peer.
This commit is contained in:
53
src/main2.ts
53
src/main2.ts
@@ -741,20 +741,47 @@ class App {
|
||||
connectURL: string = "";
|
||||
firstRun = false;
|
||||
peerManager: PeerManager | null = null;
|
||||
sync:Sync = new Sync();
|
||||
sync: Sync = new Sync();
|
||||
|
||||
async announceUser_rpc_response(sendingPeerID: string, userIDs: string[]) {
|
||||
if (this.isBootstrapPeer) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log.apply(null, log(`announceUsers from ${sendingPeerID}`, userIDs));
|
||||
|
||||
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)) {
|
||||
let postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
|
||||
console.log.apply(null, log(`[app] announceUsers response, gotPostIDs`, postIDs));
|
||||
let neededPosts = await this.sync.checkPostIds(userID, sendingPeerID, postIDs);
|
||||
|
||||
console.log.apply(null, log(`[app] announceUsers needed posts`, neededPosts));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async connect() {
|
||||
this.peerManager = new PeerManager(this.userID, this.peerID, this.isBootstrapPeer);
|
||||
if (this.peerManager === null) {
|
||||
throw new Error();
|
||||
}
|
||||
this.registerRPCs();
|
||||
// this.registerRPCs();
|
||||
|
||||
this.peerManager.addEventListener(PeerEventTypes.PEER_CONNECTED, async (event: any) => {
|
||||
if (!this.peerManager) {
|
||||
throw new Error();
|
||||
}
|
||||
console.log.apply(null, log(`[app]: peer connected:${event.peerID}`));
|
||||
|
||||
if (this.isBootstrapPeer) {
|
||||
return;
|
||||
}
|
||||
|
||||
let knownUsers = await this.sync.getKnownUsers();
|
||||
this.peerManager.rpc.announceUsers(event.peerID, this.peerID, knownUsers);
|
||||
// rpc saying what peers we have
|
||||
@@ -776,11 +803,7 @@ class App {
|
||||
// Basically that live "dandelion" display.
|
||||
|
||||
this.peerManager.registerRPC('announceUsers', (sendingPeerID: string, userIDs: string[]) => {
|
||||
console.log.apply(null, log(`announceUsers from ${sendingPeerID}`, userIDs));
|
||||
|
||||
for (let userID of userIDs) {
|
||||
console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
||||
}
|
||||
this.announceUser_rpc_response(sendingPeerID, userIDs);
|
||||
});
|
||||
|
||||
this.peerManager.registerRPC('getPeersForUser', (userID: any) => {
|
||||
@@ -788,8 +811,8 @@ class App {
|
||||
});
|
||||
|
||||
|
||||
this.peerManager.registerRPC('getPostIDsForUser', (userID: any) => {
|
||||
let postIDs = this.sync.getPostIdsForUser(userID);
|
||||
this.peerManager.registerRPC('getPostIDsForUser', async (userID: any) => {
|
||||
let postIDs = await this.sync.getPostIdsForUser(userID);
|
||||
|
||||
return postIDs;
|
||||
});
|
||||
@@ -1647,7 +1670,7 @@ class App {
|
||||
let urlParams = (new URL(window.location.href)).searchParams;
|
||||
if (urlParams.has('log')) {
|
||||
this.showInfo();
|
||||
}
|
||||
}
|
||||
|
||||
this.isHeadless = /\bHeadlessChrome\//.test(navigator.userAgent) || urlParams.has('headless');
|
||||
this.isArchivePeer = urlParams.has('archive');
|
||||
@@ -1659,7 +1682,7 @@ class App {
|
||||
if (limitPostsParam) {
|
||||
this.limitPosts = parseInt(limitPostsParam);
|
||||
}
|
||||
|
||||
|
||||
this.peerID = this.getPeerID();
|
||||
this.peername = this.getPeername();
|
||||
this.userID = this.getUserID();
|
||||
@@ -2059,6 +2082,14 @@ namespace App {
|
||||
CONNECT,
|
||||
};
|
||||
|
||||
|
||||
export function announceUser_rpc_response(sendingPeerID: string, userIDs: string[]) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
|
||||
export function announceUser_rpc_response(sendingPeerID: string, userIDs: string[]) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
// export function connect() {
|
||||
// throw new Error("Function not implemented.");
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user