Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Enable HTTP RPC sockets (#871)
Browse files Browse the repository at this point in the history
* fixed eth start, but crash is not graceful

* better socket connection logic, remove master ps logic for eth

* fix splash screen display of state text for eth

* better gulp download plugin, remove master passwd stuff once and for all

* HTTP socket working

* minor warning

* minor refactor

* had accidentally deleted stuff from fixEthStart merge

* show dialog msg if using http rpc

* update dialog text

* remove git conflict markers

* fix merge
  • Loading branch information
hiddentao authored Aug 3, 2016
1 parent fb50e65 commit 2f612cd
Show file tree
Hide file tree
Showing 12 changed files with 718 additions and 482 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,50 @@ In the original window you can then start Mist using wallet mode:
$ electron . --mode wallet


### Passing options to Geth/Eth
### Connecting to node via HTTP instead of IPC

You can pass command-line options directly to Geth/Eth by prefixing them
with `--node-`:
This is useful if you have a node running on another machine, though note that
it's less secure than using the default IPC method.

```bash
$ electron . --rpc http://localhost:8545
```


### Passing options to Geth

You can pass command-line options directly to Geth by prefixing them with `--node-` in
the command-line invocation:

```bash
$ electron . --mode mist --node-rpcport 19343 --node-networkid 2
```

The `--rpc` Mist option is a special case. If you set this to an IPC socket file
path then the `--ipcpath` option automatically gets set, i.e.:

```bash
$ electron . --rpc /my/geth.ipc
```

...is the same as doing...


```bash
$ electron . --rpc /my/geth.ipc --node-ipcpath /my/geth.ipc
```

### Using Mist with a privatenet

To run a private network you will need to set the `networkdid`, `ipcpath` and
`datadir` flags:
To run a private network you will need to set the IPC path, network id and data
folder:

```bash
<<<<<<< HEAD
$ electron . --rpc ~/Library/Ethereum/geth.ipc --node-networkid 1234 --node-datadir ~/Library/Ethereum/privatenet
=======
$ electron . --ipcpath ~/Library/Ethereum/geth.ipc --node-networkid 1234 --node-datadir ~/Library/Ethereum/privatenet
>>>>>>> develop
```

_NOTE: since `ipcpath` is also a Mist option you do not need to also include a
Expand Down
19 changes: 19 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Settings = require('./modules/settings');
Settings.init();



if (Settings.cli.version) {
console.log(Settings.appVersion);

Expand All @@ -39,12 +40,19 @@ if (Settings.cli.ignoreGpuBlacklist) {
// logging setup
const log = logger.create('main');


if (Settings.inAutoTestMode) {
log.info('AUTOMATED TESTING');
}

log.info(`Running in production mode: ${Settings.inProductionMode}`);

if ('http' === Settings.rpcMode) {
log.warn('Connecting to a node via HTTP instead of IPC. This is less secure!!!!'.toUpperCase());
}




// db
const db = global.db = require('./modules/db');
Expand Down Expand Up @@ -160,6 +168,17 @@ var splashWindow;
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// if using HTTP RPC then inform user
if ('http' === Settings.rpcMode) {
dialog.showErrorBox('Insecure RPC connection', `
WARNING: You are connecting to an Ethereum node via: ${Settings.rpcHttpPath}
This is less secure than using local IPC - your passwords will be sent over the wire as plaintext.
Only do this if you have secured your HTTP connection or you know what you are doing.
`);
}

// initialise the db
global.db.init().then(onReady).catch((err) => {
log.error(err);
Expand Down
27 changes: 8 additions & 19 deletions modules/ethereumNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const fs = require('fs');
const Q = require('bluebird');
const getNodePath = require('./getNodePath.js');
const EventEmitter = require('events').EventEmitter;
const getIpcPath = require('./ipc/getIpcPath.js')
const Sockets = require('./sockets');
const Settings = require('./settings');

Expand Down Expand Up @@ -42,7 +41,7 @@ class EthereumNode extends EventEmitter {
this._type = null;
this._network = null;

this._socket = Sockets.get('node-ipc', Sockets.TYPES.WEB3_IPC);
this._socket = Sockets.get('node-ipc', Settings.rpcMode);

this.on('data', _.bind(this._logNodeData, this));
}
Expand Down Expand Up @@ -123,15 +122,7 @@ class EthereumNode extends EventEmitter {
* @return {Promise}
*/
init () {


const ipcPath = getIpcPath();

// TODO: if connection to external node is successful then query it to
// determine node and network type

// check if the node is already running
return this._socket.connect({path: ipcPath})
return this._socket.connect(Settings.rpcConnectConfig)
.then(()=> {
this.state = STATES.CONNECTED;

Expand Down Expand Up @@ -262,8 +253,6 @@ class EthereumNode extends EventEmitter {
* @return {Promise}
*/
_start (nodeType, network) {
const ipcPath = getIpcPath();

log.info(`Start node: ${nodeType} ${network}`);

const isTestNet = ('test' === network);
Expand Down Expand Up @@ -295,9 +284,9 @@ class EthereumNode extends EventEmitter {
// FORK RELATED
this._saveUserData('daoFork', this.daoFork);

return this._socket.connect({ path: ipcPath }, {
timeout: 30000 /* 30s */
})
return this._socket.connect(Settings.rpcConnectConfig, {
timeout: 30000 /* 30s */
})
.then(() => {
this.state = STATES.CONNECTED;
})
Expand Down Expand Up @@ -369,7 +358,7 @@ class EthereumNode extends EventEmitter {
// START TESTNET
if ('test' == network) {
args = (nodeType === 'geth')
? ['--testnet', '--fast', '--ipcpath', getIpcPath()]
? ['--testnet', '--fast', '--ipcpath', Settings.rpcIpcPath]
: ['--morden', '--unsafe-transactions'];
}
// START MAINNET
Expand Down Expand Up @@ -527,7 +516,7 @@ class EthereumNode extends EventEmitter {
try {
return fs.readFileSync(fullPath, {encoding: 'utf8'});
} catch (err){
log.error(`Unable to read from ${fullPath}`, err);
log.warn(`Unable to read from ${fullPath}`, err);
}

return null;
Expand All @@ -542,7 +531,7 @@ class EthereumNode extends EventEmitter {
try {
fs.writeFileSync(fullPath, data, {encoding: 'utf8'});
} catch (err){
log.error(`Unable to write to ${fullPath}`, err);
log.warn(`Unable to write to ${fullPath}`, err);
}
}

Expand Down
38 changes: 0 additions & 38 deletions modules/ipc/getIpcPath.js

This file was deleted.

8 changes: 3 additions & 5 deletions modules/ipc/ipcProviderBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const fs = require('fs');
const path = require('path');

const log = require('../utils/logger').create('ipcProviderBackend');
const ipcPath = require('./getIpcPath')();
const Sockets = require('../sockets');
const Settings = require('../settings');
const ethereumNode = require('../ethereumNode');
const Windows = require('../windows');

Expand Down Expand Up @@ -82,7 +82,7 @@ class IpcProviderBackend {
} else {
log.debug(`Get/create socket connection, id=${ownerId}`);

socket = Sockets.get(ownerId, Sockets.TYPES.WEB3_IPC);
socket = Sockets.get(ownerId, Settings.rpcMode);
}
})
.then(() => {
Expand Down Expand Up @@ -152,9 +152,7 @@ class IpcProviderBackend {
}
})
.then(() => {
return socket.connect({
path: ipcPath,
}, {
return socket.connect(Settings.rpcConnectConfig, {
timeout: 5000,
});
})
Expand Down
9 changes: 8 additions & 1 deletion modules/ipc/methods/eth_compileSolidity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const _ = global._;
const solc = require('solc');
const Q = require('bluebird');
const BaseProcessor = require('./base');
Expand All @@ -21,9 +22,15 @@ module.exports = class extends BaseProcessor {
let finalResult = _.extend({}, payload);

if (!output || output.errors) {
let msg = (output ? output.errors : 'Compile error');

if (_.isArray(msg)) {
msg = msg.join(', ');
}

finalResult.error = {
code: -32700,
message: (output ? output.errors : 'Compile error')
message: msg,
};
} else {
finalResult.result = output.contracts;
Expand Down
51 changes: 46 additions & 5 deletions modules/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const electron = require('electron');
const app = electron.app;

Expand Down Expand Up @@ -50,9 +51,9 @@ const argv = require('yargs')
type: 'string',
group: 'Mist options:',
},
ipcpath: {
rpc: {
demand: false,
describe: 'Path to node IPC socket file (this will automatically get passed as an option to Geth).',
describe: 'Path to node IPC socket file OR HTTP RPC hostport (if IPC socket file then --node-ipcpath will be set with this value).',
requiresArg: true,
nargs: 1,
type: 'string',
Expand Down Expand Up @@ -117,7 +118,7 @@ const argv = require('yargs')
type: 'boolean',
},
'': {
describe: 'All options prefixed with --node- (e.g. "--node-datadir") will be passed onto the client (e.g. Geth).',
describe: 'To pass options to the underlying node (e.g. Geth) use the --node- prefix, e.g. --node-datadir',
group: 'Node options:',
}
})
Expand Down Expand Up @@ -205,8 +206,48 @@ class Settings {
return argv.ethpath;
}

get ipcPath () {
return argv.ipcpath;
get rpcMode () {
return (argv.rpc && 0 > argv.rpc.indexOf('.ipc')) ? 'http' : 'ipc';
}

get rpcConnectConfig () {
if ('ipc' === this.rpcMode) {
return {
path: this.rpcIpcPath,
};
} else {
return {
hostPort: this.rpcHttpPath,
};
}
}

get rpcHttpPath () {
return ('http' === this.rpcMode) ? argv.rpc : null;
}

get rpcIpcPath () {
let ipcPath = ('ipc' === this.rpcMode) ? argv.rpc : null;

if (ipcPath) {
return ipcPath;
}

ipcPath = this.userHomePath;

if (process.platform === 'darwin') {
ipcPath += '/Library/Ethereum/geth.ipc';
} else if (process.platform === 'freebsd' ||
process.platform === 'linux' ||
process.platform === 'sunos') {
ipcPath += '/.ethereum/geth.ipc';
} else if (process.platform === 'win32') {
ipcPath = '\\\\.\\pipe\\geth.ipc';
}

this._log.debug(`IPC path: ${ipcPath}`);

return ipcPath;
}

get nodeType () {
Expand Down
Loading

0 comments on commit 2f612cd

Please sign in to comment.