1

Qtベースのクライアントアプリケーションを書いています。を使用してリモートサーバーに接続しますQTcpSocket。実際のデータを送信する前に、zlibで圧縮されたjsonであるログイン情報を送信する必要があります。

サーバーソースから知る限り、すべてを機能させるには、非圧縮データの長さで4バイトに続いてXバイトの圧縮データを送信する必要があります。

サーバー側での解凍は次のようになります。

/* look at first 32 bits of buffer, which contains uncompressed len */
unc_len = le32toh(*((uint32_t *)buf));
if (unc_len > CLI_MAX_MSG)
    return NULL;

/* alloc buffer for uncompressed data */
obj_unc = malloc(unc_len + 1);
if (!obj_unc)
    return NULL;

/* decompress buffer (excluding first 32 bits) */
comp_p = buf + 4;
if (uncompress(obj_unc, &dest_len, comp_p, buflen - 4) != Z_OK)
    goto out;
if (dest_len != unc_len)
    goto out;
memcpy(obj_unc + unc_len, &zero, 1);    /* null terminate */

Qtの組み込みzlibを使用してjsonを圧縮しています(ヘッダーをダウンロードしてmingwのincludeフォルダーに配置しました):

char json[] = "{\"version\":1,\"user\":\"test\"}";
char pass[] = "test";

std::auto_ptr<Bytef> message(new Bytef[             // allocate memory for:
                             sizeof(ubbp_header)    //  + msg header
                             + sizeof(uLongf)       //  + uncompressed data size
                             + strlen(json)         //  + compressed data itself
                             + 64                   //  + reserve (if compressed size > uncompressed size)
                             + SHA256_DIGEST_LENGTH]);//+ SHA256 digest

uLongf unc_len = strlen(json);
uLongf enc_len = strlen(json) + 64;

// header goes first, so server will determine that we want to login
Bytef* pHdr = message.get();

// after that: uncompressed data length and data itself
Bytef* pLen = pHdr + sizeof(ubbp_header);
Bytef* pDat = pLen + sizeof(uLongf);

// hash of compressed message updated with user pass
Bytef* pSha;

if (Z_OK != compress(pLen, &enc_len, (Bytef*)json, unc_len))
{
    qDebug("Compression failed.");
    return false;
}

ここに完全な機能コード:http://pastebin.com/hMY2C4n5

サーバーは圧縮されていない長さを正しく受信しますが、をuncompress()返しZ_BUF_ERRORます。

PS:私は実際にプッシュプールのクライアントを作成して、バイナリプロトコルがどのように機能するかを理解しています。私は公式のビットコインフォーラムでこの質問をしましたが、運がありません。http://forum.bitcoin.org/index.php?topic=24257.0

4

1 に答える 1

1

サーバー側のバグであることが判明しました。詳細については、ビットコイン フォーラム スレッドをご覧ください。

于 2012-06-07T10:11:12.340 に答える