-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign to enable TLS connection reusage and resigning of messages
- Loading branch information
Showing
31 changed files
with
927 additions
and
566 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
#include "cloud/provider.hpp" | ||
#include <cassert> | ||
#include <string> | ||
//--------------------------------------------------------------------------- | ||
// AnyBlob - Universal Cloud Object Storage Library | ||
// Dominik Durner, 2024 | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
//--------------------------------------------------------------------------- | ||
namespace anyblob { | ||
//--------------------------------------------------------------------------- | ||
namespace network { | ||
class TaskedSendReceiver; | ||
}; // namespace network | ||
//--------------------------------------------------------------------------- | ||
namespace cloud { | ||
//--------------------------------------------------------------------------- | ||
/// Implements a simple http request logic | ||
class HTTP : public Provider { | ||
public: | ||
/// The settings for azure requests | ||
struct Settings { | ||
/// The container name | ||
std::string hostname; | ||
/// The port | ||
uint32_t port; | ||
}; | ||
|
||
private: | ||
/// The settings | ||
Settings _settings; | ||
|
||
public: | ||
|
||
/// The constructor | ||
HTTP(const RemoteInfo& info) : _settings({info.endpoint, info.port}) { | ||
assert(info.provider == Provider::CloudService::HTTP || info.provider == Provider::CloudService::HTTPS); | ||
_type = info.provider; | ||
} | ||
|
||
private: | ||
/// Get the settings | ||
[[nodiscard]] inline Settings getSettings() { return _settings; } | ||
|
||
/// Builds the http request for downloading a blob or listing the directory | ||
[[nodiscard]] std::unique_ptr<utils::DataVector<uint8_t>> getRequest(const std::string& filePath, const std::pair<uint64_t, uint64_t>& range) const override; | ||
/// Builds the http request for putting objects without the object data itself | ||
[[nodiscard]] std::unique_ptr<utils::DataVector<uint8_t>> putRequest(const std::string& filePath, std::string_view object) const override; | ||
// Builds the http request for deleting an objects | ||
[[nodiscard]] std::unique_ptr<utils::DataVector<uint8_t>> deleteRequest(const std::string& filePath) const override; | ||
|
||
/// Get the address of the server | ||
[[nodiscard]] std::string getAddress() const override; | ||
/// Get the port of the server | ||
[[nodiscard]] uint32_t getPort() const override; | ||
/// Get the instance details | ||
[[nodiscard]] Provider::Instance getInstanceDetails(network::TaskedSendReceiver& sendReceiver) override; | ||
|
||
friend Provider; | ||
}; | ||
//--------------------------------------------------------------------------- | ||
} // namespace cloud | ||
} // namespace anyblob |
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,118 @@ | ||
#pragma once | ||
#include "network/resolver.hpp" | ||
#include <cassert> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <liburing.h> | ||
//--------------------------------------------------------------------------- | ||
// AnyBlob - Universal Cloud Object Storage Library | ||
// Dominik Durner, 2024 | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
//--------------------------------------------------------------------------- | ||
namespace anyblob { | ||
namespace network { | ||
//--------------------------------------------------------------------------- | ||
class TLSConnection; | ||
class TLSContext; | ||
//--------------------------------------------------------------------------- | ||
// This class acts as the connection enabler, closer, and main | ||
// cache for sockets and their optional tls connection. | ||
// We further add the DNS resolution to the connection manager. | ||
class ConnectionManager { | ||
public: | ||
/// The tcp settings | ||
struct TCPSettings { | ||
/// flag for nonBlocking | ||
int nonBlocking = 1; | ||
/// flag for noDelay | ||
int noDelay = 0; | ||
/// flag for recv no wait | ||
int recvNoWait = 0; | ||
/// flag for keepAlive | ||
int keepAlive = 1; | ||
/// time for tcp keepIdle | ||
int keepIdle = 1; | ||
/// time for tcp keepIntvl | ||
int keepIntvl = 1; | ||
/// probe count | ||
int keepCnt = 1; | ||
/// recv buffer for tcp | ||
int recvBuffer = 0; | ||
/// Maximum segment size | ||
int mss = 0; | ||
/// Reuse port | ||
int reusePorts = 0; | ||
/// Lingering of tcp packets | ||
int linger = 1; | ||
/// The timeout in usec | ||
int timeout = 500 * 1000; | ||
/// Reuse sockets | ||
int reuse = 0; | ||
/// The kernel timeout parameter | ||
__kernel_timespec kernelTimeout; | ||
|
||
TCPSettings() { | ||
kernelTimeout.tv_sec = 0; | ||
kernelTimeout.tv_nsec = timeout * 1000; | ||
} | ||
}; | ||
|
||
/// The fd socket entry | ||
struct SocketEntry { | ||
/// The optional tls connection | ||
std::unique_ptr<TLSConnection> tls; | ||
/// The fd | ||
int32_t fd; | ||
/// The port | ||
unsigned port; | ||
/// The hostname | ||
std::string hostname; | ||
|
||
SocketEntry(int32_t fd, std::string hostname, unsigned port, std::unique_ptr<TLSConnection> tls); | ||
}; | ||
|
||
private: | ||
/// The socket wrapper | ||
std::unique_ptr<IOUringSocket> _socketWrapper; | ||
/// The active sockets | ||
std::unordered_map<int32_t, std::unique_ptr<SocketEntry>> _fdSockets; | ||
/// The fd socket cache, uses hostname as key | ||
std::unordered_multimap<std::string, std::unique_ptr<SocketEntry>> _fdCache; | ||
/// Resolver | ||
std::unordered_map<std::string, std::unique_ptr<Resolver>> _resolverCache; | ||
/// The tls context | ||
std::unique_ptr<network::TLSContext> _context; | ||
|
||
public: | ||
/// The constructor | ||
explicit ConnectionManager(unsigned uringEntries, unsigned resolverCacheEntries); | ||
/// The destructor | ||
~ConnectionManager(); | ||
|
||
/// Creates a new socket connection | ||
[[nodiscard]] int32_t connect(std::string hostname, uint32_t port, bool tls, const TCPSettings& tcpSettings, bool useCache = true, int retryLimit = 16); | ||
/// Disconnects the socket | ||
void disconnect(int32_t fd, std::string hostname = "", uint32_t port = 0, const TCPSettings* tcpSettings = nullptr, uint64_t bytes = 0, bool forceShutdown = false); | ||
|
||
/// Add resolver | ||
void addResolver(const std::string& hostname, std::unique_ptr<Resolver> resolver); | ||
/// Checks for a timeout | ||
bool checkTimeout(int fd, const TCPSettings& settings); | ||
|
||
/// Get the socket | ||
IOUringSocket& getSocketConnection() { | ||
assert(_socketWrapper); | ||
return *_socketWrapper.get(); | ||
} | ||
|
||
/// Get the tls connection of the fd | ||
TLSConnection* getTLSConnection(int32_t fd); | ||
}; | ||
//--------------------------------------------------------------------------- | ||
}; // namespace network | ||
}; // namespace anyblob |
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.