Skip to content

Commit

Permalink
Adapt Put to use new SupportedCode from swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Norman committed Jan 9, 2018
1 parent 7c18fc4 commit 398fa60
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
27 changes: 17 additions & 10 deletions src/dhtproto/client/request/internal/Put.d
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,26 @@ public struct Put
);
conn.flush();

// Receive status from node
auto status = conn.receiveValue!(StatusCode)();
if ( !Put.handleGlobalStatusCodes(status, context,
// Receive supported code from node
auto supported = conn.receiveValue!(SupportedStatus)();
if ( !Put.handleSupportedCodes(supported, context,
conn.remote_address) )
{
switch ( status )
// Request not supported; abort further handling.
context.shared_working.result = SharedWorking.Result.Error;
}
else
{
// Request supported; read result code from node.
auto result = conn.receiveValue!(MessageType)();
switch ( result )
{
case RequestStatusCode.Put:
case MessageType.Put:
context.shared_working.result =
SharedWorking.Result.Success;
break;

case RequestStatusCode.WrongNode:
case MessageType.WrongNode:
context.shared_working.result =
SharedWorking.Result.Error;

Expand All @@ -210,7 +217,7 @@ public struct Put
Put.notify(context.user_params, n);
break;

case RequestStatusCode.Error:
case MessageType.Error:
context.shared_working.result =
SharedWorking.Result.Error;

Expand All @@ -222,10 +229,10 @@ public struct Put
break;

default:
log.warn("Received unknown status code {} from node "
log.warn("Received unknown message code {} from node "
~ "in response to Put request. Treating as "
~ "Error.", status);
goto case RequestStatusCode.Error;
~ "Error.", result);
goto case MessageType.Error;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/dhtproto/common/Put.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

module dhtproto.common.Put;

import swarm.neo.request.Command;

/*******************************************************************************
Status code enum. Sent from the node to the client.
Message type enum. Sent from the node to the client.
*******************************************************************************/

public enum RequestStatusCode : StatusCode
public enum MessageType : ubyte
{
/// Invalid, default value
None,
Expand Down
6 changes: 3 additions & 3 deletions src/dhtproto/node/neo/request/Put.d
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public abstract scope class PutProtocol_v0
auto key = *ed.message_parser.getValue!(hash_t)(msg_payload);
auto value = ed.message_parser.getArray!(void)(msg_payload);

RequestStatusCode response;
MessageType response;

// Check record key and write to channel, if ok.
if ( this.responsibleForKey(key) )
{
response = this.put(channel, key, value)
? RequestStatusCode.Put : RequestStatusCode.Error;
? MessageType.Put : MessageType.Error;
}
else
response = RequestStatusCode.WrongNode;
response = MessageType.WrongNode;

// Send status code
ed.send(
Expand Down
9 changes: 8 additions & 1 deletion src/fakedht/neo/request/Put.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ public void handle ( Object shared_resources, RequestOnConn connection,
Command.Version cmdver, Const!(void)[] msg_payload )
{
auto resources = new SharedResources;
auto ed = connection.event_dispatcher;

switch ( cmdver )
{
case 0:
ed.send(
( ed.Payload payload )
{
payload.addConstant(SupportedStatus.RequestSupported);
}
);

scope rq = new PutImpl_v0(resources);
rq.handle(connection, msg_payload);
break;

default:
auto ed = connection.event_dispatcher;
ed.send(
( ed.Payload payload )
{
Expand Down

0 comments on commit 398fa60

Please sign in to comment.