Lite Packet algorithm for data transfer. It bypasses the CPU expensive Peernet Protocol packet encoding (which uses public key signing).

This commit is contained in:
Kleissner
2022-01-17 03:48:40 +01:00
parent 6a5312d834
commit f305e5b158
14 changed files with 403 additions and 64 deletions

View File

@@ -11,6 +11,8 @@ package core
import (
"sync"
"github.com/google/uuid"
)
// virtualPacketConn is a virtual connection.
@@ -18,11 +20,14 @@ type virtualPacketConn struct {
peer *PeerInfo
// function to send data to the remote peer
sendData func(data []byte, sequenceNumber uint32)
sendData func(data []byte, sequenceNumber uint32, transferID uuid.UUID)
// Sequence number from the first outgoing or incoming packet.
sequenceNumber uint32
// Transfer ID represents a session ID valid only for the duration of the transfer.
transferID uuid.UUID
// data channel
incomingData chan []byte
outgoingData chan []byte
@@ -35,7 +40,7 @@ type virtualPacketConn struct {
}
// newVirtualPacketConn creates a new virtual connection (both incomign and outgoing).
func newVirtualPacketConn(peer *PeerInfo, sendData func(data []byte, sequenceNumber uint32)) (v *virtualPacketConn) {
func newVirtualPacketConn(peer *PeerInfo, sendData func(data []byte, sequenceNumber uint32, transferID uuid.UUID)) (v *virtualPacketConn) {
v = &virtualPacketConn{
peer: peer,
sendData: sendData,
@@ -54,7 +59,7 @@ func (v *virtualPacketConn) writeForward() {
for {
select {
case data := <-v.outgoingData:
v.sendData(data, v.sequenceNumber)
v.sendData(data, v.sequenceNumber, v.transferID)
case <-v.terminationSignal:
return