/* This is a shim to the IPFS library, (Lists are handled in YJS or OrbitDB) See https://github.com/ipfs/js-ipfs but note its often out of date relative to the generic API doc. */ //TODO-IPFS Note API changes in https://github.com/ipfs/js-ipfs/issues/1721 probably all ipfs.files -> ipfs. const httptools = require('./httptools'); // Expose some of the httptools so that IPFS can use it as a backup const debug = require('debug')('dweb-transports:ipfs'); // IPFS components let IPFS; //TODO-SPLIT move this line lower when fix structure //TODO-SPLIT remove this import depend on archive.html or node to pre-load //IPFS = require('ipfs'); //TODO-SPLIT remove this import depend on archive.html or node to pre-load const ipfsAPI = require('ipfs-http-client'); //We now get this from IPFS.CID //const CID = require('cids'); // Library packages other than IPFS const Url = require('url'); const stream = require('readable-stream'); // Needed for the pullthrough - this is NOT Ipfs streams // Other Dweb modules const errors = require('./Errors'); // Standard Dweb Errors const Transport = require('./Transport.js'); // Base class for TransportXyz const Transports = require('./Transports'); // Manage all Transports that are loaded const utils = require('./utils'); // Utility functions const defaultoptions = { repo: '/tmp/dweb_ipfsv3107', //TODO-IPFS restarted 2018-10-06 because was caching connection ws-star //init: false, //start: false, //TODO-IPFS-Q how is this decentralized - can it run offline? Does it depend on star-signal.cloud.ipfs.team config: { // Addresses: { Swarm: [ '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star']}, // For Y - same as defaults // Addresses: { Swarm: [ ] }, // Disable WebRTC to test browser crash, note disables Y so doesnt work. //Addresses: {Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']}, // from https://github.com/ipfs/js-ipfs#faq 2017-12-05 as alternative to webrtc works sort-of //Bootstrap: ['/dns4/dweb.me/tcp/4245/wss/ipfs/QmPNgKEjC7wkpu3aHUzKKhZmbEfiGzL5TP1L8zZoHJyXZW'], // Connect via WSS to IPFS instance at IA on FnF Bootstrap: ['/dns4/dweb.me/tcp/4245/wss/ipfs/QmQz3p44VVQDeAieaW28DMjcTVzLbpxqaQB9bkXnyd7HY5'], // Connect via WSS to IPFS instance in Kube at IA // Previously was: QmQ921MRjsbP12fHSEDcdFeuHFg6qKDFurm2rXgA5K3RQD on kube }, //init: true, // Comment out for Y EXPERIMENTAL: { pubsub: true }, preload: { enabled: false }, //Off by default, it never seems to have the content (routing issues) pass as an argument if want to use //httpIPFSgateway: "https://ipfs.io", }; class TransportIPFS extends Transport { /* IPFS specific transport Fields: ipfs: object returned when starting IPFS */ constructor(options) { super(options); [ "urlUrlstore", "httpIPFSgateway"].forEach(k => { this[k] = options[k]; delete options[k]; }); this.ipfs = undefined; // Undefined till start IPFS this.options = options; // Dictionary of options this.name = "IPFS"; // For console log etc this.supportURLs = ['ipfs']; this.supportFunctions = ['fetch', 'store', 'seed', 'createReadStream']; // Does not support reverse this.supportFeatures = ['noCache']; // Note doesnt actually support noCache, but immutable is same this.status = Transport.STATUS_LOADED; } _ipfsversion(ipfs, s, cb) { ipfs.version((err, data) => { if (err) { debug("IPFS via %s present but unresponsive: %o", s, data); this.ipfstype = "FAILED"; cb(err); } else { debug("IPFS available via %s: %o", s, data); this.ipfstype = s; cb(null, ipfs); } }); } IPFSAutoConnect(cb) { if (global.Ipfs) { IPFS = global.Ipfs; //Loaded by