Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
c08579f7
Commit
c08579f7
authored
Dec 7, 2015
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Put working on client
Also updated test.sh
parent
c7bd8a22
Branches
Branches containing commit
No related tags found
1 merge request
!1
Lento
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Protocol.cpp
+22
-53
22 additions, 53 deletions
Protocol.cpp
client.cpp
+6
-5
6 additions, 5 deletions
client.cpp
test.sh
+1
-1
1 addition, 1 deletion
test.sh
with
29 additions
and
59 deletions
Protocol.cpp
+
22
−
53
View file @
c08579f7
...
@@ -116,14 +116,19 @@ int Protocol::recvMessage(int sockt){
...
@@ -116,14 +116,19 @@ int Protocol::recvMessage(int sockt){
void
Protocol
::
transmit
(
int
sockt
,
int
window
){
void
Protocol
::
transmit
(
int
sockt
,
int
window
){
int
status
;
int
status
;
vector
<
FrameItem
>
frame
;
vector
<
FrameItem
>
frame
;
int
lastFramed
=
0
;
int
lastFramed
=
-
1
;
setData
(
vector
<
BYTE
>
(
1
,
0
),
ENDTX
);
int
messagesLeft
=
messages
.
size
();
int
messagesLeft
=
messages
.
size
();
Protocol
response
;
Protocol
response
;
while
(
messagesLeft
>
0
){
while
(
messagesLeft
>
0
){
cout
<<
"Restantes: "
<<
messagesLeft
<<
endl
;
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
// FIXME: this will probably brake with many messages
if
(
frame
.
size
()
<
window
&&
frame
.
size
()
<
messagesLeft
)
{
FrameItem
fi
=
{.
index
=
lastFramed
++
,
.
sent
=
false
};
cout
<<
"frame size: "
<<
frame
.
size
()
<<
endl
;
FrameItem
fi
=
{.
index
=
++
lastFramed
,
.
sent
=
false
};
cout
<<
"lastFramed: "
<<
fi
.
index
<<
endl
;
frame
.
push_back
(
fi
);
frame
.
push_back
(
fi
);
}
if
(
!
frame
[
j
].
sent
){
if
(
!
frame
[
j
].
sent
){
sendMessage
(
sockt
,
frame
[
j
].
index
);
sendMessage
(
sockt
,
frame
[
j
].
index
);
frame
[
j
].
sent
=
true
;
frame
[
j
].
sent
=
true
;
...
@@ -135,33 +140,26 @@ void Protocol::transmit(int sockt, int window){
...
@@ -135,33 +140,26 @@ void Protocol::transmit(int sockt, int window){
if
(
status
==
NACK
){
if
(
status
==
NACK
){
printf
(
"nstoi %i
\n
"
,
response
.
getMessages
().
back
().
getDataAsString
()[
0
]);
printf
(
"nstoi %i
\n
"
,
response
.
getMessages
().
back
().
getDataAsString
()[
0
]);
int
nackIndex
=
response
.
getMessages
().
back
().
getDataAsString
()[
0
];
int
nackIndex
=
response
.
getMessages
().
back
().
getDataAsString
()[
0
];
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
window
;)
{
if
(
frame
[
j
].
index
<
nackIndex
)
{
if
(
frame
[
j
].
index
<
nackIndex
)
{
frame
.
erase
(
frame
.
begin
()
+
j
);
frame
.
erase
(
frame
.
begin
()
+
j
);
--
messagesLeft
;
--
messagesLeft
;
}
else
if
(
frame
[
j
].
index
==
nackIndex
)
{
}
else
if
(
frame
[
j
].
index
==
nackIndex
)
{
frame
[
j
].
sent
=
false
;
frame
[
j
].
sent
=
false
;
}
}
else
++
j
;
}
}
response
.
reset
();
response
.
reset
();
}
else
if
(
status
==
ACK
){
}
else
if
(
status
==
ACK
){
printf
(
"astoi %i
\n
"
,
response
.
getMessages
().
back
().
getDataAsString
()[
0
]);
printf
(
"astoi %i
\n
"
,
response
.
getMessages
().
back
().
getDataAsString
()[
0
]);
int
ackIndex
=
response
.
getMessages
().
back
().
getDataAsString
()[
0
];
int
ackIndex
=
response
.
getMessages
().
back
().
getDataAsString
()[
0
];
for
(
int
j
=
0
;
j
<
window
;
++
j
)
{
for
(
int
j
=
0
;
j
<
frame
.
size
();
)
{
if
(
frame
[
j
].
index
<=
ackIndex
)
{
if
(
frame
[
j
].
index
<=
ackIndex
)
{
frame
.
erase
(
frame
.
begin
()
+
j
);
frame
.
erase
(
frame
.
begin
()
+
j
);
--
messagesLeft
;
--
messagesLeft
;
}
}
else
++
j
;
}
}
response
.
reset
();
response
.
reset
();
// }else if(status == OK) {
// frame.erase(frame.begin());
// --messagesLeft;
// } else if(status == OUTPUT || status == ERROR) {
// frame.erase(frame.begin());
// --messagesLeft;
// cout << "Remoto:\n" << ((status == ERROR)?"ERROR: ":"") << getDataAsString() << endl;
}
else
{
}
else
{
//TODO: treat error
//TODO: treat error
}
}
...
@@ -190,54 +188,25 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){
...
@@ -190,54 +188,25 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){
continue
;
continue
;
}
else
if
(
status
==
type
)
{
}
else
if
(
status
==
type
)
{
if
(
!
messages
.
empty
()
&&
(
messages
.
back
().
sequence
.
to_ulong
()
!=
nextSequence
)){
if
(
!
messages
.
empty
()
&&
(
messages
.
back
().
sequence
.
to_ulong
()
!=
nextSequence
)){
messages
.
pop_back
();
response
.
reset
();
response
.
reset
();
vector
<
BYTE
>
val
(
1
,(
BYTE
)
nextSequence
);
vector
<
BYTE
>
val
(
1
,(
BYTE
)
nextSequence
);
response
.
setData
(
val
,
NACK
);
response
.
setData
(
val
,
NACK
);
shouldSend
=
true
;
shouldSend
=
true
;
}
else
if
(
window
==
WAIT_STOP
||
((
nextSequence
%
SLIDING
)
==
0
))
{
}
else
{
if
(
window
==
WAIT_STOP
||
((
nextSequence
%
SLIDING
)
==
0
))
{
response
.
reset
();
response
.
reset
();
vector
<
BYTE
>
val
(
1
,(
BYTE
)
messages
.
back
().
sequence
.
to_ulong
());
vector
<
BYTE
>
val
(
1
,(
BYTE
)
messages
.
back
().
sequence
.
to_ulong
());
response
.
setData
(
val
,
ACK
);
response
.
setData
(
val
,
ACK
);
nextSequence
=
(
messages
.
back
().
sequence
.
to_ulong
()
+
1
)
%
(
MAXSIZE
+
1
);
shouldSend
=
true
;
shouldSend
=
true
;
}
else
{
}
//TODO: treat something?
nextSequence
=
(
messages
.
back
().
sequence
.
to_ulong
()
+
1
)
%
(
MAXSIZE
+
1
);
}
}
}
else
if
(
status
==
ERROR
)
{
}
else
if
(
status
==
ERROR
)
{
string
str
(
messages
.
back
().
data
.
begin
(),
messages
.
back
().
data
.
end
());
string
str
(
messages
.
back
().
data
.
begin
(),
messages
.
back
().
data
.
end
());
cout
<<
"ERROR: "
<<
getDataAsString
()
<<
endl
;
cout
<<
"ERROR: "
<<
getDataAsString
()
<<
endl
;
return
-
1
;
return
-
1
;
}
}
// else if(messages.back().sequence.to_ulong() != nextSequence){
// response.reset();
// vector<BYTE> val(1,(BYTE)nextSequence);
// response.setData(val, NACK);
// shouldSend = true;
// }
// else if(status == OUTPUT) {
// cout << messages.back().getDataAsString();
//
// frame.push_back(messages.size());
//
// response.reset();
// vector<BYTE> val(1,(BYTE)messages.back().sequence.to_ulong());
// response.setData(val, ACK);
// nextSequence = (messages.back().sequence.to_ulong()+1)%(MAXSIZE+1);
// }else if(status == ERROR){
// string str(messages.back().data.begin(), messages.back().data.end());
// cout << "ERROR: " << getDataAsString() << endl;
// break;
// }else if(status == INCONSISTENT){
// response.reset();
// vector<BYTE> val(1,(BYTE)nextSequence);
// response.setData(val, NACK);
// shouldSend = true;
// }else{
// //TODO: treat error
// break;
// }
// shouldSend = shouldSend || (frame.size()%window == 0);
}
while
(
status
!=
end
);
}
while
(
status
!=
end
);
return
0
;
return
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
client.cpp
+
6
−
5
View file @
c08579f7
...
@@ -44,14 +44,14 @@ int main(){
...
@@ -44,14 +44,14 @@ int main(){
}
else
if
(
command
==
"put"
){
}
else
if
(
command
==
"put"
){
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
if
(
fexists
(
args
))
{
if
(
fexists
(
args
))
{
in
t
size
=
filesize
(
args
);
str
in
g
size
=
to_string
(
filesize
(
args
)
)
;
cout
<<
"ARQUIVO: "
<<
args
<<
"|"
<<
size
<<
endl
;
cout
<<
"ARQUIVO: "
<<
args
<<
"|"
<<
size
<<
endl
;
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
PUT
);
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
PUT
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
int
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
int
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
if
(
error
<
0
)
continue
;
if
(
error
<
0
)
continue
;
sendProtocol
.
reset
();
sendProtocol
.
reset
();
sendProtocol
.
setData
(
vector
<
BYTE
>
(
size
),
SIZE
);
sendProtocol
.
setData
(
vector
<
BYTE
>
(
size
.
begin
(),
size
.
end
()
),
SIZE
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
error
=
receiveProtocol
.
receive
(
sockt
,
OK
,
WAIT_STOP
,
false
);
if
(
error
<
0
)
continue
;
if
(
error
<
0
)
continue
;
...
@@ -59,7 +59,8 @@ int main(){
...
@@ -59,7 +59,8 @@ int main(){
ifstream
putFile
(
args
);
ifstream
putFile
(
args
);
stringstream
buffer
;
stringstream
buffer
;
buffer
<<
putFile
.
rdbuf
();
buffer
<<
putFile
.
rdbuf
();
sendProtocol
.
setData
(
vector
<
BYTE
>
(
buffer
.
str
().
begin
(),
buffer
.
str
().
begin
()),
PUT
);
string
data
=
buffer
.
str
();
sendProtocol
.
setData
(
vector
<
BYTE
>
(
data
.
begin
(),
data
.
end
()),
DATA
);
sendProtocol
.
transmit
(
sockt
,
SLIDING
);
sendProtocol
.
transmit
(
sockt
,
SLIDING
);
}
else
{
}
else
{
cout
<<
"ERROR: arquivo não existe
\n
"
;
cout
<<
"ERROR: arquivo não existe
\n
"
;
...
@@ -68,9 +69,9 @@ int main(){
...
@@ -68,9 +69,9 @@ int main(){
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
GET
);
sendProtocol
.
setData
(
vector
<
BYTE
>
(
args
.
begin
(),
args
.
end
()),
GET
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
sendProtocol
.
sendMessage
(
sockt
,
0
);
int
error
=
receiveProtocol
.
receive
(
)
sockt
,
SIZE
,
WAIT_STOP
,
false
;
int
error
=
receiveProtocol
.
receive
(
sockt
,
SIZE
,
WAIT_STOP
,
false
)
;
if
(
error
<
0
)
continue
;
if
(
error
<
0
)
continue
;
int
fileSize
=
(
int
)
receiveProtocol
.
getDataAsString
();
//
int fileSize = (int) receiveProtocol.getDataAsString()
[0]
;
}
else
if
(
command
==
"help"
){
}
else
if
(
command
==
"help"
){
printCommandsList
();
printCommandsList
();
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
test.sh
+
1
−
1
View file @
c08579f7
...
@@ -7,7 +7,7 @@ done
...
@@ -7,7 +7,7 @@ done
for
i
in
{
1..100
}
for
i
in
{
1..100
}
do
do
echo
-e
"
$i
\n
"
>>
10.txt
echo
-e
"
$i
\n
"
>>
10
0
.txt
done
done
for
i
in
{
1..1000
}
;
for
i
in
{
1..1000
}
;
...
...
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
sign in
to comment