Added some checks for "Yggdrasil only" zones.
This commit is contained in:
+18
-2
@@ -8,7 +8,7 @@ use chrono::Utc;
|
|||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use sqlite::{Connection, State, Statement};
|
use sqlite::{Connection, State, Statement};
|
||||||
|
|
||||||
use crate::{Block, Bytes, Keystore, Transaction, check_domain, get_domain_zone};
|
use crate::{Block, Bytes, Keystore, Transaction, check_domain, get_domain_zone, is_yggdrasil_record};
|
||||||
use crate::commons::constants::*;
|
use crate::commons::constants::*;
|
||||||
use crate::blockchain::types::{BlockQuality, MineResult, Options};
|
use crate::blockchain::types::{BlockQuality, MineResult, Options};
|
||||||
use crate::blockchain::types::BlockQuality::*;
|
use crate::blockchain::types::BlockQuality::*;
|
||||||
@@ -558,7 +558,7 @@ impl Chain {
|
|||||||
}
|
}
|
||||||
if let Some(transaction) = &block.transaction {
|
if let Some(transaction) = &block.transaction {
|
||||||
// TODO check for zone transaction
|
// TODO check for zone transaction
|
||||||
if !self.is_id_available(&transaction.identity, &block.pub_key, false) {
|
if !self.is_id_available(&transaction.identity, &block.pub_key, false) || !self.is_id_available(&transaction.identity, &block.pub_key, true) {
|
||||||
warn!("Block {:?} is trying to spoof an identity!", &block);
|
warn!("Block {:?} is trying to spoof an identity!", &block);
|
||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
@@ -569,6 +569,22 @@ impl Chain {
|
|||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if yggdrasil only quality of zone is not violated
|
||||||
|
if let Some(block_data) = transaction.get_domain_data() {
|
||||||
|
let zones = self.get_zones();
|
||||||
|
for z in &zones {
|
||||||
|
if z.name == block_data.zone {
|
||||||
|
if z.yggdrasil {
|
||||||
|
for record in &block_data.records {
|
||||||
|
if !is_yggdrasil_record(record) {
|
||||||
|
warn!("Someone mined domain with clearnet records for Yggdrasil only zone!");
|
||||||
|
return Bad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
match &self.last_block {
|
match &self.last_block {
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ pub fn same_hash(left: &[u8], right: &[u8]) -> bool {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns hash difficulty
|
/// Returns hash difficulty (sum of zeroes from start and end)
|
||||||
|
#[inline]
|
||||||
pub fn hash_difficulty(hash: &[u8]) -> u32 {
|
pub fn hash_difficulty(hash: &[u8]) -> u32 {
|
||||||
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
||||||
let int_start = u64::from_be_bytes(bytes);
|
let int_start = u64::from_be_bytes(bytes);
|
||||||
@@ -67,12 +68,16 @@ pub fn hash_difficulty(hash: &[u8]) -> u32 {
|
|||||||
int_start.leading_zeros() + int_end.trailing_zeros()
|
int_start.leading_zeros() + int_end.trailing_zeros()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns hash difficulty for keys (only from the start)
|
||||||
|
#[inline]
|
||||||
pub fn hash_difficulty_key(hash: &[u8]) -> u32 {
|
pub fn hash_difficulty_key(hash: &[u8]) -> u32 {
|
||||||
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
||||||
let int = u64::from_be_bytes(bytes);
|
let int = u64::from_be_bytes(bytes);
|
||||||
int.leading_zeros()
|
int.leading_zeros()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hashes data by Sha256 algorithm
|
||||||
|
#[inline]
|
||||||
pub fn hash_sha256(data: &[u8]) -> Vec<u8> {
|
pub fn hash_sha256(data: &[u8]) -> Vec<u8> {
|
||||||
let mut digest = Sha256::default();
|
let mut digest = Sha256::default();
|
||||||
digest.update(data.as_ref());
|
digest.update(data.as_ref());
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ impl Transaction {
|
|||||||
let confirmation = hash_identity(&domain, Some(&self.pub_key));
|
let confirmation = hash_identity(&domain, Some(&self.pub_key));
|
||||||
self.identity.eq(&hash) && self.confirmation.eq(&confirmation)
|
self.identity.eq(&hash) && self.confirmation.eq(&confirmation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns [DomainData] from this transaction if it has it
|
||||||
|
pub fn get_domain_data(&self) -> Option<DomainData> {
|
||||||
|
if self.class == "domain" {
|
||||||
|
if let Ok(data) = serde_json::from_str::<DomainData>(&self.data) {
|
||||||
|
return Some(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Transaction {
|
impl fmt::Debug for Transaction {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::net::IpAddr;
|
|||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
use thread_priority::*;
|
use thread_priority::*;
|
||||||
|
use crate::dns::protocol::DnsRecord;
|
||||||
|
|
||||||
/// Convert bytes array to HEX format
|
/// Convert bytes array to HEX format
|
||||||
pub fn to_hex(buf: &[u8]) -> String {
|
pub fn to_hex(buf: &[u8]) -> String {
|
||||||
@@ -94,6 +95,24 @@ pub fn is_yggdrasil(addr: &IpAddr) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if this record has IP from Yggdrasil network
|
||||||
|
/// https://yggdrasil-network.github.io
|
||||||
|
pub fn is_yggdrasil_record(record: &DnsRecord) -> bool {
|
||||||
|
match record {
|
||||||
|
DnsRecord::UNKNOWN { .. } => {}
|
||||||
|
DnsRecord::A { .. } => { return false }
|
||||||
|
DnsRecord::NS { .. } => {}
|
||||||
|
DnsRecord::CNAME { .. } => {}
|
||||||
|
DnsRecord::SOA { .. } => {}
|
||||||
|
DnsRecord::MX { .. } => {}
|
||||||
|
DnsRecord::TXT { .. } => {}
|
||||||
|
DnsRecord::AAAA { addr, .. } => { return is_yggdrasil(&IpAddr::from(*addr))}
|
||||||
|
DnsRecord::SRV { .. } => {}
|
||||||
|
DnsRecord::OPT { .. } => {}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub fn setup_miner_thread(cpu: u32) {
|
pub fn setup_miner_thread(cpu: u32) {
|
||||||
|
|||||||
+15
-1
@@ -14,7 +14,7 @@ use log::{debug, error, info, LevelFilter, trace, warn};
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use web_view::Content;
|
use web_view::Content;
|
||||||
|
|
||||||
use alfis::{Block, Bytes, Context, get_domain_zone, Keystore, Transaction, ZONE_MIN_DIFFICULTY};
|
use alfis::{Block, Bytes, Context, get_domain_zone, Keystore, Transaction, ZONE_MIN_DIFFICULTY, is_yggdrasil_record};
|
||||||
use alfis::{check_domain, keys};
|
use alfis::{check_domain, keys};
|
||||||
use alfis::blockchain::transaction::{DomainData, ZoneData};
|
use alfis::blockchain::transaction::{DomainData, ZoneData};
|
||||||
use alfis::blockchain::types::MineResult;
|
use alfis::blockchain::types::MineResult;
|
||||||
@@ -336,6 +336,20 @@ fn action_create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Check if yggdrasil only quality of zone is not violated
|
||||||
|
let zones = context.chain.get_zones();
|
||||||
|
for z in &zones {
|
||||||
|
if z.name == data.zone {
|
||||||
|
if z.yggdrasil {
|
||||||
|
for record in &data.records {
|
||||||
|
if !is_yggdrasil_record(record) {
|
||||||
|
show_warning(web_view, &format!("Zone {} is Yggdrasil only, you cannot use IPs from clearnet!", &data.zone));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
match context.chain.can_mine_domain(&name, &pub_key) {
|
match context.chain.can_mine_domain(&name, &pub_key) {
|
||||||
MineResult::Fine => {
|
MineResult::Fine => {
|
||||||
let zone = get_domain_zone(&name);
|
let zone = get_domain_zone(&name);
|
||||||
|
|||||||
Reference in New Issue
Block a user