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

@@ -121,6 +121,14 @@ func (network *Network) Listen() {
continue
}
// handle lite packets before regular ones
if isLite, err := network.networkGroup.LiteRouter.IsPacketLite(buffer[:length]); isLite && err != nil {
continue
} else if isLite {
network.networkGroup.litePacketsIncoming <- networkWire{network: network, sender: sender, raw: buffer[:length], receiverPublicKey: network.backend.peerPublicKey, unicast: true}
continue
}
if length < protocol.PacketLengthMin {
// Discard packets that do not meet the minimum length.
continue
@@ -404,3 +412,23 @@ func (backend *Backend) FeatureSupport() (feature byte) {
}
return feature
}
// Handles incoming lite packets. It will decrypt them as needed.
func (nets *Networks) packetWorkerLite() {
for wire := range nets.litePacketsIncoming {
packet, err := nets.LiteRouter.PacketLiteDecode(wire.raw)
if err != nil {
continue
}
// Handle the received data. Note this is called in the same Go routine.
// The underlying data receiver must not stall.
if v, ok := packet.Session.Data.(*virtualPacketConn); ok {
// update stats TODO
//atomic.AddUint64(&packet.Session.Data.(*virtualPacketConn).peer.StatsPacketReceived, 1)
//connection.LastPacketIn = time.Now()
v.receiveData(packet.Payload)
}
}
}