// non prioritized means that, if there's a line for bandwidth, // others will cut in front of the non-prioritized peers. // this is used by web seeds void request_bandwidth(intrusive_ptr<PeerConnection> const& peer , int blk, int priority , bandwidth_channel* chan1 = 0 , bandwidth_channel* chan2 = 0 , bandwidth_channel* chan3 = 0 , bandwidth_channel* chan4 = 0 , bandwidth_channel* chan5 = 0 ) { INVARIANT_CHECK; if (m_abort) return; TORRENT_ASSERT(blk > 0); TORRENT_ASSERT(priority > 0); TORRENT_ASSERT(!is_queued(peer.get())); bw_request<PeerConnection> bwr(peer, blk, priority); int i = 0; if (chan1 && chan1->throttle() > 0) bwr.channel[i++] = chan1; if (chan2 && chan2->throttle() > 0) bwr.channel[i++] = chan2; if (chan3 && chan3->throttle() > 0) bwr.channel[i++] = chan3; if (chan4 && chan4->throttle() > 0) bwr.channel[i++] = chan4; if (chan5 && chan5->throttle() > 0) bwr.channel[i++] = chan5; if (i == 0) { // the connection is not rate limited by any of its // bandwidth channels, or it doesn't belong to any // channels. There's no point in adding it to // the queue, just satisfy the request immediately bwr.peer->assign_bandwidth(m_channel, blk); return; } m_queued_bytes += blk; m_queue.push_back(bwr); }
void mk_coalesce::merge_rules(rule_ref& tgt, rule const& src) { SASSERT(same_body(*tgt.get(), src)); m_sub1.reset(); m_sub2.reset(); m_idx = 0; app_ref pred(m), head(m); expr_ref fml1(m), fml2(m), fml(m); app_ref_vector tail(m); ptr_vector<sort> sorts1, sorts2; expr_ref_vector conjs1(m), conjs(m); rule_ref res(rm); bool_rewriter bwr(m); svector<bool> is_neg; tgt->get_vars(sorts1); src.get_vars(sorts2); mk_pred(head, src.get_head(), tgt->get_head()); for (unsigned i = 0; i < src.get_uninterpreted_tail_size(); ++i) { mk_pred(pred, src.get_tail(i), tgt->get_tail(i)); tail.push_back(pred); is_neg.push_back(src.is_neg_tail(i)); } extract_conjs(m_sub1, src, fml1); extract_conjs(m_sub2, *tgt.get(), fml2); bwr.mk_or(fml1, fml2, fml); SASSERT(is_app(fml)); tail.push_back(to_app(fml)); is_neg.push_back(false); res = rm.mk(head, tail.size(), tail.c_ptr(), is_neg.c_ptr(), tgt->name()); if (m_ctx.generate_proof_trace()) { src.to_formula(fml1); tgt->to_formula(fml2); res->to_formula(fml); #if 0 sort* ps = m.mk_proof_sort(); sort* domain[3] = { ps, ps, m.mk_bool_sort() }; func_decl* merge = m.mk_func_decl(symbol("merge-clauses"), 3, domain, ps); // TBD: ad-hoc proof rule expr* args[3] = { m.mk_asserted(fml1), m.mk_asserted(fml2), fml }; // ...m_pc->insert(m.mk_app(merge, 3, args)); #else svector<std::pair<unsigned, unsigned> > pos; vector<expr_ref_vector> substs; proof* p = src.get_proof(); p = m.mk_hyper_resolve(1, &p, fml, pos, substs); res->set_proof(m, p); #endif } tgt = res; }
void mk_coalesce::extract_conjs(expr_ref_vector const& sub, rule const& rl, expr_ref& result) { obj_map<expr, unsigned> indices; bool_rewriter bwr(m); rule_ref r(const_cast<rule*>(&rl), rm); ptr_vector<sort> sorts; expr_ref_vector revsub(m), conjs(m); rl.get_vars(sorts); revsub.resize(sorts.size()); svector<bool> valid(sorts.size(), true); for (unsigned i = 0; i < sub.size(); ++i) { expr* e = sub[i]; sort* s = m.get_sort(e); expr_ref w(m.mk_var(i, s), m); if (is_var(e)) { unsigned v = to_var(e)->get_idx(); SASSERT(v < valid.size()); if (sorts[v]) { SASSERT(s == sorts[v]); if (valid[v]) { revsub[v] = w; valid[v] = false; } else { SASSERT(revsub[v].get()); SASSERT(m.get_sort(revsub[v].get()) == s); conjs.push_back(m.mk_eq(revsub[v].get(), w)); } } } else { SASSERT(m.is_value(e)); SASSERT(m.get_sort(e) == m.get_sort(w)); conjs.push_back(m.mk_eq(e, w)); } } for (unsigned i = 0; i < sorts.size(); ++i) { if (valid[i] && sorts[i] && !revsub[i].get()) { revsub[i] = m.mk_var(m_idx++, sorts[i]); } } var_subst vs(m, false); for (unsigned i = r->get_uninterpreted_tail_size(); i < r->get_tail_size(); ++i) { vs(r->get_tail(i), revsub.size(), revsub.c_ptr(), result); conjs.push_back(result); } bwr.mk_and(conjs.size(), conjs.c_ptr(), result); }
// non prioritized means that, if there's a line for bandwidth, // others will cut in front of the non-prioritized peers. // this is used by web seeds int bandwidth_manager::request_bandwidth(boost::shared_ptr<bandwidth_socket> const& peer , int blk, int priority, bandwidth_channel** chan, int num_channels) { INVARIANT_CHECK; if (m_abort) return 0; TORRENT_ASSERT(blk > 0); TORRENT_ASSERT(priority > 0); // if this assert is hit, the peer is requesting more bandwidth before // being assigned bandwidth for an already outstanding request TORRENT_ASSERT(!is_queued(peer.get())); if (num_channels == 0) { // the connection is not rate limited by any of its // bandwidth channels, or it doesn't belong to any // channels. There's no point in adding it to // the queue, just satisfy the request immediately return blk; } int k = 0; bw_request bwr(peer, blk, priority); for (int i = 0; i < num_channels; ++i) { if (chan[i]->need_queueing(blk)) bwr.channel[k++] = chan[i]; } if (k == 0) return blk; m_queued_bytes += blk; m_queue.push_back(bwr); return 0; }