Removed all external zones.
This commit is contained in:
@@ -1,77 +1,9 @@
|
||||
extern crate winres;
|
||||
|
||||
use std::fs::File;
|
||||
use std::fs::read_to_string;
|
||||
use std::path::Path;
|
||||
use std::io::Write;
|
||||
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha2::Sha256;
|
||||
|
||||
const IANA_FILE: &'static str = "iana-tlds.txt";
|
||||
const IANA_HASHES: &'static str = "iana-hashes.txt";
|
||||
const IANA_ZONES_URL: &'static str = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt";
|
||||
|
||||
fn main() {
|
||||
if cfg!(target_os = "windows") {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
res.set_icon("img/logo/alfis.ico");
|
||||
res.compile().unwrap();
|
||||
}
|
||||
|
||||
download_iana_zones(IANA_FILE, IANA_HASHES);
|
||||
}
|
||||
|
||||
fn download_iana_zones(zones_name: &str, hashes_name: &str) {
|
||||
let response = match read_to_string(Path::new(IANA_FILE)) {
|
||||
Ok(string) => { string }
|
||||
Err(_) => {
|
||||
let response = minreq::get(IANA_ZONES_URL).send().expect("Could not make request!");
|
||||
response.as_str().expect("Response is not a valid UTF-8!").to_lowercase()
|
||||
}
|
||||
};
|
||||
|
||||
let list: Vec<_> = response.split("\n").collect();
|
||||
let mut zones = String::new();
|
||||
let mut hashes = String::new();
|
||||
for string in list {
|
||||
if !string.starts_with("#") && !string.is_empty() {
|
||||
zones.push_str(string);
|
||||
zones.push('\n');
|
||||
|
||||
hashes.push_str(&hash_identity(string));
|
||||
hashes.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
match File::create(Path::new(zones_name)) {
|
||||
Ok(mut file) => {
|
||||
file.write_all(zones.trim().as_bytes()).expect("Error saving TLDs file!");
|
||||
}
|
||||
Err(e) => { panic!("Error opening TLDs file!\n{}", e); }
|
||||
}
|
||||
|
||||
match File::create(Path::new(hashes_name)) {
|
||||
Ok(mut file) => {
|
||||
file.write_all(hashes.trim().as_bytes()).expect("Error saving TLD-hashes file!");
|
||||
}
|
||||
Err(e) => { panic!("Error opening TLD-hashes file!\n{}", e); }
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_identity(identity: &str) -> String {
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
let mut digest = Sha256::new();
|
||||
digest.input_str(identity);
|
||||
digest.result(&mut buf);
|
||||
to_hex(&buf)
|
||||
}
|
||||
|
||||
/// Convert bytes array to HEX format
|
||||
pub fn to_hex(buf: &[u8]) -> String {
|
||||
let mut result = String::new();
|
||||
for x in buf.iter() {
|
||||
result.push_str(&format!("{:01$X}", x, 2));
|
||||
}
|
||||
result
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
pub const DB_VERSION: u32 = 0;
|
||||
pub const CHAIN_VERSION: u32 = 1;
|
||||
|
||||
pub const ORIGIN_DIFFICULTY: u32 = 30;
|
||||
pub const ORIGIN_DIFFICULTY: u32 = 28;
|
||||
pub const DOMAIN_DIFFICULTY: u32 = 24;
|
||||
pub const SIGNER_DIFFICULTY: u32 = 16;
|
||||
pub const KEYSTORE_DIFFICULTY: u32 = 23;
|
||||
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
use crate::{Chain, Bus, Keystore, Settings, ExternalZones};
|
||||
use crate::{Chain, Bus, Keystore, Settings};
|
||||
use crate::event::Event;
|
||||
#[allow(unused_imports)]
|
||||
use log::{trace, debug, info, warn, error};
|
||||
@@ -9,7 +9,6 @@ pub struct Context {
|
||||
pub settings: Settings,
|
||||
pub keystore: Option<Keystore>,
|
||||
pub chain: Chain,
|
||||
pub x_zones: ExternalZones,
|
||||
pub bus: Bus<Event>,
|
||||
pub miner_state: MinerState,
|
||||
}
|
||||
@@ -22,7 +21,6 @@ impl Context {
|
||||
settings,
|
||||
keystore,
|
||||
chain,
|
||||
x_zones: ExternalZones::new(),
|
||||
bus: Bus::new(),
|
||||
miner_state: MinerState { mining: false, full: false }
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ pub use crate::p2p::Network;
|
||||
pub use crate::settings::Settings;
|
||||
pub use crate::bytes::Bytes;
|
||||
pub use crate::keys::Keystore;
|
||||
pub use crate::x_zones::ExternalZones;
|
||||
pub use crate::simplebus::*;
|
||||
pub use crate::commons::*;
|
||||
|
||||
@@ -24,6 +23,5 @@ pub mod dns;
|
||||
pub mod dns_utils;
|
||||
pub mod settings;
|
||||
pub mod bytes;
|
||||
pub mod x_zones;
|
||||
pub mod crypto;
|
||||
|
||||
|
||||
@@ -527,12 +527,6 @@ fn handle_block(context: Arc<Mutex<Context>>, peers: &mut Peers, token: &Token,
|
||||
let peers_count = peers.get_peers_active_count();
|
||||
let peer = peers.get_mut_peer(token).unwrap();
|
||||
peer.set_received_block(block.index);
|
||||
if let Some(transaction) = &block.transaction {
|
||||
if context.lock().unwrap().x_zones.has_hash(&transaction.identity.to_string()) {
|
||||
// This peer has mined some of the forbidden zones
|
||||
return State::Banned;
|
||||
}
|
||||
}
|
||||
|
||||
let mut context = context.lock().unwrap();
|
||||
let max_height = context.chain.max_height();
|
||||
|
||||
+4
-2
@@ -42,7 +42,7 @@ pub fn run_interface(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) {
|
||||
.size(1023, 720)
|
||||
.min_size(773, 350)
|
||||
.resizable(true)
|
||||
.debug(false)
|
||||
.debug(true)
|
||||
.user_data(())
|
||||
.invoke_handler(|web_view, arg| {
|
||||
debug!("Command {}", arg);
|
||||
@@ -306,7 +306,9 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
|
||||
if index > 0 {
|
||||
c.bus.post(Event::BlockchainChanged { index });
|
||||
}
|
||||
if let Ok(zones) = serde_json::to_string(&c.chain.get_zones()) {
|
||||
let zones = c.chain.get_zones();
|
||||
info!("Loaded zones: {:?}", &zones);
|
||||
if let Ok(zones) = serde_json::to_string(&zones) {
|
||||
let _ = web_view.eval(&format!("zonesChanged('{}');", &zones));
|
||||
}
|
||||
event_info(web_view, "Application loaded");
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>ALFIS</title>
|
||||
{styles}
|
||||
{scripts}
|
||||
{styles}
|
||||
</head>
|
||||
<body onload="onLoad();">
|
||||
|
||||
|
||||
@@ -438,11 +438,8 @@ function keystoreChanged(path, pub_key, hash) {
|
||||
public_key_field.value = pub_key;
|
||||
public_key_field.title = path + "\n" + hash;
|
||||
|
||||
var save_key = document.getElementById("save_key");
|
||||
save_key.disabled = false;
|
||||
|
||||
var new_domain = document.getElementById("new_domain");
|
||||
new_domain.disabled = false;
|
||||
var save_key = document.getElementById("save_key").disabled = false;
|
||||
var new_domain = document.getElementById("new_domain").disabled = false;
|
||||
}
|
||||
|
||||
function closeZonesDropdown() {
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
use std::collections::HashSet;
|
||||
use crate::blockchain::hash_utils::hash_identity;
|
||||
|
||||
pub struct ExternalZones {
|
||||
zones: HashSet<String>,
|
||||
hashes: HashSet<String>
|
||||
}
|
||||
|
||||
impl ExternalZones {
|
||||
pub fn new() -> Self {
|
||||
let mut zones: HashSet<_> = include_str!("../iana-tlds.txt")
|
||||
.split("\n")
|
||||
.map(String::from)
|
||||
.collect();
|
||||
let mut hashes: HashSet<_> = include_str!("../iana-hashes.txt")
|
||||
.split("\n")
|
||||
.map(String::from)
|
||||
.collect();
|
||||
let open_nic: HashSet<_> = include_str!("../other-tlds.txt")
|
||||
.split("\n")
|
||||
.map(String::from)
|
||||
.collect();
|
||||
for zone in open_nic.iter() {
|
||||
if zone.is_empty() || zone.starts_with("#") {
|
||||
continue;
|
||||
}
|
||||
zones.insert(zone.to_string());
|
||||
hashes.insert(hash_identity(zone, None).to_string());
|
||||
}
|
||||
|
||||
Self { zones, hashes }
|
||||
}
|
||||
|
||||
pub fn has_zone(&self, zone: &str) -> bool {
|
||||
self.zones.contains(zone)
|
||||
}
|
||||
|
||||
pub fn has_hash(&self, hash: &str) -> bool {
|
||||
self.hashes.contains(hash)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user