LCOV - code coverage report
Current view: top level - source/common/network - connection_socket_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 22 44 50.0 %
Date: 2024-01-05 06:35:25 Functions: 8 17 47.1 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <memory>
       4             : #include <string>
       5             : #include <vector>
       6             : 
       7             : #include "envoy/common/platform.h"
       8             : #include "envoy/network/connection.h"
       9             : #include "envoy/network/listen_socket.h"
      10             : #include "envoy/network/socket.h"
      11             : #include "envoy/network/socket_interface.h"
      12             : 
      13             : #include "source/common/common/assert.h"
      14             : #include "source/common/common/dump_state_utils.h"
      15             : #include "source/common/network/socket_impl.h"
      16             : #include "source/common/network/socket_interface.h"
      17             : 
      18             : namespace Envoy {
      19             : namespace Network {
      20             : 
      21             : /**
      22             :  * Wraps a unix socket.
      23             :  */
      24             : template <Socket::Type T> struct NetworkSocketTrait {};
      25             : 
      26             : template <> struct NetworkSocketTrait<Socket::Type::Stream> {
      27             :   static constexpr Socket::Type type = Socket::Type::Stream;
      28             : };
      29             : 
      30             : template <> struct NetworkSocketTrait<Socket::Type::Datagram> {
      31             :   static constexpr Socket::Type type = Socket::Type::Datagram;
      32             : };
      33             : 
      34             : class ConnectionSocketImpl : public SocketImpl, public ConnectionSocket {
      35             : public:
      36             :   ConnectionSocketImpl(IoHandlePtr&& io_handle,
      37             :                        const Address::InstanceConstSharedPtr& local_address,
      38             :                        const Address::InstanceConstSharedPtr& remote_address)
      39        2643 :       : SocketImpl(std::move(io_handle), local_address, remote_address) {}
      40             : 
      41             :   ConnectionSocketImpl(Socket::Type type, const Address::InstanceConstSharedPtr& local_address,
      42             :                        const Address::InstanceConstSharedPtr& remote_address,
      43             :                        const SocketCreationOptions& options)
      44         515 :       : SocketImpl(type, local_address, remote_address, options) {
      45         515 :     connection_info_provider_->setLocalAddress(local_address);
      46         515 :   }
      47             : 
      48             :   // Network::ConnectionSocket
      49        1042 :   void setDetectedTransportProtocol(absl::string_view protocol) override {
      50        1042 :     transport_protocol_ = std::string(protocol);
      51        1042 :   }
      52        1938 :   absl::string_view detectedTransportProtocol() const override { return transport_protocol_; }
      53             : 
      54           0 :   void setRequestedApplicationProtocols(const std::vector<absl::string_view>& protocols) override {
      55           0 :     application_protocols_.clear();
      56           0 :     for (const auto& protocol : protocols) {
      57           0 :       application_protocols_.emplace_back(protocol);
      58           0 :     }
      59           0 :   }
      60         784 :   const std::vector<std::string>& requestedApplicationProtocols() const override {
      61         784 :     return application_protocols_;
      62         784 :   }
      63             : 
      64           0 :   void setRequestedServerName(absl::string_view server_name) override {
      65           0 :     // Always keep the server_name_ as lower case.
      66           0 :     connectionInfoProvider().setRequestedServerName(absl::AsciiStrToLower(server_name));
      67           0 :   }
      68         784 :   absl::string_view requestedServerName() const override {
      69         784 :     return connectionInfoProvider().requestedServerName();
      70         784 :   }
      71             : 
      72           0 :   void setJA3Hash(absl::string_view ja3_hash) override {
      73           0 :     connectionInfoProvider().setJA3Hash(ja3_hash);
      74           0 :   }
      75           0 :   absl::string_view ja3Hash() const override { return connectionInfoProvider().ja3Hash(); }
      76             : 
      77        1315 :   absl::optional<std::chrono::milliseconds> lastRoundTripTime() override {
      78        1315 :     return ioHandle().lastRoundTripTime();
      79        1315 :   }
      80             : 
      81           0 :   absl::optional<uint64_t> congestionWindowInBytes() const override {
      82           0 :     return ioHandle().congestionWindowInBytes();
      83           0 :   }
      84             : 
      85           0 :   void dumpState(std::ostream& os, int indent_level) const override {
      86           0 :     const char* spaces = spacesForLevel(indent_level);
      87           0 :     os << spaces << "ListenSocketImpl " << this << DUMP_MEMBER(transport_protocol_) << "\n";
      88           0 :     DUMP_DETAILS(connection_info_provider_);
      89           0 :   }
      90             : 
      91             : protected:
      92             :   std::string transport_protocol_;
      93             :   std::vector<std::string> application_protocols_;
      94             : };
      95             : 
      96             : // ConnectionSocket used with client connections.
      97             : class ClientSocketImpl : public ConnectionSocketImpl {
      98             : public:
      99             :   ClientSocketImpl(const Address::InstanceConstSharedPtr& remote_address,
     100             :                    const OptionsSharedPtr& options)
     101             :       : ConnectionSocketImpl(Network::ioHandleForAddr(Socket::Type::Stream, remote_address, {}),
     102        1328 :                              nullptr, remote_address) {
     103        1328 :     if (options) {
     104         173 :       addOptions(options);
     105         173 :     }
     106        1328 :   }
     107             : };
     108             : 
     109             : } // namespace Network
     110             : } // namespace Envoy

Generated by: LCOV version 1.15