openethereum/parity/ipfs.rs
Maciej Hirsz f97e775498 More CLI settings for IPFS API (#4608)
* TEMP: Bind to 0.0.0.0, don't check Origin

* More CLI options for IPFS

* CORS and Hosts filtering

* Allow current interface as origin

* Correctly handle CORS settings

* fix grumbles
2017-02-24 10:32:42 +01:00

41 lines
937 B
Rust

use std::sync::Arc;
use parity_ipfs_api;
use parity_ipfs_api::error::ServerError;
use ethcore::client::BlockChainClient;
use hyper::server::Listening;
#[derive(Debug, PartialEq, Clone)]
pub struct Configuration {
pub enabled: bool,
pub port: u16,
pub interface: String,
pub cors: Option<Vec<String>>,
pub hosts: Option<Vec<String>>,
}
impl Default for Configuration {
fn default() -> Self {
Configuration {
enabled: false,
port: 5001,
interface: "127.0.0.1".into(),
cors: None,
hosts: Some(Vec::new()),
}
}
}
pub fn start_server(conf: Configuration, client: Arc<BlockChainClient>) -> Result<Option<Listening>, ServerError> {
if !conf.enabled {
return Ok(None);
}
parity_ipfs_api::start_server(
conf.port,
conf.interface,
conf.cors,
conf.hosts,
client
).map(Some)
}