From aee4783e5ed1a639c43b8cf4d7c3889aa6ce0aea Mon Sep 17 00:00:00 2001 From: Nina Breznik Date: Sun, 10 Dec 2023 01:31:34 +0000 Subject: [PATCH] fix bug in refresh discovery mode --- src/node_modules/_datdot-service-helpers/hyper.js | 12 ++++-------- .../_datdot-service-helpers/try-refresh-discovery.js | 9 ++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/node_modules/_datdot-service-helpers/hyper.js b/src/node_modules/_datdot-service-helpers/hyper.js index f7ba6c9d..33090f89 100644 --- a/src/node_modules/_datdot-service-helpers/hyper.js +++ b/src/node_modules/_datdot-service-helpers/hyper.js @@ -255,9 +255,8 @@ function onconnection ({ account }) { for (const topic of peer_topics) { const stringtopic = topic.toString('hex') // only shows topics derived from a feed.discoveryKey const discovery = swarm.status(topic) + conn_log({ type: 'onconnection', data: { text: 'client for topic', stringtopic, remotestringkey, isServer: discovery?.isServer, isClient: discovery?.isClient }}) if ( - !discovery || // peer left the topic, but discovery hasn't yet been updated - !discovery.isClient || // peer is not a client anymore, but discovery mode hasn't been updated yet targets[remotestringkey]?.tasks[stringtopic] || // already handled as target connection !tasks[stringtopic] || // no task // TODO: this only checks if task is being handled by this particular peer @@ -293,11 +292,10 @@ async function make_stream_and_channel ({ account, tid, connection, remotestring // peer is a server function ondiscoverykey (discoverykey) { // client hasn't replicated the hypercores so they are asking for the 'discovery-key' event const stringtopic = discoverykey.toString('hex') // only shows topics derived from a feedn.discoveryKey - log({ type: 'ondiscovery', data: { text: 'ondiscovery cb', remotestringkey, stringtopic } }) const discovery = swarm.status(discoverykey) + log({ type: 'ondiscovery', data: { text: 'ondiscovery cb', remotestringkey, stringtopic, isServer: discovery?.isServer, isClient: discovery?.isClient } }) + if ( - !discovery || // peer left the topic, but discovery hasn't yet been updated - !discovery.isServer || // peer is not a server anymore, but discovery mode hasn't been updated yet targets[remotestringkey]?.tasks[stringtopic] || // already handled as target connection !tasks[stringtopic] || // no task tasks[stringtopic]?.connections[remotestringkey] // task is already being handled @@ -370,12 +368,10 @@ async function handle_target_connection ({ account, remotestringkey, log }) { // const { targets, sockets, tasks } = state const { channel, replicationStream } = sockets[remotestringkey] const string_msg = channel.messages[0] // get string message type for sending strings through the mux channel with that peer (channel.addMessage(...)) - log({ type: 'onconnection', data: { text: `handle target conn`, remotestringkey, target_tasks: Object.keys(targets[remotestringkey].tasks).length } }) - try { + try { log({ type: 'exchange-feedkey', data: { text: 'load channel', remotestringkey, opened: channel.opened }}) - // we need to loop over all the target tasks to find tasks for this peer const target_tasks = Object.keys(targets[remotestringkey].tasks) for (const stringtopic of target_tasks) { diff --git a/src/node_modules/_datdot-service-helpers/try-refresh-discovery.js b/src/node_modules/_datdot-service-helpers/try-refresh-discovery.js index e77e2b74..5a507ad2 100644 --- a/src/node_modules/_datdot-service-helpers/try-refresh-discovery.js +++ b/src/node_modules/_datdot-service-helpers/try-refresh-discovery.js @@ -34,15 +34,10 @@ async function try_refresh_discovery ({ swarm, topic, tasks, log }) { else if (no_client && any_server_only) mode = { server: true, client: false } try { - // NOTE: things don't get refreshed on the DHT in real time, so old mode - // might still be active for a few more seconds - // that is why we add additional checks in the onconnection cb const discovery = swarm.status(topic) if (discovery.isServer === mode.server && discovery.isClient === mode.client) return resolve(mode) - await discovery.refresh(mode) - // or - // await swarm.leave(topic) - // await swarm.join(topic, mode).flushed() + await swarm.leave(topic) + await swarm.join(topic, mode).flushed() log({ type: 'swarm', data: { text: 'refresh discovery', topic: topic.toString('hex'), /* roles: tasks, */ mode, old_mode: { server: discovery.isServer, client: discovery.isClient } }}) resolve(mode) } catch (err) {