Change update to not add self to node list

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent 833dd1a47b
commit 6a2f24945d
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,7 +1,7 @@
[package] [package]
name = "vented" name = "vented"
description = "Event driven encrypted tcp communicaton" description = "Event driven encrypted tcp communicaton"
version = "0.6.2" version = "0.6.3"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"

@ -17,7 +17,7 @@ pub(crate) const REDIRECT_CONFIRM_EVENT: &str = "conn:redirect_confirm";
pub(crate) const REDIRECT_FAIL_EVENT: &str = "conn:redirect_failed"; pub(crate) const REDIRECT_FAIL_EVENT: &str = "conn:redirect_failed";
pub(crate) const REDIRECT_REDIRECTED_EVENT: &str = "conn:redirect_redirected"; pub(crate) const REDIRECT_REDIRECTED_EVENT: &str = "conn:redirect_redirected";
pub(crate) const NODE_LIST_REQUEST_EVENT: &str = "conn:node_list_request"; pub(crate) const NODE_LIST_REQUEST_EVENT: &str = "conn:node_list_request";
const NODE_LIST_EVENT: &str = "conn:node_list"; pub const NODE_LIST_EVENT: &str = "conn:node_list";
pub const READY_EVENT: &str = "server:ready"; pub const READY_EVENT: &str = "server:ready";
@ -177,6 +177,7 @@ impl VentedServer {
}); });
self.on(NODE_LIST_EVENT, { self.on(NODE_LIST_EVENT, {
let node_list = Arc::clone(&self.known_nodes); let node_list = Arc::clone(&self.known_nodes);
let own_id = self.node_id.clone();
move |event| { move |event| {
let list = event.get_payload::<NodeListPayload>().ok()?; let list = event.get_payload::<NodeListPayload>().ok()?;
@ -190,7 +191,7 @@ impl VentedServer {
let mut new_nodes = 0; let mut new_nodes = 0;
for node in list.nodes { for node in list.nodes {
if !own_nodes.contains_key(&node.id) { if !own_nodes.contains_key(&node.id) && node.id != own_id {
own_nodes.insert( own_nodes.insert(
node.id.clone(), node.id.clone(),
Node { Node {
@ -211,10 +212,12 @@ impl VentedServer {
self.on(NODE_LIST_REQUEST_EVENT, { self.on(NODE_LIST_REQUEST_EVENT, {
let node_list = Arc::clone(&self.known_nodes); let node_list = Arc::clone(&self.known_nodes);
move |_| { move |event| {
let sender_id = event.origin?;
let nodes = node_list let nodes = node_list
.lock() .lock()
.values() .values()
.filter(|node| node.id != sender_id)
.map(|node| NodeListElement { .map(|node| NodeListElement {
id: node.id.clone(), id: node.id.clone(),
address: node.address.clone(), address: node.address.clone(),

Loading…
Cancel
Save