Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Mar 27, 2021
1 parent 66de95d commit b84318f
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -32,7 +34,5 @@

sqlite/sqlite/* linguist-vendored

*.tlo binary

*.pfx binary
*.png binary
2 changes: 1 addition & 1 deletion td/generate/tl-parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 10 additions & 3 deletions td/mtproto/RawConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions td/mtproto/RawConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions td/telegram/GroupCallManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions td/telegram/GroupCallParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "td/utils/logging.h"

#include <limits>

namespace td {

GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::groupCallParticipant> &participant,
Expand Down
4 changes: 2 additions & 2 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand All @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions td/telegram/net/ConnectionCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tdnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions tdnet/td/net/DarwinHttp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
#include "td/net/DarwinHttp.h"

#include "td/utils/logging.h"

#import <Foundation/Foundation.h>

namespace td {
Expand All @@ -16,7 +18,7 @@
}

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) {
Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions test/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#include <algorithm>
#include <limits>

#include <mutex>
#include <condition_variable>
#include <mutex>

REGISTER_TESTS(http)

Expand Down Expand Up @@ -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) << "!!!";
Expand Down

0 comments on commit b84318f

Please sign in to comment.