Skip to content

Commit

Permalink
disable all experimental stuff by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fazo96 committed Apr 13, 2018
1 parent 4fc387a commit 975e027
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 37 deletions.
13 changes: 8 additions & 5 deletions bin/chlu-service-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ async function start(options){
directory: options.directory,
ipfs: {
remote: options.externalIpfs,
enableRelayHop: options.enableRelayHop
enableRelayHop: options.relay
},
listen: options.listen,
useCircuit: options.circuit || options.relay,
useRendezvous: options.rendezvous
};
serviceNode = new ChluIPFS(config);
Expand Down Expand Up @@ -54,12 +55,14 @@ cli
cli
.command('start')
.description('run the Service Node')
.option('-n, --network <s>', 'use a custom network instead of production')
.option('-n, --network <s>', 'use a custom network instead of experimental')
.option('-d, --directory <s>', 'where to store chlu data, defaults to ~/.chlu')
.option('-e, --external-ipfs', 'connect to a running IPFS node at localhost:5001')
.option('-r, --relay', 'act as libp2p relay to help nodes connect to each other')
.option('--no-rendezvous', 'disable usage of rendezvous servers (not recommended right now)')
.option('--no-listen', "don't listen for incoming connections")
.option('--listen', 'listen for incoming connections (not recommended right now)')
// TODO: reenable these when they are supported again
// .option('-e, --external-ipfs', 'connect to a running IPFS node at localhost:5001 instead of running IPFS internally')
// .option('-c, --circuit', 'enable libp2p circuit relay to use relays to connect to peers')
// .option('-r, --relay', 'act as libp2p relay to help nodes connect to each other (implicitly turns on --circuit)')
.action(handleErrors(async cmd => {
await start(cmd);
}));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"orbit-db": "orbitdb/orbit-db#master",
"protons": "~1.0.1"
},
"resolutions": {
"//resolutions": {
"ipfs-log": "ChluNetwork/ipfs-log#custom-verification",
"ipfs-pubsub-1on1": "ChluNetwork/ipfs-pubsub-1on1#ipfs-api-fix"
},
Expand Down
23 changes: 16 additions & 7 deletions src/ChluIPFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,43 @@ class ChluIPFS {
const defaultSwarmAddresses = env.isNode()
? constants.defaultSwarmAddresses.nodeJs
: constants.defaultSwarmAddresses.browser;
const swarmAddresses = options.listen === false ? [] : defaultSwarmAddresses;
const swarmAddresses = options.listen ? defaultSwarmAddresses : [];
if (options.useRendezvous !== false) {
// By default, use rendezvous points for websocket-star
swarmAddresses.push(...constants.defaultSwarmAddresses.rendezvous);
}
if (options.circuit || options.relay) {
// Do not use circuit relay by default
// Acting as relay requires enabling circuit
this.circuit = true;
}
if (options.relay) {
// Do not act as relay by default
this.relay = true;
}
this.ipfsOptions = Object.assign(
{},
// default IPFS config
constants.defaultIPFSOptions,
// pass swarm addresses determined just now
{
config: {
Addresses: {
Swarm: swarmAddresses
}
}
},
// additional options set up just now
additionalOptions,
// finally options passed by the caller
options.ipfs || {}
);
// Set up OrbitDB Directory/Path
this.orbitDbDirectory = options.orbitDbDirectory || IPFSUtils.getDefaultOrbitDBPath(this.directory);
// Set up Chlu bootstrap nodes
this.chluBootstrapNodes = cloneDeep(constants.chluBootstrapNodes);
// enable Chlu bootstrap by default
if (options.bootstrap === false) {
this.bootstrap = false;
} else {
this.bootstrap = true;
}
// disable Chlu bootstrap by default
this.bootstrap = options.bootstrap;
// Check Chlu node type
this.type = options.type;
if (Object.values(constants.types).indexOf(this.type) < 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ module.exports = {
defaultIPFSOptions: {
// ipfs
EXPERIMENTAL: {
pubsub: true,
pubsub: true, // REQUIRED for chlu to work
relay: {
enabled: true, // enable this to use relays to connect to nodes
enabled: false, // enable this to use relays to connect to nodes
hop: {
enabled: false // disable this, we don't want to act as relay to save bandwidth
enabled: false // enable this to act as relay
}
}
},
Expand All @@ -52,7 +52,7 @@ module.exports = {
],
rendezvous: [
// Helps browser connectivity, until circuit relay can replace this
'/dns4/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star'
'/dns4/ren.chlu.io/tcp/443/wss/p2p-websocket-star'
]
},
chluBootstrapNodes: {
Expand Down
44 changes: 26 additions & 18 deletions src/modules/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ class IPFS {
if (!this.chluIpfs.ipfs) {
logger.debug('Initializing IPFS, type: ' + (this.chluIpfs.ipfsOptions.type || 'JS (Internal)'));
logger.debug('Detected environment: ' + env.isNode() ? 'Node.JS' : 'Browser');
if (this.chluIpfs.ipfsOptions.enableRelayHop) {
logger.info('Acting as libp2p relay');
}
let ipfs;
if (this.chluIpfs.ipfsOptions.remote) {
logger.debug('Connecting to IPFS API');
// Connect to existing IPFS Node
ipfs = IPFSAPI(this.chluIpfs.ipfsOptions);
// TODO: check that pubsub is supported (it might be disabled)
} else {
logger.debug('Starting JS-IPFS in this process');
// Default: Start a local IPFS Node
if (this.chluIpfs.ipfsOptions.enableRelayHop) {
set(this.chluIpfs.ipfsOptions, 'EXPERIMENTAL.relay.hop.enable', true);
if (this.chluIpfs.circuit) {
set(this.chluIpfs.ipfsOptions, 'EXPERIMENTAL.relay.enabled', true);
}
if (this.chluIpfs.relay) {
set(this.chluIpfs.ipfsOptions, 'EXPERIMENTAL.relay.hop.enabled', true);
}
ipfs = await utils.createIPFS(this.chluIpfs.ipfsOptions);
}
Expand All @@ -36,8 +37,7 @@ class IPFS {
if (this.chluIpfs.bootstrap) {
logger.debug('Connecting to bootstrap Chlu nodes');
const nodes = env.isNode() ? this.chluIpfs.chluBootstrapNodes.nodeJs : this.chluIpfs.chluBootstrapNodes.browser;
await this.connectToNodes(nodes);
logger.debug('Connected to bootstrap Chlu nodes');
this.connectToNodes(nodes); // do not await for this, let it run in the background
} else {
logger.debug('Skipping Chlu bootstrap phase');
}
Expand All @@ -55,17 +55,25 @@ class IPFS {

async connectToNodes(addrs) {
const total = addrs.length;
return Promise.all(addrs.map(async (addr, ii) => {
const i = ii + 1;
try {
this.chluIpfs.logger.debug('Connecting to IPFS address (' + i + '/' + total + ') ' + addr);
await this.chluIpfs.ipfs.swarm.connect(addr);
this.chluIpfs.logger.debug('Connected to IPFS address (' + i + '/' + total + ') ' + addr);
} catch (error) {
this.chluIpfs.logger.warn('Connection FAILED to IPFS address (' + i + '/' + total + ') ' + addr);
console.trace(error);
}
}));
this.chluIpfs.logger.debug('Started connection attempt to ' + total + ' addresses');
let connectedCount = 0;
return new Promise(resolve => {
addrs.map(async (addr, ii) => {
const i = ii + 1;
try {
this.chluIpfs.logger.debug('Connecting to IPFS address (' + i + '/' + total + ') ' + addr);
await this.chluIpfs.ipfs.swarm.connect(addr);
connectedCount++;
this.chluIpfs.logger.debug('Connected to IPFS address (' + i + '/' + total + ') ' + addr);
} catch (error) {
this.chluIpfs.logger.debug('Connection FAILED to IPFS address (' + i + '/' + total + ') ' + addr);
}
if (i === total) {
this.chluIpfs.logger.debug('Connect attempts finished. Connected to ' + connectedCount + '/' + total);
resolve(connectedCount);
}
});
});
}

async id() {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,7 @@ ipfs-block@~0.6.1:
dependencies:
cids "^0.5.2"

ipfs-log@ChluNetwork/ipfs-log#custom-verification, ipfs-log@~4.1.0:
ipfs-log@~4.1.0:
version "4.1.0"
resolved "https://codeload.github.com/ChluNetwork/ipfs-log/tar.gz/36129b31913706183e2b625c7aae658a713aba6c"
dependencies:
Expand All @@ -4018,7 +4018,7 @@ ipfs-multipart@~0.1.0:
content "^3.0.0"
dicer "^0.2.5"

ipfs-pubsub-1on1@ChluNetwork/ipfs-pubsub-1on1#ipfs-api-fix, ipfs-pubsub-1on1@~0.0.3:
ipfs-pubsub-1on1@~0.0.3:
version "0.0.3"
resolved "https://codeload.github.com/ChluNetwork/ipfs-pubsub-1on1/tar.gz/f6214bb3ecce9bd25243465d09a0211f88c895ba"
dependencies:
Expand Down

0 comments on commit 975e027

Please sign in to comment.