static vertex *vertex_split(hedge *h, vector v) { hedge *h2, *hn1, *hn2; vertex *vtxn; edge *en; face *f1; f1 = h->f; h2 = partner(h); vtxn = vertex_new(f1->s, v); hn1 = hedge_new(h, vtxn); vtxn->h = hn1; hn2 = hedge_new(h2, vtxn); hn2->e = h->e; if(h2->e->left == h2) h2->e->left = hn2; else h2->e->right = hn2; en = edge_new(f1->s); en->left = hn1; en->right = h2; hn1->e = en; h2->e = en; return vtxn; }
// find out if this packet is initiator or responder. called from accept_packet, so partner should be set void tcp_stream_t::find_direction(packet_t *packet, const layer_t *tcplay) { const tcphdr &hdr = reinterpret_cast<const tcphdr &>(*tcplay->data()); if (have_partner() && partner()->d_direction != direction_unknown) d_direction = (partner()->d_direction == direction_initiator ? direction_responder : direction_initiator); else { if (hdr.th_flags & TH_SYN) d_direction = (hdr.th_flags & TH_ACK ? direction_responder : direction_initiator); else // assume the server is the one with the lower port nubmer d_direction = (htons(hdr.th_sport) > htons(hdr.th_dport) ? direction_initiator : direction_responder); if (have_partner()) partner()->d_direction = (d_direction == direction_initiator ? direction_responder : direction_initiator); } assert(d_direction == direction_initiator || d_direction == direction_responder); }
Receiver::Rcv_state Receiver::sender_ok(const Sender *sender) const { unsigned ipc_state = state() & Thread_ipc_mask; // If Thread_send_in_progress is still set, we're still in the send phase if (EXPECT_FALSE(ipc_state != Thread_receive_wait)) return vcpu_async_ipc(sender); // Check open wait; test if this sender is really the first in queue if (EXPECT_TRUE(!partner() && (_sender_list.empty() || sender->is_head_of(&_sender_list)))) return Rs_ipc_receive; // Check closed wait; test if this sender is really who we specified if (EXPECT_TRUE(sender == partner())) return Rs_ipc_receive; return Rs_not_receiving; }
uint64_t tcp_stream_t::timeout() const { bool use_short = d_have_accepted_end; uint64_t r = d_highest_ts.tv_sec; tcp_stream_t *our_partner = NULL; if (have_partner()) { our_partner = partner(); use_short = use_short || our_partner->d_have_accepted_end; uint64_t o = our_partner->d_highest_ts.tv_sec; if (o > r) r = o; } r += (use_short ? 60 : 600); return r; }
static inline void vertex_calcnormal(vertex *vtx, jigglystruct *js) { hedge *start = vtx->h, *h=start; vector_init(vtx->n, 0, 0, 0); do { vector u, v, norm; vector_sub(h->prev->vtx->v, vtx->v, u); vector_sub(h->next->vtx->v, vtx->v, v); cross(u, v, norm); vector_add_to(vtx->n, norm); h = partner(h)->next; } while(h != start); if(!js->spooky) normalize(vtx->n); else vector_scale(vtx->n, js->spooky); }
int mincut::run(graph& G) { graph g; g.make_undirected(); // Make a local copy of the graph as mincut modifies the original graph // List of nodes in the original graph node_map <node> partner (G); node_map <node> orig (g); node x; int counter = 0; forall_nodes (x, G) { partner[x] = g.new_node(); orig[partner[x]] = x; // so we can look up original node }
// add a packet, will either queue it in d_delayed, or accept it bool tcp_stream_t::add(packet_t *packet, const layer_t *tcplay) { assert(tcplay); if (packet->ts() > d_highest_ts) d_highest_ts = packet->ts(); const tcphdr &hdr = reinterpret_cast<const tcphdr &>(*tcplay->data()); if (unlikely(d_trust_seq && !is_reasonable_seq(d_next_seq, htonl(hdr.th_seq)))) { listener()->debug_packet(packet, "unreasonable large offset in sequence numbers. quick port re-use"); return false; // quick port re-use, packet not part of this stream } if (!is_partner_set() && hdr.th_flags & TH_ACK) { seq_nr_t ack(htonl(hdr.th_ack)); if (d_smallest_ack == 0 || ack < d_smallest_ack) d_smallest_ack = ack; } bool check_partner_delayed = false; if (!d_trust_seq) { // check if we already have a starting packet find_relyable_startseq(hdr); if (d_trust_seq && have_delayed()) listener()->debug_packet(packet, "accepted sequence number %08x as start of stream", d_next_seq.d_val); if (have_partner() && d_smallest_ack != 0) { check_partner_delayed = partner()->find_seq_from_ack(d_smallest_ack); if (check_partner_delayed) listener()->debug_packet(packet, "our ack's matched with partner's seq. will accept partner's delayed packets"); } } seq_nr_t seq(htonl(hdr.th_seq)); // if we know where the packet should go -> do it if (d_trust_seq && is_partner_set()) // partner is also set if we gave up looking { if (seq <= d_next_seq) accept_packet(packet, tcplay); else { listener()->debug_packet(packet, "delaying packet because it has sequence " "number in the future (got %08x, expected %08x)", seq.d_val, d_next_seq.d_val); d_delayed.insert(delayed_t::value_type(seq, packet)); } } else { if (is_partner_set()) listener()->debug_packet(packet, "delaying packet because we don't trust " "sequence numbers yet (got %08x, current guess %08x)", seq.d_val, d_next_seq.d_val); else listener()->debug_packet(packet, "delaying packet because we don't have a partner yet"); d_delayed.insert(delayed_t::value_type(seq, packet)); } // we have reason to believe our partner can continue now if (check_partner_delayed) { listener()->debug_packet(partner()->d_delayed.begin()->second, "accepting partner because we decided so earlier"); partner()->check_delayed(false); } // fallback, don't queue too much if (d_delayed.size() > MAX_DELAYED_PACKETS) { if (!d_trust_seq) listener()->debug_packet(packet, "unable to find reasonable starting sequence, " "forcing first packet"); d_trust_seq = true; // if this wasn't set yet, it was seriously screwed up check_delayed(true); } return true; // packet belonged to this stream }
PUBLIC inline bool Receiver::in_ipc(Sender *sender) { return (state() & Thread_receive_in_progress) && (partner() == sender); }