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
4199071f
Commit
4199071f
authored
2 years ago
by
bfsc19
Browse files
Options
Downloads
Patches
Plain Diff
janelinhas
parent
1e19f075
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
headers/client.h
+3
-3
3 additions, 3 deletions
headers/client.h
headers/conexao.h
+5
-5
5 additions, 5 deletions
headers/conexao.h
headers/server.h
+28
-13
28 additions, 13 deletions
headers/server.h
received/1
+0
-0
0 additions, 0 deletions
received/1
received/1118
+0
-0
0 additions, 0 deletions
received/1118
with
36 additions
and
21 deletions
headers/client.h
+
3
−
3
View file @
4199071f
...
...
@@ -102,7 +102,7 @@ frame *client::send_frame_socket(frame *f) {
}
cout
<<
"
\t
ACK recebido:
\n
"
;
response
->
imprime
(
HEX
);
response
->
imprime
(
DEC
);
return
response
;
}
...
...
@@ -161,7 +161,7 @@ int client::send_frames(vector<frame *> frames) {
janela
.
push
(
frameCounter
);
cout
<<
"
\t
Enviando frame
\n
"
;
frames
[
iniJanela
]
->
imprime
(
HEX
);
frames
[
iniJanela
]
->
imprime
(
DEC
);
if
(
socket
->
send_frame
(
frames
[
iniJanela
+
frameCounter
])
==
-
1
)
{
cout
<<
"Falha ao enviar o frame
\n
"
;
...
...
@@ -319,10 +319,10 @@ void client::send_text(string message) {
vector
<
frame
*>
client
::
create_frames_midia
(
vector
<
char
>
vectorName
)
{
vector
<
frame
*>
framesToSend
;
vector
<
frame
*>
framesAux
;
// Cria um vetor com o tamanho do arquivo
vector
<
char
>
vectorTam
;
string
fileName
=
string
(
vectorName
.
begin
(),
vectorName
.
end
());
cout
<<
"Nome do arquivo- create frames midia: "
<<
fileName
<<
endl
;
string
fileSize
=
calc_file_size
(
fileName
);
if
(
fileSize
.
empty
())
{
return
vector
<
frame
*>
();
}
vectorTam
.
insert
(
vectorTam
.
begin
(),
fileSize
.
begin
(),
fileSize
.
end
());
...
...
This diff is collapsed.
Click to expand it.
headers/conexao.h
+
5
−
5
View file @
4199071f
...
...
@@ -23,13 +23,13 @@
#include
"frame.h"
using
namespace
std
;
#define NUM_RETRIES
1
0
#define NUM_RETRIES
5
0
#define TAM_JANELA 2
class
conexao
{
private:
// ------ Dados ------ //
int
timeoutMillis
=
500
;
// Tempo que fica tentando ler
int
sequence
=
-
1
;
// sequencia do último frame recebido
int
local
,
target
;
// local and target ip address
...
...
@@ -43,20 +43,20 @@ private:
int
device
;
struct
sockaddr_ll
endereco
;
// endereco do socket
vector
<
int
>
timeoutValues
=
{
1
,
2
,
4
,
8
,
16
,
32
,
64
,
128
,
256
,
512
};
// ----- Funçoes ------ //
int
add_escapes
(
char
*
f
,
char
*
out
);
int
remove_escapes
(
char
*
f
,
char
*
out
);
int
ConexaoRawSocket
(
char
*
device
);
long
long
timestamp
();
void
close_connection
();
// fecha a conexao
public:
int
timeoutMillis
=
500
;
// Tempo que fica tentando ler
// ------ Construtor ------ //
conexao
(
char
*
deviceIP
);
frame
*
receive_frame
();
// recebe um pacote
int
send_frame
(
frame
*
f
);
// envia um pacote
long
long
timestamp
();
int
get_socket
()
{
return
device
;
};
};
...
...
This diff is collapsed.
Click to expand it.
headers/server.h
+
28
−
13
View file @
4199071f
...
...
@@ -146,7 +146,7 @@ int server::send_nack(frame *fReceive) {
bool
server
::
verify_seq
(
int
seq
,
int
lastSeq
)
{
if
(
seq
==
0
)
{
if
(
lastSeq
!=
1
5
)
{
return
false
;
}
if
(
lastSeq
!=
TAM_JANELA
-
1
)
{
return
false
;
}
return
true
;
}
...
...
@@ -296,16 +296,23 @@ string server::create_file_destination(string fileName)
}
ofstream
server
::
create_file
(
string
fileName
)
{
cout
<<
"Criando arquivo
\n
"
;
cout
<<
"Nome do arquivo: "
<<
fileName
<<
"
\n
"
;
// long long start = socket->timestamp();
// struct timeval timeout = {.tv_sec = 0, .tv_usec = socket->timeoutMillis * 1000};
string
fileDestination
=
create_file_destination
(
fileName
);
cout
<<
BOLDWHITE
<<
"Criando arquivo "
<<
BOLDYELLOW
<<
fileDestination
<<
BOLDWHITE
<<
". Digite novo nome ou enter para continuar: "
<<
RESET
;
//
cout << BOLDWHITE << "Criando arquivo " << BOLDYELLOW << fileDestination
//
<< BOLDWHITE << ". Digite novo nome ou enter para continuar: " << RESET;
string
newDestination
=
""
;
getline
(
cin
,
newDestination
);
if
(
!
newDestination
.
empty
()
&&
newDestination
!=
"
\n
"
)
{
fileDestination
=
newDestination
;
}
// string newDestination = "";
// do {
// getline(cin, newDestination);
// } while (socket->timestamp() - start <= socket->timeoutMillis);
// if (!newDestination.empty() && newDestination != "\n") {
// fileDestination = newDestination;
// }
cout
<<
YELLOW
<<
"
\t
--Criando arquivo: "
<<
fileDestination
<<
"--
\n
"
<<
RESET
;
...
...
@@ -316,7 +323,9 @@ ofstream server::create_file(string fileName) {
}
int
server
::
receive_midia
(
frame
*
f
)
{
cout
<<
"Recebendo midia:
\n
"
<<
"Seq: "
<<
int
(
f
->
get_seq
())
<<
"
\n
"
<<
"Dado: "
<<
f
->
get_dado
()
<<
"
\n
"
;
ofstream
file
;
// Escreve o dado no arquivo
...
...
@@ -332,6 +341,7 @@ int server::receive_midia(frame *f) {
cout
<<
"Recebendo tamanho do arquivo
\n
"
;
if
(
!
create_received_dir
())
{
return
0
;
}
if
(
!
receive_file_size
(
f
))
{
return
0
;
}
return
1
;
}
// Segundo frame de midia
...
...
@@ -395,6 +405,7 @@ queue<frame *> server::receive_frames_window(int lastSeq)
{
queue
<
frame
*>
frames_queue
;
frame
*
f
;
int
midia_cnt
=
0
;
int
retries
=
0
;
do
{
...
...
@@ -420,6 +431,7 @@ queue<frame *> server::receive_frames_window(int lastSeq)
frames_queue
.
push
(
f
);
lastSeq
=
0
;
retries
=
0
;
midia_cnt
++
;
continue
;
}
...
...
@@ -428,12 +440,13 @@ queue<frame *> server::receive_frames_window(int lastSeq)
if
(
tipo
==
MIDIA
&&
tipoReceivingFrames
==
MIDIA
)
{
// Ignora se for um frame do tipo midia que nao e o segundo da sequencia
if
(
lastSeq
!=
0
||
(
TAM_JANELA
>
1
&&
f
->
get_seq
()
!
=
1
))
{
continue
;
}
if
(
!
(
midia_cnt
!=
1
&&
TAM_JANELA
=
=
1
)
)
{
continue
;
}
// Se for o segundo frame do tipo midia, muda o tipo esperado
tipoReceivingFrames
=
DADOS
;
frames_queue
.
push
(
f
);
lastSeq
=
1
;
midia_cnt
++
;
lastSeq
=
f
->
get_seq
();
retries
=
0
;
continue
;
}
...
...
@@ -469,6 +482,7 @@ void server::start_receveing_message() {
int
continueTransmission
=
1
;
int
lastSeq
=
-
1
;
int
tipo_data
=
-
1
;
int
midia_cnt
=
0
;
vector
<
char
>
data
;
queue
<
frame
*>
client_answer
;
...
...
@@ -497,7 +511,7 @@ void server::start_receveing_message() {
}
cout
<<
"Frame recebido:
\n
"
;
f
->
imprime
(
HEX
);
f
->
imprime
(
DEC
);
cout
<<
"
\n
"
;
int
tipo
=
f
->
get_tipo
();
...
...
@@ -518,9 +532,10 @@ void server::start_receveing_message() {
break
;
case
MIDIA
:
if
(
TAM_JANELA
==
1
&&
midia_cnt
==
1
)
{
f
->
set_seq
(
1
);
}
if
(
!
receive_midia
(
f
)
)
{
return
;
}
lastSeq
=
f
->
get_seq
();
tipo_data
=
next_tipo_midia
(
f
);
midia_cnt
++
;
break
;
case
DADOS
:
...
...
This diff is collapsed.
Click to expand it.
received/
texto.txt
→
received/
1
+
0
−
0
View file @
4199071f
File moved
This diff is collapsed.
Click to expand it.
received/1118
0 → 100644
+
0
−
0
View file @
4199071f
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