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; messageSuperlog = false;
watchdogInterval: number = 0; watchdogInterval: number = 0;
reconnectTimer: number | null = null; reconnectTimer: number | null = null;
peerStateSuperlog: boolean = false; peerStateSuperlog: boolean = true;
// async watchdog() { // async watchdog() {
// // Check that we're connected to at least N peers. If not, reconnect to the bootstrap server. // // 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; let numActive = 0;
for (let [id, peer] of this.peers) { for (let [id, peer] of this.peers) {
if (id === this.bootstrapPeerID || if (/*id === this.bootstrapPeerID ||*/
peer.rtcPeer?.connectionState === "new" || peer.rtcPeer?.connectionState === "new" ||
peer.rtcPeer?.connectionState === "connecting" peer.rtcPeer?.connectionState === "connecting"
) { ) {
@@ -396,11 +396,11 @@ export class PeerManager {
} }
} }
onPeerDisconnected(remotePeerID: PeerID) { onPeerDisconnected(peerID: PeerID) {
let deleted = this.peers.delete(remotePeerID); let deleted = this.peers.delete(peerID);
if (!deleted) { 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? // 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. // 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 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.bootstrapPeerID = null;
this.bootstrapPeerConnection = 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 = { static config = {
iceServers: [ iceServers: [
{ urls: "stun:ddln.app" }, { urls: "stun:ddln.app" },
{ urls: "turn:ddln.app", username: "a", credential: "b" }, // { 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:stun.l.google.com" }, // keeping this for now as my STUN server is not returning ipv6
// { urls: "stun:stun1.l.google.com" }, // { urls: "stun:stun1.l.google.com" },
// { urls: "stun:stun2.l.google.com" }, // { urls: "stun:stun2.l.google.com" },
// { urls: "stun:stun3.l.google.com" }, // { urls: "stun:stun3.l.google.com" },