b5c8b69547
* Experiment with serde * Framed encoding serde POC * Outfox framing * Outfox rest compat (#3333) * Outfox forwarding compat * Tidy up interface * PacketSize compat * Address PR comments * Rebase on develop commit342883fcbeAuthor: durch <durch@users.noreply.github.com> Date: Thu Apr 27 09:17:18 2023 +0200 Put back PacketType 1 commit61a0ee5a19Author: Tommy Verrall <tommyvez@protonmail.com> Date: Wed Apr 26 16:37:29 2023 +0100 change output for cpu-cycle management logs commit3956109c7eAuthor: Tommy Verrall <tommy@nymtech.net> Date: Wed Apr 26 12:13:22 2023 +0100 change the workflow file to build with cpucycles commit8d725b13c5Author: durch <durch@users.noreply.github.com> Date: Mon Apr 24 13:14:58 2023 +0200 Outfox client compat commit4d166c389bAuthor: durch <durch@users.noreply.github.com> Date: Fri Apr 21 00:30:46 2023 +0200 Address PR comments commit145c3c1223Author: durch <durch@users.noreply.github.com> Date: Fri Apr 21 00:12:35 2023 +0200 Rename PacketMode commitcbd654d6fdAuthor: Drazen Urch <drazen@urch.eu> Date: Thu Apr 20 23:59:40 2023 +0200 Outfox rest compat (#3333) * Outfox forwarding compat * Tidy up interface * PacketSize compat commite7be91a94cAuthor: durch <durch@users.noreply.github.com> Date: Wed Apr 19 16:36:48 2023 +0200 Remove serde cruft commit582e7d566aAuthor: durch <durch@users.noreply.github.com> Date: Wed Apr 19 16:24:09 2023 +0200 Outfox framing commit6464da5f01Author: durch <durch@users.noreply.github.com> Date: Tue Apr 18 22:23:02 2023 +0200 Framing compat commitd5e77e499bAuthor: durch <durch@users.noreply.github.com> Date: Tue Apr 18 18:18:54 2023 +0200 Framed encoding serde POC commitf086f9c35aAuthor: durch <durch@users.noreply.github.com> Date: Tue Apr 18 16:54:21 2023 +0200 Experiment with serde * Client tweaks * Speed up from_plaintext * SurbAcks * More work on the reciever end, and outfox format * Cleanup and fmt * Wrap up rebase * Happy clippy * Fix lock files * Final cleanup
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{PacketSize, CURRENT_PACKET_VERSION_NUMBER};
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum PacketVersion {
|
|
// this will allow updated mixnodes to still understand packets from before the update
|
|
Legacy,
|
|
Versioned(u8),
|
|
}
|
|
|
|
impl PacketVersion {
|
|
pub fn new(use_legacy: bool) -> Self {
|
|
if use_legacy {
|
|
Self::new_legacy()
|
|
} else {
|
|
Self::new_versioned(CURRENT_PACKET_VERSION_NUMBER)
|
|
}
|
|
}
|
|
|
|
pub fn new_legacy() -> Self {
|
|
PacketVersion::Legacy
|
|
}
|
|
|
|
pub fn new_versioned(version: u8) -> Self {
|
|
PacketVersion::Versioned(version)
|
|
}
|
|
|
|
pub fn is_legacy(&self) -> bool {
|
|
matches!(self, PacketVersion::Legacy)
|
|
}
|
|
|
|
pub fn as_u8(&self) -> Option<u8> {
|
|
match self {
|
|
PacketVersion::Legacy => None,
|
|
PacketVersion::Versioned(version) => Some(*version),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<u8> for PacketVersion {
|
|
fn from(v: u8) -> Self {
|
|
match v {
|
|
n if n == PacketSize::RegularPacket as u8 => PacketVersion::Legacy,
|
|
n if n == PacketSize::AckPacket as u8 => PacketVersion::Legacy,
|
|
n if n == PacketSize::ExtendedPacket8 as u8 => PacketVersion::Legacy,
|
|
n if n == PacketSize::ExtendedPacket16 as u8 => PacketVersion::Legacy,
|
|
n if n == PacketSize::ExtendedPacket32 as u8 => PacketVersion::Legacy,
|
|
n => PacketVersion::Versioned(n),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for PacketVersion {
|
|
fn default() -> Self {
|
|
PacketVersion::Versioned(CURRENT_PACKET_VERSION_NUMBER)
|
|
}
|
|
}
|