Skip to content

Commit

Permalink
Improve peer list storage (#415)
Browse files Browse the repository at this point in the history
* Improve peer list storage

* Add entry to changelog

* Fixes #416

* Update changelog
  • Loading branch information
icidasset committed Aug 29, 2022
1 parent 0a92ca5 commit 01b57e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#### Bug fixes

Fixes the depedency-injected `lookupDnsLink` function
- Fixes the depedency-injected `lookupDnsLink` function
- Fixes issue with IPFS peer-list storage
- Removes Vite warning caused by a dynamic import


### v0.34.0
Expand All @@ -22,6 +24,7 @@ Enable new EXPERIMENTAL public file system version 3.0.0 using rs-wnfs. Use this
- No longer uses a locally-shared IPFS client (was originally using a shared worker). This fixes various error messages you may have seen relating to CIDs.



### v0.32.0

#### Features
Expand All @@ -37,15 +40,18 @@ Fixes issue with loading private shares.
Updated ipfs-related dependencies.



### v0.31.1

Move `madge` and `typedoc-plugin-missing-exports` from `dependencies` into `devDependencies`.


### v0.31.0

Fixes circular dependencies.



### v0.30.0

#### Breaking Changes
Expand Down
3 changes: 1 addition & 2 deletions src/ipfs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const nodeWithPkg = (pkg: IPFSPackage): Promise<IPFS> => {
*/
export const pkgFromCDN = async (cdn_url: string): Promise<IPFSPackage> => {
if (!cdn_url) throw new Error("This function requires a URL to a CDN")
/* @vite-ignore */
return import(/* webpackIgnore: true */ cdn_url).then(_ => (self as any).IpfsCore as IPFSPackage)
return import(/* @vite-ignore *//* webpackIgnore: true */ cdn_url).then(_ => (self as any).IpfsCore as IPFSPackage)
}

// /**
Expand Down
12 changes: 6 additions & 6 deletions src/ipfs/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ export async function createAndConnect(pkg: IPFSPackage): Promise<IPFSCore> {
// PEERS
// -----

const STORAGE_KEY = "ipfs_peers_1660901513"
const STORAGE_KEY = "ipfs_peers_1661540056"


export function fetchFissionPeers(): Promise<string[]> {
const peersUrl = `${setup.getApiEndpoint()}/ipfs/peers`
const peersUrl = `${setup.endpoints.api}/ipfs/peers`

return fetch(peersUrl)
.then(r => r.json())
Expand All @@ -167,19 +167,19 @@ export async function listPeers(): Promise<Multiaddr[]> {
let peers
const maybePeers = await localforage.getItem(STORAGE_KEY)

if (t.isString(maybePeers)) {
peers = maybePeers.split(",")
if (t.isString(maybePeers) && maybePeers.trim() !== "") {
peers = JSON.parse(maybePeers)

fetchFissionPeers().then(list =>
localforage.setItem(STORAGE_KEY, list.join(","))
localforage.setItem(STORAGE_KEY, JSON.stringify(list))
).catch(err => {
// don't throw
console.error(err)
})

} else {
peers = await fetchFissionPeers()
await localforage.setItem(STORAGE_KEY, peers.join(","))
await localforage.setItem(STORAGE_KEY, JSON.stringify(peers))

}

Expand Down

0 comments on commit 01b57e2

Please sign in to comment.