Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
quic: remove typedef enum
Browse files Browse the repository at this point in the history
Using `typedef enum` is a C-ism.

PR-URL: #126
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Sep 23, 2019
1 parent dcd4636 commit 52c0cd7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/node_quic_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct CryptoContext {
};

// TODO(@jasnell): Remove once we move to ngtcp2_crypto
typedef enum ngtcp2_crypto_side {
enum ngtcp2_crypto_side {
/**
* ``NGTCP2_CRYPTO_SIDE_CLIENT`` indicates that the application is
* client.
Expand All @@ -70,7 +70,7 @@ typedef enum ngtcp2_crypto_side {
* server.
*/
NGTCP2_CRYPTO_SIDE_SERVER
} ngtcp2_crypto_side;
};

BIO_METHOD* CreateBIOMethod();

Expand Down
20 changes: 10 additions & 10 deletions src/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ class QuicSessionConfig {
// QuicServerSession. These are set on the QuicSocket when
// the listen() function is called and are passed to the
// constructor of the QuicServerSession.
typedef enum QuicServerSessionOptions : uint32_t {
enum QuicServerSessionOptions : uint32_t {
// When set, instructs the QuicServerSession to reject
// client authentication certs that cannot be verified.
QUICSERVERSESSION_OPTION_REJECT_UNAUTHORIZED = 0x1,

// When set, instructs the QuicServerSession to request
// a client authentication cert
QUICSERVERSESSION_OPTION_REQUEST_CERT = 0x2
} QuicServerSessionOptions;
};

// Options to alter the behavior of various functions on the
// QuicClientSession. These are set on the QuicClientSession
// constructor.
typedef enum QuicClientSessionOptions : uint32_t {
enum QuicClientSessionOptions : uint32_t {
// When set, instructs the QuicClientSession to include an
// OCSP request in the initial TLS handshake
QUICCLIENTSESSION_OPTION_REQUEST_OCSP = 0x1,
Expand All @@ -120,14 +120,14 @@ typedef enum QuicClientSessionOptions : uint32_t {
// When set, instructs the QuicClientSession to perform
// additional checks on TLS session resumption.
QUICCLIENTSESSION_OPTION_RESUME = 0x4
} QuicClientSessionOptions;
};


// The QuicSessionState enums are used with the QuicSession's
// private state_ array. This is exposed to JavaScript via an
// aliased buffer and is used to communicate various types of
// state efficiently across the native/JS boundary.
typedef enum QuicSessionState : int {
enum QuicSessionState : int {
// Communicates whether a 'keylog' event listener has been
// registered on the JavaScript QuicSession object. The
// value will be either 1 or 0. When set to 1, the native
Expand Down Expand Up @@ -165,7 +165,7 @@ typedef enum QuicSessionState : int {
// Just the number of session state enums for use when
// creating the AliasedBuffer.
IDX_QUIC_SESSION_STATE_COUNT
} QuicSessionState;
};

// The QuicSession class is an virtual class that serves as
// the basis for both QuicServerSession and QuicClientSession.
Expand Down Expand Up @@ -744,7 +744,7 @@ class QuicSession : public AsyncWrap,
void StopRetransmitTimer();
void StopIdleTimer();

typedef enum QuicSessionFlags : uint32_t {
enum QuicSessionFlags : uint32_t {
// Initial state when a QuicSession is created but nothing yet done.
QUICSESSION_FLAG_INITIAL = 0x1,

Expand Down Expand Up @@ -777,7 +777,7 @@ class QuicSession : public AsyncWrap,
// Set if the QuicSession is in the middle of a silent close
// (that is, a CONNECTION_CLOSE should not be sent)
QUICSESSION_FLAG_SILENT_CLOSE = 0x200
} QuicSessionFlags;
};

void SetFlag(QuicSessionFlags flag, bool on = true) {
if (on)
Expand Down Expand Up @@ -1022,11 +1022,11 @@ class QuicSession : public AsyncWrap,

class QuicServerSession : public QuicSession {
public:
typedef enum InitialPacketResult : int {
enum InitialPacketResult : int {
PACKET_OK,
PACKET_IGNORE,
PACKET_VERSION
} InitialPacketResult;
};

static InitialPacketResult Accept(
ngtcp2_pkt_hd* hd,
Expand Down
8 changes: 4 additions & 4 deletions src/node_quic_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace quic {

static constexpr size_t MAX_VALIDATE_ADDRESS_LRU = 10;

typedef enum QuicSocketOptions : uint32_t {
enum QuicSocketOptions : uint32_t {
// When enabled the QuicSocket will validate the address
// using a RETRY packet to the peer.
QUICSOCKET_OPTIONS_VALIDATE_ADDRESS = 0x1,
Expand All @@ -41,7 +41,7 @@ typedef enum QuicSocketOptions : uint32_t {
// validated addresses. Address validation will be skipped
// if the address is currently in the cache.
QUICSOCKET_OPTIONS_VALIDATE_ADDRESS_LRU = 0x2,
} QuicSocketOptions;
};

class QuicSocket : public HandleWrap,
public mem::Tracker {
Expand Down Expand Up @@ -205,7 +205,7 @@ class QuicSocket : public HandleWrap,
// Fields and TypeDefs
typedef uv_udp_t HandleType;

typedef enum QuicSocketFlags : uint32_t {
enum QuicSocketFlags : uint32_t {
QUICSOCKET_FLAGS_NONE = 0x0,

// Indicates that the QuicSocket has entered a graceful
Expand All @@ -214,7 +214,7 @@ class QuicSocket : public HandleWrap,
QUICSOCKET_FLAGS_PENDING_CLOSE = 0x2,
QUICSOCKET_FLAGS_SERVER_LISTENING = 0x4,
QUICSOCKET_FLAGS_SERVER_BUSY = 0x8,
} QuicSocketFlags;
};

void SetFlag(QuicSocketFlags flag, bool on = true) {
if (on)
Expand Down
4 changes: 2 additions & 2 deletions src/node_quic_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace node {

typedef enum QuicSessionConfigIndex : int {
enum QuicSessionConfigIndex : int {
IDX_QUIC_SESSION_ACTIVE_CONNECTION_ID_LIMIT,
IDX_QUIC_SESSION_MAX_STREAM_DATA_BIDI_LOCAL,
IDX_QUIC_SESSION_MAX_STREAM_DATA_BIDI_REMOTE,
Expand All @@ -22,7 +22,7 @@ typedef enum QuicSessionConfigIndex : int {
IDX_QUIC_SESSION_MAX_ACK_DELAY,
IDX_QUIC_SESSION_MAX_CRYPTO_BUFFER,
IDX_QUIC_SESSION_CONFIG_COUNT
} QuicSessionConfigIndex;
};

class QuicState {
public:
Expand Down
12 changes: 6 additions & 6 deletions src/node_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class QuicStream : public AsyncWrap,
public StreamBase,
public std::enable_shared_from_this<QuicStream> {
public:
typedef enum QuicStreamStates : uint32_t {
enum QuicStreamStates : uint32_t {
// QuicStream is fully open. Readable and Writable
QUICSTREAM_FLAG_INITIAL = 0x0,

Expand Down Expand Up @@ -125,24 +125,24 @@ class QuicStream : public AsyncWrap,

// QuicStream has been destroyed
QUICSTREAM_FLAG_DESTROYED = 0x40
} QuicStreamStates;
};

typedef enum QuicStreamDirection {
enum QuicStreamDirection {
// The QuicStream is readable and writable in both directions
QUIC_STREAM_BIRECTIONAL,

// The QuicStream is writable and readable in only one direction.
// The direction depends on the QuicStreamOrigin.
QUIC_STREAM_UNIDIRECTIONAL
} QuicStreamDirection;
};

typedef enum QuicStreamOrigin {
enum QuicStreamOrigin {
// The QuicStream was created by the server.
QUIC_STREAM_SERVER,

// The QuicStream was created by the client.
QUIC_STREAM_CLIENT
} QuicStreamOrigin;
};


static void Initialize(
Expand Down
8 changes: 4 additions & 4 deletions src/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ constexpr uint64_t DEFAULT_MAX_STREAMS_UNI = 3;
constexpr uint64_t DEFAULT_IDLE_TIMEOUT = 10 * 1000;
constexpr uint64_t DEFAULT_RETRYTOKEN_EXPIRATION = 10ULL;

typedef enum SelectPreferredAddressPolicy : int {
enum SelectPreferredAddressPolicy : int {
// Ignore the server-provided preferred address
QUIC_PREFERRED_ADDRESS_IGNORE,
// Accept the server-provided preferred address
QUIC_PREFERRED_ADDRESS_ACCEPT
} SelectPreferredAddressPolicy;
};

// Fun hash combine trick based on a variadic template that
// I came across a while back but can't remember where. Will add an attribution
Expand All @@ -70,11 +70,11 @@ inline void hash_combine(size_t* seed, const T& value, Args... rest) {
// look at the ALPN identifier to determine exactly what it
// means. Connection (Session) and Crypto errors, on the other
// hand, share the same meaning regardless of the ALPN.
typedef enum QuicErrorFamily : int {
enum QuicErrorFamily : int {
QUIC_ERROR_SESSION,
QUIC_ERROR_CRYPTO,
QUIC_ERROR_APPLICATION
} QuicErrorFamily;
};

struct QuicError {
QuicErrorFamily family;
Expand Down

0 comments on commit 52c0cd7

Please sign in to comment.