Revision ffebdf87 src/transaction.c

View differences:

src/transaction.c
63 63
			stl->forward->backward = stl->backward;
64 64
		}
65 65
	}
66
	nodeid_free(stl->st.id);
66 67
	free(stl);
67 68
}	
68 69

  
......
112 113
}
113 114

  
114 115
// register the moment when a transaction is started
115
// return a  new transaction id
116
// return a  new transaction id or 0 in case of failure
116 117
uint16_t transaction_create(struct service_times_element ** stl, struct nodeID *id)
117 118
{
118
	static uint16_t trans_id = 1;
119

  
120 119
	struct service_times_element *stl2;
121 120
	struct timeval current_time;
122 121

  
123
	check_neighbor_status_list(stl);
122
	if (stl && id)
123
	{
124
		check_neighbor_status_list(stl);
124 125

  
125
	gettimeofday(&current_time, NULL);
126
		gettimeofday(&current_time, NULL);
126 127

  
127
	//create new trans_id;
128
	trans_id++;
129
	//skip 0
130
	if (!trans_id) trans_id++;
131 128

  
132
	// create a new element in the list with its offer_sent_time and set accept_received_time to -1.0
133
	stl2 = (struct service_times_element*) malloc(sizeof(struct service_times_element));
134
	stl2->st.trans_id = trans_id;
135
	stl2->st.offer_sent_time = current_time.tv_sec + current_time.tv_usec*1e-6;
136
	stl2->st.accept_received_time = -1.0;
137
	stl2->st.id = id;	//TODO: nodeid_dup
129
		// create a new element in the list with its offer_sent_time and set accept_received_time to -1.0
130
		stl2 = (struct service_times_element*) malloc(sizeof(struct service_times_element));
131
		stl2->st.offer_sent_time = current_time.tv_sec + current_time.tv_usec*1e-6;
132
		stl2->st.accept_received_time = -1.0;
133
		stl2->st.id = nodeid_dup(id);
138 134

  
139
	dprintf("LIST: adding trans_id %d to the list, offer_sent_time %f -- LIST IS NOT EMPTY\n", trans_id, (current_time.tv_sec + current_time.tv_usec*1e-6));
135
		stl2->backward = NULL;
140 136

  
141
	stl2->backward = NULL;
137
		if (*stl)
138
		{
139
			stl2->st.trans_id = (*stl)->st.trans_id + 1 ? (*stl)->st.trans_id + 1 : 1;
140
			(*stl)->backward = stl2;
141
			stl2->forward = (*stl);
142
			*stl = stl2;
143
		} else {
144
			stl2->st.trans_id = 1;
145
			stl2->forward = NULL;
146
			*stl = stl2;
147
		}
148
		dprintf("LIST: adding trans_id %d to the list, offer_sent_time %f -- LIST IS NOT EMPTY\n", stl2->st.trans_id, (current_time.tv_sec + current_time.tv_usec*1e-6));
142 149

  
143
	if (*stl)
144
	{
145
		(*stl)->backward = stl2;
146
		stl2->forward = (*stl);
147
		*stl = stl2;
148
	} else {
149
		stl2->forward = NULL;
150
		*stl = stl2;
150
		return stl2->st.trans_id;
151 151
	}
152

  
153
	return trans_id;
152
	return 0;
154 153
}
155 154

  
156 155

  
......
161 160
	struct service_times_element *stl_iterator;
162 161
	struct timeval current_time;
163 162

  
164
	gettimeofday(&current_time, NULL);
165
	stl_iterator = stl;
166

  
167
	// if an accept was received, look for the trans_id and add current_time to accept_received_time field
168
	dprintf("LIST: changing trans_id %d to the list, accept received %f\n", trans_id, current_time.tv_sec + current_time.tv_usec*1e-6);
169
	// Iterate the list until you get the right element
170
	while (stl_iterator != NULL) {
171
			if (stl_iterator->st.trans_id == trans_id) {
172
				stl_iterator->st.accept_received_time = current_time.tv_sec + current_time.tv_usec*1e-6;
173
#ifndef MONL
174
				offer_accept_rtt_measure(id,stl_iterator->st.accept_received_time - stl_iterator->st.offer_sent_time);
175
				reception_measure(id);
176
#endif
177
				return true;
178
				}
179
			stl_iterator = stl_iterator->forward;
163
	if (stl && id && trans_id)
164
	{
165
		gettimeofday(&current_time, NULL);
166
		stl_iterator = stl;
167

  
168
		// if an accept was received, look for the trans_id and add current_time to accept_received_time field
169
		dprintf("LIST: changing trans_id %d to the list, accept received %f\n", trans_id, current_time.tv_sec + current_time.tv_usec*1e-6);
170
		// Iterate the list until you get the right element
171
		while (stl_iterator != NULL) {
172
				if (stl_iterator->st.trans_id == trans_id) {
173
					stl_iterator->st.accept_received_time = current_time.tv_sec + current_time.tv_usec*1e-6;
174
	#ifndef MONL
175
					offer_accept_rtt_measure(id,stl_iterator->st.accept_received_time - stl_iterator->st.offer_sent_time);
176
					reception_measure(id);
177
	#endif
178
					return true;
179
					}
180
				stl_iterator = stl_iterator->forward;
181
		}
180 182
	}
181 183
	return false;
182 184
}
......
216 218
	return to_return;
217 219
}
218 220

  
219
void transactions_destroy(struct service_times_element * head)
221
void transaction_destroy(struct service_times_element ** head)
220 222
{
221
	while(head)
223
	while(*head)
222 224
	{
223
		_transaction_remove(&head, head);
225
		_transaction_remove(head, *head);
224 226
		// in case of nodeid_dup we should free that as well
225 227
	}
226 228

  

Also available in: Unified diff