Browse Source

[node] bugfixes? [make] cross compilation automatisation

main
Unbewohnte 3 years ago
parent
commit
1a302cb9fb
  1. 5
      Makefile
  2. 35
      src/node/node.go
  3. 10
      src/protocol/headers.go

5
Makefile

@ -7,6 +7,11 @@ INSTALLATION_DIR := /usr/local/bin/
all:
cd $(SRC_DIR) && go build && mv $(EXE_NAME) ..
cross:
cd $(SRC_DIR) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ftu_linux_amd64 && mv ftu_linux_amd64 ..
cd $(SRC_DIR) && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ftu_darwin_amd64 && mv ftu_darwin_amd64 ..
cd $(SRC_DIR) && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ftu_windows_amd64.exe && mv ftu_windows_amd64.exe ..
race:
cd $(SRC_DIR) && go build -race && mv $(EXE_NAME) ..

35
src/node/node.go

@ -354,8 +354,12 @@ func (node *Node) Start() {
if err != nil {
panic(err)
}
}
filesInfoDonePacket := protocol.Packet{
Header: protocol.HeaderFilesInfoDone,
}
protocol.SendPacket(node.netInfo.Conn, filesInfoDonePacket)
case false:
// send a filepacket of a single file
@ -586,15 +590,6 @@ func (node *Node) Start() {
panic(err)
}
// notify the node that we`re ready to transportation. No need
// for encryption because the body is nil
err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady,
})
if err != nil {
panic(err)
}
} else {
// no
@ -621,7 +616,7 @@ func (node *Node) Start() {
panic(err)
}
if file.RelativeParentPath == "" {
if strings.TrimSpace(file.RelativeParentPath) == "" {
// does not have a parent dir
file.Path = filepath.Join(node.transferInfo.Receiving.DownloadsPath, file.Name)
} else {
@ -641,16 +636,19 @@ func (node *Node) Start() {
// check if it is the exact file
existingFileHandler, err := os.Open(file.Path)
if err != nil {
os.Remove(file.Path)
panic(err)
}
existingFileChecksum, _ := checksum.GetPartialCheckSum(existingFileHandler)
existingFileChecksum, err := checksum.GetPartialCheckSum(existingFileHandler)
if err != nil {
panic(err)
}
if existingFileChecksum == file.Checksum {
// it`s the exact same file. No need to receive it again
// notify the other node
fmt.Printf("Already have \"%s\". Skipping...\n\n", file.Name)
fmt.Printf("| Already have \"%s\". Skipping...\n\n", file.Name)
alreadyHavePacketBodyBuffer := new(bytes.Buffer)
binary.Write(alreadyHavePacketBodyBuffer, binary.BigEndian, file.ID)
@ -660,12 +658,13 @@ func (node *Node) Start() {
Body: alreadyHavePacketBodyBuffer.Bytes(),
}
if node.netInfo.EncryptionKey != nil {
encryptedBody, err := encryption.Encrypt(node.netInfo.EncryptionKey, alreadyHavePacket.Body)
if err != nil {
panic(err)
}
alreadyHavePacket.Body = encryptedBody
}
protocol.SendPacket(node.netInfo.Conn, alreadyHavePacket)
@ -720,6 +719,14 @@ func (node *Node) Start() {
}
}
readyPacket := protocol.Packet{
Header: protocol.HeaderReady,
}
protocol.SendPacket(node.netInfo.Conn, readyPacket)
case protocol.HeaderFilesInfoDone:
// have all information about the files
// notify the other node that this one is ready
err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady,

10
src/protocol/headers.go

@ -55,11 +55,19 @@ const HeaderDone Header = "DONE"
// READY.
// Sent by receiver when it has read and processed the last
// FILEBYTES packet. The sender is not allowed to "spam" FILEBYTES
// FILEBYTES packet or when it has information about all the files and it`s ready to
// receive bytes (FILESINFODONE). The sender is not allowed to "spam" FILEBYTES
// packets without the permission of receiver.
// ie: READY!~
const HeaderReady Header = "READY"
// FILESINFODONE.
// Sent by sender after it`s announced about all the files that are
// going to be sent. It is not allowed to send any file bytes before
// packet with this header was sent.
// ie: FILESINFODONE~
const HeaderFilesInfoDone Header = "FILESINFODONE"
// BYE!.
// Packet with this header can be sent both by receiver and sender.
// It`s used when the sender or the receiver are going to disconnect

Loading…
Cancel
Save