Minor improvements.

This commit is contained in:
levlam 2021-03-27 05:19:22 +03:00
parent 66de95d93c
commit b84318fed4
12 changed files with 52 additions and 38 deletions

4
.gitattributes vendored
View File

@ -5,6 +5,7 @@
*.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
*.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
*.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
@ -18,6 +19,7 @@
*.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
*.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
*.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
@ -32,7 +34,5 @@
sqlite/sqlite/* linguist-vendored
*.tlo binary
*.pfx binary
*.png binary

View File

@ -15,5 +15,5 @@ endif()
add_executable(${PROJECT_NAME} ${SOURCES})
if (NOT WIN32)
target_link_libraries(${PROJECT_NAME} m)
target_link_libraries(${PROJECT_NAME} PRIVATE m)
endif()

View File

@ -7,18 +7,26 @@
#include "td/mtproto/RawConnection.h"
#include "td/mtproto/AuthKey.h"
#include "td/mtproto/IStreamTransport.h"
#include "td/mtproto/ProxySecret.h"
#include "td/mtproto/Transport.h"
#if TD_EXPERIMENTAL_WATCH_OS
#include "td/net/DarwinHttp.h"
#endif
#include "td/utils/BufferedFd.h"
#include "td/utils/format.h"
#include "td/utils/logging.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/StorerBase.h"
#include <map>
#include <memory>
#include <utility>
namespace td {
@ -441,9 +449,8 @@ class RawConnectionHttp : public RawConnection {
};
#endif
td::unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd,
TransportType transport_type,
unique_ptr<StatsCallback> stats_callback) {
unique_ptr<RawConnection> RawConnection::create(IPAddress ip_address, SocketFd socket_fd, TransportType transport_type,
unique_ptr<StatsCallback> stats_callback) {
#if TD_EXPERIMENTAL_WATCH_OS
return td::make_unique<RawConnectionHttp>(ip_address, std::move(stats_callback));
#else

View File

@ -6,22 +6,19 @@
//
#pragma once
#include "td/mtproto/IStreamTransport.h"
#include "td/telegram/StateManager.h"
#include "td/mtproto/PacketInfo.h"
#include "td/mtproto/TransportType.h"
#include "td/utils/buffer.h"
#include "td/utils/BufferedFd.h"
#include "td/utils/common.h"
#include "td/utils/port/detail/PollableFd.h"
#include "td/utils/port/IPAddress.h"
#include "td/utils/port/SocketFd.h"
#include "td/utils/Status.h"
#include "td/utils/StorerBase.h"
#include "td/telegram/StateManager.h"
#include <map>
namespace td {
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_mtproto_error() = 0;
};
RawConnection() = default;
RawConnection(const RawConnection &) = delete;
RawConnection &operator=(const RawConnection &) = delete;
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;

View File

@ -10,6 +10,7 @@
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/GroupCallId.h"
#include "td/telegram/GroupCallParticipant.h"
#include "td/telegram/GroupCallParticipantOrder.h"
#include "td/telegram/InputGroupCallId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"

View File

@ -12,6 +12,8 @@
#include "td/utils/logging.h"
#include <limits>
namespace td {
GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant,

View File

@ -30481,7 +30481,7 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
tl_object_ptr<telegram_api::InputPeer> input_peer;
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) {
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());
}
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) {

View File

@ -566,12 +566,12 @@ class TestProxyRequest : public RequestOnceActor {
set_timeout_in(timeout_);
promise_ = std::move(promise);
IPAddress ip;
auto status = ip.init_host_port(proxy_.server(), proxy_.port());
IPAddress ip_address;
auto status = ip_address.init_host_port(proxy_.server(), proxy_.port());
if (status.is_error()) {
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()) {
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));
});
child_ =
ConnectionCreator::prepare_connection(ip, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address, get_transport(),
"Test", "TestPingDC2", nullptr, {}, false, std::move(connection_promise));
child_ = ConnectionCreator::prepare_connection(ip_address, r_socket_fd.move_as_ok(), proxy_, mtproto_ip_address,
get_transport(), "Test", "TestPingDC2", nullptr, {}, false,
std::move(connection_promise));
}
void on_connection_data(Result<ConnectionCreator::ConnectionData> r_data) {

View File

@ -323,19 +323,20 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
continue;
}
auto ip = info.option->get_ip_address();
auto r_socket_fd = SocketFd::open(ip);
auto ip_address = info.option->get_ip_address();
auto r_socket_fd = SocketFd::open(ip_address);
if (r_socket_fd.is_error()) {
LOG(DEBUG) << "Failed to open socket: " << r_socket_fd.error();
on_ping_main_dc_result(token, r_socket_fd.move_as_error());
continue;
}
ping_proxy_socket_fd(
ip, r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(), PSTRING() << info.option->get_ip_address(),
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));
}));
ping_proxy_socket_fd(std::move(ip_address), r_socket_fd.move_as_ok(), r_transport_type.move_as_ok(),
PSTRING() << info.option->get_ip_address(),
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));
}));
}
return;
}

View File

@ -47,7 +47,7 @@ set(TDNET_SOURCE
)
if (TD_EXPERIMENTAL_WATCH_OS)
set (TDNET_SOURCE
set(TDNET_SOURCE
${TDNET_SOURCE}
td/net/DarwinHttp.mm
td/net/DarwinHttp.h

View File

@ -6,6 +6,8 @@
//
#include "td/net/DarwinHttp.h"
#include "td/utils/logging.h"
#import <Foundation/Foundation.h>
namespace td {
@ -16,7 +18,7 @@ NSString *to_ns_string(CSlice slice) {
}
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) {
@ -37,17 +39,17 @@ auto http_post(CSlice url, Slice data) {
return request;
}
void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
void http_send(NSURLRequest *request, Promise<BufferSlice> promise) {
__block auto callback = std::move(promise);
NSURLSessionDataTask* dataTask =
NSURLSessionDataTask *dataTask =
[NSURLSession.sharedSession
dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil) {
callback(BufferSlice(Slice((const char *)([data bytes]), [data length])));
if (error == nil) {
callback(BufferSlice(Slice((const char *)([data bytes]), [data length])));
} else {
callback(Status::Error(static_cast<int32>([error code])));
callback(Status::Error(static_cast<int32>([error code]), "HTTP request failed"));
}
}];
[dataTask resume];

View File

@ -42,8 +42,8 @@
#include <algorithm>
#include <limits>
#include <mutex>
#include <condition_variable>
#include <mutex>
REGISTER_TESTS(http)
@ -498,7 +498,7 @@ TEST(Http, Darwin) {
Baton baton;
//LOG(ERROR) << "???";
td::DarwinHttp::get("http://example.com", [&](td::BufferSlice data) {
LOG(ERROR) << data.as_slice();
//LOG(ERROR) << data.as_slice();
baton.post();
});
//LOG(ERROR) << "!!!";