Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
project_TRTP
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Samuel de Meester de Ravestein
project_TRTP
Validations
30ccd445
Valider
30ccd445
rédigé
3 years ago
par
Samuel de Meester de Ravestein
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
adding comments + cleaner for sender
parent
6b7abeb1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
4
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
src/sender.c
+3
-3
3 ajouts, 3 suppressions
src/sender.c
src/sender_utils.c
+3
-4
3 ajouts, 4 suppressions
src/sender_utils.c
src/sender_utils.h
+30
-26
30 ajouts, 26 suppressions
src/sender_utils.h
tests/simple_test.sh
+8
-8
8 ajouts, 8 suppressions
tests/simple_test.sh
avec
44 ajouts
et
41 suppressions
src/sender.c
+
3
−
3
Voir le fichier @
30ccd445
...
...
@@ -132,7 +132,7 @@ int main(int argc, char **argv) {
return
EXIT_FAILURE
;
}
// Setting a timer only when waiting for the last ACK
(so the sender buffer is 30)
// Setting a timer only when waiting for the
very
last ACK
gettimeofday
(
&
curr_time
,
NULL
);
if
(
state
->
last_pkt_sent
==
CLOSING_PKT
&&
((
curr_time
.
tv_sec
-
closing_pkt_sent_time
.
tv_sec
)
>
SENDER_INACTIVE_TIMEOUT
))
{
...
...
@@ -179,8 +179,8 @@ int main(int argc, char **argv) {
rvalue
=
checking_timer
(
state
,
socket_fd
);
if
(
rvalue
==
-
1
)
{
// If an error occured when trying to send back the
closing pkt
,
// we guess that the receiver has simply disconnected and the ACK of the
closing pkt
was lost.
// If an error occured when trying to send back the
CLOSING_PKT
,
// we guess that the receiver has simply disconnected and the ACK of the
CLOSING_PKT
was lost.
if
(
state
->
last_pkt_sent
==
CLOSING_PKT
)
{
DEBUG
(
"The sender can't send anything to the receiver anymore (which has probably disconnected) so it'll disconnect !"
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/sender_utils.c
+
3
−
4
Voir le fichier @
30ccd445
...
...
@@ -38,7 +38,7 @@ void state_del(sender_state_t *state)
free
(
state
);
}
int
can_send
(
sender_state_t
*
state
)
bool
can_send
(
sender_state_t
*
state
)
{
if
(
state
->
last_pkt_sent
==
RANDOM_DATA_PKT
)
{
...
...
@@ -48,7 +48,7 @@ int can_send(sender_state_t *state)
{
// I want to be sure all the data pkt has been received before letting know the receiver
// it was the end of the file (so that I can set a timer for timeout)
return
state
->
s_window_size
==
WINDOW_SIZE
;
return
state
->
s_window_size
==
MAX_
WINDOW_SIZE
;
}
else
{
...
...
@@ -127,7 +127,7 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd)
uint8_t
place_last_ack
=
state
->
map_seqnum_to_buffer_place
[
seqnum_ack
];
uint8_t
place_last_nack
=
state
->
map_seqnum_to_buffer_place
[
seqnum_nack
];
// Nothing
new
need to be acked
// Nothing need to be acked
if
(
place_last_ack
==
OUT_OFF_WINDOW
)
{
// Checking if it's in my window:
...
...
@@ -178,7 +178,6 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd)
int
checking_timer
(
sender_state_t
*
state
,
int
socket_fd
)
{
struct
timeval
time
;
// Checking if the slot contains a sended packet
if
(
state
->
buffer
[
state
->
tail
]
!=
NULL
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/sender_utils.h
+
30
−
26
Voir le fichier @
30ccd445
...
...
@@ -17,13 +17,13 @@
#include
"packet_interface.h"
#define SEQNUM_RANGE 256
#define TIMER_LIMIT
2
// It's in seconds, in this network, the latency to send is = [0, 2s]
#define SENDER_INACTIVE_TIMEOUT 30 // Only waits 30sec for the
last ACK
#define WINDOW_SIZE 31
#define OUT_OFF_WINDOW 255
#define SEQNUM_RANGE
256
#define TIMER_LIMIT
2
// It's in seconds, in this network, the latency to send is = [0, 2s]
#define SENDER_INACTIVE_TIMEOUT 30
// Only waits 30sec for the
ACK of the CLOSING_PKT (the very last sended pkt)
#define WINDOW_SIZE
31
#define OUT_OFF_WINDOW
255
// It is used to identify what kind of pkt w
hat
sen
d
lately
// It is used to identify what kind of pkt w
as
sen
t
lately
#define RANDOM_DATA_PKT 0
#define LAST_DATA_PKT 1
#define CLOSING_PKT 2
...
...
@@ -37,8 +37,8 @@ typedef struct state {
uint8_t
s_window_size
;
// sender (our) buffer space
time_t
timers
[
WINDOW_SIZE
];
// Time in seconds (corresponds to the timers of the sended pkt)
pkt_t
*
buffer
[
WINDOW_SIZE
];
// When the buffer fields are not used, they MUST be se to NULL
uint8_t
head
;
// place last element insert +1 in the buffer (free place) | Head and tail are used
uint8_t
tail
;
// place oldest element insert in the buffer |
used to know
the start of the sende
d
window
uint8_t
head
;
// place last element insert +1 in the buffer (free place)
| Head and tail are used
to know
uint8_t
tail
;
// place oldest element insert in the buffer
| the start
and end
of the sende
r
window
(of the sended pkt)
uint8_t
next_seqnum
;
uint8_t
map_seqnum_to_buffer_place
[
SEQNUM_RANGE
];
// Default value is: OUT_OFF_WINDOW
uint8_t
last_pkt_sent
;
// Can either be: RANDOM_DATA_PKT, LAST_DATA_PKT or CLOSING_PKT
...
...
@@ -60,12 +60,16 @@ sender_state_t *state_new();
void
state_del
(
sender_state_t
*
state
);
/**
* @brief Checking if
both
the sender
and receiver buffer has some room lef
t
* @brief Checking if the sender
is allowed to send a NEW pk
t
*
* @param state : The variable representing the sender (state).
* @return int : 1 if there are enough space in the buffer, 0 otherwise.
* @return bool :
* - true : if there are enough room in the buffers and some pkt still need to be sent
* - false: if there are no room in the buffer
* or if we're waiting for the last ACK of the DATATYPE
* or if all pkt have been sent
*/
int
can_send
(
sender_state_t
*
state
);
bool
can_send
(
sender_state_t
*
state
);
/**
* @brief Cautious this function is used for sending and sending back pkt !
...
...
@@ -79,32 +83,32 @@ int can_send(sender_state_t *state);
int
send_pkt
(
sender_state_t
*
state
,
pkt_t
*
pkt
,
uint8_t
position
,
int
socket_fd
);
/**
* @brief
* @brief
The function handle ACK and NACK pkt.
*
* @param state
* @param socket_fd
* @return int
* @param state
: The variable representing the sender (state).
* @param socket_fd
: The socket on which pkt are sent.
* @return int
: 0 if no error, -1 otherwise
*/
int
handle_returning_ack_nack
(
sender_state_t
*
state
,
int
socket_fd
);
/**
* @brief
* @brief The function checks if the oldest not acked pkt has exceeded the timer (TIMER_LIMIT).
* If it has exceeded the timer then it is sent back.
*
* @param state
* @param socket_fd
* @return int
* @param state
: The variable representing the sender (state).
* @param socket_fd
: The socket on which pkt are sent.
* @return int
: 0 if no error, -1 otherwise
*/
int
checking_timer
(
sender_state_t
*
state
,
int
socket_fd
);
/**
* @brief When this function is called, the sender MUST be allowed to send a data pkt
* @brief When this function is called, the sender MUST be allowed to send a data pkt.
* It sends the next pkt and update the variable 'last_pkt_sent' of state.
*
* @param state
* @param sending_fd
* @param socket_fd
* @return int : 1 if it has sent the empty datatype pkt else 0
* -1 if an error occured
* -2 Both sender and receiver buffer are full
* @param state : The variable representing the sender (state).
* @param sending_fd : The file descriptor of the file to be send
* @param socket_fd : The socket on which pkt are sent.
* @return int : 0 if no error, -1 otherwise
*/
int
read_and_send
(
sender_state_t
*
state
,
int
sending_fd
,
int
socket_fd
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
tests/simple_test.sh
+
8
−
8
Voir le fichier @
30ccd445
...
...
@@ -33,9 +33,9 @@ cleanup()
}
trap
cleanup SIGINT
# Kill les process en arrière plan en cas de ^-C
#
On démarre l
e transfer
t
#
We start th
e transfer
if
!
valgrind
--leak-check
=
full
--log-file
=
./unwanted_logs/valgrind_
${
BSNM_PRE
}
_sender.log ./sender
-f
${
FILENAME
}
::1 65197 2> ./unwanted_logs/
${
BSNM_PRE
}
_sender.log
;
then
echo
"
Crash du sender
!"
echo
"
The sender crashed
!"
cat
./unwanted_logs/
${
BSNM_PRE
}
_sender.log
err
=
1
# On enregistre l'erreur
fi
...
...
@@ -46,21 +46,21 @@ if kill -0 $receiver_pid &> /dev/null ; then
echo
"Le receiver ne s'est pas arreté à la fin du transfert!"
kill
-9
$receiver_pid
err
=
1
else
#
On teste la valeur de retour du
receiver
else
#
We check the return value of the
receiver
if
!
wait
$receiver_pid
;
then
echo
"
Crash du
receiver!"
echo
"
The
receiver
crashed
!"
cat
./unwanted_logs/
${
BSNM_PRE
}
_receiver.log
err
=
1
fi
fi
#
On vérifie que le transfert s'est bien déroulé
#
We check that the transfer ran through properly
if
[[
"
$(
md5sum
${
FILENAME
}
|
awk
'{print $1}'
)
"
!=
"
$(
md5sum
./unwanted_logs/
${
BSNM_PRE
}
_received_file.
${
BSNM_EXT
}
|
awk
'{print $1}'
)
"
]]
;
then
echo
"
L
e transfer
t a
corr
ompu le fichier
!"
echo
"
Th
e transfer
has
corr
upted the file
!"
echo
"Diff binaire des deux fichiers: (attendu vs produit)"
diff
-C
9 <
(
od
-Ax
-t
x1z
${
FILENAME
}
)
<
(
od
-Ax
-t
x1z ./unwanted_logs/
${
BSNM_PRE
}
_received_file.
${
BSNM_EXT
}
)
exit
1
else
echo
-e
"
${
GREEN
}
L
e transfer
t est réussi
!
${
NC
}
"
exit
${
err
:-
0
}
#
E
n cas
d'erreurs avant, on renvoie le code d'erreur
echo
-e
"
${
GREEN
}
Th
e transfer
has succeeded
!
${
NC
}
"
exit
${
err
:-
0
}
#
I
n cas
e of error, we send back the error code.
fi
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter