Consider the boostrap peer as a real peer for reconnect purposes. We really need more intelligent syncing overall.

This commit is contained in:
2025-05-30 19:13:40 -07:00
parent a840464152
commit c171906b03

View File

@@ -44,7 +44,7 @@ export class PeerManager {
messageSuperlog = false;
watchdogInterval: number = 0;
reconnectTimer: number | null = null;
peerStateSuperlog: boolean = false;
peerStateSuperlog: boolean = true;
// async watchdog() {
// // Check that we're connected to at least N peers. If not, reconnect to the bootstrap server.
@@ -293,7 +293,7 @@ export class PeerManager {
let numActive = 0;
for (let [id, peer] of this.peers) {
if (id === this.bootstrapPeerID ||
if (/*id === this.bootstrapPeerID ||*/
peer.rtcPeer?.connectionState === "new" ||
peer.rtcPeer?.connectionState === "connecting"
) {
@@ -396,11 +396,11 @@ export class PeerManager {
}
}
onPeerDisconnected(remotePeerID: PeerID) {
let deleted = this.peers.delete(remotePeerID);
onPeerDisconnected(peerID: PeerID) {
let deleted = this.peers.delete(peerID);
if (!deleted) {
throw new Error(`Can't find peer that disconnected ${remotePeerID}`);
throw new Error(`Can't find peer that disconnected ${peerID}`);
}
// TODO: What do we do if we lose connection to the bootstrap peer?
@@ -409,12 +409,14 @@ export class PeerManager {
// We should disconnect from the websocket once we connect to our intial peers.
// If we have no peer connections, try to connect. If connection fails, start a timer to reconnect.
if (remotePeerID === this.bootstrapPeerID) {
if (peerID === this.bootstrapPeerID) {
this.bootstrapPeerID = null;
this.bootstrapPeerConnection = null;
}
this.dispatchEvent(PeerEventTypes.PEER_DISCONNECTED, { peerID: remotePeerID });
this.peerStateSuperlog && console.log.apply(null, log(`PeerManager: disconnected from peer ${peerID}`));
this.dispatchEvent(PeerEventTypes.PEER_DISCONNECTED, { peerID: peerID });
}
@@ -518,8 +520,8 @@ 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: "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" },