本文整理汇总了C++中net::buffer类的典型用法代码示例。如果您正苦于以下问题:C++ buffer类的具体用法?C++ buffer怎么用?C++ buffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了buffer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void connection::write(const net::buffer& data)
{
if(m_service.check_this_loop()){
write_in_loop(data.data(),data.size());
}else{
m_service.run_task( boost::bind(&connection::write_in_loop,this,data.data(),data.size()) );
}
}
示例2: memcmp
bool message_udp::recv::pong::expect(const net::buffer & recv_buf)
{
if(recv_buf.size() != protocol_udp::pong_size){
return false;
}
if(recv_buf[0] != protocol_udp::pong){
return false;
}
return std::memcmp(recv_buf.data()+1, random.data(), 4) == 0;
}
示例3: random
bool message_udp::recv::store_node::recv(const net::buffer & recv_buf,
const net::endpoint & endpoint)
{
if(!expect(recv_buf)){
return false;
}
net::buffer random(recv_buf.data()+1, 4);
std::string remote_ID(convert::bin_to_hex(std::string(
reinterpret_cast<const char *>(recv_buf.data())+5, 20)));
func(endpoint, random, remote_ID);
return true;
}
示例4: recv_rB
void encryption::recv_rB(const net::buffer & buf)
{
assert(enable_recv_rB);
set_enable_false();
enable_crypt = true;
assert(buf.size() == protocol_tcp::DH_key_size);
remote_result = mpa::mpint(buf.data(), protocol_tcp::DH_key_size);
shared_key = mpa::exptmod(remote_result, s, p);
std::string bin = shared_key.bin(protocol_tcp::DH_key_size);
PRNG_send.seed(reinterpret_cast<const unsigned char *>(bin.data()), bin.size());
PRNG_recv.seed(reinterpret_cast<const unsigned char *>(bin.data()), bin.size());
}
示例5: crypt_send
void encryption::crypt_send(net::buffer & send_buff, const int index)
{
assert(enable_crypt);
for(int x=index; x<send_buff.size(); ++x){
send_buff[x] ^= PRNG_send.byte();
}
}
示例6: crypt_recv
void encryption::crypt_recv(net::buffer & recv_buff, const int index)
{
assert(enable_crypt);
for(int x=index; x<recv_buff.size(); ++x){
recv_buff[x] ^= PRNG_recv.byte();
}
}
示例7: BF
//BEGIN send::host_list
message_udp::send::host_list::host_list(const net::buffer & random,
const std::string & local_ID,
const std::list<net::endpoint> & hosts)
{
assert(random.size() == 4);
assert(hosts.size() <= protocol_udp::host_list_elements);
bit_field BF(16);
unsigned cnt = 0;
for(std::list<net::endpoint>::const_iterator it_cur = hosts.begin(),
it_end = hosts.end(); it_cur != it_end; ++it_cur)
{
if(it_cur->version() == net::IPv4){
BF[cnt] = 0;
}else{
BF[cnt] = 1;
}
++cnt;
}
buf.append(protocol_udp::host_list)
.append(random)
.append(convert::hex_to_bin(local_ID))
.append(BF.get_buf());
//append addresses
for(std::list<net::endpoint>::const_iterator it_cur = hosts.begin(),
it_end = hosts.end(); it_cur != it_end; ++it_cur)
{
buf.append(it_cur->IP_bin())
.append(it_cur->port_bin());
}
}
示例8: remote_ID
bool message_udp::recv::host_list::recv(const net::buffer & recv_buf,
const net::endpoint & endpoint)
{
if(!expect(recv_buf)){
return false;
}
std::string remote_ID(convert::bin_to_hex(std::string(
reinterpret_cast<const char *>(recv_buf.data())+5, 20)));
bit_field BF(recv_buf.data()+25, 2, 16);
std::list<net::endpoint> hosts;
unsigned offset = protocol_udp::host_list_size;
for(unsigned x=0; x<16 && offset != recv_buf.size(); ++x){
if(BF[x] == 0){
//IPv4
boost::optional<net::endpoint> ep = net::bin_to_endpoint(
recv_buf.str(offset, 4), recv_buf.str(offset + 4, 2));
if(ep){
hosts.push_back(*ep);
}
offset += 6;
}else{
//IPv6
boost::optional<net::endpoint> ep = net::bin_to_endpoint(
recv_buf.str(offset, 16), recv_buf.str(offset + 16, 2));
if(ep){
hosts.push_back(*ep);
}
offset += 18;
}
}
func(endpoint, remote_ID, hosts);
return true;
}
示例9:
//BEGIN send::store_node
message_udp::send::store_node::store_node(const net::buffer & random,
const std::string & local_ID)
{
assert(random.size() == 4);
assert(local_ID.size() == SHA1::hex_size);
buf.append(protocol_udp::store_node)
.append(random)
.append(convert::hex_to_bin(local_ID));
}
示例10: recv_p_rA
bool encryption::recv_p_rA(const net::buffer & buf)
{
assert(enable_recv_p_rA);
set_enable_false();
enable_send_rB = true;
assert(buf.size() == protocol_tcp::DH_key_size * 2);
p = mpa::mpint(buf.data(), protocol_tcp::DH_key_size);
if(!mpa::is_prime(p)){
return false;
}
remote_result = mpa::mpint(buf.data() + protocol_tcp::DH_key_size, protocol_tcp::DH_key_size);
local_result = mpa::exptmod(g, s, p);
shared_key = mpa::exptmod(remote_result, s, p);
std::string bin = shared_key.bin(protocol_tcp::DH_key_size);
PRNG_send.seed(reinterpret_cast<const unsigned char *>(bin.data()), bin.size());
PRNG_recv.seed(reinterpret_cast<const unsigned char *>(bin.data()), bin.size());
return true;
}