Node icon indicating copy to clipboard operation
Node copied to clipboard

Change Neighborhood DB to contain Free World Bit and Country code

Open czarte opened this issue 1 year ago • 0 comments

We have decided to contain Fere World Bit and Country Code in NodeRecordInner_0v1

#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub struct NodeRecordInner_0v1 {
    pub public_key: PublicKey,
    pub earning_wallet: Wallet,
    pub rate_pack: RatePack,
    pub neighbors: BTreeSet<PublicKey>,
    pub accepts_connections: bool,
    pub routes_data: bool,
    pub version: u32,
    pub free_world_bit: bool,
    pub country_code: String,
}

There is need to be implemented location: Option<NodeLocation> into impl NodeRecord

impl NodeRecord {
    pub fn new(
        public_key: &PublicKey,
        ...
        location: Option<NodeLocation>,
    ) -> NodeRecord {
        let mut free_world = false;
        let mut country = String::default();
        match location.as_ref() {
            Some(node_location) => {
                free_world = node_location.free_world;
                country = node_location.country.clone();
            },
            None => {  },
        };
        let mut node_record = NodeRecord {
            metadata: NodeRecordMetadata::new(location),
            inner: NodeRecordInner_0v1 {
                public_key: public_key.clone(),
                ...
                free_world_bit: free_world,
                country_code: country
            },
            signed_gossip: PlainData::new(&[]),
            signature: CryptData::new(&[]),
        };
        node_record.regenerate_signed_gossip(cryptde);
        node_record
    }
}

in NodeRecordMetadata we want to store the FreeWorldScore to handle the undesirability of the current Node to Exiting our Routes.

  1. Add node_location: NodeLocation to struct NodeRecordMetadata
    pub struct NodeRecordMetadata {
        pub last_update: u32,
        pub node_addr_opt: Option<NodeAddr>,
        pub unreachable_hosts: HashSet<String>,
        pub node_location: Option<NodeLocation>,
        pub free_world_score: u32
    }
    
  2. Put node_location to constructor pub fn new(node_location: NodeLocation) into impl NodeRecordMetadata
  3. Introduce new struct NodeData to pass it in NodeRecord::new() instead of too many of variables:
    NodeData {
        public_key: &PublicKey,
        earning_wallet: Wallet,
        rate_pack: RatePack,
        accepts_connections: bool,
        routes_data: bool,
        version: u32,
        cryptde: &dyn CryptDE,
        node_location: NodeLocation
    }
    

czarte avatar Apr 26 '24 08:04 czarte