void put_pkt(buf_ptr &buf) { size_t rank; size_t block = super::rlnc_hdr_block(buf); if (!validate_block(block)) { if (m_late_pkts++ % 5 == 1) send_ack(block, base::m_coder->symbols()); return; } assert(buf->data_val() % 4u == 0); assert(buf->data_len() >= super::rlnc_symbol_size()); rank = base::m_coder->rank(); super::rlnc_hdr_del(buf); base::m_coder->decode(buf->head()); assert(base::m_coder->rank() <= base::m_coder->remote_rank()); if (base::m_coder->rank() == rank) { ++m_linear; ++m_linear_block; ++m_linear_count; } else { m_linear = 0; } if (m_linear < 50) return; std::cout << "emergency ack " << base::m_coder->rank() << std::endl; send_ack(super::rlnc_hdr_block(), base::m_coder->rank()); }
void get_pkt(buf_ptr &buf) { size_t len, max_len = base::m_coder->payload_size(); len = base::m_coder->encode(buf->data_put(max_len)); buf->data_trim(len); super::rlnc_hdr_add_enc(buf); }
void get_pkt(buf_ptr &buf) { size_t size = base::m_coder->symbol_size(); memcpy(buf->head(), base::m_coder->symbol(m_decoded++), size); buf->trim(size); ++m_decoded_count; }
void put_pkt(buf_ptr &buf) { assert(buf->head_val() % 4u == 0); sak::const_storage symbol(buf->head(), buf->len()); base::m_coder->set_symbol(base::m_coder->symbols_initialized(), symbol); super::increase_budget(); }
bool read_pkt(buf_ptr &buf) { size_t offset = sizeof(struct ethhdr) % 4; buf->move(-offset); buf->head_reserve(ETH_HLEN); if (!super::read_pkt(buf)) return false; buf->head_pull(ETH_HLEN); return true; }
bool write_pkt(buf_ptr &buf) { int res = sendto(fd(), buf->head(), buf->len(), 0, sa_send(), sa_send_len()); if (res > 0) { buf->pull(res); return true; } if (res < 0 && (errno == EAGAIN || errno == ENOBUFS)) return false; throw std::system_error(errno, std::system_category(), "unable to write packet"); }
void send_to_connection(buf_ptr buf, short message_id, int size) { ((Header*)write_header_)->message_id = message_id; ((Header*)write_header_)->body_size = size; std::memcpy(write_data_, write_header_, sizeof(Header)); std::memcpy(write_data_ + sizeof(Header), buf->get_buffer(), size); do_write(size + sizeof(Header)); do_write(size + sizeof(Header)); }
bool read_pkt(buf_ptr &buf, size_t len, size_t offset = 0) { int res = recvfrom(fd(), buf->head() + offset, len, 0, sa_recv(), sa_recv_len()); if (res > 0) { buf->push(res); return true; } if (res == 0) throw std::runtime_error("connection closed"); if (res < 0 && errno == EAGAIN) return false; throw std::system_error(errno, std::system_category(), "unable to recv packet"); }
bool write_pkt(buf_ptr &buf) { struct ethhdr *hdr = header(buf->head_push(ETH_HLEN)); memcpy(hdr->h_dest, super::neighbor_addr(), ETH_ALEN); memcpy(hdr->h_source, super::interface_address(), ETH_ALEN); hdr->h_proto = htons(super::proto()); return super::write_pkt(buf); }
bool read_pkt(buf_ptr &buf) { int res; res = read(m_fd, buf->data(), buf->max_len()); if (res > 0) { buf->trim(res); return true; } if (res == 0) return false; if (res < 0 && errno == EAGAIN) return false; throw std::system_error(errno, std::system_category(), "unable to read pkt"); }
bool write_pkt(buf_ptr &buf) { int len = buf->len(); int res = write(m_fd, buf->head(), buf->len()); if (res == len) return true; if (res > 0) { std::cout << "incomplete write: " << res << std::endl; throw std::runtime_error("incomplete write"); } if (res == 0) return false; if (res < 0 && errno == EAGAIN) return false; throw std::system_error(errno, std::system_category(), "unable to write pkt"); }
void process_ack(buf_ptr &buf) { size_t block = super::rlnc_hdr_block(buf); if (!validate_block(block)) return; base::put_status(buf->data(), &m_decoder_rank); std::cout << "enc ack rank " << m_decoder_rank << std::endl; if (m_decoder_rank < super::rlnc_symbols()) return; std::cout << "enc ack block " << block << std::endl; increment(); }
bool read_pkt(buf_ptr &buf) { return read_pkt(buf, buf->max_len()); }
bool compare_source(buf_ptr &buf, uint8_t *addr) { return addr && memcmp(hdr_source(buf->head()), addr, ETH_ALEN) == 0; }
void do_write(buf_ptr buf){ boost::asio::async_write(socket_, boost::asio::buffer(buf->get_buffer(), buf->get_size()),[&buf](const boost::system::error_code&, std::size_t){}); }