Skip to content

Commit 786e2a8

Browse files
Improve stability of channels_test:Key rotation (#6782)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 45ea315 commit 786e2a8

File tree

3 files changed

+244
-133
lines changed

3 files changed

+244
-133
lines changed

src/ds/non_blocking.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ namespace ringbuffer
102102
{
103103
for (auto& it : pending)
104104
{
105-
const auto buffer_end = it.buffer.data() + it.buffer.size();
106-
if (
107-
it.marker == marker.value() &&
108-
marker.value() != reinterpret_cast<uint64_t>(buffer_end))
105+
if (it.finished)
106+
{
107+
continue;
108+
}
109+
110+
if (it.marker == marker.value())
109111
{
110112
// This is a pending write - dump data directly to write marker,
111113
// which should be within the appropriate buffer
@@ -118,6 +120,7 @@ namespace ringbuffer
118120
(size_t)it.buffer.data()));
119121
}
120122

123+
const auto buffer_end = it.buffer.data() + it.buffer.size();
121124
if (dest + size > buffer_end)
122125
{
123126
throw std::runtime_error(fmt::format(
@@ -128,7 +131,11 @@ namespace ringbuffer
128131
(size_t)buffer_end));
129132
}
130133

131-
std::memcpy(dest, bytes, size);
134+
if (size != 0)
135+
{
136+
std::memcpy(dest, bytes, size);
137+
}
138+
132139
dest += size;
133140
it.marker = (size_t)dest;
134141
return {it.marker};

src/node/channels.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ namespace ccf
145145
}
146146
}
147147

148-
class KeyExchangeProtocol
149-
{};
150-
151148
// Key exchange states are:
152149
// - Have nothing
153150
// - Initiated (have my own share)
@@ -251,6 +248,8 @@ namespace ccf
251248

252249
send_key = nullptr;
253250
recv_key = nullptr;
251+
reset_key_exchange();
252+
initiate();
254253
}
255254
}
256255

@@ -542,6 +541,8 @@ namespace ccf
542541
// shares back to the initiator
543542
send_key_exchange_response();
544543

544+
flush_pending_outgoing();
545+
545546
return true;
546547
}
547548

@@ -633,6 +634,8 @@ namespace ccf
633634

634635
send_key_exchange_final();
635636

637+
flush_pending_outgoing();
638+
636639
update_recv_key();
637640

638641
establish();
@@ -804,7 +807,10 @@ namespace ccf
804807
"Node certificate serial numbers: node={} peer={}",
805808
node_cv->serial_number(),
806809
peer_cv->serial_number());
810+
}
807811

812+
void flush_pending_outgoing()
813+
{
808814
if (outgoing_consensus_msg.has_value())
809815
{
810816
send_unsafe(

0 commit comments

Comments
 (0)