Developing pushpool clientHello,
I'm really interested in
jgarzik's pushpool (it's binary protocol in particular) and writing Qt-based client.
Problem is that I can't make it through
LOGIN step.
As far as I undestand from forum's threads and (mostly) pushpool's source code, I need to send
ubbp_header with
BC_OP_LOGIN operation code and message's length in bytes. Message is SHA256 of compressed json updated with userpass following compressed json.
Json looks something like this (protocol is always 1, config is always null):
{"protocol":1, "user":"username", "config":null}
And I'm doing following (
higlighted version):
ubbp_header header;
strcpy((char*)header.magic, PUSHPOOL_UBBP_MAGIC);
QSocket socket;
socket.connectToHost("my.pushpool.host", 8336);
socket.waitForConnected();
// add compressed json to data
dataToSend = json.toUtf8();
dataToSend = (qCompress(dataToSend, 9));
// Since qCompress() adding length (first 4 bytes in dataToSend) in Big-Endian,
// but server uses le32toh() to get it, change endianness to Little-Endian:
dataToSend.remove(0, 4);
uint32_t len = json.length();
dataToSend.insert(0, (char*)&len;, sizeof(uint32_t));
// add compressed json digest
char pass[] = "test";
uchar md[SHA256_DIGEST_LENGTH];
SHA256_CTX ctx;
SHA256_Init(&ctx;);
SHA256_Update(&ctx;, dataToSend.data(), dataToSend.size());
SHA256_Update(&ctx;, pass, strlen(pass));
SHA256_Final(md, &ctx;);
dataToSend.append((char*)md, SHA256_DIGEST_LENGTH);
// Send operation code & message size
header.op_size = UBBP_OP_SIZE(BC_OP_LOGIN, dataToSend.size());
socket.write((char*)&header;, sizeof(ubbp_header));
socket.waitForBytesWritten();
// Send message
socket.write(dataToSend);
socket.waitForBytesWritten();
// Here's a problem:
// after message sent, I get
// QAbstractSocket::error() with 'Remote host closed connection'
My assumptions:
- JSON compressed by qCompress() cannot be uncompressed by zlib (even after my manipulation)
- I'm calculating wrong SHA256
- Something wrong with json (i.e. config must not be null)
After puzzling for almost whole day, I'm writing here.
Guys, please help.