Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bfsc19
Caco Project
Commits
f6bd98d9
Commit
f6bd98d9
authored
2 years ago
by
Nico Ramos
Browse files
Options
Downloads
Patches
Plain Diff
sdafsd
parent
30e43be7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
headers/client.h
+27
-27
27 additions, 27 deletions
headers/client.h
headers/conexao.h
+2
-2
2 additions, 2 deletions
headers/conexao.h
received/caco.png
+0
-0
0 additions, 0 deletions
received/caco.png
with
29 additions
and
29 deletions
headers/client.h
+
27
−
27
View file @
f6bd98d9
...
...
@@ -80,10 +80,10 @@ frame *client::receive_ack_nack() {
if
(
!
(
response
=
socket
->
receive_frame
()))
{
continue
;
}
}
while
(
response
==
NULL
&&
retries
<
NUM_RETRIES
);
//
if (response && response->get_tipo() == ERRO) {
//
cout << BOLDYELLOW << "Espaco insulficiente no destino\n" << RESET;
//
return NULL;
//
}
if
(
response
&&
response
->
get_tipo
()
==
ERRO
)
{
cout
<<
BOLDYELLOW
<<
"Espaco insulficiente no destino
\n
"
<<
RESET
;
return
NULL
;
}
}
while
(
response
&&
!
(
verify_ack_nack
(
response
)));
return
response
;
...
...
@@ -99,15 +99,15 @@ frame *client::send_frame_socket(frame *f) {
if
(
!
response
)
return
NULL
;
}
while
(
response
->
get_dado
()[
0
]
!=
f
->
get_seq
());
//
cout << "\tACK recebido:\n"; // ->log
//
response->imprime(DEC); // ->log
cout
<<
"
\t
ACK recebido:
\n
"
;
// ->log
response
->
imprime
(
DEC
);
// ->log
return
response
;
}
// Inicia a transmissao com o servidor
int
client
::
start_transmission
()
{
//
cout<< YELLOW << "\tIniciando transmissao\n" << RESET; ->log
cout
<<
YELLOW
<<
"
\t
Iniciando transmissao
\n
"
<<
RESET
;
->
log
frame
*
ini
=
new
frame
(
INIT
,
0
,
vector
<
char
>
(
1
,
0
));
frame
*
enviado
=
new
frame
();
enviado
=
send_frame_socket
(
ini
);
...
...
@@ -117,21 +117,21 @@ int client::start_transmission() {
enviado
=
send_frame_socket
(
ini
);
}
if
(
!
enviado
)
{
//
cout<< BOLDRED << "\tFalha ao iniciar a transmissao\n" << RESET; ->log
cout
<<
BOLDRED
<<
"
\t
Falha ao iniciar a transmissao
\n
"
<<
RESET
;
->
log
return
0
;
}
//
cout<< GREEN << "\tTransmissao iniciada com sucesso\n" << RESET; ->log
cout
<<
GREEN
<<
"
\t
Transmissao iniciada com sucesso
\n
"
<<
RESET
;
->
log
return
1
;
}
// Encerra a transmissao com o servidor
int
client
::
end_transmission
()
{
//
cout << "\tEncerrando a transmissao\n"; // ->log
cout
<<
"
\t
Encerrando a transmissao
\n
"
;
// ->log
frame
*
end
=
new
frame
(
FIMT
,
0
,
vector
<
char
>
(
1
,
0
));
frame
*
enviado
=
send_frame_socket
(
end
);
if
(
!
enviado
)
{
//
cout << "\tFalha ao encerrar a transmissao\n"; // ->log
cout
<<
"
\t
Falha ao encerrar a transmissao
\n
"
;
// ->log
return
0
;
}
...
...
@@ -149,9 +149,9 @@ int client::send_frames(vector<frame *> frames) {
if
(
frames
.
empty
())
{
return
0
;
}
//
cout << "\tstart transmission\n"; ->log
cout
<<
"
\t
start transmission
\n
"
;
->
log
if
(
!
start_transmission
())
{
return
0
;
}
//
cout << "\t ->>> started transmission <<< -\n"; ->log
cout
<<
"
\t
->>> started transmission <<< -
\n
"
;
->
log
// Adiciona o frame de fim de transmissao
int
next_seq
=
frames
.
back
()
->
get_seq
()
+
1
;
...
...
@@ -169,20 +169,20 @@ int client::send_frames(vector<frame *> frames) {
if
(
iniJanela
+
frameCounter
==
frames
.
size
())
{
break
;
}
janela
.
push
((
iniJanela
+
frameCounter
)
%
16
);
//
cout << "\tEnviando frame: " << iniJanela + frameCounter << "\n";
cout
<<
"
\t
Enviando frame: "
<<
iniJanela
+
frameCounter
<<
"
\n
"
;
// frames[iniJanela + frameCounter]->imprime(DEC);
if
(
socket
->
send_frame
(
frames
[
iniJanela
+
frameCounter
])
==
-
1
)
{
//
cout << "Falha ao enviar o frame\n"; ->log
cout
<<
"Falha ao enviar o frame
\n
"
;
->
log
continue
;
}
//
cout << "\tFrame enviado com sucesso\n"; ->log
cout
<<
"
\t
Frame enviado com sucesso
\n
"
;
->
log
}
// Recebe a resposta do servidor
while
(
!
janela
.
empty
())
{
//
cout << "Janela size: " << janela.size() << "\n";
cout
<<
"Janela size: "
<<
janela
.
size
()
<<
"
\n
"
;
frame
*
res
=
NULL
;
int
retries
=
0
;
...
...
@@ -192,16 +192,16 @@ int client::send_frames(vector<frame *> frames) {
}
while
(
res
==
NULL
&&
retries
<
NUM_RETRIES
);
if
(
res
==
NULL
&&
retries
==
NUM_RETRIES
)
{
//
cout << "Numero maximo de tentativas excedido\n"; ->log
cout
<<
"Numero maximo de tentativas excedido
\n
"
;
->
log
break
;
}
//
cout << "Resposta recebida\n";
//
cout << "Numero ack/nack: " << (int)res->get_dado()[0] << " ---- "
//
<< "Janela front: " << janela.front() << "\n";
cout
<<
"Resposta recebida
\n
"
;
cout
<<
"Numero ack/nack: "
<<
(
int
)
res
->
get_dado
()[
0
]
<<
" ---- "
<<
"Janela front: "
<<
janela
.
front
()
<<
"
\n
"
;
if
(
res
->
get_tipo
()
==
NACK
&&
res
->
get_dado
()[
0
]
==
janela
.
front
())
{
//
cout << "NACK " << (int)res->get_dado()[0] << " recebido\n"; ->log
cout
<<
"NACK "
<<
(
int
)
res
->
get_dado
()[
0
]
<<
" recebido
\n
"
;
->
log
iniJanela
+=
res
->
get_dado
()[
0
];
janela
.
pop
();
break
;
...
...
@@ -216,18 +216,18 @@ int client::send_frames(vector<frame *> frames) {
}
if
(
res
->
get_tipo
()
==
ACK
&&
res
->
get_dado
()[
0
]
==
janela
.
front
())
{
//
cout << "ACK " << (int)res->get_dado()[0] << " recebido\n";
cout
<<
"ACK "
<<
(
int
)
res
->
get_dado
()[
0
]
<<
" recebido
\n
"
;
iniJanela
++
;
janela
.
pop
();
}
}
// apaga a janela
//
while (!janela.empty())
//
janela.pop();
while
(
!
janela
.
empty
())
janela
.
pop
();
}
//
cout << "\tTerminou de enviar todos os frames\n"; //->log
cout
<<
"
\t
Terminou de enviar todos os frames
\n
"
;
//->log
return
1
;
}
...
...
@@ -242,7 +242,7 @@ int client::send_frames(vector<frame *> frames) {
*/
bool
client
::
verify_ack_nack
(
frame
*
received
)
{
// received error frame
//
cout << "Verificando ACK/NACK/Error\n"; ->log
cout
<<
"Verificando ACK/NACK/Error
\n
"
;
->
log
return
((
received
->
get_tipo
()
==
ACK
||
received
->
get_tipo
()
==
NACK
||
received
->
get_tipo
()
==
ERRO
)
&&
...
...
This diff is collapsed.
Click to expand it.
headers/conexao.h
+
2
−
2
View file @
f6bd98d9
...
...
@@ -140,7 +140,7 @@ int conexao::add_escapes(char *f, char *out) {
for
(
size_t
i
=
0
;
i
<
sizeof
(
frame
);
i
++
)
{
out
[
j
++
]
=
f
[
i
];
if
(
f
[
i
]
==
0x88
||
f
[
i
]
==
0x81
)
out
[
j
++
]
=
0xFF
;
if
(
f
[
i
]
==
(
char
)
0x88
||
f
[
i
]
==
(
char
)
0x81
)
out
[
j
++
]
=
0xFF
;
}
...
...
@@ -152,7 +152,7 @@ int conexao::remove_escapes(char *f, char *out) {
for
(
size_t
i
=
0
;
j
<
sizeof
(
frame
);
i
++
)
{
out
[
j
++
]
=
f
[
i
];
if
(
f
[
i
]
==
0x88
||
f
[
i
]
==
0x81
)
i
++
;
if
(
f
[
i
]
==
(
char
)
0x88
||
f
[
i
]
==
(
char
)
0x81
)
i
++
;
}
return
j
;
...
...
This diff is collapsed.
Click to expand it.
received/caco.png
0 → 100644
+
0
−
0
View file @
f6bd98d9
1.07 MiB
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment