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:
2025-05-19 00:06:23 -07:00
parent b49e760bf3
commit cedc1d7b36
4 changed files with 146 additions and 32 deletions

View File

@@ -573,17 +573,37 @@ class App {
mediaID: ''
};
}
async announceUser_rpc_response(sendingPeerID, userIDs) {
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) => {
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
@@ -599,16 +619,13 @@ class App {
// Would be lovely to show a little display of peers connecting, whether you're connected directly to a friend's peer etc.
// Basically that live "dandelion" display.
this.peerManager.registerRPC('announceUsers', (sendingPeerID, userIDs) => {
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) => {
return [1, 2, 3, 4, 5];
});
this.peerManager.registerRPC('getPostIDsForUser', (userID) => {
let postIDs = this.sync.getPostIdsForUser(userID);
this.peerManager.registerRPC('getPostIDsForUser', async (userID) => {
let postIDs = await this.sync.getPostIdsForUser(userID);
return postIDs;
});
await this.peerManager.connect();
@@ -1550,6 +1567,14 @@ class App {
Route[Route["CONNECT"] = 5] = "CONNECT";
})(Route = App.Route || (App.Route = {}));
;
function announceUser_rpc_response(sendingPeerID, userIDs) {
throw new Error("Function not implemented.");
}
App.announceUser_rpc_response = announceUser_rpc_response;
function announceUser_rpc_response(sendingPeerID, userIDs) {
throw new Error("Function not implemented.");
}
App.announceUser_rpc_response = announceUser_rpc_response;
// export function connect() {
// throw new Error("Function not implemented.");
// }