Browse Source

[node] bugfixes? [make] cross compilation automatisation

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

5
Makefile

@ -7,6 +7,11 @@ INSTALLATION_DIR := /usr/local/bin/
all: all:
cd $(SRC_DIR) && go build && mv $(EXE_NAME) .. 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: race:
cd $(SRC_DIR) && go build -race && mv $(EXE_NAME) .. cd $(SRC_DIR) && go build -race && mv $(EXE_NAME) ..

43
src/node/node.go

@ -354,8 +354,12 @@ func (node *Node) Start() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
}
filesInfoDonePacket := protocol.Packet{
Header: protocol.HeaderFilesInfoDone,
} }
protocol.SendPacket(node.netInfo.Conn, filesInfoDonePacket)
case false: case false:
// send a filepacket of a single file // send a filepacket of a single file
@ -586,15 +590,6 @@ func (node *Node) Start() {
panic(err) 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 { } else {
// no // no
@ -621,7 +616,7 @@ func (node *Node) Start() {
panic(err) panic(err)
} }
if file.RelativeParentPath == "" { if strings.TrimSpace(file.RelativeParentPath) == "" {
// does not have a parent dir // does not have a parent dir
file.Path = filepath.Join(node.transferInfo.Receiving.DownloadsPath, file.Name) file.Path = filepath.Join(node.transferInfo.Receiving.DownloadsPath, file.Name)
} else { } else {
@ -641,16 +636,19 @@ func (node *Node) Start() {
// check if it is the exact file // check if it is the exact file
existingFileHandler, err := os.Open(file.Path) existingFileHandler, err := os.Open(file.Path)
if err != nil { 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 { if existingFileChecksum == file.Checksum {
// it`s the exact same file. No need to receive it again // it`s the exact same file. No need to receive it again
// notify the other node // 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) alreadyHavePacketBodyBuffer := new(bytes.Buffer)
binary.Write(alreadyHavePacketBodyBuffer, binary.BigEndian, file.ID) binary.Write(alreadyHavePacketBodyBuffer, binary.BigEndian, file.ID)
@ -660,13 +658,14 @@ func (node *Node) Start() {
Body: alreadyHavePacketBodyBuffer.Bytes(), Body: alreadyHavePacketBodyBuffer.Bytes(),
} }
encryptedBody, err := encryption.Encrypt(node.netInfo.EncryptionKey, alreadyHavePacket.Body) if node.netInfo.EncryptionKey != nil {
if err != nil { encryptedBody, err := encryption.Encrypt(node.netInfo.EncryptionKey, alreadyHavePacket.Body)
panic(err) if err != nil {
panic(err)
}
alreadyHavePacket.Body = encryptedBody
} }
alreadyHavePacket.Body = encryptedBody
protocol.SendPacket(node.netInfo.Conn, alreadyHavePacket) protocol.SendPacket(node.netInfo.Conn, alreadyHavePacket)
} else { } else {
@ -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 // notify the other node that this one is ready
err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{ err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady, Header: protocol.HeaderReady,

10
src/protocol/headers.go

@ -55,11 +55,19 @@ const HeaderDone Header = "DONE"
// READY. // READY.
// Sent by receiver when it has read and processed the last // 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. // packets without the permission of receiver.
// ie: READY!~ // ie: READY!~
const HeaderReady Header = "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!. // BYE!.
// Packet with this header can be sent both by receiver and sender. // 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 // It`s used when the sender or the receiver are going to disconnect

Loading…
Cancel
Save