-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add content * Update README.md * Add .gitignore
- Loading branch information
1 parent
8902498
commit ca4ca16
Showing
19 changed files
with
1,153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.DS_Store | ||
seeder.log | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
/target/ | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "grin-seeder" | ||
version = "0.1.0" | ||
authors = ["Quentin Le Sceller <[email protected]>"] | ||
|
||
[dependencies] | ||
grin_seeder_config = { path = "./config"} | ||
grin_seeder_util = { path = "./util"} | ||
grin_seeder_dns_server = { path = "./dns_server"} | ||
|
||
clap = "^2.23.3" | ||
daemonize = "^0.2.3" | ||
lazy_static = "~0.2.8" | ||
slog = { version = "^2.0.12", features = ["max_level_trace", "release_max_level_trace"] } | ||
slog-term = "^2.2.0" | ||
slog-async = "^2.1.0" | ||
time = "^0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,66 @@ | ||
# seeder | ||
# grin-seeder | ||
DNS seed server for Grin | ||
|
||
## Building | ||
|
||
### Build Prerequisites | ||
|
||
In order to compile and run Grin on your machine, you should have installed: | ||
|
||
* <b>Git</b> - to clone the repository | ||
* <b>Rust</b> - 1.21.0 or greater via [Rustup](https://www.rustup.rs/) - Can be installed via your package manager or manually via the following commands: | ||
``` | ||
curl https://sh.rustup.rs -sSf | sh | ||
source $HOME/.cargo/env | ||
``` | ||
|
||
### Build Instructions (Linux/Unix) | ||
|
||
|
||
#### Clone Grin | ||
|
||
``` | ||
git clone https://github.com/mimblewimble/seeder.git | ||
``` | ||
|
||
#### Build Grin | ||
```sh | ||
cd grin-seeder | ||
git checkout 0.1 | ||
cargo build | ||
``` | ||
|
||
## Usage | ||
|
||
Let's say you want to run your dns seed on seed.example.com. | ||
In that case, you'll need an authorative NS record in example.com's domain record, poiting to, for example, vps.example.com: | ||
|
||
``` | ||
$ dig -t NS seed.example.com | ||
;; ANSWER SECTION | ||
seed.example.com. 86400 IN NS vps.example.com. | ||
``` | ||
|
||
Then, on the system vps.example.com, you can run grin-seeder: | ||
```sh | ||
grin-seeder -h dnsseed.example.com -n vps.example.com | ||
``` | ||
|
||
If you want the DNS server to report SOA records, please provide an | ||
e-mail address (with the @ part replaced by .) using -m. | ||
|
||
|
||
## Running as non-root | ||
|
||
Typically, you'll need root privileges to listen to port 53 (name service). | ||
|
||
One solution is using an iptables rule (Linux only) to redirect it to | ||
a non-privileged port: | ||
|
||
```sh | ||
$ iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-port 5353 | ||
``` | ||
|
||
If properly configured, this will allow you to run grin-seeder in userspace, using | ||
the -p 5353 option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "grin_seeder_config" | ||
version = "0.1.0" | ||
authors = ["Quentin Le Sceller <[email protected]>"] | ||
workspace = ".." | ||
|
||
[dependencies] | ||
grin_seeder_dns_server = { path = "../dns_server"} | ||
grin_seeder_util = { path = "../util"} | ||
|
||
serde = "~1.0.8" | ||
serde_derive = "~1.0.8" | ||
toml = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright 2018 The Grin Developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Configuration file management | ||
use std::env; | ||
use std::io::Read; | ||
use std::path::PathBuf; | ||
use std::fs::File; | ||
|
||
use dns_server::DNSConfig; | ||
use toml; | ||
use types::{ConfigError, ConfigMembers, GlobalConfig}; | ||
use util::LoggingConfig; | ||
|
||
const CONFIG_FILE_NAME: &'static str = "seed.toml"; | ||
|
||
/// Returns the defaults, as strewn throughout the code | ||
impl Default for ConfigMembers { | ||
fn default() -> ConfigMembers { | ||
ConfigMembers { | ||
dns_server: DNSConfig::default(), | ||
logging: Some(LoggingConfig::default()), | ||
} | ||
} | ||
} | ||
|
||
impl Default for GlobalConfig { | ||
fn default() -> GlobalConfig { | ||
GlobalConfig { | ||
config_file_path: None, | ||
using_config_file: false, | ||
members: Some(ConfigMembers::default()), | ||
} | ||
} | ||
} | ||
|
||
impl GlobalConfig { | ||
/// Need to decide on rules where to read the config file from, | ||
/// but will take a stab at logic for now | ||
fn derive_config_location(&mut self) -> Result<(), ConfigError> { | ||
// First, check working directory | ||
let mut config_path = env::current_dir().unwrap(); | ||
config_path.push(CONFIG_FILE_NAME); | ||
if config_path.exists() { | ||
self.config_file_path = Some(config_path); | ||
return Ok(()); | ||
} | ||
// Next, look in directory of executable | ||
let mut config_path = env::current_exe().unwrap(); | ||
config_path.pop(); | ||
config_path.push(CONFIG_FILE_NAME); | ||
if config_path.exists() { | ||
self.config_file_path = Some(config_path); | ||
return Ok(()); | ||
} | ||
|
||
// Give up | ||
Err(ConfigError::FileNotFoundError(String::from(""))) | ||
} | ||
|
||
/// Takes the path to a config file, or if NONE, tries | ||
/// to determine a config file based on rules in | ||
/// derive_config_location | ||
pub fn new(file_path: Option<&str>) -> Result<GlobalConfig, ConfigError> { | ||
let mut return_value = GlobalConfig::default(); | ||
if let Some(fp) = file_path { | ||
return_value.config_file_path = Some(PathBuf::from(&fp)); | ||
} else { | ||
let _result = return_value.derive_config_location(); | ||
} | ||
|
||
// No attempt at a config file, just return defaults | ||
if let None = return_value.config_file_path { | ||
return Ok(return_value); | ||
} | ||
|
||
// Config file path is given but not valid | ||
if !return_value.config_file_path.as_mut().unwrap().exists() { | ||
return Err(ConfigError::FileNotFoundError(String::from( | ||
return_value | ||
.config_file_path | ||
.as_mut() | ||
.unwrap() | ||
.to_str() | ||
.unwrap() | ||
.clone(), | ||
))); | ||
} | ||
|
||
// Try to parse the config file if it exists | ||
// explode if it does exist but something's wrong | ||
// with it | ||
return_value.read_config() | ||
} | ||
|
||
/// Read config | ||
pub fn read_config(mut self) -> Result<GlobalConfig, ConfigError> { | ||
let mut file = File::open(self.config_file_path.as_mut().unwrap())?; | ||
let mut contents = String::new(); | ||
file.read_to_string(&mut contents)?; | ||
let decoded: Result<ConfigMembers, toml::de::Error> = toml::from_str(&contents); | ||
match decoded { | ||
Ok(gc) => { | ||
// Put the struct back together, because the config | ||
// file was flattened a bit | ||
self.using_config_file = true; | ||
self.members = Some(gc); | ||
return Ok(self); | ||
} | ||
Err(e) => { | ||
return Err(ConfigError::ParseError( | ||
String::from( | ||
self.config_file_path | ||
.as_mut() | ||
.unwrap() | ||
.to_str() | ||
.unwrap() | ||
.clone(), | ||
), | ||
String::from(format!("{}", e)), | ||
)); | ||
} | ||
} | ||
} | ||
|
||
/// Serialize config | ||
pub fn ser_config(&mut self) -> Result<String, ConfigError> { | ||
let encoded: Result<String, toml::ser::Error> = | ||
toml::to_string(self.members.as_mut().unwrap()); | ||
match encoded { | ||
Ok(enc) => return Ok(enc), | ||
Err(e) => { | ||
return Err(ConfigError::SerializationError(String::from(format!( | ||
"{}", | ||
e | ||
)))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018 The Grin Developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
extern crate grin_seeder_dns_server as dns_server; | ||
extern crate grin_seeder_util as util; | ||
|
||
extern crate serde; | ||
#[macro_use] | ||
extern crate serde_derive; | ||
extern crate toml; | ||
|
||
pub mod config; | ||
pub mod types; | ||
|
||
pub use types::{ConfigError, ConfigMembers, GlobalConfig}; |
Oops, something went wrong.