Revision 4123e0f7 peer_event.c

View differences:

peer_event.c
54 54
	return (struct action_event *) po;
55 55
}
56 56

  
57
/********************LINK OFFER******************************/
58
struct link_offer_event{
59
	struct action_event ae;
60
	struct ed_simulator * eds;
61
	struct peer * src;
62
	int dst_idx;
63
};
64

  
65
void link_offer_event_destroy(struct action_event ** ae)
66
{
67
	struct link_offer_event * po;
68
	po = (struct link_offer_event *) *ae;
69
	free(po);
70
	*ae = NULL;
71
}
72

  
73
int link_offer_event_trigger(struct action_event * ae)
74
{
75
	int chunk, t;
76
	struct peer * dst;
77
	struct link_offer_event * po;
78

  
79
	po = (struct link_offer_event *) ae;
80
//	fprintf(stderr,"[DEBUG] peer %d is offering\n", (po->src)->id);
81
	t = (int) ed_simulator_time(po->eds);
82
	dst = (po->src)->neighbour[po->dst_idx];
83
	peer_send_chunk(po->src, t, &chunk, dst);
84
	if (chunk >= 0)
85
	{
86
		//fprintf(stderr,"[DEBUG] %d: peer %d send chunk %d to %d\n", t, (po->src)->id, chunk, dst->id);
87
		(po->src)->chunks[win_idx(po->src, chunk)]->dl += ed_simulator_server_period(po->eds);
88
		ed_simulator_send_chunk(po->eds, chunk, dst, (po->src)->chunks[win_idx(po->src, chunk)]->dl);
89
	}
90
	//fprintf(stderr,"[DEBUG] offer rate: %f, prob: %f, interval: %f\n", (po->src)->offer_rate,  (po->src)->neighbour_prob[po->dst_idx], (po->src)->offer_rate * 1/((po->src)->neighbour_prob[po->dst_idx]));
91
	ed_simulator_schedule(po->eds, ae, (po->src)->offer_rate * 1/((po->src)->neighbour_prob[po->dst_idx]));
92
	return chunk >= 0 ? 0 : -1;
93
}
94

  
95
struct action_event * link_offer_event_new(struct ed_simulator * eds, struct peer *src, int dst_idx)
96
{
97
	struct link_offer_event * po;
98
	po = (struct link_offer_event *) malloc (sizeof(struct link_offer_event));
99
	action_event_init((struct action_event *)&(po->ae), link_offer_event_trigger, link_offer_event_destroy);
100
	po->eds = eds;
101
	po->src = src;
102
	po->dst_idx = dst_idx;
103
	return (struct action_event *) po;
104
}
57 105
/********************PEER RECEPTION******************************/
58 106
struct peer_reception_event{
59 107
	struct action_event ae;

Also available in: Unified diff