Skip to content

Fabiokleis/fserver-udp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fserver-udp

udp file server, transfer files over udp socket.

this project uses protobuf to encode and decode messages: https://protobuf.dev/ see golang implementation in https://pkg.go.dev/google.golang.org/protobuf

obs: acho q protobuf para encodar e decodar cada pacote nao foi uma boa ideia

apresentação yt: https://www.youtube.com/watch?v=9T7bCWwy4N0

Protocol

The protocol are divided in two sections, first byte is reserved to the packet identification byte, next bytes are reserved for data. Check protobuf file to known which type data are encoded.

  Server packet: [Header|Protobuf...] 1024 bytes
  header byte types:
  1 -> RESPONSE     // file chunk
  2 -> CONFIRMATION // result
  ...1024 bytes -> Protobuf encoded data

  Client packet: [Header|Protobuf...] 256 bytes
  header byte types:
  0 -> REQUEST      // file
  2 -> CONFIRMATION // result
  ...256 bytes -> Protobuf encoded data

  file name length should be less or equal 200 bytes

Client

in order to create a client implementation you must send a request message to server containing the file name, then start receiving file chunks from server and send confirmation for each packet, server will wait to send next packets until a confirmation packet, if a packet was losted, client must send a missing packet confirmation and then server will return sending next packets. After all packets was received, now you can reconstruct file and generate sha256 checksum to validate it, if validation succeed you must send a confirmation of the checksum to the server. All needed messages types are described in protobuf file, so every programming languague that has protocol buffers compiler could be a client.

Communication flow

flux

Docker

to build and test easilly just run:

docker build -t fserver-udp .
docker container run -d -p 2224:2224 --name fserver fserver-udp

Build

setup golang protobuf compiler by running:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

generate golang protobuf bindings by running:

./proto.sh # chmod +x proto.sh

Run

start udp server by running:

go run ./cmd/fserver-udp/main.go