continue to refactor

This commit is contained in:
John Smith
2021-12-21 22:20:55 -05:00
parent c0a42ac90c
commit 5826551763
22 changed files with 381 additions and 551 deletions
+23 -12
View File
@@ -5,7 +5,9 @@ use alloc::fmt;
pub struct NodeRef {
routing_table: RoutingTable,
node_id: DHTKey,
protocol_address_type: Option<ProtocolAddressType>,
// Filters
protocol_type: Option<ProtocolType>,
address_type: Option<AddressType>,
}
impl NodeRef {
@@ -14,20 +16,23 @@ impl NodeRef {
Self {
routing_table,
node_id: key,
protocol_address_type: None,
protocol_type: None,
address_type: None,
}
}
pub fn new_filtered(
routing_table: RoutingTable,
key: DHTKey,
entry: &mut BucketEntry,
protocol_address_type: ProtocolAddressType,
protocol_type: Option<ProtocolType>,
address_type: Option<AddressType>,
) -> Self {
entry.ref_count += 1;
Self {
routing_table,
node_id: key,
protocol_address_type: Some(protocol_address_type),
protocol_type,
address_type,
}
}
@@ -35,15 +40,20 @@ impl NodeRef {
self.node_id
}
pub fn protocol_address_type(&self) -> Option<ProtocolAddressType> {
self.protocol_address_type
pub fn protocol_type(&self) -> Option<ProtocolType> {
self.protocol_type
}
pub fn set_protocol_address_type(
&mut self,
protocol_address_type: Option<ProtocolAddressType>,
) {
self.protocol_address_type = protocol_address_type;
pub fn set_protocol_type(&mut self, protocol_type: Option<ProtocolType>) {
self.protocol_type = protocol_type;
}
pub fn address_type(&self) -> Option<AddressType> {
self.address_type
}
pub fn set_address_type(&mut self, address_type: Option<AddressType>) {
self.address_type = address_type;
}
pub fn operate<T, F>(&self, f: F) -> T
@@ -53,8 +63,9 @@ impl NodeRef {
self.routing_table.operate_on_bucket_entry(self.node_id, f)
}
xxx fix the notion of 'best dial info' to sort by capability and udp/tcp/ws/wss preference order
pub fn dial_info(&self) -> Option<DialInfo> {
match self.protocol_address_type {
if self.protocol_type || self. {
None => self.operate(|e| e.best_dial_info()),
Some(pat) => self.operate(|e| {
e.filtered_dial_info(|die| die.dial_info().protocol_address_type() == pat)