Files
swift-nio/Sources/NIO/AddressedEnvelope.swift
T
Peter AdamsandCory Benfield c8e253206b Add Optional ECN MetaData to Addressed Envelope (#1502)
Add Optional ECN MetaData to Addressed Envelope

Motivation:

This is a very small step along the path to #1472

Modifications:

Add an optional metadata field to addressed envelope. Currently the only possible data is ECN information. This is not currently populated anywhere.

Result:

Metadata in place for future work.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-05-05 10:30:17 +01:00

55 lines
1.9 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// A data structure for processing addressed datagrams, such as those used by UDP.
///
/// The AddressedEnvelope is used extensively on `DatagramChannel`s in order to keep track
/// of source or destination address metadata: that is, where some data came from or where
/// it is going.
public struct AddressedEnvelope<DataType> {
public var remoteAddress: SocketAddress
public var data: DataType
/// Any metadata associated with this `AddressedEnvelope`
public var metadata: Metadata? = nil
public init(remoteAddress: SocketAddress, data: DataType) {
self.remoteAddress = remoteAddress
self.data = data
}
/// Any metadata associated with an `AddressedEnvelope`
public struct Metadata: Hashable {
/// Details of any congestion state.
public var ecnState: NIOExplicitCongestionNotificationState
}
}
extension AddressedEnvelope: CustomStringConvertible {
public var description: String {
return "AddressedEnvelope { remoteAddress: \(self.remoteAddress), data: \(self.data) }"
}
}
/// Possible Explicit Congestion Notification States
public enum NIOExplicitCongestionNotificationState: Hashable {
/// Non-ECN Capable Transport.
case transportNotCapable
/// ECN Capable Transport (flag 0).
case transportCapableFlag0
/// ECN Capable Transport (flag 1).
case transportCapableFlag1
/// Congestion Experienced.
case congestionExperienced
}