Procházet zdrojové kódy

storage-node: discovery fix bug in discovery if not account info found for provider

Mokhtar Naamani před 4 roky
rodič
revize
a9a99d6422

+ 3 - 1
storage-node/packages/colossus/bin/cli.js

@@ -203,7 +203,7 @@ function get_service_information (publicUrl) {
 async function announce_public_url (api, publicUrl) {
   // re-announce in future
   const reannounce = function (timeoutMs) {
-    setTimeout(announce_public_url, timeoutMs, api)
+    setTimeout(announce_public_url, timeoutMs, api, publicUrl)
   }
 
   debug('announcing public url')
@@ -253,6 +253,8 @@ const commands = {
       throw new Error('Must specify a --public-url argument')
     }
 
+    // TODO: check valid url
+
     // Continue with server setup
     const store = get_storage(api)
     banner()

+ 1 - 2
storage-node/packages/colossus/paths/discover/v0/{id}.js

@@ -53,10 +53,9 @@ module.exports = function(flags, runtime)
           } else {
             res.status(200).send(info);
           }
-
         } catch (err) {
           debug(`${err}`);
-          res.status(400).end()
+          res.status(404).end()
         }
     }
   };

+ 24 - 3
storage-node/packages/discovery/discover.js

@@ -36,7 +36,13 @@ async function discover_over_ipfs_http_gateway (storageProviderId, runtimeApi, g
 
   const identity = await getIpnsIdentity(storageProviderId, runtimeApi)
 
+  if (identity == null) {
+    // dont waste time trying to resolve if no identity was found
+    throw new Error('no identity to resolve')
+  }
+
   gateway = gateway || 'http://localhost:8080'
+  gateway = stripEndingSlash(gateway)
 
   const url = `${gateway}/ipns/${identity}`
 
@@ -84,11 +90,16 @@ async function discover_over_local_ipfs_node (storageProviderId, runtimeApi) {
   let isProvider = await runtimeApi.workers.isStorageProvider(storageProviderId)
 
   if (!isProvider) {
-    throw new Error('Cannot discover non actor account service info')
+    throw new Error('Cannot discover non storage providers')
   }
 
   const identity = await getIpnsIdentity(storageProviderId, runtimeApi)
 
+  if (identity == null) {
+    // dont waste time trying to resolve if no identity was found
+    throw new Error('no identity to resolve')
+  }
+
   const ipns_address = `/ipns/${identity}/`
 
   debug('resolved ipns to ipfs object')
@@ -163,6 +174,7 @@ async function _discover (storageProviderId, runtimeApi) {
     } else {
       result = await discover_over_local_ipfs_node(storageProviderId, runtimeApi)
     }
+
     debug(result)
     result = JSON.stringify(result)
     accountInfoCache[id] = {
@@ -174,10 +186,19 @@ async function _discover (storageProviderId, runtimeApi) {
     delete activeDiscoveries[id]
     return result
   } catch (err) {
+    // we catch the error so we can update all callers
+    // and throw again to inform the first caller.
     debug(err.message)
-    deferredDiscovery.reject(err)
     delete activeDiscoveries[id]
-    throw err
+    // deferredDiscovery.reject(err)
+    deferredDiscovery.resolve(null) // resolve to null until we figure out the issue below
+    // throw err // <-- throwing but this isn't being
+    // caught correctly in express server! Is it because there is an uncaught promise somewhere
+    // in the prior .reject() call ?
+    // I've only seen this behaviour when error is from ipfs-client
+    // ... is this unique to errors thrown from ipfs-client?
+    // Problem is its crashing the node so just return null for now
+    return null
   }
 }