Skip to content

Commit

Permalink
Node Push: Use VoidBufferAsArrayOf!(cstring) + small improvements
Browse files Browse the repository at this point in the history
Fixes sociomantic-tsunami#2.

- Use `VoidBufferAsArrayOf!(cstring)` instead of `cast(cstring[]*)`, which
  is dangerous because the array length is set after the cast.
- Set the array length once instead of appending incrementally.
- Use `parseBody` to parse the value to enforce it is the last field in the
  message payload.
  • Loading branch information
david-eckardt-sociomantic authored and Gavin Norman committed Feb 2, 2018
1 parent e3be0b3 commit 044120e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/dmqproto/node/neo/request/Push.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract scope class PushProtocol_v2
import dmqproto.node.neo.request.core.Mixins;

import swarm.neo.node.RequestOnConn;
import swarm.neo.util.VoidBufferAsArrayOf;
import dmqproto.common.Push;

import ocean.transition;
Expand Down Expand Up @@ -54,20 +55,20 @@ public abstract scope class PushProtocol_v2

// Acquire a buffer to contain slices to the channel names in the
// message payload (i.e. not a buffer of buffers, a buffer of slices)
auto channel_names = cast(cstring[]*)this.resources.getVoidBuffer();
auto channel_names = VoidBufferAsArrayOf!(cstring)(this.resources.getVoidBuffer());
channel_names.length = *parser.getValue!(ubyte)(msg_payload);

auto num_channels = *parser.getValue!(ubyte)(msg_payload);

for ( size_t i; i < num_channels; i++ )
foreach ( ref channel_name; channel_names.array )
{
*channel_names ~= parser.getArray!(char)(msg_payload);
channel_name = parser.getArray!(Const!(char))(msg_payload);
}

auto value = parser.getArray!(char)(msg_payload);
Const!(void)[] value;
parser.parseBody(msg_payload, value);

if ( this.prepareChannels(*channel_names) )
if ( this.prepareChannels(channel_names.array) )
{
foreach ( channel_name; *channel_names )
foreach ( channel_name; channel_names.array )
{
this.pushToStorage(channel_name, value);
}
Expand Down

0 comments on commit 044120e

Please sign in to comment.