txid.rs 623 B

123456789101112131415161718192021222324
  1. //! Transaction ID generation.
  2. /// A **transaction ID generator** is used to create unique ID numbers to
  3. /// identify each packet, as part of the DNS protocol.
  4. #[derive(PartialEq, Debug, Copy, Clone)]
  5. pub enum TxidGenerator {
  6. /// Generate random transaction IDs each time.
  7. Random,
  8. /// Generate transaction IDs in a sequence, starting from the given value,
  9. /// wrapping around.
  10. Sequence(u16),
  11. }
  12. impl TxidGenerator {
  13. pub fn generate(self) -> u16 {
  14. match self {
  15. Self::Random => rand::random(),
  16. Self::Sequence(start) => start, // todo
  17. }
  18. }
  19. }