Exemple #1
0
ed_key c_netuser::get_public_key_resp(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
	boost::system::error_code ec;

	char header[2];
	DBG_MTX(dbg_mtx, "read header");
    size_t pkresp = socket_.read_some(buffer(header, 2), ec);
    DBG_MTX(dbg_mtx, "pk: " << pkresp << ":[" <<header[0] << header[1] << "]");

	DBG_MTX(dbg_mtx, "read public key size");
    size_t pub_key_size = 4;
    uint32_t key_size = 0;
    size_t recieved_bytes = socket_.read_some(buffer(&key_size, pub_key_size), ec);
    DBG_MTX(dbg_mtx, "size:" << recieved_bytes << ":[" <<key_size << "]");

    assert(recieved_bytes == pub_key_size);

    const std::unique_ptr<unsigned char[]> pub_key_data(new unsigned char[key_size]);

	DBG_MTX(dbg_mtx, "read public key data");
    recieved_bytes = socket_.read_some(buffer(pub_key_data.get(), key_size), ec);
    DBG_MTX(dbg_mtx, "data:" << recieved_bytes << ":[" << ed_key(pub_key_data.get(),recieved_bytes) << "]");
    assert(recieved_bytes == key_size);

    ed_key pub_key(pub_key_data.get(), key_size);
	DBG_MTX(dbg_mtx, "END");
	return pub_key;
}
Exemple #2
0
string c_netuser::recv_coin(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
	boost::system::error_code ec;

    size_t recieved_bytes = 0;

	uint32_t coin_size = 0;
	recieved_bytes = socket_.read_some(buffer(&coin_size, 4), ec);
	DBG_MTX(dbg_mtx, "get " << recieved_bytes << " bytes");
	assert(recieved_bytes == 4);

	const std::unique_ptr<char[]> coin_data(new char[coin_size]);

	recieved_bytes = socket_.read_some(buffer(coin_data.get(), coin_size), ec);
	assert(recieved_bytes == coin_size);
	return std::string(coin_data.get(), coin_size);
}
Exemple #3
0
void c_netuser::server_read(ip::tcp::socket socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
    boost::system::error_code ec;
    DBG_MTX(dbg_mtx,"server read");
	while (!ec && !m_stop_flag) {
		char header[2] = {0, 0};
		socket_.read_some(buffer(header, 2), ec);
		if (header[0] == 'p' && header[1] == 'k') {
			send_public_key_resp(socket_);
		}
		else if (header[0] == '$' && header[1] == 't') {
			std::string coin_data = recv_coin(socket_);
			recieve_from_packet(coin_data);
		}
	}
	socket_.close();
}