refactor: reconnectDelay and _peers need to store by the string version of peer id

This commit is contained in:
Derrick Hammer 2023-08-31 02:32:04 -04:00
parent 56bb5007f6
commit 91034708bc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 8 deletions

View File

@ -170,9 +170,9 @@ export class P2PService {
continue; continue;
} }
if (this._peers.has(peerId)) { if (this._peers.has(peerId.toString())) {
try { try {
this._peers.get(peerId)?.sendMessage(event); this._peers.get(peerId.toString())?.sendMessage(event);
} catch (e) { } catch (e) {
this.logger.catched(e); this.logger.catched(e);
} }
@ -211,8 +211,8 @@ export class P2PService {
throw "Remote node does not support required features"; throw "Remote node does not support required features";
} }
this._peers.set(peer.id, peer); this._peers.set(peer.id.toString(), peer);
this.reconnectDelay.set(peer.id, 1); this.reconnectDelay.set(peer.id.toString(), 1);
const connectionUrisCount = u.unpackInt() as number; const connectionUrisCount = u.unpackInt() as number;
@ -257,7 +257,11 @@ export class P2PService {
// TODO Fully support multiple connection uris // TODO Fully support multiple connection uris
const uri = new URL(connectionUris[0].toString()); const uri = new URL(connectionUris[0].toString());
uri.username = id.toBase58(); uri.username = id.toBase58();
if (!this.reconnectDelay.has(NodeId.decode(uri.username))) { if (
!this.reconnectDelay.has(
NodeId.decode(uri.username).toString(),
)
) {
this.connectToNode([uri]); this.connectToNode([uri]);
} }
} }
@ -274,8 +278,8 @@ export class P2PService {
{ {
onDone: async () => { onDone: async () => {
try { try {
if (this._peers.has(peer.id)) { if (this._peers.has(peer.id.toString())) {
this._peers.delete(peer.id); this._peers.delete(peer.id.toString());
this.logger.info( this.logger.info(
`[-] ${peer.id.toString()} (${peer `[-] ${peer.id.toString()} (${peer
.renderLocationUri() .renderLocationUri()
@ -480,7 +484,10 @@ export class P2PService {
const id = NodeId.decode(connectionUri.username); const id = NodeId.decode(connectionUri.username);
this.reconnectDelay.set(id, this.reconnectDelay.get(id) || 1); this.reconnectDelay.set(
id.toString(),
this.reconnectDelay.get(id.toString()) || 1,
);
if (id.equals(this.localNodeId)) { if (id.equals(this.localNodeId)) {
return; return;