better route selection
This commit is contained in:
		@@ -646,22 +646,43 @@ impl RouteSpecStore {
 | 
			
		||||
                let v = v.unwrap();
 | 
			
		||||
 | 
			
		||||
                // Exclude our relay if we have one
 | 
			
		||||
                if let Some(relay_id) = opt_relay_id {
 | 
			
		||||
                    if k == relay_id {
 | 
			
		||||
                if let Some(own_relay_id) = opt_relay_id {
 | 
			
		||||
                    if k == own_relay_id {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Exclude nodes on our local network
 | 
			
		||||
                let on_local_network = v.with(rti, |_rti, e| {
 | 
			
		||||
                    e.node_info(RoutingDomain::LocalNetwork).is_some()
 | 
			
		||||
                });
 | 
			
		||||
                if on_local_network {
 | 
			
		||||
                // Exclude nodes we have specifically chosen to avoid
 | 
			
		||||
                if avoid_node_ids.contains(&k) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Exclude nodes we have specifically chosen to avoid
 | 
			
		||||
                if avoid_node_ids.contains(&k) {
 | 
			
		||||
                // Process node info exclusions
 | 
			
		||||
                let keep = v.with(rti, |_rti, e| {
 | 
			
		||||
                    // Exclude nodes on our local network
 | 
			
		||||
                    if e.node_info(RoutingDomain::LocalNetwork).is_some() {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    // Exclude nodes that have no publicinternet signednodeinfo
 | 
			
		||||
                    let Some(sni) = e.signed_node_info(RoutingDomain::PublicInternet) else {    
 | 
			
		||||
                        return false;
 | 
			
		||||
                    };
 | 
			
		||||
                    // Relay check
 | 
			
		||||
                    if let Some(relay_id) = sni.relay_id() {
 | 
			
		||||
                        // Exclude nodes whose relays we have chosen to avoid
 | 
			
		||||
                        if avoid_node_ids.contains(&relay_id.key) {
 | 
			
		||||
                            return false;
 | 
			
		||||
                        }
 | 
			
		||||
                        // Exclude nodes whose relay is our own relay if we have one
 | 
			
		||||
                        if let Some(own_relay_id) = opt_relay_id {
 | 
			
		||||
                            if own_relay_id == relay_id.key {
 | 
			
		||||
                                return false;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    return true;
 | 
			
		||||
                });
 | 
			
		||||
                if !keep {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -774,6 +795,22 @@ impl RouteSpecStore {
 | 
			
		||||
                return None;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Ensure the route doesn't contain both a node and its relay
 | 
			
		||||
            let mut seen_nodes: HashSet<DHTKey> = HashSet::new();
 | 
			
		||||
            for n in permutation {
 | 
			
		||||
                let node = nodes.get(*n).unwrap();
 | 
			
		||||
                if !seen_nodes.insert(node.node_id.key) {
 | 
			
		||||
                    // Already seen this node, should not be in the route twice
 | 
			
		||||
                    return None;
 | 
			
		||||
                }
 | 
			
		||||
                if let Some(relay_id) = node.signed_node_info.relay_id() {
 | 
			
		||||
                    if !seen_nodes.insert(relay_id.key) {
 | 
			
		||||
                        // Already seen this node, should not be in the route twice
 | 
			
		||||
                        return None;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Ensure this route is viable by checking that each node can contact the next one
 | 
			
		||||
            if directions.contains(Direction::Outbound) {
 | 
			
		||||
                let mut previous_node = &our_peer_info;
 | 
			
		||||
 
 | 
			
		||||
@@ -294,8 +294,10 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail {
 | 
			
		||||
            // Get the target's inbound relay, it must have one or it is not reachable
 | 
			
		||||
            if let Some(node_b_relay) = peer_b.signed_node_info.relay_info() {
 | 
			
		||||
                let node_b_relay_id = peer_b.signed_node_info.relay_id().unwrap();
 | 
			
		||||
 | 
			
		||||
                // Note that relay_peer_info could be node_a, in which case a connection already exists
 | 
			
		||||
                // and we shouldn't have even gotten here
 | 
			
		||||
                // and we only get here if the connection had dropped, in which case node_a is unreachable until
 | 
			
		||||
                // it gets a new relay connection up
 | 
			
		||||
                if node_b_relay_id.key == peer_a.node_id.key {
 | 
			
		||||
                    return ContactMethod::Existing;
 | 
			
		||||
                }
 | 
			
		||||
@@ -375,6 +377,13 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail {
 | 
			
		||||
        // If the node B has no direct dial info, it needs to have an inbound relay
 | 
			
		||||
        else if let Some(node_b_relay) = peer_b.signed_node_info.relay_info() {
 | 
			
		||||
            let node_b_relay_id = peer_b.signed_node_info.relay_id().unwrap();
 | 
			
		||||
            
 | 
			
		||||
            // Note that relay_peer_info could be node_a, in which case a connection already exists
 | 
			
		||||
            // and we only get here if the connection had dropped, in which case node_a is unreachable until
 | 
			
		||||
            // it gets a new relay connection up
 | 
			
		||||
            if node_b_relay_id.key == peer_a.node_id.key {
 | 
			
		||||
                return ContactMethod::Existing;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Can we reach the full relay?
 | 
			
		||||
            if first_filtered_dial_info_detail(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user