@@ -27,6 +27,9 @@ static const int DEFAULT_CONNECT_TIMEOUT = 5000;
27
27
// ! -dns default
28
28
static const int DEFAULT_NAME_LOOKUP = true ;
29
29
30
+ /* * Prefix for unix domain socket addresses (which are local filesystem paths) */
31
+ const std::string ADDR_PREFIX_UNIX = " unix:" ;
32
+
30
33
enum class ConnectionDirection {
31
34
None = 0 ,
32
35
In = (1U << 0 ),
@@ -43,16 +46,44 @@ static inline bool operator&(ConnectionDirection a, ConnectionDirection b) {
43
46
return (underlying (a) & underlying (b));
44
47
}
45
48
49
+ /* *
50
+ * Check if a string is a valid UNIX domain socket path
51
+ *
52
+ * @param name The string provided by the user representing a local path
53
+ *
54
+ * @returns Whether the string has proper format, length, and points to an existing file path
55
+ */
56
+ bool IsUnixSocketPath (const std::string& name);
57
+
46
58
class Proxy
47
59
{
48
60
public:
49
- Proxy (): randomize_credentials(false ) {}
50
- explicit Proxy (const CService &_proxy, bool _randomize_credentials=false ): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
51
-
52
- bool IsValid () const { return proxy.IsValid (); }
61
+ Proxy (): m_is_unix_socket(false ), randomize_credentials(false ) {}
62
+ explicit Proxy (const CService &_proxy, bool _randomize_credentials=false ): proxy(_proxy), m_is_unix_socket(false ), randomize_credentials(_randomize_credentials) {}
63
+ explicit Proxy (const std::string path, bool _randomize_credentials=false ): m_unix_socket_path(path), m_is_unix_socket(true ), randomize_credentials(_randomize_credentials) {}
53
64
54
65
CService proxy;
66
+ std::string m_unix_socket_path;
67
+ bool m_is_unix_socket;
55
68
bool randomize_credentials;
69
+
70
+ bool IsValid () const
71
+ {
72
+ if (m_is_unix_socket) return IsUnixSocketPath (m_unix_socket_path);
73
+ return proxy.IsValid ();
74
+ }
75
+
76
+ sa_family_t GetFamily () const
77
+ {
78
+ if (m_is_unix_socket) return AF_UNIX;
79
+ return proxy.GetSAFamily ();
80
+ }
81
+
82
+ std::string ToString () const
83
+ {
84
+ if (m_is_unix_socket) return m_unix_socket_path;
85
+ return proxy.ToStringAddrPort ();
86
+ }
56
87
};
57
88
58
89
/* * Credentials for proxy authentication */
0 commit comments