| 1 |
// Copyright (C) 2021, Cloudflare, Inc. |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// Redistribution and use in source and binary forms, with or without |
| 5 |
// modification, are permitted provided that the following conditions are |
| 6 |
// met: |
| 7 |
// |
| 8 |
// * Redistributions of source code must retain the above copyright notice, |
| 9 |
// this list of conditions and the following disclaimer. |
| 10 |
// |
| 11 |
// * Redistributions in binary form must reproduce the above copyright |
| 12 |
// notice, this list of conditions and the following disclaimer in the |
| 13 |
// documentation and/or other materials provided with the distribution. |
| 14 |
// |
| 15 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 16 |
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 |
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 19 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
|
| 27 |
use serde::Deserialize; |
| 28 |
use serde::Serialize; |
| 29 |
|
| 30 |
use super::ApplicationErrorCode; |
| 31 |
use super::Bytes; |
| 32 |
use super::ConnectionErrorCode; |
| 33 |
|
| 34 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 35 |
#[serde(rename_all = "snake_case")] |
| 36 |
pub enum TransportOwner { |
| 37 |
Local, |
| 38 |
Remote, |
| 39 |
} |
| 40 |
|
| 41 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 42 |
#[serde(rename_all = "snake_case")] |
| 43 |
pub enum ConnectionState { |
| 44 |
Attempted, |
| 45 |
PeerValidated, |
| 46 |
HandshakeStarted, |
| 47 |
EarlyWrite, |
| 48 |
HandshakeCompleted, |
| 49 |
HandshakeConfirmed, |
| 50 |
Closing, |
| 51 |
Draining, |
| 52 |
Closed, |
| 53 |
} |
| 54 |
|
| 55 |
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)] |
| 56 |
#[serde(rename_all = "snake_case")] |
| 57 |
pub enum ConnectivityEventType { |
| 58 |
ServerListening, |
| 59 |
ConnectionStarted, |
| 60 |
ConnectionClosed, |
| 61 |
ConnectionIdUpdated, |
| 62 |
SpinBitUpdated, |
| 63 |
ConnectionStateUpdated, |
| 64 |
MtuUpdated, |
| 65 |
} |
| 66 |
|
| 67 |
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)] |
| 68 |
#[serde(rename_all = "snake_case")] |
| 69 |
pub enum ConnectionClosedTrigger { |
| 70 |
Clean, |
| 71 |
HandshakeTimeout, |
| 72 |
IdleTimeout, |
| 73 |
Error, |
| 74 |
StatelessReset, |
| 75 |
VersionMismatch, |
| 76 |
Application, |
| 77 |
} |
| 78 |
|
| 79 |
#[serde_with::skip_serializing_none] |
| 80 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 81 |
pub struct ServerListening { |
| 82 |
pub ip_v4: Option<String>, // human-readable or bytes |
| 83 |
pub ip_v6: Option<String>, // human-readable or bytes |
| 84 |
pub port_v4: Option<u16>, |
| 85 |
pub port_v6: Option<u16>, |
| 86 |
|
| 87 |
retry_required: Option<bool>, |
| 88 |
} |
| 89 |
|
| 90 |
#[serde_with::skip_serializing_none] |
| 91 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 92 |
pub struct ConnectionStarted { |
| 93 |
pub ip_version: Option<String>, // "v4" or "v6" |
| 94 |
pub src_ip: String, // human-readable or bytes |
| 95 |
pub dst_ip: String, // human-readable or bytes |
| 96 |
|
| 97 |
pub protocol: Option<String>, |
| 98 |
pub src_port: Option<u16>, |
| 99 |
pub dst_port: Option<u16>, |
| 100 |
|
| 101 |
pub src_cid: Option<Bytes>, |
| 102 |
pub dst_cid: Option<Bytes>, |
| 103 |
} |
| 104 |
|
| 105 |
#[serde_with::skip_serializing_none] |
| 106 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 107 |
pub struct ConnectionClosed { |
| 108 |
pub owner: Option<TransportOwner>, |
| 109 |
|
| 110 |
pub connection_code: Option<ConnectionErrorCode>, |
| 111 |
pub application_code: Option<ApplicationErrorCode>, |
| 112 |
pub internal_code: Option<u32>, |
| 113 |
|
| 114 |
pub reason: Option<String>, |
| 115 |
|
| 116 |
pub trigger: Option<ConnectionClosedTrigger>, |
| 117 |
} |
| 118 |
|
| 119 |
#[serde_with::skip_serializing_none] |
| 120 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 121 |
pub struct ConnectionIdUpdated { |
| 122 |
pub owner: Option<TransportOwner>, |
| 123 |
|
| 124 |
pub old: Option<Bytes>, |
| 125 |
pub new: Option<Bytes>, |
| 126 |
} |
| 127 |
|
| 128 |
#[serde_with::skip_serializing_none] |
| 129 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 130 |
pub struct SpinBitUpdated { |
| 131 |
pub state: bool, |
| 132 |
} |
| 133 |
|
| 134 |
#[serde_with::skip_serializing_none] |
| 135 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 136 |
pub struct ConnectionStateUpdated { |
| 137 |
pub old: Option<ConnectionState>, |
| 138 |
pub new: ConnectionState, |
| 139 |
} |
| 140 |
|
| 141 |
#[serde_with::skip_serializing_none] |
| 142 |
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] |
| 143 |
pub struct MtuUpdated { |
| 144 |
pub old: Option<u16>, |
| 145 |
pub new: u16, |
| 146 |
pub done: Option<bool>, |
| 147 |
} |