radicle-node: distinguish announcment nodes
Its easy to confuse what/who 'node' or 'session' is. Rename session to 'relayer' to convey its role as message propagator. Rename the announcement's node to 'announcer', clarifying its as the source. Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
parent
a8895aee80
commit
3c900f106f
|
|
@ -599,17 +599,21 @@ where
|
||||||
/// and `false` if it should not.
|
/// and `false` if it should not.
|
||||||
pub fn handle_announcement(
|
pub fn handle_announcement(
|
||||||
&mut self,
|
&mut self,
|
||||||
session: &NodeId,
|
relayer: &NodeId,
|
||||||
announcement: &Announcement,
|
announcement: &Announcement,
|
||||||
) -> Result<bool, session::Error> {
|
) -> Result<bool, session::Error> {
|
||||||
if !announcement.verify() {
|
if !announcement.verify() {
|
||||||
return Err(session::Error::Misbehavior);
|
return Err(session::Error::Misbehavior);
|
||||||
}
|
}
|
||||||
let Announcement { node, message, .. } = announcement;
|
let Announcement {
|
||||||
|
node: announcer,
|
||||||
|
message,
|
||||||
|
..
|
||||||
|
} = announcement;
|
||||||
let now = self.clock.local_time();
|
let now = self.clock.local_time();
|
||||||
let timestamp = message.timestamp();
|
let timestamp = message.timestamp();
|
||||||
let relay = self.config.relay;
|
let relay = self.config.relay;
|
||||||
let peer = self.nodes.entry(*node).or_insert_with(Node::default);
|
let peer = self.nodes.entry(*announcer).or_insert_with(Node::default);
|
||||||
|
|
||||||
// Don't allow messages from too far in the future.
|
// Don't allow messages from too far in the future.
|
||||||
if timestamp.saturating_sub(now.as_secs()) > MAX_TIME_DELTA.as_secs() {
|
if timestamp.saturating_sub(now.as_secs()) > MAX_TIME_DELTA.as_secs() {
|
||||||
|
|
@ -621,16 +625,16 @@ where
|
||||||
// Discard inventory messages we've already seen, otherwise update
|
// Discard inventory messages we've already seen, otherwise update
|
||||||
// out last seen time.
|
// out last seen time.
|
||||||
if !peer.inventory_announced(timestamp) {
|
if !peer.inventory_announced(timestamp) {
|
||||||
debug!("Ignoring stale inventory announcement from {node}");
|
debug!("Ignoring stale inventory announcement from {announcer}");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = self.process_inventory(&message.inventory, *node) {
|
if let Err(err) = self.process_inventory(&message.inventory, *announcer) {
|
||||||
error!("Error processing inventory from {}: {}", node, err);
|
error!("Error processing inventory from {}: {}", announcer, err);
|
||||||
|
|
||||||
if let Error::Fetch(storage::FetchError::Verify(err)) = err {
|
if let Error::Fetch(storage::FetchError::Verify(err)) = err {
|
||||||
// Disconnect the peer if it is the signer of this message.
|
// Disconnect the peer if it is the signer of this message.
|
||||||
if node == session {
|
if announcer == relayer {
|
||||||
return Err(session::Error::VerificationFailed(err));
|
return Err(session::Error::VerificationFailed(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +652,7 @@ where
|
||||||
// Discard inventory messages we've already seen, otherwise update
|
// Discard inventory messages we've already seen, otherwise update
|
||||||
// out last seen time.
|
// out last seen time.
|
||||||
if !peer.refs_announced(message.id, timestamp) {
|
if !peer.refs_announced(message.id, timestamp) {
|
||||||
debug!("Ignoring stale refs announcement from {node}");
|
debug!("Ignoring stale refs announcement from {announcer}");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
// TODO: Check refs to see if we should try to fetch or not.
|
// TODO: Check refs to see if we should try to fetch or not.
|
||||||
|
|
@ -659,13 +663,13 @@ where
|
||||||
.storage
|
.storage
|
||||||
.repository(message.id)
|
.repository(message.id)
|
||||||
.map_err(storage::FetchError::from)
|
.map_err(storage::FetchError::from)
|
||||||
.and_then(|mut r| r.fetch(session, Namespaces::default()))
|
.and_then(|mut r| r.fetch(relayer, Namespaces::default()))
|
||||||
{
|
{
|
||||||
Ok(updated) => updated,
|
Ok(updated) => updated,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(
|
error!(
|
||||||
"Error fetching repository {} from {}: {}",
|
"Error fetching repository {} from {}: {}",
|
||||||
message.id, session, err
|
message.id, relayer, err
|
||||||
);
|
);
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
@ -673,7 +677,7 @@ where
|
||||||
let is_updated = !updated.is_empty();
|
let is_updated = !updated.is_empty();
|
||||||
|
|
||||||
self.reactor.event(Event::RefsFetched {
|
self.reactor.event(Event::RefsFetched {
|
||||||
from: *session,
|
from: *relayer,
|
||||||
project: message.id,
|
project: message.id,
|
||||||
updated,
|
updated,
|
||||||
});
|
});
|
||||||
|
|
@ -692,7 +696,7 @@ where
|
||||||
// Discard node messages we've already seen, otherwise update
|
// Discard node messages we've already seen, otherwise update
|
||||||
// out last seen time.
|
// out last seen time.
|
||||||
if !peer.node_announced(timestamp) {
|
if !peer.node_announced(timestamp) {
|
||||||
debug!("Ignoring stale node announcement from {node}");
|
debug!("Ignoring stale node announcement from {announcer}");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -705,13 +709,13 @@ where
|
||||||
let alias = match str::from_utf8(alias) {
|
let alias = match str::from_utf8(alias) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Dropping node announcement from {node}: invalid alias: {e}");
|
warn!("Dropping node announcement from {announcer}: invalid alias: {e}");
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match self.addresses.insert(
|
match self.addresses.insert(
|
||||||
node,
|
announcer,
|
||||||
*features,
|
*features,
|
||||||
alias,
|
alias,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
|
@ -722,13 +726,15 @@ where
|
||||||
Ok(updated) => {
|
Ok(updated) => {
|
||||||
// Only relay if we received new information.
|
// Only relay if we received new information.
|
||||||
if updated {
|
if updated {
|
||||||
debug!("Address store entry for node {node} updated at {timestamp}");
|
debug!(
|
||||||
|
"Address store entry for node {announcer} updated at {timestamp}"
|
||||||
|
);
|
||||||
return Ok(relay);
|
return Ok(relay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// An error here is due to a fault in our address store.
|
// An error here is due to a fault in our address store.
|
||||||
error!("Error processing node announcement from {node}: {err}");
|
error!("Error processing node announcement from {announcer}: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -787,11 +793,11 @@ where
|
||||||
return Err(session::Error::Misbehavior);
|
return Err(session::Error::Misbehavior);
|
||||||
}
|
}
|
||||||
// Process a peer announcement.
|
// Process a peer announcement.
|
||||||
(session::State::Negotiated { id, .. }, Message::Announcement(ann)) => {
|
(session::State::Negotiated { id: relayer, .. }, Message::Announcement(ann)) => {
|
||||||
let id = *id;
|
let relayer = *relayer;
|
||||||
|
|
||||||
// Returning true here means that the message should be relayed.
|
// Returning true here means that the message should be relayed.
|
||||||
if self.handle_announcement(&id, &ann)? {
|
if self.handle_announcement(&relayer, &ann)? {
|
||||||
self.gossip.received(ann.clone(), ann.message.timestamp());
|
self.gossip.received(ann.clone(), ann.message.timestamp());
|
||||||
|
|
||||||
// Choose peers we should relay this message to.
|
// Choose peers we should relay this message to.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue