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 {
|
||||
peer *Peer
|
||||
usage path.Usage
|
||||
ttl uint8
|
||||
packet []byte
|
||||
offset int
|
||||
peer *Peer
|
||||
elem *QueueOutboundElement
|
||||
}
|
||||
|
||||
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{
|
||||
peer: peer,
|
||||
usage: usage,
|
||||
ttl: ttl,
|
||||
packet: packet,
|
||||
offset: offset,
|
||||
peer: peer,
|
||||
elem: elem,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,13 +90,8 @@ func (device *Device) RoutineSendPacket() {
|
|||
}
|
||||
elem = device.NewOutboundElement()
|
||||
params := <-device.chan_send_packet
|
||||
offset := params.offset
|
||||
packet := params.packet
|
||||
elem := params.elem
|
||||
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() {
|
||||
peer.StagePacket(elem)
|
||||
elem = nil
|
||||
|
|
|
@ -217,13 +217,11 @@ func (device *Device) RoutineReadFromTUN() {
|
|||
|
||||
device.log.Verbosef("Routine: TUN reader - started")
|
||||
|
||||
elem := &QueueOutboundElement{
|
||||
buffer: &[MaxMessageSize]byte{},
|
||||
}
|
||||
var elem *QueueOutboundElement
|
||||
|
||||
for {
|
||||
elem = device.NewOutboundElement()
|
||||
// read packet
|
||||
|
||||
offset := MessageTransportHeaderSize
|
||||
size, err := device.tap.device.Read(elem.buffer[:], offset+path.EgHeaderLen)
|
||||
|
||||
|
@ -279,7 +277,10 @@ func (device *Device) RoutineReadFromTUN() {
|
|||
if peer == nil {
|
||||
continue
|
||||
}
|
||||
device.SendPacket(peer, elem.Type, elem.TTL, elem.packet, offset)
|
||||
device.chan_send_packet <- &packet_send_params{
|
||||
peer: peer,
|
||||
elem: elem,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
device.BoardcastPacket(make(map[mtypes.Vertex]bool, 0), elem.Type, elem.TTL, elem.packet, offset)
|
||||
|
|
Loading…
Reference in New Issue