Fix compilation errors and formatting.

This commit is contained in:
levlam 2021-03-26 18:52:45 +03:00
parent 258b6dd3bd
commit 66de95d93c
9 changed files with 54 additions and 33 deletions

View File

@ -9,16 +9,16 @@
#include "td/mtproto/AuthKey.h" #include "td/mtproto/AuthKey.h"
#include "td/mtproto/Transport.h" #include "td/mtproto/Transport.h"
#if TD_EXPERIMENTAL_WATCH_OS
#include "td/net/DarwinHttp.h"
#endif
#include "td/utils/format.h" #include "td/utils/format.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/misc.h" #include "td/utils/misc.h"
#include "td/utils/Status.h" #include "td/utils/Status.h"
#include "td/utils/StorerBase.h" #include "td/utils/StorerBase.h"
#if TD_EXPERIMENTAL_WATCH_OS
#include "td/net/DarwinHttp.h"
#endif
#include <utility> #include <utility>
namespace td { namespace td {

View File

@ -92,11 +92,11 @@ class Transport {
MutableSlice dest = MutableSlice()); MutableSlice dest = MutableSlice());
static std::pair<uint32, UInt128> calc_message_key2(const AuthKey &auth_key, int X, Slice to_encrypt); static std::pair<uint32, UInt128> calc_message_key2(const AuthKey &auth_key, int X, Slice to_encrypt);
private: private:
template <class HeaderT> template <class HeaderT>
static std::pair<uint32, UInt128> calc_message_ack_and_key(const HeaderT &head, size_t data_size); static std::pair<uint32, UInt128> calc_message_ack_and_key(const HeaderT &head, size_t data_size);
template <class HeaderT> template <class HeaderT>
static size_t calc_crypto_size(size_t data_size); static size_t calc_crypto_size(size_t data_size);

View File

@ -613,7 +613,8 @@ class TestProxyRequest : public RequestOnceActor {
}; };
auto handshake = make_unique<mtproto::AuthKeyHandshake>(dc_id_, 3600); auto handshake = make_unique<mtproto::AuthKeyHandshake>(dc_id_, 3600);
auto data = r_data.move_as_ok(); auto data = r_data.move_as_ok();
auto raw_connection = mtproto::RawConnection::create(data.ip_address, std::move(data.socket_fd), get_transport(), nullptr); auto raw_connection =
mtproto::RawConnection::create(data.ip_address, std::move(data.socket_fd), get_transport(), nullptr);
child_ = create_actor<mtproto::HandshakeActor>( child_ = create_actor<mtproto::HandshakeActor>(
"HandshakeActor", std::move(handshake), std::move(raw_connection), make_unique<HandshakeContext>(), 10.0, "HandshakeActor", std::move(handshake), std::move(raw_connection), make_unique<HandshakeContext>(), 10.0,
PromiseCreator::lambda([actor_id = actor_id(this)](Result<unique_ptr<mtproto::RawConnection>> raw_connection) { PromiseCreator::lambda([actor_id = actor_id(this)](Result<unique_ptr<mtproto::RawConnection>> raw_connection) {

View File

@ -92,8 +92,9 @@ class ConnectionCreator : public NetQueryCallback {
static DcOptions get_default_dc_options(bool is_test); static DcOptions get_default_dc_options(bool is_test);
static ActorOwn<> prepare_connection(IPAddress ip_address, SocketFd socket_fd, const Proxy &proxy, const IPAddress &mtproto_ip_address, static ActorOwn<> prepare_connection(IPAddress ip_address, SocketFd socket_fd, const Proxy &proxy,
mtproto::TransportType transport_type, Slice actor_name_prefix, Slice debug_str, const IPAddress &mtproto_ip_address, mtproto::TransportType transport_type,
Slice actor_name_prefix, Slice debug_str,
unique_ptr<mtproto::RawConnection::StatsCallback> stats_callback, unique_ptr<mtproto::RawConnection::StatsCallback> stats_callback,
ActorShared<> parent, bool use_connection_token, ActorShared<> parent, bool use_connection_token,
Promise<ConnectionData> promise); Promise<ConnectionData> promise);
@ -248,8 +249,8 @@ class ConnectionCreator : public NetQueryCallback {
void ping_proxy_resolved(int32 proxy_id, IPAddress ip_address, Promise<double> promise); void ping_proxy_resolved(int32 proxy_id, IPAddress ip_address, Promise<double> promise);
void ping_proxy_socket_fd(IPAddress ip_address, SocketFd socket_fd, mtproto::TransportType transport_type, string debug_str, void ping_proxy_socket_fd(IPAddress ip_address, SocketFd socket_fd, mtproto::TransportType transport_type,
Promise<double> promise); string debug_str, Promise<double> promise);
void on_ping_main_dc_result(uint64 token, Result<double> result); void on_ping_main_dc_result(uint64 token, Result<double> result);
}; };

View File

@ -44,18 +44,15 @@ set(TDNET_SOURCE
td/net/TcpListener.h td/net/TcpListener.h
td/net/TransparentProxy.h td/net/TransparentProxy.h
td/net/Wget.h td/net/Wget.h
td/net/DarwinHttp.mm
td/net/DarwinHttp.h
) )
if (TD_EXPERIMENTAL_WATCH_OS) if (TD_EXPERIMENTAL_WATCH_OS)
set (TDNET_SOURCE set (TDNET_SOURCE
${TDNET_SOURCE} ${TDNET_SOURCE}
td/net/DarwinHttp.mm td/net/DarwinHttp.mm
td/net/DarwinHttp.h td/net/DarwinHttp.h
) )
set_source_files_properties(td/net/DarwinHttp.mm PROPERTIES COMPILE_FLAGS -fobjc-arc) set_source_files_properties(td/net/DarwinHttp.mm PROPERTIES COMPILE_FLAGS -fobjc-arc)
endif() endif()
#RULES #RULES
@ -78,8 +75,10 @@ if (WIN32)
endif() endif()
endif() endif()
find_library(FOUNDATION_LIBRARY Foundation REQUIRED) if (TD_EXPERIMENTAL_WATCH_OS)
target_link_libraries(tdnet PRIVATE ${FOUNDATION_LIBRARY}) find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
target_link_libraries(tdnet PRIVATE ${FOUNDATION_LIBRARY})
endif()
install(TARGETS tdnet EXPORT TdTargets install(TARGETS tdnet EXPORT TdTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"

View File

@ -1,13 +1,22 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once #pragma once
#include "td/actor/PromiseFuture.h" #include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/Slice.h"
namespace td { namespace td {
class DarwinHttp { class DarwinHttp {
public: public:
static void get(CSlice url, Promise<BufferSlice> promise); static void get(CSlice url, Promise<BufferSlice> promise);
static void post(CSlice url, Slice data, Promise<BufferSlice> promise); static void post(CSlice url, Slice data, Promise<BufferSlice> promise);
}; };
} // namespace td } // namespace td

View File

@ -1,8 +1,15 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/net/DarwinHttp.h" #include "td/net/DarwinHttp.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
namespace td { namespace td {
namespace { namespace {
NSString *to_ns_string(CSlice slice) { NSString *to_ns_string(CSlice slice) {
return [NSString stringWithUTF8String:slice.c_str()]; return [NSString stringWithUTF8String:slice.c_str()];
@ -45,7 +52,7 @@ void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
}]; }];
[dataTask resume]; [dataTask resume];
} }
} } // namespace
void DarwinHttp::get(CSlice url, Promise<BufferSlice> promise) { void DarwinHttp::get(CSlice url, Promise<BufferSlice> promise) {
return http_send(http_get(url), std::move(promise)); return http_send(http_get(url), std::move(promise));
@ -54,4 +61,5 @@ void DarwinHttp::get(CSlice url, Promise<BufferSlice> promise) {
void DarwinHttp::post(CSlice url, Slice data, Promise<BufferSlice> promise) { void DarwinHttp::post(CSlice url, Slice data, Promise<BufferSlice> promise) {
return http_send(http_post(url, data), std::move(promise)); return http_send(http_post(url, data), std::move(promise));
} }
}
} // namespace td

View File

@ -6,13 +6,15 @@
// //
#include "data.h" #include "data.h"
#if TD_EXPERIMENTAL_WATCH_OS
#include "td/net/DarwinHttp.h"
#endif
#include "td/net/HttpChunkedByteFlow.h" #include "td/net/HttpChunkedByteFlow.h"
#include "td/net/HttpHeaderCreator.h" #include "td/net/HttpHeaderCreator.h"
#include "td/net/HttpQuery.h" #include "td/net/HttpQuery.h"
#include "td/net/HttpReader.h" #include "td/net/HttpReader.h"
#include "td/net/DarwinHttp.h"
#include "td/utils/AesCtrByteFlow.h" #include "td/utils/AesCtrByteFlow.h"
#include "td/utils/algorithm.h" #include "td/utils/algorithm.h"
#include "td/utils/base64.h" #include "td/utils/base64.h"
@ -468,6 +470,7 @@ TEST(Http, gzip_bomb_with_limit) {
ASSERT_TRUE(ok); ASSERT_TRUE(ok);
} }
#if TD_EXPERIMENTAL_WATCH_OS
struct Baton { struct Baton {
std::mutex mutex; std::mutex mutex;
std::condition_variable cond; std::condition_variable cond;
@ -501,3 +504,4 @@ TEST(Http, Darwin) {
//LOG(ERROR) << "!!!"; //LOG(ERROR) << "!!!";
baton.wait(); baton.wait();
} }
#endif

View File

@ -216,9 +216,9 @@ class TestPingActor : public Actor {
} }
ping_connection_ = mtproto::PingConnection::create_req_pq( ping_connection_ = mtproto::PingConnection::create_req_pq(
mtproto::RawConnection::create( mtproto::RawConnection::create(ip_address_, r_socket.move_as_ok(),
ip_address_, r_socket.move_as_ok(), mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()}, mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()},
nullptr), nullptr),
3); 3);
Scheduler::subscribe(ping_connection_->get_poll_info().extract_pollable_fd(this)); Scheduler::subscribe(ping_connection_->get_poll_info().extract_pollable_fd(this));
@ -338,9 +338,8 @@ class HandshakeTestActor : public Actor {
} }
raw_connection_ = mtproto::RawConnection::create( raw_connection_ = mtproto::RawConnection::create(
ip_address, ip_address, r_socket.move_as_ok(),
r_socket.move_as_ok(), mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()}, mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()}, nullptr);
nullptr);
} }
if (!wait_for_handshake_ && !handshake_) { if (!wait_for_handshake_ && !handshake_) {
handshake_ = make_unique<mtproto::AuthKeyHandshake>(dc_id_, 3600); handshake_ = make_unique<mtproto::AuthKeyHandshake>(dc_id_, 3600);
@ -545,8 +544,8 @@ class FastPingTestActor : public Actor {
} }
auto raw_connection = mtproto::RawConnection::create( auto raw_connection = mtproto::RawConnection::create(
ip_address, ip_address, r_socket.move_as_ok(),
r_socket.move_as_ok(), mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()}, nullptr); mtproto::TransportType{mtproto::TransportType::Tcp, 0, mtproto::ProxySecret()}, nullptr);
auto handshake = make_unique<mtproto::AuthKeyHandshake>(get_default_dc_id(), 60 * 100 /*temp*/); auto handshake = make_unique<mtproto::AuthKeyHandshake>(get_default_dc_id(), 60 * 100 /*temp*/);
create_actor<mtproto::HandshakeActor>( create_actor<mtproto::HandshakeActor>(
"HandshakeActor", std::move(handshake), std::move(raw_connection), make_unique<HandshakeContext>(), 10.0, "HandshakeActor", std::move(handshake), std::move(raw_connection), make_unique<HandshakeContext>(), 10.0,