Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d2904cd authored by Tamas Berghammer's avatar Tamas Berghammer Committed by Elliott Hughes
Browse files

Increase size of the the adb packets sent over the wire

The reason behing this change is to increase the adb push/pull speed
with reduceing the number of packets sent between the host and the
device because the communication is heavily bound by packet latency.

The change maintains two way compatibility in the communication
protocol with negotiating a packet size between the target and the
host with the CONNECT packets.

After this change the push/pull speeds improved significantly
(measured from Linux-x86_64 with 100MB of data):

           | Old push | Old pull || New push  | New pull  |
-----------------------------------------------------------
Hammerhead | 4.6 MB/s | 3.9 MB/s || 13.1 MB/s | 16.5 MB/s |
-----------------------------------------------------------
Volantis   | 6.0 MB/s | 6.2 MS/s || 25.9 MB/s | 29.0 MB/s |
-----------------------------------------------------------
Fugu       | 6.0 MB/s | 5.1 MB/s || 27.9 MB/s | 33.2 MB/s |
-----------------------------------------------------------

Change-Id: Id9625de31266e43394289e325c7e7e473379c5d8
parent f5b46079
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -334,10 +334,10 @@ void send_connect(atransport *t)
    D("Calling send_connect \n");
    D("Calling send_connect \n");
    apacket *cp = get_apacket();
    apacket *cp = get_apacket();
    cp->msg.command = A_CNXN;
    cp->msg.command = A_CNXN;
    cp->msg.arg0 = A_VERSION;
    cp->msg.arg0 = t->get_protocol_version();
    cp->msg.arg1 = MAX_PAYLOAD;
    cp->msg.arg1 = t->get_max_payload();
    cp->msg.data_length = fill_connect_data((char *)cp->data,
    cp->msg.data_length = fill_connect_data((char *)cp->data,
                                            sizeof(cp->data));
                                            MAX_PAYLOAD_V1);
    send_packet(cp, t);
    send_packet(cp, t);
}
}


@@ -424,12 +424,12 @@ void handle_packet(apacket *p, atransport *t)
        return;
        return;


    case A_CNXN: /* CONNECT(version, maxdata, "system-id-string") */
    case A_CNXN: /* CONNECT(version, maxdata, "system-id-string") */
            /* XXX verify version, etc */
        if(t->connection_state != kCsOffline) {
        if(t->connection_state != kCsOffline) {
            t->connection_state = kCsOffline;
            t->connection_state = kCsOffline;
            handle_offline(t);
            handle_offline(t);
        }
        }


        t->update_version(p->msg.arg0, p->msg.arg1);
        parse_banner(reinterpret_cast<const char*>(p->data), t);
        parse_banner(reinterpret_cast<const char*>(p->data), t);


        if (HOST || !auth_required) {
        if (HOST || !auth_required) {
+14 −1
Original line number Original line Diff line number Diff line
@@ -25,7 +25,9 @@
#include "adb_trace.h"
#include "adb_trace.h"
#include "fdevent.h"
#include "fdevent.h"


#define MAX_PAYLOAD 4096
constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024;
constexpr size_t MAX_PAYLOAD_V2 = 256 * 1024;
constexpr size_t MAX_PAYLOAD = MAX_PAYLOAD_V2;


#define A_SYNC 0x434e5953
#define A_SYNC 0x434e5953
#define A_CNXN 0x4e584e43
#define A_CNXN 0x4e584e43
@@ -137,6 +139,8 @@ struct asocket {


        /* A socket is bound to atransport */
        /* A socket is bound to atransport */
    atransport *transport;
    atransport *transport;

    size_t get_max_payload() const;
};
};




@@ -193,6 +197,8 @@ public:
    atransport() {
    atransport() {
        auth_fde = {};
        auth_fde = {};
        transport_fde = {};
        transport_fde = {};
        protocol_version = A_VERSION;
        max_payload = MAX_PAYLOAD;
    }
    }


    virtual ~atransport() {}
    virtual ~atransport() {}
@@ -234,7 +240,14 @@ public:


    const char* connection_state_name() const;
    const char* connection_state_name() const;


    void update_version(int version, size_t payload);
    int get_protocol_version() const;
    size_t get_max_payload() const;

private:
private:
    int protocol_version;
    size_t max_payload;

    DISALLOW_COPY_AND_ASSIGN(atransport);
    DISALLOW_COPY_AND_ASSIGN(atransport);
};
};


+1 −1
Original line number Original line Diff line number Diff line
@@ -75,7 +75,7 @@ void send_auth_publickey(atransport *t)
    apacket *p = get_apacket();
    apacket *p = get_apacket();
    int ret;
    int ret;


    ret = adb_auth_get_userkey(p->data, sizeof(p->data));
    ret = adb_auth_get_userkey(p->data, MAX_PAYLOAD_V1);
    if (!ret) {
    if (!ret) {
        D("Failed to get user public key\n");
        D("Failed to get user public key\n");
        put_apacket(p);
        put_apacket(p);
+2 −2
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ static bool needs_retry = false;
static void read_keys(const char *file, struct listnode *list)
static void read_keys(const char *file, struct listnode *list)
{
{
    FILE *f;
    FILE *f;
    char buf[MAX_PAYLOAD];
    char buf[MAX_PAYLOAD_V1];
    char *sep;
    char *sep;
    int ret;
    int ret;


@@ -191,7 +191,7 @@ static void adb_auth_event(int fd, unsigned events, void *data)


void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t)
void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t)
{
{
    char msg[MAX_PAYLOAD];
    char msg[MAX_PAYLOAD_V1];
    int ret;
    int ret;


    if (!usb_transport) {
    if (!usb_transport) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -157,7 +157,7 @@ static int write_public_keyfile(RSA *private_key, const char *private_key_path)
{
{
    RSAPublicKey pkey;
    RSAPublicKey pkey;
    FILE *outfile = NULL;
    FILE *outfile = NULL;
    char path[PATH_MAX], info[MAX_PAYLOAD];
    char path[PATH_MAX], info[MAX_PAYLOAD_V1];
    uint8_t* encoded = nullptr;
    uint8_t* encoded = nullptr;
    size_t encoded_length;
    size_t encoded_length;
    int ret = 0;
    int ret = 0;
Loading