mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-22 07:13:09 +01:00
Fix performance issue(remove redundant copy)
This commit is contained in:
parent
fd551988cd
commit
7775441e24
@ -30,11 +30,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type packet_send_params struct {
|
type packet_send_params struct {
|
||||||
peer *Peer
|
peer *Peer
|
||||||
usage path.Usage
|
elem *QueueOutboundElement
|
||||||
ttl uint8
|
|
||||||
packet []byte
|
|
||||||
offset int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) SendPacket(peer *Peer, usage path.Usage, ttl uint8, packet []byte, offset int) {
|
func (device *Device) SendPacket(peer *Peer, usage path.Usage, ttl uint8, packet []byte, offset int) {
|
||||||
@ -72,13 +69,15 @@ func (device *Device) SendPacket(peer *Peer, usage path.Usage, ttl uint8, packet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var elem *QueueOutboundElement
|
||||||
|
elem = device.NewOutboundElement()
|
||||||
|
copy(elem.buffer[offset:offset+len(packet)], packet)
|
||||||
|
elem.Type = usage
|
||||||
|
elem.TTL = ttl
|
||||||
|
elem.packet = elem.buffer[offset : offset+len(packet)]
|
||||||
device.chan_send_packet <- &packet_send_params{
|
device.chan_send_packet <- &packet_send_params{
|
||||||
peer: peer,
|
peer: peer,
|
||||||
usage: usage,
|
elem: elem,
|
||||||
ttl: ttl,
|
|
||||||
packet: packet,
|
|
||||||
offset: offset,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +90,8 @@ func (device *Device) RoutineSendPacket() {
|
|||||||
}
|
}
|
||||||
elem = device.NewOutboundElement()
|
elem = device.NewOutboundElement()
|
||||||
params := <-device.chan_send_packet
|
params := <-device.chan_send_packet
|
||||||
offset := params.offset
|
elem := params.elem
|
||||||
packet := params.packet
|
|
||||||
peer := params.peer
|
peer := params.peer
|
||||||
copy(elem.buffer[offset:offset+len(packet)], packet)
|
|
||||||
elem.Type = params.usage
|
|
||||||
elem.TTL = params.ttl
|
|
||||||
elem.packet = elem.buffer[offset : offset+len(packet)]
|
|
||||||
if peer.isRunning.Get() {
|
if peer.isRunning.Get() {
|
||||||
peer.StagePacket(elem)
|
peer.StagePacket(elem)
|
||||||
elem = nil
|
elem = nil
|
||||||
|
@ -217,13 +217,11 @@ func (device *Device) RoutineReadFromTUN() {
|
|||||||
|
|
||||||
device.log.Verbosef("Routine: TUN reader - started")
|
device.log.Verbosef("Routine: TUN reader - started")
|
||||||
|
|
||||||
elem := &QueueOutboundElement{
|
var elem *QueueOutboundElement
|
||||||
buffer: &[MaxMessageSize]byte{},
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
elem = device.NewOutboundElement()
|
||||||
// read packet
|
// read packet
|
||||||
|
|
||||||
offset := MessageTransportHeaderSize
|
offset := MessageTransportHeaderSize
|
||||||
size, err := device.tap.device.Read(elem.buffer[:], offset+path.EgHeaderLen)
|
size, err := device.tap.device.Read(elem.buffer[:], offset+path.EgHeaderLen)
|
||||||
|
|
||||||
@ -279,7 +277,10 @@ func (device *Device) RoutineReadFromTUN() {
|
|||||||
if peer == nil {
|
if peer == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
device.SendPacket(peer, elem.Type, elem.TTL, elem.packet, offset)
|
device.chan_send_packet <- &packet_send_params{
|
||||||
|
peer: peer,
|
||||||
|
elem: elem,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
device.BoardcastPacket(make(map[mtypes.Vertex]bool, 0), elem.Type, elem.TTL, elem.packet, offset)
|
device.BoardcastPacket(make(map[mtypes.Vertex]bool, 0), elem.Type, elem.TTL, elem.packet, offset)
|
||||||
|
Loading…
Reference in New Issue
Block a user