diff --git a/.gitignore b/.gitignore index b24468a..98dd696 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ FTU FTU.exe +ftu +ftu.exe release/ downloads/ \ No newline at end of file diff --git a/README.md b/README.md index 8fe083b..c4b1a99 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,20 @@ --- -## What is that ? -This application is like an FTP server, but overcomplicated and probably overengineered monstrosity. (basically a file server, but P2P). +## ● What is that ? +A P2P file sharing program, but overcomplicated and probably an overengineered one. ---- - -## Why ? +## ● Why ? Learning ---- -## How does this work ? +## ● How does this work ? In order to transfer one file on one computer to another - they need to establish a connection. -In order to establish a connection - there needs to be a 1) sender (server) (the owner of the file), waiting for connections, and a 2) receiver (client), who will try to connect to a sender (server). If the requirements are met - a client will connect to a server and the packet exchange will begin. +In order to establish a connection - there needs to be a 1) sender (server) (the owner of the file), waiting for connections, and a 2) receiver (client), who will try to connect to a sender (server). If the requirements are met - client will connect to server and the packet exchange will begin. -The server and the client needs to communicate with packets according to certain rules, given by a [protocol](https://github.com/Unbewohnte/FTU/tree/main/protocol). +The server and the client needs to communicate with packets according to certain rules, given by a [protocol](https://github.com/Unbewohnte/ftu/tree/main/protocol). The packet has its header and body. They are divided into several groups of use by headers, this way we can specify what kind of data is stored inside packet`s body and react accordingly. @@ -28,62 +25,65 @@ Thus, with a connection and a way of communication, the sender will send some pa --- -## Known issues|problems|lack of features|reasons why it`s bad -- **VERY** slow; somewhat FIXED - [x], now **faster** than before -- **VERY** expensive on resources; somewhat FIXED - [x], no more **json manipulations**, only **raw bytes**`s wizardry ! -- If `MAXFILEDATASIZE` is bigger than appr. 1024 - the packets on the other end will not be unmarshalled due to error ??; FIXED - [x], unnecessary, wrong, deprecated, **destroyed !!!** -- Lack of proper error-handling; somewhat FIXED - [x] -- Lack of information about the process of transferring; FIXED - [x] -- No way to verify if the transferred file is not corrupted; FIXED via checksum- [x] -- No encryption; FIXED via AES encryption of packets` body - [x] -- Messy and hard to follow code && file structure; FIXED? - [x] -- No tests; FIXED - [x]; Not every packet has its tests, but they are present +## ● Known issues|problems|lack of features|reasons why it`s bad +- ~~**VERY** slow~~ +- ~~**VERY**~~ expensive on resources +- ~~Lack of proper error-handling~~ +- ~~Lack of information about the process of transferring~~ +- ~~No way to verify if the transferred file is not corrupted~~ +- ~~No encryption~~ +- ~~No tests~~ +- ~~No interrupt signal handling~~ -## Good points +## ● Good points - It works. --- -## Installation +## ● Installation -### From release (Pre-compiled) -- Proceed to [releases page](https://github.com/Unbewohnte/FTU/releases) +### ● From release (Pre-compiled) +- Proceed to [releases page](https://github.com/Unbewohnte/ftu/releases) - Choose a version/architecture you have and download an archive - Unpack an archive -### From source (Compile it yourself) (You need [Go](https://golang.org/dl/) and [git](https://git-scm.com/) to be installed on your machine) -- `git clone https://github.com/Unbewohnte/FTU.git` +### ● From source (Compile it yourself) (You need [Go](https://golang.org/dl/) and [git](https://git-scm.com/) to be installed on your machine) +- `git clone https://github.com/Unbewohnte/ftu.git` - `cd` into the folder -- `go build` - to simply compile for your OS/ARCHITECTURE || `CGO_ENABLED=0 GOOS=os_here GOARCH=arch_here go build` - to cross-compile a static executable for the OS/ARCHITECTURE of your choice (`go tool dist list` - to view the available ones) +- `go build` - to simply compile for your OS/ARCHITECTURE || `CGO_ENABLED=0 go build` - to compile a static executable + +### ● Final steps (optional) +- `cd` into folder if you`re not there already +- `chmod +x install.sh` - make installation script executable +- `sudo ./install.sh` -### After installation -- You probably want to put the executable in some folder and in order not to use it directly from there all the time - add it to the **$PATH** variable +Now you have ftu installed ! --- -## Usage -`./FTU [FLAGS_HERE]` or `FTU [FLAGS_HERE]` +## ● Usage +`ftu [FLAGS_HERE]` -### Flags -`./FTU --help` - to get all flags` description +### ● Flags +`ftu --help` - to get all flags` description - `-port` (int) - specifies a working port (if sending - listens on this port, else - tries to connect to this port); - `-addr` (string) - specifies an address to connect to; - `-sharefile` (string) - specifies path to a file you want to share, if given a valid path - sender will offer to download this file to receiver; - `-downloadto` (string) - specifies path to a folder where the receiver wants to store downloaded file; -### Examples +### ● Examples -- `./FTU -sharefile="/home/some_path_here/FILETOSHARE.zip"` - creates a server that will share `FILETOSHARE.zip` on port `8080` -- `./FTU -sharefile="/home/some_path_here/FILETOSHARE.zip" - port=727` - same as before, but on port `727` -- `./FTU -downloadto="/home/some_path_here/Downloads/" -addr="192.168.1.104"` - creates a client (receiver) that will try to connect to `192.168.1.104` (local device) on port `8080` and if successful - downloads a file to given path -- `./FTU -downloadto="/home/some_path_here/Downloads/" -addr=145.125.53.212 -port=8888` - same as before, but will try to connect to `145.125.53.212` on port `8888` +- `ftu -sharefile="/home/some_path_here/FILETOSHARE.zip"` - creates a server that will share `FILETOSHARE.zip` on port `8080` +- `ftu -sharefile="/home/some_path_here/FILETOSHARE.zip" - port=727` - same as before, but on port `727` +- `ftu -downloadto="/home/some_path_here/Downloads/" -addr="192.168.1.104"` - creates a client (receiver) that will try to connect to `192.168.1.104` (local device) on port `8080` and if successful - downloads a file to given path +- `ftu -downloadto="/home/some_path_here/Downloads/" -addr=145.125.53.212 -port=8888` - same as before, but will try to connect to `145.125.53.212` on port `8888` --- -## Testing +## ● Testing -In FTU directory: +In 'ftu' directory: - `go test ./...` - to test everything - `go test -v ./...` - to test everything, with additional information @@ -91,16 +91,16 @@ In FTU directory: --- -## IMPORTANT NOTE +## ● IMPORTANT NOTE This is NOT intended to be a serious application. I'm learning and this is a product of my curiosity. If you're a beginner too, please don't try to find something useful in my code, I am not an expert. -Also, this utility only works if both the server and the client have a port-forwarding|virtual server enabled and configured. Fortunatelly, locally it works without any port-forwarding|virtual servers. +Also, this utility only works if the server side has a port-forwarding|virtual server enabled and configured. Fortunatelly, locally it works without any port-forwarding|virtual servers. --- -## Inspired by [croc](https://github.com/schollz/croc) +## ● Inspired by [croc](https://github.com/schollz/croc) --- -## License +## ● License MIT \ No newline at end of file diff --git a/go.mod b/go.mod index b22f201..21c6671 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/Unbewohnte/FTU +module github.com/Unbewohnte/ftu -go 1.16 +go 1.17 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..6eb0277 --- /dev/null +++ b/install.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +EXECUTABLE_NAME=ftu +DESTDIR=/usr/bin/ + +# if ftu is in the same directory - copy it to $DESTDIR +if [ -e $EXECUTABLE_NAME ] +then + cp $EXECUTABLE_NAME $DESTDIR +else + echo "No '${EXECUTABLE_NAME}' in current directory !" +fi \ No newline at end of file diff --git a/main.go b/main.go index 1f62279..9fd8384 100644 --- a/main.go +++ b/main.go @@ -6,8 +6,8 @@ import ( "os" "strings" - "github.com/Unbewohnte/FTU/receiver" - "github.com/Unbewohnte/FTU/sender" + "github.com/Unbewohnte/ftu/receiver" + "github.com/Unbewohnte/ftu/sender" ) // flags diff --git a/protocol/packet.go b/protocol/packet.go index e066e7d..47f8fa9 100644 --- a/protocol/packet.go +++ b/protocol/packet.go @@ -13,7 +13,7 @@ import ( "net" "strconv" - "github.com/Unbewohnte/FTU/encryption" + "github.com/Unbewohnte/ftu/encryption" ) // Internal representation of packet before|after the transportation diff --git a/receiver/file.go b/receiver/file.go index 5c13330..b1db6c2 100644 --- a/receiver/file.go +++ b/receiver/file.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/Unbewohnte/FTU/checksum" + "github.com/Unbewohnte/ftu/checksum" ) // Receiver`s file struct. Used internally by receiver diff --git a/receiver/receiver.go b/receiver/receiver.go index 86285d6..510feae 100644 --- a/receiver/receiver.go +++ b/receiver/receiver.go @@ -10,9 +10,9 @@ import ( "strings" "time" - "github.com/Unbewohnte/FTU/checksum" - "github.com/Unbewohnte/FTU/encryption" - "github.com/Unbewohnte/FTU/protocol" + "github.com/Unbewohnte/ftu/checksum" + "github.com/Unbewohnte/ftu/encryption" + "github.com/Unbewohnte/ftu/protocol" ) // Representation of a receiver @@ -39,7 +39,7 @@ func NewReceiver(downloadsFolder string) *Receiver { panic("Downloads folder is not a directory") } - incomingPacketsChan := make(chan protocol.Packet, 5000) + incomingPacketsChan := make(chan protocol.Packet, 100) fmt.Println("Created a new receiver") return &Receiver{ diff --git a/sender/file.go b/sender/file.go index 17a6d29..f722b20 100644 --- a/sender/file.go +++ b/sender/file.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/Unbewohnte/FTU/checksum" + "github.com/Unbewohnte/ftu/checksum" ) // Struct that represents the served file. Used internally in the sender diff --git a/sender/sender.go b/sender/sender.go index 2f9f1ca..6c0e0e6 100644 --- a/sender/sender.go +++ b/sender/sender.go @@ -8,9 +8,9 @@ import ( "strconv" "time" - "github.com/Unbewohnte/FTU/checksum" - "github.com/Unbewohnte/FTU/encryption" - "github.com/Unbewohnte/FTU/protocol" + "github.com/Unbewohnte/ftu/checksum" + "github.com/Unbewohnte/ftu/encryption" + "github.com/Unbewohnte/ftu/protocol" ) // The main sender struct @@ -38,7 +38,7 @@ func NewSender(port int, filepath string) *Sender { if err != nil { panic(err) } - incomingPacketsChan := make(chan protocol.Packet, 5000) + incomingPacketsChan := make(chan protocol.Packet, 100) remoteIP, err := GetRemoteIP() if err != nil {