node: Rename 'hello' message to 'initialize'

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-09-15 14:05:22 +02:00
parent 381080a5a5
commit d3dd83447e
No known key found for this signature in database
5 changed files with 22 additions and 23 deletions

View File

@ -755,7 +755,7 @@ where
fn handshake_messages(&self) -> [Message; 4] {
let git = self.config.git_url.clone();
[
Message::hello(
Message::init(
self.node_id(),
self.timestamp(),
self.config.listen.clone(),
@ -790,7 +790,6 @@ where
}
fn fetch(&mut self, proj_id: &Id, remote: &Url) -> Vec<RefUpdate> {
// TODO: Verify refs before adding them to storage.
let mut repo = self.storage.repository(proj_id).unwrap();
let mut path = remote.path.clone();

View File

@ -30,7 +30,7 @@ pub struct Hostname(String);
#[repr(u16)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageType {
Hello = 0,
Initialize = 0,
NodeAnnouncement = 2,
InventoryAnnouncement = 4,
RefsAnnouncement = 6,
@ -48,7 +48,7 @@ impl TryFrom<u16> for MessageType {
fn try_from(other: u16) -> Result<Self, Self::Error> {
match other {
0 => Ok(MessageType::Hello),
0 => Ok(MessageType::Initialize),
2 => Ok(MessageType::NodeAnnouncement),
4 => Ok(MessageType::InventoryAnnouncement),
6 => Ok(MessageType::RefsAnnouncement),
@ -337,8 +337,8 @@ impl wire::Decode for InventoryAnnouncement {
/// These are the messages peers send to each other.
#[derive(Clone, PartialEq, Eq)]
pub enum Message {
/// Say hello to a peer. This is the first message sent to a peer after connection.
Hello {
/// The first message sent to a peer after connection.
Initialize {
// TODO: This is currently untrusted.
id: NodeId,
timestamp: Timestamp,
@ -384,8 +384,8 @@ pub enum Message {
}
impl Message {
pub fn hello(id: NodeId, timestamp: Timestamp, addrs: Vec<Address>, git: git::Url) -> Self {
Self::Hello {
pub fn init(id: NodeId, timestamp: Timestamp, addrs: Vec<Address>, git: git::Url) -> Self {
Self::Initialize {
id,
timestamp,
version: PROTOCOL_VERSION,
@ -428,7 +428,7 @@ impl Message {
pub fn type_id(&self) -> u16 {
match self {
Self::Hello { .. } => MessageType::Hello,
Self::Initialize { .. } => MessageType::Initialize,
Self::Subscribe { .. } => MessageType::Subscribe,
Self::NodeAnnouncement { .. } => MessageType::NodeAnnouncement,
Self::InventoryAnnouncement { .. } => MessageType::InventoryAnnouncement,
@ -441,7 +441,7 @@ impl Message {
impl fmt::Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Hello { id, .. } => write!(f, "Hello({})", id),
Self::Initialize { id, .. } => write!(f, "Initialize({})", id),
Self::Subscribe(Subscribe { since, until, .. }) => {
write!(f, "Subscribe({}..{})", since, until)
}
@ -477,7 +477,7 @@ impl wire::Encode for Message {
let mut n = self.type_id().encode(writer)?;
match self {
Self::Hello {
Self::Initialize {
id,
timestamp,
version,
@ -536,14 +536,14 @@ impl wire::Decode for Message {
let type_id = reader.read_u16::<NetworkEndian>()?;
match MessageType::try_from(type_id) {
Ok(MessageType::Hello) => {
Ok(MessageType::Initialize) => {
let id = NodeId::decode(reader)?;
let timestamp = Timestamp::decode(reader)?;
let version = u32::decode(reader)?;
let addrs = Vec::<Address>::decode(reader)?;
let git = git::Url::decode(reader)?;
Ok(Self::Hello {
Ok(Self::Initialize {
id,
timestamp,
version,

View File

@ -115,7 +115,7 @@ impl Peer {
match (&self.state, envelope.msg) {
(
PeerState::Initial,
Message::Hello {
Message::Initialize {
id,
timestamp,
version,
@ -132,7 +132,7 @@ impl Peer {
return Err(PeerError::WrongVersion(version));
}
// Nb. This is a very primitive handshake. Eventually we should have anyhow
// extra "acknowledgment" message sent when the `Hello` is well received.
// extra "acknowledgment" message sent when the `Initialize` is well received.
if self.link.is_inbound() {
ctx.write_all(self.addr, ctx.handshake_messages());
}
@ -236,7 +236,7 @@ impl Peer {
(PeerState::Negotiated { .. }, Message::Subscribe(subscribe)) => {
self.subscribe = Some(subscribe);
}
(PeerState::Negotiated { .. }, Message::Hello { .. }) => {
(PeerState::Negotiated { .. }, Message::Initialize { .. }) => {
debug!(
"Disconnecting peer {} for sending us a redundant handshake message",
self.ip()

View File

@ -144,7 +144,7 @@ where
self.protocol.connected(remote, &local, Link::Inbound);
self.receive(
&remote,
Message::hello(
Message::init(
peer.node_id(),
self.local_time().as_secs(),
vec![Address::from(remote)],
@ -153,8 +153,8 @@ where
);
let mut msgs = self.messages(&remote);
msgs.find(|m| matches!(m, Message::Hello { .. }))
.expect("`hello` is sent");
msgs.find(|m| matches!(m, Message::Initialize { .. }))
.expect("`initialize` is sent");
msgs.find(|m| matches!(m, Message::InventoryAnnouncement { .. }))
.expect("`inventory-announcement` is sent");
}
@ -168,15 +168,15 @@ where
.connected(remote, &self.local_addr, Link::Outbound);
let mut msgs = self.messages(&remote);
msgs.find(|m| matches!(m, Message::Hello { .. }))
.expect("`hello` is sent");
msgs.find(|m| matches!(m, Message::Initialize { .. }))
.expect("`initialize` is sent");
msgs.find(|m| matches!(m, Message::InventoryAnnouncement { .. }))
.expect("`inventory-announcement` is sent");
let git = peer.config().git_url.clone();
self.receive(
&remote,
Message::hello(
Message::init(
peer.node_id(),
self.local_time().as_secs(),
peer.config().listen.clone(),

View File

@ -112,7 +112,7 @@ fn test_handshake_invalid_timestamp() {
alice.connected(bob.addr(), &local, Link::Inbound);
alice.receive(
&bob.addr(),
Message::hello(
Message::init(
bob.node_id(),
alice.timestamp() - time_delta,
vec![],