123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931 |
- #define TRACE_TAG SOCKETS
- #include "sysdeps.h"
- #include <ctype.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <algorithm>
- #include <chrono>
- #include <mutex>
- #include <string>
- #include <vector>
- #if !ADB_HOST
- #include <android-base/properties.h>
- #include <log/log_properties.h>
- #endif
- #include "adb.h"
- #include "adb_io.h"
- #include "adb_utils.h"
- #include "transport.h"
- #include "types.h"
- using namespace std::chrono_literals;
- static std::recursive_mutex& local_socket_list_lock = *new std::recursive_mutex();
- static unsigned local_socket_next_id = 1;
- static auto& local_socket_list = *new std::vector<asocket*>();
- static auto& local_socket_closing_list = *new std::vector<asocket*>();
- asocket* find_local_socket(unsigned local_id, unsigned peer_id) {
- asocket* result = nullptr;
- std::lock_guard<std::recursive_mutex> lock(local_socket_list_lock);
- for (asocket* s : local_socket_list) {
- if (s->id != local_id) {
- continue;
- }
- if (peer_id == 0 || (s->peer && s->peer->id == peer_id)) {
- result = s;
- }
- break;
- }
- return result;
- }
- void install_local_socket(asocket* s) {
- std::lock_guard<std::recursive_mutex> lock(local_socket_list_lock);
- s->id = local_socket_next_id++;
-
- if (local_socket_next_id == 0) {
- LOG(FATAL) << "local socket id overflow";
- }
- local_socket_list.push_back(s);
- }
- void remove_socket(asocket* s) {
- std::lock_guard<std::recursive_mutex> lock(local_socket_list_lock);
- for (auto list : { &local_socket_list, &local_socket_closing_list }) {
- list->erase(std::remove_if(list->begin(), list->end(), [s](asocket* x) { return x == s; }),
- list->end());
- }
- }
- void close_all_sockets(atransport* t) {
-
- std::lock_guard<std::recursive_mutex> lock(local_socket_list_lock);
- restart:
- for (asocket* s : local_socket_list) {
- if (s->transport == t || (s->peer && s->peer->transport == t)) {
- s->close(s);
- goto restart;
- }
- }
- }
- enum class SocketFlushResult {
- Destroyed,
- TryAgain,
- Completed,
- };
- static SocketFlushResult local_socket_flush_incoming(asocket* s) {
- if (!s->packet_queue.empty()) {
- std::vector<adb_iovec> iov = s->packet_queue.iovecs();
- ssize_t rc = adb_writev(s->fd, iov.data(), iov.size());
- if (rc > 0 && static_cast<size_t>(rc) == s->packet_queue.size()) {
- s->packet_queue.clear();
- } else if (rc > 0) {
-
- s->packet_queue.take_front(rc);
- fdevent_add(s->fde, FDE_WRITE);
- return SocketFlushResult::TryAgain;
- } else if (rc == -1 && errno == EAGAIN) {
- fdevent_add(s->fde, FDE_WRITE);
- return SocketFlushResult::TryAgain;
- } else {
-
-
- s->has_write_error = true;
- }
- }
-
- if (s->closing) {
- s->close(s);
- return SocketFlushResult::Destroyed;
- }
- fdevent_del(s->fde, FDE_WRITE);
- return SocketFlushResult::Completed;
- }
- static bool local_socket_flush_outgoing(asocket* s) {
- const size_t max_payload = s->get_max_payload();
- apacket::payload_type data;
- data.resize(max_payload);
- char* x = &data[0];
- size_t avail = max_payload;
- int r = 0;
- int is_eof = 0;
- while (avail > 0) {
- r = adb_read(s->fd, x, avail);
- D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu", s->id, s->fd, r,
- r < 0 ? errno : 0, avail);
- if (r == -1) {
- if (errno == EAGAIN) {
- break;
- }
- } else if (r > 0) {
- avail -= r;
- x += r;
- continue;
- }
-
- is_eof = 1;
- break;
- }
- D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d", s->id, s->fd, r, is_eof,
- s->fde->force_eof);
- if (avail != max_payload && s->peer) {
- data.resize(max_payload - avail);
-
-
- unsigned saved_id = s->id;
- int saved_fd = s->fd;
- r = s->peer->enqueue(s->peer, std::move(data));
- D("LS(%u): fd=%d post peer->enqueue(). r=%d", saved_id, saved_fd, r);
- if (r < 0) {
-
-
-
-
-
-
- return false;
- }
- if (r > 0) {
-
- fdevent_del(s->fde, FDE_READ);
- }
- }
-
- if ((s->fde->force_eof && !r) || is_eof) {
- D(" closing because is_eof=%d r=%d s->fde.force_eof=%d", is_eof, r, s->fde->force_eof);
- s->close(s);
- return false;
- }
- return true;
- }
- static int local_socket_enqueue(asocket* s, apacket::payload_type data) {
- D("LS(%d): enqueue %zu", s->id, data.size());
- s->packet_queue.append(std::move(data));
- switch (local_socket_flush_incoming(s)) {
- case SocketFlushResult::Destroyed:
- return -1;
- case SocketFlushResult::TryAgain:
- return 1;
- case SocketFlushResult::Completed:
- return 0;
- }
- return !s->packet_queue.empty();
- }
- static void local_socket_ready(asocket* s) {
-
- fdevent_add(s->fde, FDE_READ);
- }
- struct ClosingSocket {
- std::chrono::steady_clock::time_point begin;
- };
- static void deferred_close(unique_fd fd) {
-
-
- adb_shutdown(fd.get(), SHUT_WR);
- auto callback = [](fdevent* fde, unsigned event, void* arg) {
- auto socket_info = static_cast<ClosingSocket*>(arg);
- if (event & FDE_READ) {
- ssize_t rc;
- char buf[BUFSIZ];
- while ((rc = adb_read(fde->fd.get(), buf, sizeof(buf))) > 0) {
- continue;
- }
- if (rc == -1 && errno == EAGAIN) {
-
- auto duration = std::chrono::steady_clock::now() - socket_info->begin;
- if (duration > 1s) {
- LOG(WARNING) << "timeout expired while flushing socket, closing";
- } else {
- return;
- }
- }
- } else if (event & FDE_TIMEOUT) {
- LOG(WARNING) << "timeout expired while flushing socket, closing";
- }
-
- fdevent_destroy(fde);
- delete socket_info;
- };
- ClosingSocket* socket_info = new ClosingSocket{
- .begin = std::chrono::steady_clock::now(),
- };
- fdevent* fde = fdevent_create(fd.release(), callback, socket_info);
- fdevent_add(fde, FDE_READ);
- fdevent_set_timeout(fde, 1s);
- }
- static void local_socket_destroy(asocket* s) {
- int exit_on_close = s->exit_on_close;
- D("LS(%d): destroying fde.fd=%d", s->id, s->fd);
- deferred_close(fdevent_release(s->fde));
- remove_socket(s);
- delete s;
- if (exit_on_close) {
- D("local_socket_destroy: exiting");
- exit(1);
- }
- }
- static void local_socket_close(asocket* s) {
- D("entered local_socket_close. LS(%d) fd=%d", s->id, s->fd);
- std::lock_guard<std::recursive_mutex> lock(local_socket_list_lock);
- if (s->peer) {
- D("LS(%d): closing peer. peer->id=%d peer->fd=%d", s->id, s->peer->id, s->peer->fd);
-
- if (s->peer->shutdown) {
- s->peer->shutdown(s->peer);
- }
- s->peer->peer = nullptr;
- s->peer->close(s->peer);
- s->peer = nullptr;
- }
-
- if (s->closing || s->has_write_error || s->packet_queue.empty()) {
- int id = s->id;
- local_socket_destroy(s);
- D("LS(%d): closed", id);
- return;
- }
-
- D("LS(%d): closing", s->id);
- s->closing = 1;
- fdevent_del(s->fde, FDE_READ);
- remove_socket(s);
- D("LS(%d): put on socket_closing_list fd=%d", s->id, s->fd);
- local_socket_closing_list.push_back(s);
- CHECK_EQ(FDE_WRITE, s->fde->state & FDE_WRITE);
- }
- static void local_socket_event_func(int fd, unsigned ev, void* _s) {
- asocket* s = reinterpret_cast<asocket*>(_s);
- D("LS(%d): event_func(fd=%d(==%d), ev=%04x)", s->id, s->fd, fd, ev);
-
- if (ev & FDE_WRITE) {
- switch (local_socket_flush_incoming(s)) {
- case SocketFlushResult::Destroyed:
- return;
- case SocketFlushResult::TryAgain:
- break;
- case SocketFlushResult::Completed:
- s->peer->ready(s->peer);
- break;
- }
- }
- if (ev & FDE_READ) {
- if (!local_socket_flush_outgoing(s)) {
- return;
- }
- }
- if (ev & FDE_ERROR) {
-
- D("LS(%d): FDE_ERROR (fd=%d)", s->id, s->fd);
- return;
- }
- }
- asocket* create_local_socket(unique_fd ufd) {
- int fd = ufd.release();
- asocket* s = new asocket();
- s->fd = fd;
- s->enqueue = local_socket_enqueue;
- s->ready = local_socket_ready;
- s->shutdown = nullptr;
- s->close = local_socket_close;
- install_local_socket(s);
- s->fde = fdevent_create(fd, local_socket_event_func, s);
- D("LS(%d): created (fd=%d)", s->id, s->fd);
- return s;
- }
- asocket* create_local_service_socket(std::string_view name, atransport* transport) {
- #if !ADB_HOST
- if (asocket* s = daemon_service_to_socket(name); s) {
- return s;
- }
- #endif
- unique_fd fd = service_to_fd(name, transport);
- if (fd < 0) {
- return nullptr;
- }
- int fd_value = fd.get();
- asocket* s = create_local_socket(std::move(fd));
- LOG(VERBOSE) << "LS(" << s->id << "): bound to '" << name << "' via " << fd_value;
- #if !ADB_HOST
- if ((name.starts_with("root:") && getuid() != 0 && __android_log_is_debuggable()) ||
- (name.starts_with("unroot:") && getuid() == 0) || name.starts_with("usb:") ||
- name.starts_with("tcpip:")) {
- D("LS(%d): enabling exit_on_close", s->id);
- s->exit_on_close = 1;
- }
- #endif
- return s;
- }
- static int remote_socket_enqueue(asocket* s, apacket::payload_type data) {
- D("entered remote_socket_enqueue RS(%d) WRITE fd=%d peer.fd=%d", s->id, s->fd, s->peer->fd);
- apacket* p = get_apacket();
- p->msg.command = A_WRTE;
- p->msg.arg0 = s->peer->id;
- p->msg.arg1 = s->id;
- if (data.size() > MAX_PAYLOAD) {
- put_apacket(p);
- return -1;
- }
- p->payload = std::move(data);
- p->msg.data_length = p->payload.size();
- send_packet(p, s->transport);
- return 1;
- }
- static void remote_socket_ready(asocket* s) {
- D("entered remote_socket_ready RS(%d) OKAY fd=%d peer.fd=%d", s->id, s->fd, s->peer->fd);
- apacket* p = get_apacket();
- p->msg.command = A_OKAY;
- p->msg.arg0 = s->peer->id;
- p->msg.arg1 = s->id;
- send_packet(p, s->transport);
- }
- static void remote_socket_shutdown(asocket* s) {
- D("entered remote_socket_shutdown RS(%d) CLOSE fd=%d peer->fd=%d", s->id, s->fd,
- s->peer ? s->peer->fd : -1);
- apacket* p = get_apacket();
- p->msg.command = A_CLSE;
- if (s->peer) {
- p->msg.arg0 = s->peer->id;
- }
- p->msg.arg1 = s->id;
- send_packet(p, s->transport);
- }
- static void remote_socket_close(asocket* s) {
- if (s->peer) {
- s->peer->peer = nullptr;
- D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d", s->id, s->peer->id, s->peer->fd);
- s->peer->close(s->peer);
- }
- D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d", s->id, s->fd,
- s->peer ? s->peer->fd : -1);
- D("RS(%d): closed", s->id);
- delete s;
- }
- asocket* create_remote_socket(unsigned id, atransport* t) {
- if (id == 0) {
- LOG(FATAL) << "invalid remote socket id (0)";
- }
- asocket* s = new asocket();
- s->id = id;
- s->enqueue = remote_socket_enqueue;
- s->ready = remote_socket_ready;
- s->shutdown = remote_socket_shutdown;
- s->close = remote_socket_close;
- s->transport = t;
- D("RS(%d): created", s->id);
- return s;
- }
- void connect_to_remote(asocket* s, std::string_view destination) {
- D("Connect_to_remote call RS(%d) fd=%d", s->id, s->fd);
- apacket* p = get_apacket();
- LOG(VERBOSE) << "LS(" << s->id << ": connect(" << destination << ")";
- p->msg.command = A_OPEN;
- p->msg.arg0 = s->id;
-
-
- p->payload.resize(destination.size() + 1);
- memcpy(p->payload.data(), destination.data(), destination.size());
- p->payload[destination.size()] = '\0';
- p->msg.data_length = p->payload.size();
- CHECK_LE(p->msg.data_length, s->get_max_payload());
- send_packet(p, s->transport);
- }
- static void local_socket_ready_notify(asocket* s) {
- s->ready = local_socket_ready;
- s->shutdown = nullptr;
- s->close = local_socket_close;
- SendOkay(s->fd);
- s->ready(s);
- }
- static void local_socket_close_notify(asocket* s) {
- s->ready = local_socket_ready;
- s->shutdown = nullptr;
- s->close = local_socket_close;
- SendFail(s->fd, "closed");
- s->close(s);
- }
- static unsigned unhex(const char* s, int len) {
- unsigned n = 0, c;
- while (len-- > 0) {
- switch ((c = *s++)) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- c -= '0';
- break;
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- c = c - 'a' + 10;
- break;
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- c = c - 'A' + 10;
- break;
- default:
- return 0xffffffff;
- }
- n = (n << 4) | c;
- }
- return n;
- }
- #if ADB_HOST
- namespace internal {
- bool parse_host_service(std::string_view* out_serial, std::string_view* out_command,
- std::string_view full_service) {
- if (full_service.empty()) {
- return false;
- }
- std::string_view serial;
- std::string_view command = full_service;
-
- auto consume = [&full_service, &serial, &command](size_t count) {
- CHECK_LE(count, command.size());
- if (!serial.empty()) {
- CHECK_EQ(serial.data() + serial.size(), command.data());
- }
- serial = full_service.substr(0, serial.size() + count);
- command.remove_prefix(count);
- };
-
- auto finish = [out_serial, out_command, &serial, &command] {
- if (serial.empty() || command.empty()) {
- return false;
- }
- CHECK_EQ(':', serial.back());
- serial.remove_suffix(1);
- *out_serial = serial;
- *out_command = command;
- return true;
- };
- static constexpr std::string_view prefixes[] = {"usb:", "product:", "model:", "device:"};
- for (std::string_view prefix : prefixes) {
- if (command.starts_with(prefix)) {
- consume(prefix.size());
- size_t offset = command.find_first_of(':');
- if (offset == std::string::npos) {
- return false;
- }
- consume(offset + 1);
- return finish();
- }
- }
-
- if (command.starts_with("tcp:") || command.starts_with("udp:")) {
- consume(4);
- if (command.empty()) {
- return false;
- }
- }
- if (command.starts_with("vsock:")) {
-
- size_t next_colon = command.find(':');
- if (next_colon == std::string::npos) {
- return false;
- }
- consume(next_colon + 1);
- }
- bool found_address = false;
- if (command[0] == '[') {
-
-
- size_t ipv6_end = command.find_first_of(']');
- if (ipv6_end != std::string::npos) {
- consume(ipv6_end + 1);
- if (command.empty()) {
-
- return false;
- } else if (command[0] != ':') {
-
- return false;
- }
- consume(1);
- found_address = true;
- }
- }
- if (!found_address) {
-
- size_t offset = command.find_first_of(':');
- if (offset == std::string::npos) {
- return false;
- }
- consume(offset + 1);
- }
-
-
- size_t next_colon = command.find_first_of(':');
- if (next_colon == std::string::npos) {
-
- return finish();
- }
- bool port_valid = true;
- if (command.size() <= next_colon) {
- return false;
- }
- std::string_view port = command.substr(0, next_colon);
- for (auto digit : port) {
- if (!isdigit(digit)) {
-
- port_valid = false;
- break;
- }
- }
- if (port_valid) {
- consume(next_colon + 1);
- }
- return finish();
- }
- }
- #endif
- static int smart_socket_enqueue(asocket* s, apacket::payload_type data) {
- #if ADB_HOST
- std::string_view service;
- std::string_view serial;
- TransportId transport_id = 0;
- TransportType type = kTransportAny;
- #endif
- D("SS(%d): enqueue %zu", s->id, data.size());
- if (s->smart_socket_data.empty()) {
-
- s->smart_socket_data.assign(data.begin(), data.end());
- } else {
- std::copy(data.begin(), data.end(), std::back_inserter(s->smart_socket_data));
- }
-
- if (s->smart_socket_data.size() < 4) {
- return 0;
- }
- uint32_t len = unhex(s->smart_socket_data.data(), 4);
- if (len == 0 || len > MAX_PAYLOAD) {
- D("SS(%d): bad size (%u)", s->id, len);
- goto fail;
- }
- D("SS(%d): len is %u", s->id, len);
-
- if ((len + 4) > s->smart_socket_data.size()) {
- D("SS(%d): waiting for %zu more bytes", s->id, len + 4 - s->smart_socket_data.size());
- return 0;
- }
- s->smart_socket_data[len + 4] = 0;
- D("SS(%d): '%s'", s->id, (char*)(s->smart_socket_data.data() + 4));
- #if ADB_HOST
- service = std::string_view(s->smart_socket_data).substr(4);
- if (ConsumePrefix(&service, "host-serial:")) {
-
- if (!internal::parse_host_service(&serial, &service, service)) {
- LOG(ERROR) << "SS(" << s->id << "): failed to parse host service: " << service;
- goto fail;
- }
- } else if (ConsumePrefix(&service, "host-transport-id:")) {
- if (!ParseUint(&transport_id, service, &service)) {
- LOG(ERROR) << "SS(" << s->id << "): failed to parse host transport id: " << service;
- return -1;
- }
- if (!ConsumePrefix(&service, ":")) {
- LOG(ERROR) << "SS(" << s->id << "): host-transport-id without command";
- return -1;
- }
- } else if (ConsumePrefix(&service, "host-usb:")) {
- type = kTransportUsb;
- } else if (ConsumePrefix(&service, "host-local:")) {
- type = kTransportLocal;
- } else if (ConsumePrefix(&service, "host:")) {
- type = kTransportAny;
- } else {
- service = std::string_view{};
- }
- if (!service.empty()) {
- asocket* s2;
-
-
- auto host_request_result = handle_host_request(
- service, type, serial.empty() ? nullptr : std::string(serial).c_str(), transport_id,
- s->peer->fd, s);
- switch (host_request_result) {
- case HostRequestResult::Handled:
- LOG(VERBOSE) << "SS(" << s->id << "): handled host service '" << service << "'";
- goto fail;
- case HostRequestResult::SwitchedTransport:
- D("SS(%d): okay transport", s->id);
- s->smart_socket_data.clear();
- return 0;
- case HostRequestResult::Unhandled:
- break;
- }
-
-
- s2 = host_service_to_socket(service, serial, transport_id);
- if (s2 == nullptr) {
- LOG(VERBOSE) << "SS(" << s->id << "): couldn't create host service '" << service << "'";
- SendFail(s->peer->fd, "unknown host service");
- goto fail;
- }
-
- SendOkay(s->peer->fd);
- s->peer->ready = local_socket_ready;
- s->peer->shutdown = nullptr;
- s->peer->close = local_socket_close;
- s->peer->peer = s2;
- s2->peer = s->peer;
- s->peer = nullptr;
- D("SS(%d): okay", s->id);
- s->close(s);
-
- s2->ready(s2);
- return 0;
- }
- #else
- if (s->transport == nullptr) {
- std::string error_msg = "unknown failure";
- s->transport = acquire_one_transport(kTransportAny, nullptr, 0, nullptr, &error_msg);
- if (s->transport == nullptr) {
- SendFail(s->peer->fd, error_msg);
- goto fail;
- }
- }
- #endif
- if (!s->transport) {
- SendFail(s->peer->fd, "device offline (no transport)");
- goto fail;
- } else if (!ConnectionStateIsOnline(s->transport->GetConnectionState())) {
-
- SendFail(s->peer->fd, "device offline (transport offline)");
- goto fail;
- }
-
- s->peer->ready = local_socket_ready_notify;
- s->peer->shutdown = nullptr;
- s->peer->close = local_socket_close_notify;
- s->peer->peer = nullptr;
-
- s->peer->transport = s->transport;
- connect_to_remote(s->peer, std::string_view(s->smart_socket_data).substr(4));
- s->peer = nullptr;
- s->close(s);
- return 1;
- fail:
-
- s->close(s);
- return -1;
- }
- static void smart_socket_ready(asocket* s) {
- D("SS(%d): ready", s->id);
- }
- static void smart_socket_close(asocket* s) {
- D("SS(%d): closed", s->id);
- if (s->peer) {
- s->peer->peer = nullptr;
- s->peer->close(s->peer);
- s->peer = nullptr;
- }
- delete s;
- }
- static asocket* create_smart_socket(void) {
- D("Creating smart socket");
- asocket* s = new asocket();
- s->enqueue = smart_socket_enqueue;
- s->ready = smart_socket_ready;
- s->shutdown = nullptr;
- s->close = smart_socket_close;
- D("SS(%d)", s->id);
- return s;
- }
- void connect_to_smartsocket(asocket* s) {
- D("Connecting to smart socket");
- asocket* ss = create_smart_socket();
- s->peer = ss;
- ss->peer = s;
- s->ready(s);
- }
- size_t asocket::get_max_payload() const {
- size_t max_payload = MAX_PAYLOAD;
- if (transport) {
- max_payload = std::min(max_payload, transport->get_max_payload());
- }
- if (peer && peer->transport) {
- max_payload = std::min(max_payload, peer->transport->get_max_payload());
- }
- return max_payload;
- }
|