私はQtベースのクライアントアプリケーションを書いています。 QTcpSocket
を使用してリモートサーバーに接続します。実際のデータを送信する前に、zlibで圧縮されたjsonというログイン情報を送信する必要があります。不思議なことにzlibのuncompress()がZ_BUF_ERRORを返す
サーバのソースからわかっている限り、すべてを動作させるために、圧縮されていないデータの長さが4バイトに続くXバイトの圧縮データを送信する必要があります。サーバー側で
解凍は次のようになります。
:私は(私はmingwののinclude
フォルダにヘッダをダウンロードして配置した)Qtは、組み込みのzlibを使用してJSONを圧縮してい
/* 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 */
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
サーバーが正常に圧縮されていない長さをrecievesにもかかわらず、uncompress()
Z_BUF_ERROR
を返す。
P .:私は実際にプッシュプルのクライアントを書いて、バイナリプロトコルの仕組みを理解しています。私は公式のビットコインフォーラムでこの質問をしましたが、そこに運はありません。 http://forum.bitcoin.org/index.php?topic=24257.0