Vous êtes sur la page 1sur 5

Assumptions

It is necessary to know the identifcation (ID) of at least one peer when a new peer
attempts
to join the fle sharing network.
Message Types
All of the packets should start with the header in ig. !" where the frst # $its are
for the
protocol %ersion" the second # $its are for the message type which will $e
e&plained in the
se'uel" and the ID (port) and ID (I() are for the sender.
)e'uest all peers
This message is of type * and is constructed only from the a$o%e mentioned
header.
)ecei%e all peers
This message is of type ! and is constructed from the a$o%e mentioned header
followed $y
the message in ig. +. The count is the num$er of peers in the list of peers" peer
ID (!) is
the peer ID of the frst peer" peer ID (+) is the peer ID of the second peer and so
on.
)e'uest" do you ha%e a fle &,
)e'uest" do you ha%e a fle &,
This message is of type + and is constructed from the mentioned header followed
$y the
message in ig. -" where fle ID is the ID of the fle we are in'uiring a$out.
)ecei%e the response to your fle en'uiry
This message is of type - and is constructed from the mentioned header followed
$y the
message in ig. ." where /reply/ is of type uint-+ t with reply0! if you ha%e the
fle and
reply0* if you do not.
)e'uest list of all fles
This message is of type . and is constructed only from the mentioned header.
)ecei%e list of all fles
This message is of type 1 and is constructed from the mentioned header followed
$y the
message in ig. 1" where count is the num$er of fles in the list of fles" fle ID (!) is
the fle
ID of the frst fle" fle ID (+) is the fle ID of the second fle and so on.
)e'uest $lock & from fle y
This message is of type 2 and is constructed from the mentioned header followed
$y the mes3
sage in ig. 2" where the fle is constructed from consecuti%e $locks num$ered in
ascending
order and starting from *.
4tructure ormats
The following two su$sections e&plain the peer ID structure and the fle ID
structure.
(eer ID
The peer ID is defned $y the structure $elow" where the port and I( is for the
peer.
! struct peerID {
2 uint16_t port;
3 struct in_addr IP;
4 };
ile ID
The fle ID is defned $y the structure $elow" where the peer ID was defned in the
pre%ious
su$section" /si5e fle/ is the si5e of the fle in $ytes" and /name fle/ is the name
of the fle.
! struct fileID {
2 struct peerID ;
3 uint32_t size_file;
4 char [64] nae_file;
! };
6otes
7 or e%ery time a message is sent" a connection is esta$lished" the message is
sent" and
then the connection is closed.
7 8oth the peer ID and the fle ID are structures.
7 The peer ID in the fle ID structure contains the author9s ID.
7 :nly when a peer has a complete fle" it can then include it in it9s list of fles.
;&tension
Message Type #
)e'uest ile
I. This will contain a struct header with the fle id.
Message <
4i5e (= of $ytes)
This includes the 4i5e(= of $ytes of fle)
include in struct header the ile ID and ile Data

Vous aimerez peut-être aussi