-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a large refactor that moves away from representing addresses internally as strings of "URL" form into proper objects. With this change in place, it should be very straightforward to add IPv6 support, as most places in the code no longer need to understand anything about the underlying address. Additionally, adding NT support in the future should also be easier. There are still some unfortunate legacy aspects, such as the fact that when loading from configuration we still parse tcp:// as well as unix:// style addresses. In the future this should likely become ip:// as well as pipe:// but we will probably need to continue to support both. Note that although this change is huge in number of lines, most of it is very straightforward, and certain portions of the code have become substantially simpler such as listener handling and client connection handling. Fixes #390
- Loading branch information
1 parent
1260794
commit 8131743
Showing
93 changed files
with
1,095 additions
and
803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#pragma once | ||
|
||
#include "envoy/common/optional.h" | ||
#include "envoy/common/pure.h" | ||
|
||
namespace Network { | ||
namespace Address { | ||
|
||
/** | ||
* Interface for an Ipv4 address. | ||
*/ | ||
class Ipv4 { | ||
public: | ||
virtual ~Ipv4() {} | ||
|
||
/** | ||
* @return the 32-bit IPv4 address in network byte order. | ||
*/ | ||
virtual uint32_t address() const PURE; | ||
}; | ||
|
||
enum class IpVersion { v4 }; | ||
|
||
/** | ||
* Interface for a generic IP address. | ||
*/ | ||
class Ip { | ||
public: | ||
virtual ~Ip() {} | ||
|
||
/** | ||
* @return the address as a string. E.g., "1.2.3.4" for an IPv4 address. | ||
*/ | ||
virtual const std::string& addressAsString() const PURE; | ||
|
||
/** | ||
* @return Ipv4 address data IFF type() == IpVersion::v4, otherwise nullptr. | ||
*/ | ||
virtual const Ipv4* ipv4() const PURE; | ||
|
||
/** | ||
* @return the port associated with the address. Port may be zero if not specified or applicable. | ||
* The port is in host byte order. | ||
*/ | ||
virtual uint32_t port() const PURE; | ||
|
||
/** | ||
* @return the version of IP address. | ||
*/ | ||
virtual IpVersion version() const PURE; | ||
}; | ||
|
||
enum class Type { Ip, Pipe }; | ||
enum class SocketType { Stream, Datagram }; | ||
|
||
/** | ||
* Interface for all network addresses. | ||
*/ | ||
class Instance { | ||
public: | ||
virtual ~Instance() {} | ||
|
||
virtual bool operator==(const Instance& rhs) const PURE; | ||
|
||
/** | ||
* @return a human readable string for the address. | ||
* | ||
* This string will be in the following format: | ||
* For IP addresses: "1.2.3.4:80" | ||
* For pipe addresses: "/foo" | ||
*/ | ||
virtual const std::string& asString() const PURE; | ||
|
||
/** | ||
* Bind a socket to to this address. The socket should have been created with a call to socket() | ||
* on this object. | ||
* @param fd supplies the platform socket handle. | ||
* @return the platform error code. | ||
*/ | ||
virtual int bind(int fd) const PURE; | ||
|
||
/** | ||
* Connect a socket to this address. The socket should have been created with a call to socket() | ||
* on this object. | ||
* @param fd supplies the platform socket handle. | ||
* @return the platform error code. | ||
*/ | ||
virtual int connect(int fd) const PURE; | ||
|
||
/** | ||
* @return the IP address information IFF type() == Type::Ip, otherwise nullptr. | ||
*/ | ||
virtual const Ip* ip() const PURE; | ||
|
||
/** | ||
* Create a socket for this address. | ||
* @param type supplies the socket type to create. | ||
* @return the platform error code. | ||
*/ | ||
virtual int socket(SocketType type) const PURE; | ||
|
||
/** | ||
* @return the type of address. | ||
*/ | ||
virtual Type type() const PURE; | ||
}; | ||
|
||
typedef std::shared_ptr<const Instance> InstancePtr; | ||
|
||
} // Address | ||
} // Network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.