Don't craft buffers if we don't need them (#416)

This commit is contained in:
Nathan Brown 2021-03-22 18:25:06 -05:00 committed by GitHub
parent 7073d204a8
commit 7a9f9dbded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -599,12 +599,19 @@ func (i *HostInfo) handshakeComplete() {
//TODO: this should be managed by the handshake state machine to set it based on how many handshake were seen. //TODO: this should be managed by the handshake state machine to set it based on how many handshake were seen.
// Clamping it to 2 gets us out of the woods for now // Clamping it to 2 gets us out of the woods for now
atomic.StoreUint64(&i.ConnectionState.atomicMessageCounter, 2) atomic.StoreUint64(&i.ConnectionState.atomicMessageCounter, 2)
if l.Level >= logrus.DebugLevel {
i.logger().Debugf("Sending %d stored packets", len(i.packetStore)) i.logger().Debugf("Sending %d stored packets", len(i.packetStore))
}
if len(i.packetStore) > 0 {
nb := make([]byte, 12, 12) nb := make([]byte, 12, 12)
out := make([]byte, mtu) out := make([]byte, mtu)
for _, cp := range i.packetStore { for _, cp := range i.packetStore {
cp.callback(cp.messageType, cp.messageSubType, i, cp.packet, nb, out) cp.callback(cp.messageType, cp.messageSubType, i, cp.packet, nb, out)
} }
}
i.packetStore = make([]*cachedPacket, 0) i.packetStore = make([]*cachedPacket, 0)
i.ConnectionState.ready = true i.ConnectionState.ready = true
i.ConnectionState.queueLock.Unlock() i.ConnectionState.queueLock.Unlock()