Minor improvements.
This commit is contained in:
parent
66de95d93c
commit
b84318fed4
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -5,6 +5,7 @@
|
|||||||
*.h text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.h text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.c text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.c text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.tl text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.tl text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
|
*.mm text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.txt text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.txt text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.sh text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent eol=lf
|
*.sh text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent eol=lf
|
||||||
*.php text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.php text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
@ -18,6 +19,7 @@
|
|||||||
*.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.js text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.js text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
|
*.patch text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.swift text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.swift text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.pbxproj text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.pbxproj text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
*.cs text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
*.cs text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent
|
||||||
@ -32,7 +34,5 @@
|
|||||||
|
|
||||||
sqlite/sqlite/* linguist-vendored
|
sqlite/sqlite/* linguist-vendored
|
||||||
|
|
||||||
*.tlo binary
|
|
||||||
|
|
||||||
*.pfx binary
|
*.pfx binary
|
||||||
*.png binary
|
*.png binary
|
||||||
|
@ -15,5 +15,5 @@ endif()
|
|||||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} m)
|
target_link_libraries(${PROJECT_NAME} PRIVATE m)
|
||||||
endif()
|
endif()
|
||||||
|
@ -7,18 +7,26 @@
|
|||||||
#include "td/mtproto/RawConnection.h"
|
#include "td/mtproto/RawConnection.h"
|
||||||
|
|
||||||
#include "td/mtproto/AuthKey.h"
|
#include "td/mtproto/AuthKey.h"
|
||||||
|
#include "td/mtproto/IStreamTransport.h"
|
||||||
|
#include "td/mtproto/ProxySecret.h"
|
||||||
#include "td/mtproto/Transport.h"
|
#include "td/mtproto/Transport.h"
|
||||||
|
|
||||||
#if TD_EXPERIMENTAL_WATCH_OS
|
#if TD_EXPERIMENTAL_WATCH_OS
|
||||||
#include "td/net/DarwinHttp.h"
|
#include "td/net/DarwinHttp.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "td/utils/BufferedFd.h"
|
||||||
#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/MpscPollableQueue.h"
|
||||||
|
#include "td/utils/port/EventFd.h"
|
||||||
|
#include "td/utils/Slice.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/StorerBase.h"
|
#include "td/utils/StorerBase.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -441,9 +449,8 @@ class RawConnectionHttp : public RawConnection {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
td::unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd,
|
unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
|
||||||
TransportType transport_type,
|
unique_ptr<StatsCallback> stats_callback) {
|
||||||
unique_ptr<StatsCallback> stats_callback) {
|
|
||||||
#if TD_EXPERIMENTAL_WATCH_OS
|
#if TD_EXPERIMENTAL_WATCH_OS
|
||||||
return td::make_unique<RawConnectionHttp>(ip_address, std::move(stats_callback));
|
return td::make_unique<RawConnectionHttp>(ip_address, std::move(stats_callback));
|
||||||
#else
|
#else
|
||||||
|
@ -6,22 +6,19 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/mtproto/IStreamTransport.h"
|
#include "td/telegram/StateManager.h"
|
||||||
|
|
||||||
#include "td/mtproto/PacketInfo.h"
|
#include "td/mtproto/PacketInfo.h"
|
||||||
#include "td/mtproto/TransportType.h"
|
#include "td/mtproto/TransportType.h"
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/BufferedFd.h"
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/port/detail/PollableFd.h"
|
#include "td/utils/port/detail/PollableFd.h"
|
||||||
|
#include "td/utils/port/IPAddress.h"
|
||||||
#include "td/utils/port/SocketFd.h"
|
#include "td/utils/port/SocketFd.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/StorerBase.h"
|
#include "td/utils/StorerBase.h"
|
||||||
|
|
||||||
#include "td/telegram/StateManager.h"
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace mtproto {
|
namespace mtproto {
|
||||||
|
|
||||||
@ -39,9 +36,13 @@ class RawConnection {
|
|||||||
virtual void on_error() = 0; // called on RawConnection error. Such error should be very rare on good connections.
|
virtual void on_error() = 0; // called on RawConnection error. Such error should be very rare on good connections.
|
||||||
virtual void on_mtproto_error() = 0;
|
virtual void on_mtproto_error() = 0;
|
||||||
};
|
};
|
||||||
|
RawConnection() = default;
|
||||||
|
RawConnection(const RawConnection &) = delete;
|
||||||
|
RawConnection &operator=(const RawConnection &) = delete;
|
||||||
virtual ~RawConnection() = default;
|
virtual ~RawConnection() = default;
|
||||||
static td::unique_ptr<RawConnection> create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
|
|
||||||
unique_ptr<StatsCallback> stats_callback);
|
static unique_ptr<RawConnection> create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
|
||||||
|
unique_ptr<StatsCallback> stats_callback);
|
||||||
|
|
||||||
virtual void set_connection_token(StateManager::ConnectionToken connection_token) = 0;
|
virtual void set_connection_token(StateManager::ConnectionToken connection_token) = 0;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "td/telegram/DialogParticipant.h"
|
#include "td/telegram/DialogParticipant.h"
|
||||||
#include "td/telegram/GroupCallId.h"
|
#include "td/telegram/GroupCallId.h"
|
||||||
#include "td/telegram/GroupCallParticipant.h"
|
#include "td/telegram/GroupCallParticipant.h"
|
||||||
|
#include "td/telegram/GroupCallParticipantOrder.h"
|
||||||
#include "td/telegram/InputGroupCallId.h"
|
#include "td/telegram/InputGroupCallId.h"
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant,
|
GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant,
|
||||||
|
@ -30481,7 +30481,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
|
|||||||
|
|
||||||
tl_object_ptr<telegram_api::InputPeer> input_peer;
|
tl_object_ptr<telegram_api::InputPeer> input_peer;
|
||||||
if (action == DialogAction::get_speaking_action()) {
|
if (action == DialogAction::get_speaking_action()) {
|
||||||
input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
input_peer = get_input_peer(dialog_id, AccessRights::Read);
|
||||||
if (input_peer == nullptr) {
|
if (input_peer == nullptr) {
|
||||||
return promise.set_error(Status::Error(400, "Have no access to the chat"));
|
return promise.set_error(Status::Error(400, "Have no access to the chat"));
|
||||||
}
|
}
|
||||||
@ -30498,7 +30498,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
|
|||||||
return promise.set_value(Unit());
|
return promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
input_peer = get_input_peer(dialog_id, AccessRights::Write);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dialog_id.get_type() == DialogType::SecretChat) {
|
if (dialog_id.get_type() == DialogType::SecretChat) {
|
||||||
|
@ -566,12 +566,12 @@ class TestProxyRequest : public RequestOnceActor {
|
|||||||
set_timeout_in(timeout_);
|
set_timeout_in(timeout_);
|
||||||
|
|
||||||
promise_ = std::move(promise);
|
promise_ = std::move(promise);
|
||||||
IPAddress ip;
|
IPAddress ip_address;
|
||||||
auto status = ip.init_host_port(proxy_.server(), proxy_.port());
|
auto status = ip_address.init_host_port(proxy_.server(), proxy_.port());
|
||||||
if (status.is_error()) {
|
if (status.is_error()) {
|
||||||
return promise_.set_error(Status::Error(400, status.public_message()));
|
return promise_.set_error(Status::Error(400, status.public_message()));
|
||||||
}
|
}
|
||||||
auto r_socket_fd = SocketFd::open(ip);
|
auto r_socket_fd = SocketFd::open(ip_address);
|
||||||
if (r_socket_fd.is_error()) {
|
if (r_socket_fd.is_error()) {
|
||||||
return promise_.set_error(Status::Error(400, r_socket_fd.error().public_message()));
|
return promise_.set_error(Status::Error(400, r_socket_fd.error().public_message()));
|
||||||
}
|
}
|
||||||
@ -590,9 +590,9 @@ class TestProxyRequest : public RequestOnceActor {
|
|||||||
send_closure(actor_id, &TestProxyRequest::on_connection_data, std::move(r_data));
|
send_closure(actor_id, &TestProxyRequest::on_connection_data, std::move(r_data));
|
||||||
});
|
});
|
||||||
|
|
||||||
child_ =
|
child_ = ConnectionCreator::prepare_connection(ip_address, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address,
|
||||||
ConnectionCreator::prepare_connection(ip, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address, get_transport(),
|
get_transport(), "Test", "TestPingDC2", nullptr, {}, false,
|
||||||
"Test", "TestPingDC2", nullptr, {}, false, std::move(connection_promise));
|
std::move(connection_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_connection_data(Result<ConnectionCreator::ConnectionData> r_data) {
|
void on_connection_data(Result<ConnectionCreator::ConnectionData> r_data) {
|
||||||
|
@ -323,19 +323,20 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ip = info.option->get_ip_address();
|
auto ip_address = info.option->get_ip_address();
|
||||||
auto r_socket_fd = SocketFd::open(ip);
|
auto r_socket_fd = SocketFd::open(ip_address);
|
||||||
if (r_socket_fd.is_error()) {
|
if (r_socket_fd.is_error()) {
|
||||||
LOG(DEBUG) << "Failed to open socket: " << r_socket_fd.error();
|
LOG(DEBUG) << "Failed to open socket: " << r_socket_fd.error();
|
||||||
on_ping_main_dc_result(token, r_socket_fd.move_as_error());
|
on_ping_main_dc_result(token, r_socket_fd.move_as_error());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ping_proxy_socket_fd(
|
ping_proxy_socket_fd(std::move(ip_address), r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(),
|
||||||
ip, r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(), PSTRING() << info.option->get_ip_address(),
|
PSTRING() << info.option->get_ip_address(),
|
||||||
PromiseCreator::lambda([actor_id = actor_id(this), token](Result<double> result) {
|
PromiseCreator::lambda([actor_id = actor_id(this), token](Result<double> result) {
|
||||||
send_closure(actor_id, &ConnectionCreator::on_ping_main_dc_result, token, std::move(result));
|
send_closure(actor_id, &ConnectionCreator::on_ping_main_dc_result, token,
|
||||||
}));
|
std::move(result));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ set(TDNET_SOURCE
|
|||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
//
|
//
|
||||||
#include "td/net/DarwinHttp.h"
|
#include "td/net/DarwinHttp.h"
|
||||||
|
|
||||||
|
#include "td/utils/logging.h"
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -16,7 +18,7 @@ NSString *to_ns_string(CSlice slice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSData *to_ns_data(Slice data) {
|
NSData *to_ns_data(Slice data) {
|
||||||
return [NSData dataWithBytes:static_cast<const void*>(data.data()) length:data.size()];
|
return [NSData dataWithBytes:static_cast<const void *>(data.data()) length:data.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto http_get(CSlice url) {
|
auto http_get(CSlice url) {
|
||||||
@ -37,17 +39,17 @@ auto http_post(CSlice url, Slice data) {
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
|
void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
|
||||||
__block auto callback = std::move(promise);
|
__block auto callback = std::move(promise);
|
||||||
NSURLSessionDataTask* dataTask =
|
NSURLSessionDataTask *dataTask =
|
||||||
[NSURLSession.sharedSession
|
[NSURLSession.sharedSession
|
||||||
dataTaskWithRequest:request
|
dataTaskWithRequest:request
|
||||||
completionHandler:
|
completionHandler:
|
||||||
^(NSData *data, NSURLResponse *response, NSError *error) {
|
^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||||
if(error == nil) {
|
if (error == nil) {
|
||||||
callback(BufferSlice(Slice((const char *)([data bytes]), [data length])));
|
callback(BufferSlice(Slice((const char *)([data bytes]), [data length])));
|
||||||
} else {
|
} else {
|
||||||
callback(Status::Error(static_cast<int32>([error code])));
|
callback(Status::Error(static_cast<int32>([error code]), "HTTP request failed"));
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
[dataTask resume];
|
[dataTask resume];
|
||||||
|
@ -42,8 +42,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
REGISTER_TESTS(http)
|
REGISTER_TESTS(http)
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ TEST(Http, Darwin) {
|
|||||||
Baton baton;
|
Baton baton;
|
||||||
//LOG(ERROR) << "???";
|
//LOG(ERROR) << "???";
|
||||||
td::DarwinHttp::get("http://example.com", [&](td::BufferSlice data) {
|
td::DarwinHttp::get("http://example.com", [&](td::BufferSlice data) {
|
||||||
LOG(ERROR) << data.as_slice();
|
//LOG(ERROR) << data.as_slice();
|
||||||
baton.post();
|
baton.post();
|
||||||
});
|
});
|
||||||
//LOG(ERROR) << "!!!";
|
//LOG(ERROR) << "!!!";
|
||||||
|
Loading…
Reference in New Issue
Block a user