From 5ce0c2d71c4b55d4c116a96dc09e7215ac00dd94 Mon Sep 17 00:00:00 2001 From: mrfry Date: Tue, 11 Apr 2023 10:48:41 +0200 Subject: [PATCH] removed pw from self info, checking if third party peers file exists, minor logging fix --- src/modules/api/submodules/p2p.ts | 16 ++++++++++------ src/utils/files.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/api/submodules/p2p.ts b/src/modules/api/submodules/p2p.ts index 69cbbf4..c86ccb6 100644 --- a/src/modules/api/submodules/p2p.ts +++ b/src/modules/api/submodules/p2p.ts @@ -96,8 +96,10 @@ interface SyncDataRes { function updateThirdPartyPeers( newVal: Omit[] ) { - // TODO: check if thirdPartyPeersFile exists! - const prevVal = utils.ReadJSON(paths.thirdPartyPeersFile) + const prevVal = utils.FileExists(paths.thirdPartyPeersFile) + ? utils.ReadJSON(paths.thirdPartyPeersFile) + : [] + const dataToWrite = newVal.reduce((acc, peer) => { const isIncluded = acc.find((x) => { return peerToString(x) === peerToString(peer) @@ -466,7 +468,11 @@ function setup(data: SubmoduleData): Submodule { function getSelfInfo(includeVerboseInfo?: boolean) { const result: RemotePeerInfo = { selfInfo: { ...selfInfo, publicKey: publicKey }, - myPeers: peers, + myPeers: peers.map((peer) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { pw, ...restOfPeer } = peer + return restOfPeer + }), } if (includeVerboseInfo) { @@ -964,8 +970,7 @@ function setup(data: SubmoduleData): Submodule { remoteInfo: getSelfInfo(), } - // TODO: hostname is invalid, should be remote host? - let hostToLog = req.hostname + let hostToLog = remoteHost || 'Unknown host' if (remoteHost) { const remotePeerInfo = peers.find((peer) => { return peerToString(peer) === remoteHost @@ -1000,7 +1005,6 @@ function setup(data: SubmoduleData): Submodule { ) if (remoteHost.includes(':')) { const [host, port] = remoteHost.split(':') - // TODO: add public key updateThirdPartyPeers([ { host: host, diff --git a/src/utils/files.ts b/src/utils/files.ts index cc204bf..64e412d 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -286,6 +286,7 @@ export const files = { }, thirdPartyPeersFile: { path: 'data/p2p/thirdPartyPeers.json', + defaultValue: JSON.stringify([]), description: 'json of third party peers reported by other peers', }, keyFile: {