diff --git a/node/src/protocol.rs b/node/src/protocol.rs index 199ad24b..d407906f 100644 --- a/node/src/protocol.rs +++ b/node/src/protocol.rs @@ -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 { - // TODO: Verify refs before adding them to storage. let mut repo = self.storage.repository(proj_id).unwrap(); let mut path = remote.path.clone(); diff --git a/node/src/protocol/message.rs b/node/src/protocol/message.rs index 93d60282..cc1db72c 100644 --- a/node/src/protocol/message.rs +++ b/node/src/protocol/message.rs @@ -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 for MessageType { fn try_from(other: u16) -> Result { 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
, git: git::Url) -> Self { - Self::Hello { + pub fn init(id: NodeId, timestamp: Timestamp, addrs: Vec
, 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::()?; 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::
::decode(reader)?; let git = git::Url::decode(reader)?; - Ok(Self::Hello { + Ok(Self::Initialize { id, timestamp, version, diff --git a/node/src/protocol/peer.rs b/node/src/protocol/peer.rs index ce5a4cf3..726f190b 100644 --- a/node/src/protocol/peer.rs +++ b/node/src/protocol/peer.rs @@ -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() diff --git a/node/src/test/peer.rs b/node/src/test/peer.rs index 8efed1db..2191304c 100644 --- a/node/src/test/peer.rs +++ b/node/src/test/peer.rs @@ -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(), diff --git a/node/src/test/tests.rs b/node/src/test/tests.rs index 2c00ca09..c6dc73af 100644 --- a/node/src/test/tests.rs +++ b/node/src/test/tests.rs @@ -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![],