diff --git a/integrationtest/channelserializer/main.d b/integrationtest/channelserializer/main.d index 30577f99..e6691918 100644 --- a/integrationtest/channelserializer/main.d +++ b/integrationtest/channelserializer/main.d @@ -85,7 +85,7 @@ int main ( istring[] args ) { auto ser = new ChannelSerializer!(S)("failed_channel"); - void dumpRecord ( void delegate ( hash_t, ref Contiguous!(S) ) record_dg ) + void dumpRecord ( scope void delegate ( hash_t, ref Contiguous!(S) ) record_dg ) { throw new Exception("File write error"); } diff --git a/src/dhtproto/client/DhtClient.d b/src/dhtproto/client/DhtClient.d index 1bbab263..d14d6fec 100644 --- a/src/dhtproto/client/DhtClient.d +++ b/src/dhtproto/client/DhtClient.d @@ -560,7 +560,7 @@ public class DhtClient : IClient ***********************************************************************/ - public void opCall ( RequestParams.GetBoolDg output, + public void opCall ( scope RequestParams.GetBoolDg output, NotifierDg user_notifier ) { this.reset(output, user_notifier); @@ -585,7 +585,7 @@ public class DhtClient : IClient ***********************************************************************/ - private void reset ( RequestParams.GetBoolDg output, + private void reset ( scope RequestParams.GetBoolDg output, NotifierDg user_notifier ) { this.output = output; @@ -993,8 +993,8 @@ public class DhtClient : IClient ***************************************************************************/ - public void nodeHandshake ( RequestParams.GetBoolDg output, - RequestNotification.Callback user_notifier ) + public void nodeHandshake ( scope RequestParams.GetBoolDg output, + scope RequestNotification.Callback user_notifier ) { this.node_handshake(output, user_notifier); } @@ -1066,8 +1066,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public Put put ( Key ) ( cstring channel, Key key, RequestParams.PutValueDg input, - RequestNotification.Callback notifier ) + public Put put ( Key ) ( cstring channel, Key key, scope RequestParams.PutValueDg input, + scope RequestNotification.Callback notifier ) { return *Put(DhtConst.Command.E.Put, notifier).channel(channel).key(key) .io(input).contextFromKey(); @@ -1106,8 +1106,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public Get get ( Key ) ( cstring channel, Key key, RequestParams.GetValueDg output, - RequestNotification.Callback notifier ) + public Get get ( Key ) ( cstring channel, Key key, scope RequestParams.GetValueDg output, + scope RequestNotification.Callback notifier ) { return *Get(DhtConst.Command.E.Get, notifier).channel(channel).key(key) .io(output).contextFromKey(); @@ -1144,8 +1144,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public Exists exists ( Key ) ( cstring channel, Key key, RequestParams.GetBoolDg output, - RequestNotification.Callback notifier ) + public Exists exists ( Key ) ( cstring channel, Key key, scope RequestParams.GetBoolDg output, + scope RequestNotification.Callback notifier ) { return *Exists(DhtConst.Command.E.Exists, notifier).channel(channel) .key(key).io(output).contextFromKey(); @@ -1177,7 +1177,7 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public Remove remove ( Key ) ( cstring channel, Key key, RequestNotification.Callback notifier ) + public Remove remove ( Key ) ( cstring channel, Key key, scope RequestNotification.Callback notifier ) { return *Remove(DhtConst.Command.E.Remove, notifier).channel(channel) .key(key).contextFromKey(); @@ -1222,8 +1222,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetAll getAll ( cstring channel, RequestParams.GetPairDg output, - RequestNotification.Callback notifier ) + public GetAll getAll ( cstring channel, scope RequestParams.GetPairDg output, + scope RequestNotification.Callback notifier ) { return *GetAll(DhtConst.Command.E.GetAll, notifier).channel(channel) .io(output); @@ -1267,8 +1267,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetAllKeys getAllKeys ( cstring channel, RequestParams.GetValueDg output, - RequestNotification.Callback notifier ) + public GetAllKeys getAllKeys ( cstring channel, scope RequestParams.GetValueDg output, + scope RequestNotification.Callback notifier ) { return *GetAllKeys(DhtConst.Command.E.GetAllKeys, notifier) .channel(channel).io(output); @@ -1311,8 +1311,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public Listen listen ( cstring channel, RequestParams.GetPairDg output, - RequestNotification.Callback notifier ) + public Listen listen ( cstring channel, scope RequestParams.GetPairDg output, + scope RequestNotification.Callback notifier ) { return *Listen(DhtConst.Command.E.Listen, notifier).channel(channel) .io(output); @@ -1354,8 +1354,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetChannels getChannels ( RequestParams.GetNodeValueDg output, - RequestNotification.Callback notifier ) + public GetChannels getChannels ( scope RequestParams.GetNodeValueDg output, + scope RequestNotification.Callback notifier ) { return *GetChannels(DhtConst.Command.E.GetChannels, notifier).io(output); } @@ -1395,7 +1395,7 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetSize getSize ( RequestParams.GetSizeInfoDg output, RequestNotification.Callback notifier ) + public GetSize getSize ( scope RequestParams.GetSizeInfoDg output, scope RequestNotification.Callback notifier ) { return *GetSize(DhtConst.Command.E.GetSize, notifier).io(output); } @@ -1438,7 +1438,7 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetChannelSize getChannelSize ( cstring channel, RequestParams.GetChannelSizeInfoDg output, RequestNotification.Callback notifier ) + public GetChannelSize getChannelSize ( cstring channel, scope RequestParams.GetChannelSizeInfoDg output, scope RequestNotification.Callback notifier ) { return *GetChannelSize(DhtConst.Command.E.GetChannelSize, notifier) .channel(channel).io(output); @@ -1472,7 +1472,7 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public RemoveChannel removeChannel ( cstring channel, RequestNotification.Callback notifier ) + public RemoveChannel removeChannel ( cstring channel, scope RequestNotification.Callback notifier ) { return *RemoveChannel(DhtConst.Command.E.RemoveChannel, notifier) .channel(channel); @@ -1513,8 +1513,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetNumConnections getNumConnections ( RequestParams.GetNumConnectionsDg output, - RequestNotification.Callback notifier ) + public GetNumConnections getNumConnections ( scope RequestParams.GetNumConnectionsDg output, + scope RequestNotification.Callback notifier ) { return *GetNumConnections(DhtConst.Command.E.GetNumConnections, notifier) .io(output); @@ -1557,8 +1557,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetVersion getVersion ( RequestParams.GetNodeValueDg output, - RequestNotification.Callback notifier ) + public GetVersion getVersion ( scope RequestParams.GetNodeValueDg output, + scope RequestNotification.Callback notifier ) { return *GetVersion(DhtConst.Command.E.GetVersion, notifier).io(output); } @@ -1599,8 +1599,8 @@ public class DhtClient : IClient mixin RequestParamsSetup; // private setup() method, used by assign() } - public GetResponsibleRange getResponsibleRange ( RequestParams.GetResponsibleRangeDg output, - RequestNotification.Callback notifier ) + public GetResponsibleRange getResponsibleRange ( scope RequestParams.GetResponsibleRangeDg output, + scope RequestNotification.Callback notifier ) { return *GetResponsibleRange(DhtConst.Command.E.GetResponsibleRange, notifier).io(output); @@ -1623,7 +1623,7 @@ public class DhtClient : IClient ***************************************************************************/ override protected void scopeRequestParams ( - void delegate ( IRequestParams params ) dg ) + scope void delegate ( IRequestParams params ) dg ) { scope params = new RequestParams; dg(params); diff --git a/src/dhtproto/client/NotifierTypes.d b/src/dhtproto/client/NotifierTypes.d index c8d4d526..2fc2f5cc 100644 --- a/src/dhtproto/client/NotifierTypes.d +++ b/src/dhtproto/client/NotifierTypes.d @@ -47,12 +47,12 @@ public struct RequestRecordInfo ***************************************************************************/ - public void toString ( void delegate ( cstring chunk ) sink ) + public void toString ( scope void delegate ( cstring chunk ) sink ) { Formatter.sformat( sink, "Request #{} provided the record 0x{:x16}:{}", - this.request_id, this.key, this.value); + (&this).request_id, (&this).key, (&this).value); } } @@ -92,12 +92,12 @@ public struct RequestDataUpdateInfo ***************************************************************************/ - public void toString ( void delegate ( cstring chunk ) sink ) + public void toString ( scope void delegate ( cstring chunk ) sink ) { Formatter.sformat( sink, "Request #{} provided the record {} to be updated", - this.request_id, this.value); + (&this).request_id, (&this).value); } } @@ -126,12 +126,12 @@ public struct RequestKeyInfo ***************************************************************************/ - public void toString ( void delegate ( cstring chunk ) sink ) + public void toString ( scope void delegate ( cstring chunk ) sink ) { Formatter.sformat( sink, "Request #{} provided the key 0x{:x16}", - this.request_id, this.key); + (&this).request_id, (&this).key); } } diff --git a/src/dhtproto/client/helper/ChannelSerializer.d b/src/dhtproto/client/helper/ChannelSerializer.d index 3b6fd933..eaa21157 100644 --- a/src/dhtproto/client/helper/ChannelSerializer.d +++ b/src/dhtproto/client/helper/ChannelSerializer.d @@ -97,7 +97,7 @@ public class ChannelSerializer ( S ) public this ( istring path ) { - const buffer_size = 64 * 1024; + static immutable buffer_size = 64 * 1024; this.path = path; this.buffered_output = new BufferedOutput(null, buffer_size); @@ -124,7 +124,7 @@ public class ChannelSerializer ( S ) public bool dump ( Contiguous!(S)[hash_t] aa, bool block = false ) { - void dumpAA ( void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) + void dumpAA ( scope void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) { foreach ( k, v; aa) dump_record(k, v); @@ -148,7 +148,7 @@ public class ChannelSerializer ( S ) public bool dump ( Map!(Contiguous!(S), hash_t) map, bool block = false ) { - void dumpMap ( void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) + void dumpMap ( scope void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) { foreach ( k, v; map) dump_record(k, v); @@ -171,7 +171,7 @@ public class ChannelSerializer ( S ) ***************************************************************************/ - public bool dump ( DumpRecordDg record_dump_dg, bool block = false ) + public bool dump ( scope DumpRecordDg record_dump_dg, bool block = false ) { this.record_dump_dg = record_dump_dg; return this.fork.call(block); @@ -222,7 +222,7 @@ public class ChannelSerializer ( S ) ***************************************************************************/ - public void load ( LoadRecordDg record_load_dg ) + public void load ( scope LoadRecordDg record_load_dg ) { size_t num_records; scope file = new File(this.path, File.ReadExisting); @@ -346,7 +346,7 @@ unittest void dumpChannelFromContainer ( ) { void containerIterator ( - void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) + scope void delegate ( hash_t, ref Contiguous!(S) ) dump_record ) { Contiguous!(S) v; diff --git a/src/dhtproto/client/internal/NodeHashRanges.d b/src/dhtproto/client/internal/NodeHashRanges.d index 7639632e..3f4642eb 100644 --- a/src/dhtproto/client/internal/NodeHashRanges.d +++ b/src/dhtproto/client/internal/NodeHashRanges.d @@ -53,7 +53,7 @@ public final class NodeHashRanges : NodeHashRangesBase ***************************************************************************/ - public this ( ConnectionSet connections, NewNodeNotifier new_node_dg ) + public this ( ConnectionSet connections, scope NewNodeNotifier new_node_dg ) { this.connections = connections; this.new_node_dg = new_node_dg; @@ -88,8 +88,8 @@ public final class NodeHashRanges : NodeHashRangesBase ***************************************************************************/ public void getFromNode ( hash_t h, - VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, UseNodeDg use_node, - bool delegate ( RequestOnConn.EventDispatcher ) get ) + VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, scope UseNodeDg use_node, + scope bool delegate ( RequestOnConn.EventDispatcher ) get ) { auto nodes = this.getNodesForHash(h, node_hash_ranges); if ( nodes.length == 0 ) @@ -146,8 +146,8 @@ public final class NodeHashRanges : NodeHashRangesBase ***************************************************************************/ public void removeFromNodes ( hash_t h, - VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, UseNodeDg use_node, - bool delegate ( RequestOnConn.EventDispatcher ) remove ) + VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, scope UseNodeDg use_node, + scope bool delegate ( RequestOnConn.EventDispatcher ) remove ) { auto nodes = this.getNodesForHash(h, node_hash_ranges); if ( nodes.length == 0 ) @@ -190,8 +190,8 @@ public final class NodeHashRanges : NodeHashRangesBase ***************************************************************************/ public void putToNode ( hash_t h, - VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, UseNodeDg use_node, - void delegate ( RequestOnConn.EventDispatcher ) put ) + VoidBufferAsArrayOf!(NodeHashRange) node_hash_ranges, scope UseNodeDg use_node, + scope void delegate ( RequestOnConn.EventDispatcher ) put ) { auto nodes = this.getNodesForHash(h, node_hash_ranges); if ( nodes.length == 0 ) diff --git a/src/dhtproto/client/internal/SharedResources.d b/src/dhtproto/client/internal/SharedResources.d index 07c0d089..c321223f 100644 --- a/src/dhtproto/client/internal/SharedResources.d +++ b/src/dhtproto/client/internal/SharedResources.d @@ -245,7 +245,7 @@ public final class SharedResources ***********************************************************************/ - public MessageFiber getFiber ( void delegate ( ) fiber_method ) + public MessageFiber getFiber ( scope void delegate ( ) fiber_method ) { bool new_fiber = false; diff --git a/src/dhtproto/client/legacy/DhtConst.d b/src/dhtproto/client/legacy/DhtConst.d index 68ba4b93..ece17585 100644 --- a/src/dhtproto/client/legacy/DhtConst.d +++ b/src/dhtproto/client/legacy/DhtConst.d @@ -56,7 +56,7 @@ static: ***************************************************************************/ - public const ApiVersion = "20110401"; + public enum ApiVersion = "20110401"; /*************************************************************************** @@ -66,7 +66,7 @@ static: ***************************************************************************/ - public const RecordSizeLimit = RecordBatcher.DefaultMaxBatchSize; + public enum RecordSizeLimit = RecordBatcher.DefaultMaxBatchSize; /*************************************************************************** @@ -221,6 +221,6 @@ public struct NodeHashRange public equals_t opEquals ( NodeHashRange rhs ) { - return this.opCmp(rhs) == 0; + return (&this).opCmp(rhs) == 0; } } diff --git a/src/dhtproto/client/legacy/common/NodeRecordBatcher.d b/src/dhtproto/client/legacy/common/NodeRecordBatcher.d index b909d241..03172346 100644 --- a/src/dhtproto/client/legacy/common/NodeRecordBatcher.d +++ b/src/dhtproto/client/legacy/common/NodeRecordBatcher.d @@ -95,10 +95,10 @@ public class NodeRecordBatcher { private hash_t[] hashes; - public int opApply ( int delegate ( ref hash_t hash ) dg ) + public int opApply ( scope int delegate ( ref hash_t hash ) dg ) { int r; - foreach ( h; this.hashes ) + foreach ( h; (&this).hashes ) { r = dg(h); if ( r ) break; diff --git a/src/dhtproto/client/legacy/internal/helper/ChannelMirror.d b/src/dhtproto/client/legacy/internal/helper/ChannelMirror.d index ca8cfa95..5eb6e01d 100644 --- a/src/dhtproto/client/legacy/internal/helper/ChannelMirror.d +++ b/src/dhtproto/client/legacy/internal/helper/ChannelMirror.d @@ -79,7 +79,7 @@ abstract public class ChannelMirror ( Dht : DhtClient ) : MirrorBase!(Dht) ***********************************************************************/ - public this ( Dht.RequestNotification.Callback notifier = null ) + public this ( scope Dht.RequestNotification.Callback notifier = null ) { super(this.outer.dht.listen(this.outer.channel_, &this.outer.listenReceiveRecord, notifier)); @@ -158,7 +158,7 @@ abstract public class ChannelMirror ( Dht : DhtClient ) : MirrorBase!(Dht) ***********************************************************************/ - public this ( Dht.RequestNotification.Callback notifier = null ) + public this ( scope Dht.RequestNotification.Callback notifier = null ) { super(this.outer.dht.getAll(this.outer.channel_, &this.outer.getAllReceiveRecord, @@ -273,7 +273,7 @@ abstract public class ChannelMirror ( Dht : DhtClient ) : MirrorBase!(Dht) public this ( Dht dht, cstring channel, uint update_time_s, uint retry_time_s, - Dht.RequestNotification.Callback notifier = null ) + scope Dht.RequestNotification.Callback notifier = null ) { super(dht, channel, update_time_s, retry_time_s); @@ -305,7 +305,7 @@ abstract public class ChannelMirror ( Dht : DhtClient ) : MirrorBase!(Dht) public this ( Dht dht, cstring channel, uint update_time_s, uint retry_time_s, lazy ListenRequest listen, lazy GetAllRequest get_all, - Dht.RequestNotification.Callback notifier = null ) + scope Dht.RequestNotification.Callback notifier = null ) { super(dht, channel, update_time_s, retry_time_s); @@ -437,8 +437,8 @@ unittest // Dummy concrete channel mirror class class Mirror : ChannelMirror!(SchedulingDhtClient) { - const UpdatePeriod = 60; // do a GetAll every 60 seconds - const RetryPeriod = 3; // retry failed requests after 3 seconds + static immutable UpdatePeriod = 60; // do a GetAll every 60 seconds + static immutable RetryPeriod = 3; // retry failed requests after 3 seconds public this ( SchedulingDhtClient dht, in char[] channel ) { diff --git a/src/dhtproto/client/legacy/internal/helper/ExtensibleChannelMirror.d b/src/dhtproto/client/legacy/internal/helper/ExtensibleChannelMirror.d index d03c920a..b3271d78 100644 --- a/src/dhtproto/client/legacy/internal/helper/ExtensibleChannelMirror.d +++ b/src/dhtproto/client/legacy/internal/helper/ExtensibleChannelMirror.d @@ -158,8 +158,8 @@ public class ExtensibleMirror public this ( Dht dht, cstring channel, uint update_time_s, uint retry_time_s, - Dht.RequestNotification.Callback request_notifier, - PluginNotifier plugin_notifier, + scope Dht.RequestNotification.Callback request_notifier, + scope PluginNotifier plugin_notifier, Plugins plugin_instances ) { super(dht, channel, update_time_s, retry_time_s, request_notifier); @@ -312,7 +312,7 @@ unittest istring toString ( ) { return format("[{}, {}, {}]", - this.update_time, this.id, this.count); + (&this).update_time, (&this).id, (&this).count); } } @@ -331,7 +331,7 @@ unittest enforce(handshake_ok); // Add some records to the channel being mirrored - const num_records = 10; + static immutable num_records = 10; for ( hash_t i = 0; i < num_records; i++ ) { mstring put_dg ( DhtClient.RequestContext c ) @@ -520,7 +520,7 @@ public class RawRecordDeserializer ( T ) ***************************************************************************/ - private const bool isVersioned = Version.Info!(T).exists; + private static immutable bool isVersioned = Version.Info!(T).exists; static if (isVersioned) { diff --git a/src/dhtproto/client/legacy/internal/helper/Mirror.d b/src/dhtproto/client/legacy/internal/helper/Mirror.d index 354b256d..48dbb486 100644 --- a/src/dhtproto/client/legacy/internal/helper/Mirror.d +++ b/src/dhtproto/client/legacy/internal/helper/Mirror.d @@ -391,7 +391,7 @@ abstract public class Mirror ( Dht : DhtClient ) : MirrorBase!(Dht) ***************************************************************************/ public this ( Dht dht, cstring channel, uint update_time_s, - uint retry_time_s, Dht.RequestNotification.Callback notifier = null ) + uint retry_time_s, scope Dht.RequestNotification.Callback notifier = null ) { super(dht, channel, update_time_s, retry_time_s); this.user_notifier = notifier; @@ -568,8 +568,8 @@ unittest // Dummy concrete channel mirror class class ExampleMirror : Mirror!(SchedulingDhtClient) { - const UpdatePeriod = 60; // do a GetAll every 60 seconds - const RetryPeriod = 3; // retry failed requests after 3 seconds + static immutable UpdatePeriod = 60; // do a GetAll every 60 seconds + static immutable RetryPeriod = 3; // retry failed requests after 3 seconds public this ( SchedulingDhtClient dht, cstring channel ) { diff --git a/src/dhtproto/client/legacy/internal/helper/NodeAvailability.d b/src/dhtproto/client/legacy/internal/helper/NodeAvailability.d index 037a2c60..cd757127 100644 --- a/src/dhtproto/client/legacy/internal/helper/NodeAvailability.d +++ b/src/dhtproto/client/legacy/internal/helper/NodeAvailability.d @@ -47,15 +47,15 @@ public struct NodeAvailabilty public void error ( NodeItem node ) { - if ( auto tracker = node.toHash() in this.error_trackers ) + if ( auto tracker = node.toHash() in (&this).error_trackers ) { tracker.error(); } else { - auto tracker = NodeErrorTracker(this); + auto tracker = NodeErrorTracker((&this)); tracker.error(); - this.error_trackers[node.toHash()] = tracker; + (&this).error_trackers[node.toHash()] = tracker; } } @@ -104,7 +104,7 @@ public struct NodeAvailabilty public bool available ( NodeItem node ) { - if ( auto tracker = node.toHash() in this.error_trackers ) + if ( auto tracker = node.toHash() in (&this).error_trackers ) return tracker.available(); else return true; @@ -128,7 +128,7 @@ public struct NodeAvailabilty public void error ( ) { - this.last_error_timestamp = time(); + (&this).last_error_timestamp = time(); } /*********************************************************************** @@ -144,8 +144,8 @@ public struct NodeAvailabilty public bool available ( ) { - auto diff = time() - this.last_error_timestamp; - return diff >= this.outer.retry_delay_s; + auto diff = time() - (&this).last_error_timestamp; + return diff >= (&this).outer.retry_delay_s; } /*********************************************************************** diff --git a/src/dhtproto/client/legacy/internal/helper/RetryHandshake.d b/src/dhtproto/client/legacy/internal/helper/RetryHandshake.d index 1da26d06..5441bf8d 100644 --- a/src/dhtproto/client/legacy/internal/helper/RetryHandshake.d +++ b/src/dhtproto/client/legacy/internal/helper/RetryHandshake.d @@ -76,8 +76,8 @@ class RetryHandshake ***************************************************************************/ public this ( EpollSelectDispatcher epoll, DhtClient dht, - size_t wait_time, void delegate ( ) handshake_complete_dg = null, - void delegate ( NodeItem ) one_node_handshake_dg = null ) + size_t wait_time, scope void delegate ( ) handshake_complete_dg = null, + scope void delegate ( NodeItem ) one_node_handshake_dg = null ) { this.wait_time = wait_time; @@ -244,18 +244,18 @@ unittest // event loop running. void main ( ) { - this.epoll = new EpollSelectDispatcher; - this.dht = new DhtClient(this.epoll); + (&this).epoll = new EpollSelectDispatcher; + (&this).dht = new DhtClient((&this).epoll); // In a real app, you should call `this.dht.addNodes(...);` // Start the handshake auto retry_delay_seconds = 3; // Store the reference to the RetryHandshake // object so it doesn't get garbage collected. - auto handshake = new RetryHandshake(this.epoll, this.dht, retry_delay_seconds, - &this.handshake_complete_dg, &this.node_connected_dg); + auto handshake = new RetryHandshake((&this).epoll, (&this).dht, retry_delay_seconds, + &(&this).handshake_complete_dg, &(&this).node_connected_dg); - this.epoll.eventLoop(); + (&this).epoll.eventLoop(); } // Called when an individual node is initially connected. diff --git a/src/dhtproto/client/legacy/internal/helper/mirror/ContiguousRecordCache.d b/src/dhtproto/client/legacy/internal/helper/mirror/ContiguousRecordCache.d index 43c08b08..56c47660 100644 --- a/src/dhtproto/client/legacy/internal/helper/mirror/ContiguousRecordCache.d +++ b/src/dhtproto/client/legacy/internal/helper/mirror/ContiguousRecordCache.d @@ -152,7 +152,7 @@ unittest equals_t opEquals ( S rhs ) { - return this.x == rhs.x && this.y == rhs.y && this.s == rhs.s; + return (&this).x == rhs.x && (&this).y == rhs.y && (&this).s == rhs.s; } } diff --git a/src/dhtproto/client/legacy/internal/registry/DhtNodeRegistry.d b/src/dhtproto/client/legacy/internal/registry/DhtNodeRegistry.d index 2aa083a1..a40ed201 100644 --- a/src/dhtproto/client/legacy/internal/registry/DhtNodeRegistry.d +++ b/src/dhtproto/client/legacy/internal/registry/DhtNodeRegistry.d @@ -72,7 +72,7 @@ public class DhtNodeRegistry : NodeRegistry, IDhtNodeRegistryInfo ***************************************************************************/ - private const expected_nodes = 100; + private static immutable expected_nodes = 100; /*************************************************************************** @@ -404,7 +404,7 @@ public class DhtNodeRegistry : NodeRegistry, IDhtNodeRegistryInfo **************************************************************************/ - public int opApply ( int delegate ( ref IDhtNodeConnectionPoolInfo ) dg ) + public int opApply ( scope int delegate ( ref IDhtNodeConnectionPoolInfo ) dg ) { int ret; @@ -583,7 +583,7 @@ public class DhtNodeRegistry : NodeRegistry, IDhtNodeRegistryInfo ***************************************************************************/ - private int opApply ( int delegate ( ref DhtNodeConnectionPool ) dg ) + private int opApply ( scope int delegate ( ref DhtNodeConnectionPool ) dg ) { int res; foreach ( pool; this.nodes.list ) @@ -605,7 +605,7 @@ public class DhtNodeRegistry : NodeRegistry, IDhtNodeRegistryInfo ***************************************************************************/ - private int opApply ( int delegate ( ref size_t, ref DhtNodeConnectionPool ) dg ) + private int opApply ( scope int delegate ( ref size_t, ref DhtNodeConnectionPool ) dg ) { int res; size_t i; diff --git a/src/dhtproto/client/legacy/internal/registry/model/IDhtNodeRegistryInfo.d b/src/dhtproto/client/legacy/internal/registry/model/IDhtNodeRegistryInfo.d index 5a6e0fea..ecbbfd44 100644 --- a/src/dhtproto/client/legacy/internal/registry/model/IDhtNodeRegistryInfo.d +++ b/src/dhtproto/client/legacy/internal/registry/model/IDhtNodeRegistryInfo.d @@ -122,7 +122,7 @@ public interface IDhtNodeRegistryInfo : INodeRegistryInfo **************************************************************************/ - public int opApply ( int delegate ( ref IDhtNodeConnectionPoolInfo ) dg ); + public int opApply ( scope int delegate ( ref IDhtNodeConnectionPoolInfo ) dg ); /*************************************************************************** diff --git a/src/dhtproto/client/legacy/internal/request/params/RequestParams.d b/src/dhtproto/client/legacy/internal/request/params/RequestParams.d index dd8553c8..2b54e650 100644 --- a/src/dhtproto/client/legacy/internal/request/params/RequestParams.d +++ b/src/dhtproto/client/legacy/internal/request/params/RequestParams.d @@ -173,7 +173,7 @@ public class RequestParams : IChannelRequestParams ***************************************************************************/ - override protected void notify_ ( void delegate ( IRequestNotification ) info_dg ) + override protected void notify_ ( scope void delegate ( IRequestNotification ) info_dg ) { scope info = new RequestNotification(cast(DhtConst.Command.E)this.command, this.context); diff --git a/src/dhtproto/client/mixins/NeoSupport.d b/src/dhtproto/client/mixins/NeoSupport.d index a7f55ec6..0dfa3f38 100644 --- a/src/dhtproto/client/mixins/NeoSupport.d +++ b/src/dhtproto/client/mixins/NeoSupport.d @@ -205,7 +205,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId put ( cstring channel, hash_t key, Const!(void)[] value, - Put.Notifier notifier ) + scope Put.Notifier notifier ) { auto params = Const!(Internals.Put.UserSpecifiedParams)( Const!(Put.Args)(channel, key, value), notifier); @@ -238,7 +238,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId get ( Options ... ) ( cstring channel, hash_t key, - Get.Notifier notifier, Options options ) + scope Get.Notifier notifier, Options options ) { auto params = Const!(Internals.Get.UserSpecifiedParams)( Const!(Get.Args)(channel, key), notifier); @@ -277,7 +277,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId exists ( cstring channel, hash_t key, - Exists.Notifier notifier ) + scope Exists.Notifier notifier ) { auto params = Const!(Internals.Exists.UserSpecifiedParams)( Const!(Exists.Args)(channel, key), notifier); @@ -307,7 +307,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId remove ( cstring channel, hash_t key, - Remove.Notifier notifier ) + scope Remove.Notifier notifier ) { auto params = Const!(Internals.Remove.UserSpecifiedParams)( Const!(Remove.Args)(channel, key), notifier); @@ -337,7 +337,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId update ( cstring channel, hash_t key, - Update.Notifier notifier ) + scope Update.Notifier notifier ) { auto params = Const!(Internals.Update.UserSpecifiedParams)( Const!(Update.Args)(channel, key), notifier); @@ -370,7 +370,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId mirror ( Options ... ) ( cstring channel, - Mirror.Notifier notifier, Options options ) + scope Mirror.Notifier notifier, Options options ) { Mirror.Settings settings; @@ -415,7 +415,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId getAll ( Options ... ) ( cstring channel, - GetAll.Notifier notifier, Options options ) + scope GetAll.Notifier notifier, Options options ) { GetAll.Settings settings; @@ -454,7 +454,7 @@ template NeoSupport ( ) ***********************************************************************/ - public RequestId getChannels ( GetChannels.Notifier notifier ) + public RequestId getChannels ( scope GetChannels.Notifier notifier ) { auto params = Const!(Internals.GetChannels.UserSpecifiedParams)( Const!(GetChannels.Args)(), notifier); @@ -484,7 +484,7 @@ template NeoSupport ( ) ***********************************************************************/ public RequestId removeChannel ( cstring channel, - RemoveChannel.Notifier notifier ) + scope RemoveChannel.Notifier notifier ) { auto params = Const!(Internals.RemoveChannel.UserSpecifiedParams)( Const!(RemoveChannel.Args)(channel), notifier); @@ -555,7 +555,7 @@ template NeoSupport ( ) ***********************************************************************/ public bool control ( ControllerInterface ) ( RequestId id, - void delegate ( ControllerInterface ) dg ) + scope void delegate ( ControllerInterface ) dg ) { alias Request!(ControllerInterface) R; @@ -753,7 +753,7 @@ template NeoSupport ( ) ***********************************************************************/ - private void waitHashRangeQuery ( bool delegate ( ) finished ) + private void waitHashRangeQuery ( scope bool delegate ( ) finished ) { auto task = Task.getThis(); verify(task !is null, "This method may only be called from inside a Task"); @@ -804,7 +804,7 @@ template NeoSupport ( ) ***********************************************************************/ public void put ( cstring channel, hash_t key, Const!(void)[] value, - Neo.Put.Notifier user_notifier ) + scope Neo.Put.Notifier user_notifier ) { verify(user_notifier !is null); auto task = Task.getThis(); @@ -934,7 +934,7 @@ template NeoSupport ( ) ***********************************************************************/ public void get ( cstring channel, hash_t key, - Neo.Get.Notifier user_notifier ) + scope Neo.Get.Notifier user_notifier ) { verify(user_notifier !is null); auto task = Task.getThis(); @@ -1079,7 +1079,7 @@ template NeoSupport ( ) ***********************************************************************/ public void update ( cstring channel, hash_t key, - Neo.Update.Notifier user_notifier ) + scope Neo.Update.Notifier user_notifier ) { verify(user_notifier !is null); auto task = Task.getThis(); @@ -1130,7 +1130,7 @@ template NeoSupport ( ) ***********************************************************************/ public void exists ( cstring channel, hash_t key, - Neo.Exists.Notifier user_notifier ) + scope Neo.Exists.Notifier user_notifier ) { verify(user_notifier !is null); auto task = Task.getThis(); @@ -1266,7 +1266,7 @@ template NeoSupport ( ) ***********************************************************************/ public void remove ( cstring channel, hash_t key, - Neo.Remove.Notifier user_notifier ) + scope Neo.Remove.Notifier user_notifier ) { verify(user_notifier !is null); auto task = Task.getThis(); @@ -1464,17 +1464,17 @@ template NeoSupport ( ) { case received: // Ignore all received value on user break. - if (this.state == State.Stopped) + if ((&this).state == State.Stopped) break; // Store the received value. - this.record_key = info.received.key; + (&this).record_key = info.received.key; - copy(*this.record_value, info.received.value); + copy(*(&this).record_value, info.received.value); - if (this.task.suspended()) + if ((&this).task.suspended()) { - this.task.resume(); + (&this).task.resume(); } break; @@ -1482,8 +1482,8 @@ template NeoSupport ( ) case finished: // Even if the user has requested stopping, // but finished arrived, we will just finish and exit. - this.state = State.Finished; - this.task.resume(); + (&this).state = State.Finished; + (&this).task.resume(); break; case suspended: // Unexepected (unsupported by blocking API) @@ -1492,12 +1492,12 @@ template NeoSupport ( ) case node_error: case unsupported: // Ignore all errors on user break. - if (this.state == State.Stopped) + if ((&this).state == State.Stopped) break; // Otherwise flag an error and allow the request to // finish normally. - this.error = true; + (&this).error = true; break; case received_key: @@ -1518,30 +1518,30 @@ template NeoSupport ( ) *******************************************************************/ - public int opApply ( int delegate ( ref hash_t key, + public int opApply ( scope int delegate ( ref hash_t key, ref void[] value ) dg ) { int ret; - this.rq_id = this.neo.getAll(this.channel, &this.notifier); + (&this).rq_id = (&this).neo.getAll((&this).channel, &(&this).notifier); - while (this.state != State.Finished) + while ((&this).state != State.Finished) { Task.getThis().suspend(); // No more records. - if (this.state == State.Finished - || this.state == State.Stopped - || this.error) + if ((&this).state == State.Finished + || (&this).state == State.Stopped + || (&this).error) break; - ret = dg(this.record_key, *this.record_value); + ret = dg((&this).record_key, *(&this).record_value); if (ret) { - this.state = State.Stopped; + (&this).state = State.Stopped; - this.neo.control(this.rq_id, + (&this).neo.control((&this).rq_id, ( Neo.GetAll.IController get_all ) { get_all.stop(); @@ -1650,33 +1650,33 @@ template NeoSupport ( ) { case received: // Ignore all received value on user break. - if (this.state == State.Stopped) + if ((&this).state == State.Stopped) break; - copy(*this.channel_name, + copy(*(&this).channel_name, cast(cstring)info.received.value); - if (this.task.suspended()) + if ((&this).task.suspended()) { - this.task.resume(); + (&this).task.resume(); } break; case finished: - this.state = State.Finished; - this.task.resume(); + (&this).state = State.Finished; + (&this).task.resume(); break; case node_disconnected: case node_error: case unsupported: // Ignore all errors on user break. - if (this.state == State.Stopped) + if ((&this).state == State.Stopped) break; // Otherwise flag an error and allow the request to // finish normally. - this.error = true; + (&this).error = true; break; mixin(typeof(info).handleInvalidCases); @@ -1689,27 +1689,27 @@ template NeoSupport ( ) *******************************************************************/ - public int opApply ( int delegate ( ref mstring channel_name ) dg ) + public int opApply ( scope int delegate ( ref mstring channel_name ) dg ) { int ret; - this.neo.getChannels(&this.notifier); + (&this).neo.getChannels(&(&this).notifier); - while (this.state != State.Finished) + while ((&this).state != State.Finished) { Task.getThis().suspend(); // No more records. - if (this.state == State.Finished - || this.state == State.Stopped - || this.error) + if ((&this).state == State.Finished + || (&this).state == State.Stopped + || (&this).error) break; - ret = dg(*this.channel_name); + ret = dg(*(&this).channel_name); if (ret) { - this.state = State.Stopped; + (&this).state = State.Stopped; // Wait for the request to finish. Task.getThis().suspend(); diff --git a/src/dhtproto/client/request/Put.d b/src/dhtproto/client/request/Put.d index cc7e0e5c..1f3df2c6 100644 --- a/src/dhtproto/client/request/Put.d +++ b/src/dhtproto/client/request/Put.d @@ -47,7 +47,7 @@ import swarm.util.RecordBatcher; // calculating the required size of a record batch based on the size of a record // that can fit in it is lacking. // See https://github.com/sociomantic-tsunami/swarm/issues/142 -public const MaxRecordSize = +public static immutable MaxRecordSize = RecordBatcher.DefaultMaxBatchSize - hash_t.sizeof - (size_t.sizeof * 2); /******************************************************************************* diff --git a/src/dhtproto/client/request/internal/Exists.d b/src/dhtproto/client/request/internal/Exists.d index e51e263c..f0be6a6b 100644 --- a/src/dhtproto/client/request/internal/Exists.d +++ b/src/dhtproto/client/request/internal/Exists.d @@ -122,7 +122,7 @@ public struct Exists ***************************************************************************/ - public static void handler ( UseNodeDg use_node, void[] context_blob ) + public static void handler ( scope UseNodeDg use_node, void[] context_blob ) { auto context = Exists.getContext(context_blob); context.shared_working.result = SharedWorking.Result.Failure; diff --git a/src/dhtproto/client/request/internal/Get.d b/src/dhtproto/client/request/internal/Get.d index af5275c4..ce3a8c95 100644 --- a/src/dhtproto/client/request/internal/Get.d +++ b/src/dhtproto/client/request/internal/Get.d @@ -136,7 +136,7 @@ public struct Get ***************************************************************************/ - public static void handler ( UseNodeDg use_node, void[] context_blob ) + public static void handler ( scope UseNodeDg use_node, void[] context_blob ) { auto context = Get.getContext(context_blob); context.shared_working.result = SharedWorking.Result.Failure; diff --git a/src/dhtproto/client/request/internal/GetChannels.d b/src/dhtproto/client/request/internal/GetChannels.d index e9cb4b1e..f0b8dace 100644 --- a/src/dhtproto/client/request/internal/GetChannels.d +++ b/src/dhtproto/client/request/internal/GetChannels.d @@ -94,11 +94,11 @@ public struct GetChannels // Acquire the array of channel name slices that is shared by all // RoCs, if it's not already acquired. - if ( this.notified_channels == typeof(this.notified_channels).init ) - this.notified_channels = resources.getBufferList(); + if ( (&this).notified_channels == typeof((&this).notified_channels).init ) + (&this).notified_channels = resources.getBufferList(); else already_notified = - (this.notified_channels.array().contains(channel) == true); + ((&this).notified_channels.array().contains(channel) == true); // If this channel name has not been seen before, copy it into a new // buffer and add a slice to that buffer to the array of channel @@ -108,7 +108,7 @@ public struct GetChannels auto buf = resources.getVoidBuffer(); auto void_channel = cast(void[])channel; (*buf).copy(void_channel); - this.notified_channels ~= cast(char[])(*buf); + (&this).notified_channels ~= cast(char[])(*buf); } return !already_notified; diff --git a/src/dhtproto/client/request/internal/Put.d b/src/dhtproto/client/request/internal/Put.d index 47de28ef..cc822d99 100644 --- a/src/dhtproto/client/request/internal/Put.d +++ b/src/dhtproto/client/request/internal/Put.d @@ -114,7 +114,7 @@ public struct Put ***************************************************************************/ - public static void handler ( UseNodeDg use_node, void[] context_blob ) + public static void handler ( scope UseNodeDg use_node, void[] context_blob ) { auto context = Put.getContext(context_blob); context.shared_working.result = SharedWorking.Result.Failure; diff --git a/src/dhtproto/client/request/internal/Remove.d b/src/dhtproto/client/request/internal/Remove.d index c632a1af..722c2058 100644 --- a/src/dhtproto/client/request/internal/Remove.d +++ b/src/dhtproto/client/request/internal/Remove.d @@ -116,7 +116,7 @@ public struct Remove ***************************************************************************/ - public static void handler ( UseNodeDg use_node, void[] context_blob ) + public static void handler ( scope UseNodeDg use_node, void[] context_blob ) { auto context = Remove.getContext(context_blob); context.shared_working.result = SharedWorking.Result.Failure; diff --git a/src/dhtproto/client/request/internal/Update.d b/src/dhtproto/client/request/internal/Update.d index c1d91989..7af70899 100644 --- a/src/dhtproto/client/request/internal/Update.d +++ b/src/dhtproto/client/request/internal/Update.d @@ -119,7 +119,7 @@ public struct Update SharedWorking, Notification); /// Fiber resume code. - const SecondROCFinished = 1; + enum SecondROCFinished = 1; /*************************************************************************** @@ -141,8 +141,8 @@ public struct Update ***************************************************************************/ - public static void handler ( UseNodeDg use_node, - NewRequestOnConnDg new_request_on_conn, void[] context_blob ) + public static void handler ( scope UseNodeDg use_node, + scope NewRequestOnConnDg new_request_on_conn, void[] context_blob ) { auto context = Update.getContext(context_blob); context.shared_working.result = SharedWorking.Result.Error; @@ -255,18 +255,18 @@ private struct FirstROCHandler public void handle ( ) { auto shared_resources = SharedResources.fromObject( - this.context.shared_resources); + (&this).context.shared_resources); scope acquired_resources = shared_resources.new RequestResources; // Get the list of nodes reponsible for this hash. auto nodes = shared_resources.node_hash_ranges.getNodesForHash( - this.context.user_params.args.key, + (&this).context.user_params.args.key, acquired_resources.getNodeHashRangeBuffer()); // If no node covers the record's hash, exit. if ( nodes.array.length == 0 ) { - this.context.shared_working.result = + (&this).context.shared_working.result = Update.SharedWorking.Result.NoNode; return; } @@ -279,12 +279,12 @@ private struct FirstROCHandler scope conn_dg = ( RequestOnConn.EventDispatcher conn ) { - auto ret = this.tryConnection(conn, nodes.array[0].addr, + auto ret = (&this).tryConnection(conn, nodes.array[0].addr, acquired_resources); with ( Action ) final switch ( ret ) { case Success: - this.context.shared_working.result = + (&this).context.shared_working.result = Update.SharedWorking.Result.Succeeded; success = true; break; @@ -302,7 +302,7 @@ private struct FirstROCHandler } } }; - this.use_node(node_hash_range.addr, conn_dg); + (&this).use_node(node_hash_range.addr, conn_dg); if ( error ) break; @@ -310,7 +310,7 @@ private struct FirstROCHandler // The specified record does not currently exist in the DHT. Do nothing. if ( !success && !error ) - this.context.shared_working.result = + (&this).context.shared_working.result = Update.SharedWorking.Result.NoRecord; } @@ -339,7 +339,7 @@ private struct FirstROCHandler try { // Start the request on this node. - auto ret = this.queryValueFromNode(conn); + auto ret = (&this).queryValueFromNode(conn); if ( ret != Action.Success ) return ret; @@ -349,7 +349,7 @@ private struct FirstROCHandler conn.receive( ( in void[] const_payload ) { - ret = this.handleResponse(conn, const_payload, + ret = (&this).handleResponse(conn, const_payload, acquired_resources); } ); @@ -358,18 +358,18 @@ private struct FirstROCHandler // If a value was received, send the updated value to the DHT. bool success; - if ( this.context.shared_working.updated_value !is null ) + if ( (&this).context.shared_working.updated_value !is null ) { if ( conn.remote_address == newest_responsible_node_addr ) - success = this.updateOnNode(conn); + success = (&this).updateOnNode(conn); else - success = this.updateOnDifferentNode(conn, + success = (&this).updateOnDifferentNode(conn, newest_responsible_node_addr); } // If the user did not provide an updated value, tell the node to // leave the record as is. else - success = this.leaveRecordOnNode(conn); + success = (&this).leaveRecordOnNode(conn); return success ? Action.Success : Action.Abort; } @@ -378,8 +378,8 @@ private struct FirstROCHandler // Notify user of connection error. Update.Notification n; n.node_disconnected = RequestNodeExceptionInfo( - this.context.request_id, conn.remote_address, e); - Update.notify(this.context.user_params, n); + (&this).context.request_id, conn.remote_address, e); + Update.notify((&this).context.user_params, n); return Action.Abort; } } @@ -405,8 +405,8 @@ private struct FirstROCHandler payload.add(Update.cmd.code); payload.add(Update.cmd.ver); payload.addCopy(MessageType.GetRecord); - payload.addArray(this.context.user_params.args.channel); - payload.add(this.context.user_params.args.key); + payload.addArray((&this).context.user_params.args.channel); + payload.add((&this).context.user_params.args.key); } ); @@ -415,7 +415,7 @@ private struct FirstROCHandler // Receive supported code from node. auto supported = conn.receiveValue!(SupportedStatus)(); - if ( !Update.handleSupportedCodes(supported, this.context, + if ( !Update.handleSupportedCodes(supported, (&this).context, conn.remote_address) ) { // Unsupported; abort request. @@ -453,16 +453,16 @@ private struct FirstROCHandler case RecordValue: auto value = conn.message_parser.getArray!(void)(payload); - this.context.shared_working.original_hash = Fnv1a(value); - verify(this.context.shared_working.updated_value is null); - this.context.shared_working.updated_value = + (&this).context.shared_working.original_hash = Fnv1a(value); + verify((&this).context.shared_working.updated_value is null); + (&this).context.shared_working.updated_value = acquired_resources.getVoidBuffer(); Update.Notification n; n.received = RequestDataUpdateInfo( - this.context.request_id, value, - this.context.shared_working.updated_value); - Update.notify(this.context.user_params, n); + (&this).context.request_id, value, + (&this).context.shared_working.updated_value); + Update.notify((&this).context.user_params, n); return Action.Success; @@ -473,17 +473,17 @@ private struct FirstROCHandler case WrongNode: // The node is not reponsible for the key. Notify the user. Update.Notification n; - n.wrong_node = RequestNodeInfo(this.context.request_id, + n.wrong_node = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return Action.Abort; case Error: // The node returned an error code. Notify the user. Update.Notification n; - n.node_error = RequestNodeInfo(this.context.request_id, + n.node_error = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return Action.Abort; default: @@ -513,8 +513,8 @@ private struct FirstROCHandler ( conn.Payload payload ) { payload.addCopy(MessageType.UpdateRecord); - payload.add(this.context.shared_working.original_hash); - payload.addArray(*this.context.shared_working.updated_value); + payload.add((&this).context.shared_working.original_hash); + payload.addArray(*(&this).context.shared_working.updated_value); } ); @@ -529,16 +529,16 @@ private struct FirstROCHandler return true; case UpdateConflict: - this.context.shared_working.result = + (&this).context.shared_working.result = Update.SharedWorking.Result.Conflict; return false; case Error: // The node returned an error code. Notify the user. Update.Notification n; - n.node_error = RequestNodeInfo(this.context.request_id, + n.node_error = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return false; default: @@ -571,8 +571,8 @@ private struct FirstROCHandler private bool updateOnDifferentNode ( RequestOnConn.EventDispatcher conn, AddrPort second_node_addr ) { - this.context.shared_working.first_request_on_conn = conn; - this.context.shared_working.second_node_addr = second_node_addr; + (&this).context.shared_working.first_request_on_conn = conn; + (&this).context.shared_working.second_node_addr = second_node_addr; // Start a new request-on-conn to write to the other node. This will // cause the static `handler()` function to be called again in a new @@ -591,7 +591,7 @@ private struct FirstROCHandler // If the request on the second request-on-conn failed, the result code // will already have been set in the shared working data. - if ( this.context.shared_working.second_node_failed ) + if ( (&this).context.shared_working.second_node_failed ) return false; // Send message to the node that was read from, informing it that the @@ -616,9 +616,9 @@ private struct FirstROCHandler case Error: // The node returned an error code. Notify the user. Update.Notification n; - n.node_error = RequestNodeInfo(this.context.request_id, + n.node_error = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return false; default: @@ -667,9 +667,9 @@ private struct FirstROCHandler case Error: // The node returned an error code. Notify the user. Update.Notification n; - n.node_error = RequestNodeInfo(this.context.request_id, + n.node_error = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return false; default: @@ -709,10 +709,10 @@ private struct SecondROCHandler scope conn_dg = ( RequestOnConn.EventDispatcher conn ) { - if ( !this.handleRequest(conn) ) - this.context.shared_working.second_node_failed = true; + if ( !(&this).handleRequest(conn) ) + (&this).context.shared_working.second_node_failed = true; }; - this.use_node(this.context.shared_working.second_node_addr, conn_dg); + (&this).use_node((&this).context.shared_working.second_node_addr, conn_dg); } /*************************************************************************** @@ -739,10 +739,10 @@ private struct SecondROCHandler payload.add(Update.cmd.code); payload.add(Update.cmd.ver); payload.addCopy(MessageType.UpdateRecord); - payload.addArray(this.context.user_params.args.channel); - payload.add(this.context.user_params.args.key); - payload.add(this.context.shared_working.original_hash); - payload.addArray(*this.context.shared_working.updated_value); + payload.addArray((&this).context.user_params.args.channel); + payload.add((&this).context.user_params.args.key); + payload.add((&this).context.shared_working.original_hash); + payload.addArray(*(&this).context.shared_working.updated_value); } ); @@ -751,7 +751,7 @@ private struct SecondROCHandler // Receive supported code from node. auto supported = conn.receiveValue!(SupportedStatus)(); - if ( !Update.handleSupportedCodes(supported, this.context, + if ( !Update.handleSupportedCodes(supported, (&this).context, conn.remote_address) ) { // Request not supported; abort further handling. @@ -766,24 +766,24 @@ private struct SecondROCHandler return true; case UpdateConflict: - this.context.shared_working.result = + (&this).context.shared_working.result = Update.SharedWorking.Result.Conflict; return false; case WrongNode: // The node is not reponsible for the key. Notify the user. Update.Notification n; - n.wrong_node = RequestNodeInfo(this.context.request_id, + n.wrong_node = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return false; case Error: // The node returned an error code. Notify the user. Update.Notification n; - n.node_error = RequestNodeInfo(this.context.request_id, + n.node_error = RequestNodeInfo((&this).context.request_id, conn.remote_address); - Update.notify(this.context.user_params, n); + Update.notify((&this).context.user_params, n); return false; default: @@ -798,8 +798,8 @@ private struct SecondROCHandler // Notify user of connection error. Update.Notification n; n.node_disconnected = RequestNodeExceptionInfo( - this.context.request_id, conn.remote_address, e); - Update.notify(this.context.user_params, n); + (&this).context.request_id, conn.remote_address, e); + Update.notify((&this).context.user_params, n); return false; } diff --git a/src/dhtproto/node/neo/request/Get.d b/src/dhtproto/node/neo/request/Get.d index 581309fe..3ee9a00b 100644 --- a/src/dhtproto/node/neo/request/Get.d +++ b/src/dhtproto/node/neo/request/Get.d @@ -86,7 +86,7 @@ public abstract class GetProtocol_v0 : IRequestHandler auto ed = this.connection.event_dispatcher(); void sendResponse ( MessageType status_code, - void delegate ( ed.Payload ) extra = null ) + scope void delegate ( ed.Payload ) extra = null ) { ed.send( ( ed.Payload payload ) @@ -163,5 +163,5 @@ public abstract class GetProtocol_v0 : IRequestHandler ***************************************************************************/ abstract protected bool get ( cstring channel, hash_t key, - void delegate ( Const!(void)[] value ) dg ); + scope void delegate ( Const!(void)[] value ) dg ); } diff --git a/src/dhtproto/node/neo/request/GetAll.d b/src/dhtproto/node/neo/request/GetAll.d index 861b4bc7..ca37fff1 100644 --- a/src/dhtproto/node/neo/request/GetAll.d +++ b/src/dhtproto/node/neo/request/GetAll.d @@ -89,8 +89,8 @@ public abstract class GetAllProtocol_v0 : IRequestHandler { if ( filter.length > 0 ) { - this.matcher = search(cast(Const!(ubyte)[])filter); - this.active = true; + (&this).matcher = search(cast(Const!(ubyte)[])filter); + (&this).active = true; } } @@ -109,8 +109,8 @@ public abstract class GetAllProtocol_v0 : IRequestHandler public bool match ( in void[] value ) { - if ( this.active ) - return this.matcher.forward(cast(Const!(ubyte)[])value) + if ( (&this).active ) + return (&this).matcher.forward(cast(Const!(ubyte)[])value) < value.length; else return true; @@ -269,7 +269,7 @@ public abstract class GetAllProtocol_v0 : IRequestHandler ***************************************************************************/ abstract protected bool getNext ( - void delegate ( hash_t key, Const!(void)[] value ) dg ); + scope void delegate ( hash_t key, Const!(void)[] value ) dg ); /*************************************************************************** @@ -292,7 +292,7 @@ public abstract class GetAllProtocol_v0 : IRequestHandler public DelayedSuspender suspender; /// Fiber resume code used to resume DelayedSuspender. - private const ResumeAfterSuspension = 1; + private static immutable ResumeAfterSuspension = 1; /*********************************************************************** diff --git a/src/dhtproto/node/neo/request/GetChannels.d b/src/dhtproto/node/neo/request/GetChannels.d index 7a1c49b0..acd7d4d9 100644 --- a/src/dhtproto/node/neo/request/GetChannels.d +++ b/src/dhtproto/node/neo/request/GetChannels.d @@ -96,5 +96,5 @@ public abstract class GetChannelsProtocol_v0 : IRequestHandler ***************************************************************************/ - protected abstract int opApply ( int delegate ( ref cstring ) dg ); + protected abstract int opApply ( scope int delegate ( ref cstring ) dg ); } diff --git a/src/dhtproto/node/neo/request/Mirror.d b/src/dhtproto/node/neo/request/Mirror.d index b481c385..94fa8a09 100644 --- a/src/dhtproto/node/neo/request/Mirror.d +++ b/src/dhtproto/node/neo/request/Mirror.d @@ -86,7 +86,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler private E[] queue; /// Maximum allowed size of the queue in bytes. - private const max_size = 256 * 1024; + private enum max_size = 256 * 1024; /// Maximum allowed elements of type E of the queue. private size_t max_elems; @@ -103,11 +103,11 @@ public abstract class MirrorProtocol_v0 : IRequestHandler /// Tests for basic sanity of num_elems and the read/write indices. invariant ( ) { - if ( this.num_elems == 0 ) - assert(this.write_to_elem == this.read_from_elem); + if ( (&this).num_elems == 0 ) + assert((&this).write_to_elem == (&this).read_from_elem); else - assert(this.write_to_elem == - (this.read_from_elem + this.num_elems) % this.max_elems); + assert((&this).write_to_elem == + ((&this).read_from_elem + (&this).num_elems) % (&this).max_elems); } /*********************************************************************** @@ -122,9 +122,9 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public void initialise ( ref void[] buf ) { - this.max_elems = (max_size / E.sizeof) * E.sizeof; - buf.length = this.max_elems * E.sizeof; - this.queue = cast(E[])buf; + (&this).max_elems = (max_size / E.sizeof) * E.sizeof; + buf.length = (&this).max_elems * E.sizeof; + (&this).queue = cast(E[])buf; } /*********************************************************************** @@ -141,12 +141,12 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public bool push ( E e ) { - if ( this.num_elems >= this.max_elems ) + if ( (&this).num_elems >= (&this).max_elems ) return false; - this.queue[this.write_to_elem] = e; - this.incWrap(this.write_to_elem); - this.num_elems++; + (&this).queue[(&this).write_to_elem] = e; + (&this).incWrap((&this).write_to_elem); + (&this).num_elems++; return true; } @@ -163,11 +163,11 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public E pop ( ) { - verify(this.num_elems > 0); + verify((&this).num_elems > 0); E e; - e = this.queue[this.read_from_elem]; - this.incWrap(this.read_from_elem); - this.num_elems--; + e = (&this).queue[(&this).read_from_elem]; + (&this).incWrap((&this).read_from_elem); + (&this).num_elems--; return e; } @@ -181,7 +181,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public size_t length ( ) { - return this.num_elems; + return (&this).num_elems; } /*********************************************************************** @@ -193,7 +193,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public bool isFull ( ) { - return this.num_elems == this.max_elems; + return (&this).num_elems == (&this).max_elems; } /*********************************************************************** @@ -209,8 +209,8 @@ public abstract class MirrorProtocol_v0 : IRequestHandler private void incWrap ( ref size_t elem_index ) { elem_index++; - verify(elem_index <= this.max_elems); - if ( elem_index == this.max_elems ) + verify(elem_index <= (&this).max_elems); + if ( elem_index == (&this).max_elems ) elem_index = 0; } } @@ -222,7 +222,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler Queue!(Update) q; q.initialise(backing); - const elems_per_cycle = 7; + static immutable elems_per_cycle = 7; uint write_wraps, read_wraps; Update update; for ( uint i; i < q.max_elems; i++ ) @@ -292,8 +292,8 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public void opPostInc ( ) { - this.last_overflow_time = time(null); - this.count_since_last_notification++; + (&this).last_overflow_time = time(null); + (&this).count_since_last_notification++; } /*********************************************************************** @@ -305,7 +305,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public bool notification_pending ( ) { - return this.last_overflow_time > this.last_notified_overflow_time; + return (&this).last_overflow_time > (&this).last_notified_overflow_time; } /*********************************************************************** @@ -316,8 +316,8 @@ public abstract class MirrorProtocol_v0 : IRequestHandler public void notification_sent ( ) { - this.last_notified_overflow_time = this.last_overflow_time; - this.count_since_last_notification = 0; + (&this).last_notified_overflow_time = (&this).last_overflow_time; + (&this).count_since_last_notification = 0; } } @@ -419,7 +419,7 @@ public abstract class MirrorProtocol_v0 : IRequestHandler this.value_buffer = this.resources.getVoidBuffer(); this.update_queue.initialise(*this.resources.getVoidBuffer()); this.refresh_queue.initialise(*this.resources.getVoidBuffer()); - const max_batch_size = 64 * 1024; // TODO: read from config + static immutable max_batch_size = 64 * 1024; // TODO: read from config this.refresh_batch.initialise(this.resources.getVoidBuffer(), max_batch_size); this.compress_buffer = this.resources.getVoidBuffer(); diff --git a/src/dhtproto/node/neo/request/Update.d b/src/dhtproto/node/neo/request/Update.d index 4326181c..346f6533 100644 --- a/src/dhtproto/node/neo/request/Update.d +++ b/src/dhtproto/node/neo/request/Update.d @@ -283,7 +283,7 @@ public abstract class UpdateProtocol_v0 : IRequestHandler ***************************************************************************/ abstract protected bool get ( cstring channel, hash_t key, - void delegate ( Const!(void)[] value ) dg ); + scope void delegate ( Const!(void)[] value ) dg ); /*************************************************************************** diff --git a/src/dhtproto/node/neo/request/core/IRequestResources.d b/src/dhtproto/node/neo/request/core/IRequestResources.d index e59e73fc..a70106f7 100644 --- a/src/dhtproto/node/neo/request/core/IRequestResources.d +++ b/src/dhtproto/node/neo/request/core/IRequestResources.d @@ -55,7 +55,7 @@ public interface IRequestResources ***************************************************************************/ - MessageFiber getFiber ( void delegate ( ) fiber_method ); + MessageFiber getFiber ( scope void delegate ( ) fiber_method ); /*************************************************************************** @@ -82,7 +82,7 @@ public interface IRequestResources ***************************************************************************/ - ITimer getTimer ( uint period_s, uint period_ms, void delegate ( ) timer_dg ); + ITimer getTimer ( uint period_s, uint period_ms, scope void delegate ( ) timer_dg ); /*************************************************************************** diff --git a/src/dhttest/DhtClient.d b/src/dhttest/DhtClient.d index 3ca542ba..cb4563ee 100644 --- a/src/dhttest/DhtClient.d +++ b/src/dhttest/DhtClient.d @@ -185,7 +185,7 @@ class DhtClient { this.log = Log.lookup("dhttest"); - const max_connections = 2; + static immutable max_connections = 2; this.swarm_client = new SwarmClient(theScheduler.epoll, max_connections); } @@ -551,7 +551,7 @@ class DhtClient public Listener startListen ( cstring channel ) { - const hash_t key = 0xDEAD; + static immutable hash_t key = 0xDEAD; auto listener = new Listener; diff --git a/src/dhttest/DhtTestCase.d b/src/dhttest/DhtTestCase.d index b2eb416c..d664ee7f 100644 --- a/src/dhttest/DhtTestCase.d +++ b/src/dhttest/DhtTestCase.d @@ -192,7 +192,7 @@ abstract class NeoDhtTestCase : TestCase { cstring auth_name = "admin"; auto auth_key = Key.init; - const max_connections = 2; + static immutable max_connections = 2; this.dht = new DhtClient(theScheduler.epoll, auth_name, auth_key.content, &this.neoConnectionNotifier, max_connections); diff --git a/src/dhttest/cases/Basic.d b/src/dhttest/cases/Basic.d index 3be78d76..9f9153b1 100644 --- a/src/dhttest/cases/Basic.d +++ b/src/dhttest/cases/Basic.d @@ -23,7 +23,7 @@ import ocean.transition; import ocean.core.Test; import dhttest.DhtTestCase; -const PRIORITY = 100; +static immutable PRIORITY = 100; /******************************************************************************* diff --git a/src/dhttest/cases/BasicListen.d b/src/dhttest/cases/BasicListen.d index 3ef6c6ef..efadfcf0 100644 --- a/src/dhttest/cases/BasicListen.d +++ b/src/dhttest/cases/BasicListen.d @@ -26,7 +26,7 @@ import ocean.core.Test; import ocean.io.select.fiber.SelectFiber; import ocean.io.select.client.FiberTimerEvent; -const PRIORITY = 90; +static immutable PRIORITY = 90; /******************************************************************************* @@ -51,7 +51,7 @@ class ListenRemovedChannel : DhtTestCase override public void run ( ) { auto listener = this.dht.startListen(this.test_channel); - const key = 0; + static immutable key = 0; this.dht.put(this.test_channel, key, "whatever"[]); listener.waitNextEvent(); test(!listener.finished); @@ -87,7 +87,7 @@ class ListenTrigger : DhtTestCase { auto listener = this.dht.startListen(this.test_channel); - const key = 5; + static immutable key = 5; this.dht.put(this.test_channel, key, "value"[]); listener.waitNextEvent(); test!("==")(listener.data.length, 1); diff --git a/src/dhttest/cases/neo/GetAll.d b/src/dhttest/cases/neo/GetAll.d index abc9332b..6aa69c74 100644 --- a/src/dhttest/cases/neo/GetAll.d +++ b/src/dhttest/cases/neo/GetAll.d @@ -44,7 +44,7 @@ public class GetAllBlocking : NeoDhtTestCase { auto task = Task.getThis(); - const num_records = 1000; + static immutable num_records = 1000; putRecords(this.dht, this.test_channel, num_records); void[] buf; @@ -87,7 +87,7 @@ public class GetAllSuspend : NeoDhtTestCase { auto task = Task.getThis(); - const num_records = 1000; + static immutable num_records = 1000; putRecords(this.dht, this.test_channel, num_records); auto getall = GetAll(this.dht); @@ -168,7 +168,7 @@ public class GetAllConnError : NeoDhtTestCase { auto task = Task.getThis(); - const num_records = 1000; + static immutable num_records = 1000; putRecords(this.dht, this.test_channel, num_records); uint disconnection_count; @@ -272,16 +272,16 @@ private struct GetAll ***************************************************************************/ public void start ( cstring channel, - DhtClient.Neo.GetAll.Notifier user_notifier ) + scope DhtClient.Neo.GetAll.Notifier user_notifier ) out { - assert(this.user_notifier !is null); + assert((&this).user_notifier !is null); } body { - verify(this.user_notifier is null); - this.user_notifier = user_notifier; - this.id = this.dht.neo.getAll(channel, &this.counterNotifier); + verify((&this).user_notifier is null); + (&this).user_notifier = user_notifier; + (&this).id = (&this).dht.neo.getAll(channel, &(&this).counterNotifier); } /*************************************************************************** @@ -294,8 +294,8 @@ private struct GetAll public void suspend ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.GetAll.IController getall ) { getall.suspend(); @@ -313,8 +313,8 @@ private struct GetAll public void resume ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.GetAll.IController getall ) { getall.resume(); @@ -331,8 +331,8 @@ private struct GetAll public void stop ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.GetAll.IController getall ) { getall.stop(); @@ -357,15 +357,15 @@ private struct GetAll with ( info.Active ) switch ( info.active ) { case received: - if ( info.received.key in this.received_keys ) - this.duplicate = true; - this.received_keys[info.received.key] = true; + if ( info.received.key in (&this).received_keys ) + (&this).duplicate = true; + (&this).received_keys[info.received.key] = true; break; default: break; } - this.user_notifier(info, args); + (&this).user_notifier(info, args); } } diff --git a/src/dhttest/cases/neo/GetChannels.d b/src/dhttest/cases/neo/GetChannels.d index 586ead79..bfa543df 100644 --- a/src/dhttest/cases/neo/GetChannels.d +++ b/src/dhttest/cases/neo/GetChannels.d @@ -31,7 +31,7 @@ public class GetChannels : NeoDhtTestCase import ocean.task.Task; import ocean.core.array.Search : contains; - private const channels = ["channel1", "channel2", "channel3", "channel4"]; + private static immutable channels = ["channel1", "channel2", "channel3", "channel4"]; override public Description description ( ) { @@ -80,7 +80,7 @@ public class GetChannelsRemove : NeoDhtTestCase import ocean.task.Task; import ocean.core.array.Search : contains; - private const channels = ["channel1", "channel2", "channel3", "channel4"]; + private static immutable channels = ["channel1", "channel2", "channel3", "channel4"]; override public Description description ( ) { diff --git a/src/dhttest/cases/neo/Mirror.d b/src/dhttest/cases/neo/Mirror.d index aa3be834..7b622e56 100644 --- a/src/dhttest/cases/neo/Mirror.d +++ b/src/dhttest/cases/neo/Mirror.d @@ -50,7 +50,7 @@ public class MirrorRemove : NeoDhtTestCase void delNotifier ( DhtClient.RequestNotification info ) { } - const end_after_deletions = 5; + static immutable end_after_deletions = 5; auto mirror = Mirror(this.dht); mirror.start(mirror_settings, this.test_channel, ( DhtClient.Neo.Mirror.Notification info, @@ -120,7 +120,7 @@ public class MirrorUpdate : NeoDhtTestCase void putNotifier ( DhtClient.Neo.Put.Notification info, Const!(DhtClient.Neo.Put.Args) args ) { } - const num_written = 100; + static immutable num_written = 100; auto mirror = Mirror(this.dht); mirror.start(mirror_settings, this.test_channel, ( DhtClient.Neo.Mirror.Notification info, @@ -181,7 +181,7 @@ public class MirrorConnError : NeoDhtTestCase { auto task = Task.getThis(); - const num_written = 100; + static immutable num_written = 100; putRecords(this.dht, this.test_channel, num_written); DhtClient.Neo.Mirror.Settings mirror_settings; @@ -261,7 +261,7 @@ public class MirrorSuspend : NeoDhtTestCase mirror_settings.initial_refresh = false; mirror_settings.periodic_refresh_s = 0; - const end_after_updates = 1_000; + static immutable end_after_updates = 1_000; size_t num_written; auto mirror = Mirror(this.dht); @@ -372,10 +372,10 @@ public class MirrorRefresh : NeoDhtTestCase mirror_settings.initial_refresh = false; mirror_settings.periodic_refresh_s = 1; - const num_written = 1_000; + static immutable num_written = 1_000; putRecords(this.dht, this.test_channel, num_written); - const end_after_refreshes = num_written * 3; + static immutable end_after_refreshes = num_written * 3; auto mirror = Mirror(this.dht); mirror.start(mirror_settings, this.test_channel, ( DhtClient.Neo.Mirror.Notification info, @@ -434,7 +434,7 @@ public class MirrorRefreshSuspend : NeoDhtTestCase mirror_settings.initial_refresh = false; mirror_settings.periodic_refresh_s = 1; - const num_written = 500; + static immutable num_written = 500; putRecords(this.dht, this.test_channel, num_written); auto mirror = Mirror(this.dht); @@ -448,7 +448,7 @@ public class MirrorRefreshSuspend : NeoDhtTestCase ); bool mirror_suspended; - const end_after_refreshes = num_written * 3; + static immutable end_after_refreshes = num_written * 3; bool received_while_suspended; mirror.start(mirror_settings, this.test_channel, ( DhtClient.Neo.Mirror.Notification info, @@ -577,7 +577,7 @@ public class MirrorRemoveChannel : NeoDhtTestCase *******************************************************************************/ private void putRecords ( DhtClient dht, cstring channel, size_t num_records, - DhtClient.Neo.Put.Notifier notifier = null ) + scope DhtClient.Neo.Put.Notifier notifier = null ) { ubyte[] val; val.length = 128; @@ -631,16 +631,16 @@ private struct Mirror ***************************************************************************/ public void start ( DhtClient.Neo.Mirror.Settings mirror_settings, - cstring channel, DhtClient.Neo.Mirror.Notifier user_notifier ) + cstring channel, scope DhtClient.Neo.Mirror.Notifier user_notifier ) out { - assert(this.user_notifier !is null); + assert((&this).user_notifier !is null); } body { - verify(this.user_notifier is null); - this.user_notifier = user_notifier; - this.id = this.dht.neo.mirror(channel, &this.counterNotifier, + verify((&this).user_notifier is null); + (&this).user_notifier = user_notifier; + (&this).id = (&this).dht.neo.mirror(channel, &(&this).counterNotifier, mirror_settings); } @@ -654,8 +654,8 @@ private struct Mirror public void suspend ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.Mirror.IController mirror ) { mirror.suspend(); @@ -673,8 +673,8 @@ private struct Mirror public void resume ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.Mirror.IController mirror ) { mirror.resume(); @@ -691,8 +691,8 @@ private struct Mirror public void stop ( ) { - verify(this.id != this.id.init); - this.dht.neo.control(this.id, + verify((&this).id != (&this).id.init); + (&this).dht.neo.control((&this).id, ( DhtClient.Neo.Mirror.IController mirror ) { mirror.stop(); @@ -717,21 +717,21 @@ private struct Mirror with ( info.Active ) switch ( info.active ) { case updated: - this.updated_count++; + (&this).updated_count++; break; case refreshed: - this.refreshed_count++; + (&this).refreshed_count++; break; case deleted: - this.deleted_count++; + (&this).deleted_count++; break; default: break; } - this.user_notifier(info, args); + (&this).user_notifier(info, args); } } diff --git a/src/dhttest/util/LocalStore.d b/src/dhttest/util/LocalStore.d index 7b8b116f..9f6159dd 100644 --- a/src/dhttest/util/LocalStore.d +++ b/src/dhttest/util/LocalStore.d @@ -54,7 +54,7 @@ struct LocalStore public void put ( hash_t key, cstring val ) { - this.data[key] = val.dup; + (&this).data[key] = val.dup; } /*************************************************************************** @@ -68,7 +68,7 @@ struct LocalStore public void remove ( hash_t key ) { - this.data.remove(key); + (&this).data.remove(key); } } @@ -107,14 +107,14 @@ public struct LegacyVerifier public void verifyAgainstDht ( ref LocalStore local, DhtClient dht, cstring channel ) { - this.local = &local; - - this.verifyGetChannelSize(dht, channel); - this.verifyGetAll(dht, channel); - this.verifyGetAllFilter(dht, channel); - this.verifyGetAllKeys(dht, channel); - this.verifyExists(dht, channel); - this.verifyGet(dht, channel); + (&this).local = &local; + + (&this).verifyGetChannelSize(dht, channel); + (&this).verifyGetAll(dht, channel); + (&this).verifyGetAllFilter(dht, channel); + (&this).verifyGetAllKeys(dht, channel); + (&this).verifyExists(dht, channel); + (&this).verifyGet(dht, channel); } /*************************************************************************** @@ -136,8 +136,8 @@ public struct LegacyVerifier ulong records, bytes; dht.getChannelSize(channel, records, bytes); log.trace("\tVerifying channel with GetChannelSize: local:{}, remote:{}", - this.local.data.length, records); - test!("==")(this.local.data.length, records); + (&this).local.data.length, records); + test!("==")((&this).local.data.length, records); } /*************************************************************************** @@ -158,13 +158,13 @@ public struct LegacyVerifier { auto remote = dht.getAll(channel); log.trace("\tVerifying channel with GetAll: local:{}, remote:{}", - this.local.data.length, remote.length); - test!("==")(this.local.data.length, remote.length); + (&this).local.data.length, remote.length); + test!("==")((&this).local.data.length, remote.length); foreach ( k, v; remote ) { - test!("in")(k, this.local.data); - test!("==")(v, this.local.data[k]); + test!("in")(k, (&this).local.data); + test!("==")(v, (&this).local.data[k]); } } @@ -186,10 +186,10 @@ public struct LegacyVerifier private void verifyGetAllFilter ( DhtClient dht, cstring channel ) { - const filter = "0"; + enum filter = "0"; hash_t[] local; - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) { if ( v.contains(filter) ) local ~= k; @@ -203,7 +203,7 @@ public struct LegacyVerifier foreach ( k, v; remote ) { test(local.contains(k)); - test!("==")(v, this.local.data[k]); + test!("==")(v, (&this).local.data[k]); } } @@ -225,12 +225,12 @@ public struct LegacyVerifier { auto remote = dht.getAllKeys(channel); log.trace("\tVerifying channel with GetAllKeys: local:{}, remote:{}", - this.local.data.length, remote.length); - test!("==")(this.local.data.length, remote.length); + (&this).local.data.length, remote.length); + test!("==")((&this).local.data.length, remote.length); foreach ( k; remote ) { - test!("in")(k, this.local.data); + test!("in")(k, (&this).local.data); } } @@ -251,7 +251,7 @@ public struct LegacyVerifier private void verifyExists ( DhtClient dht, cstring channel ) { log.trace("\tVerifying channel with Exists"); - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) { auto exists = dht.exists(channel, k); test(exists); @@ -275,7 +275,7 @@ public struct LegacyVerifier private void verifyGet ( DhtClient dht, cstring channel ) { log.trace("\tVerifying channel with Get"); - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) { auto remote_v = dht.get(channel, k); test!("==")(remote_v, v); @@ -319,14 +319,14 @@ public struct NeoVerifier public void verifyAgainstDht ( ref LocalStore local, DhtClient dht, cstring channel ) { - this.local = &local; - - this.verifyGetChannels(dht, channel); - this.verifyGet(dht, channel); - this.verifyExists(dht, channel); - this.verifyGetAll(dht, channel); - this.verifyGetAllKeysOnly(dht, channel); - this.verifyGetAllFilter(dht, channel); + (&this).local = &local; + + (&this).verifyGetChannels(dht, channel); + (&this).verifyGet(dht, channel); + (&this).verifyExists(dht, channel); + (&this).verifyGetAll(dht, channel); + (&this).verifyGetAllKeysOnly(dht, channel); + (&this).verifyGetAllFilter(dht, channel); } /*************************************************************************** @@ -346,7 +346,7 @@ public struct NeoVerifier private void verifyGet ( DhtClient dht, cstring channel ) { log.trace("\tVerifying channel with Get"); - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) { void[] buf; auto res = dht.blocking.get(channel, k, buf); @@ -372,7 +372,7 @@ public struct NeoVerifier private void verifyExists ( DhtClient dht, cstring channel ) { log.trace("\tVerifying channel with Exists"); - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) { auto res = dht.blocking.exists(channel, k); test(res.succeeded); @@ -430,8 +430,8 @@ public struct NeoVerifier task.suspend(); test(!duplicate); - test!("==")(records.length, this.local.data.length); - foreach ( k, v; this.local.data ) + test!("==")(records.length, (&this).local.data.length); + foreach ( k, v; (&this).local.data ) { test!("in")(k, records); test!("==")(v, records[k]); @@ -517,8 +517,8 @@ public struct NeoVerifier task.suspend(); test(!duplicate); - test!("==")(keys.length, this.local.data.length); - foreach ( k, v; this.local.data ) + test!("==")(keys.length, (&this).local.data.length); + foreach ( k, v; (&this).local.data ) test!("in")(k, keys); } @@ -541,10 +541,10 @@ public struct NeoVerifier log.trace("\tVerifying channel with GetAll, filtering"); auto task = Task.getThis(); - const filter = "0"; + enum filter = "0"; hash_t[] local_filtered; - foreach ( k, v; this.local.data ) + foreach ( k, v; (&this).local.data ) if ( v.contains(filter) ) local_filtered ~= k; @@ -584,8 +584,8 @@ public struct NeoVerifier test!("==")(records.length, local_filtered.length); foreach ( k, v; records ) { - test!("in")(k, this.local.data); - test!("==")(v, this.local.data[k]); + test!("in")(k, (&this).local.data); + test!("==")(v, (&this).local.data[k]); } } } diff --git a/src/dummydhtapp/main.d b/src/dummydhtapp/main.d index c9f9856a..c2824a65 100644 --- a/src/dummydhtapp/main.d +++ b/src/dummydhtapp/main.d @@ -108,13 +108,13 @@ void main ( istring[] args ) fiber = new SelectFiber(epoll, &handshakeAndRegister, 256 * 1024); event = new FiberSelectEvent(fiber); - void ping_handler ( cstring args, void delegate ( cstring + void ping_handler ( cstring args, scope void delegate ( cstring response ) send_response ) { send_response("pong " ~ args); } - void reset_handler ( cstring args, void delegate ( cstring + void reset_handler ( cstring args, scope void delegate ( cstring response ) send_response ) { send_response("ACK"); diff --git a/src/fakedht/ConnectionHandler.d b/src/fakedht/ConnectionHandler.d index 7d34075d..0624006f 100644 --- a/src/fakedht/ConnectionHandler.d +++ b/src/fakedht/ConnectionHandler.d @@ -226,7 +226,7 @@ public class DhtConnectionHandler : ***************************************************************************/ - public this (void delegate(IConnectionHandler) finalize_dg, + public this (scope void delegate(IConnectionHandler) finalize_dg, ConnectionSetupParams setup ) { super(finalize_dg, setup); diff --git a/src/fakedht/DhtNode.d b/src/fakedht/DhtNode.d index 5a164dd8..7929e439 100644 --- a/src/fakedht/DhtNode.d +++ b/src/fakedht/DhtNode.d @@ -87,7 +87,7 @@ public class DhtNode public this ( DhtConst.NodeItem node_item, EpollSelectDispatcher epoll ) { - const backlog = 20; + static immutable backlog = 20; auto params = new ConnectionSetupParams; params.epoll = epoll; @@ -147,7 +147,7 @@ public class DhtNode ***************************************************************************/ override protected void getResourceAcquirer ( - void delegate ( Object request_resources ) handle_request_dg ) + scope void delegate ( Object request_resources ) handle_request_dg ) { // In the fake node, we don't actually store a shared resources // instance; a new one is simply passed to each request. diff --git a/src/fakedht/Storage.d b/src/fakedht/Storage.d index db9b2511..af0f53ab 100644 --- a/src/fakedht/Storage.d +++ b/src/fakedht/Storage.d @@ -72,7 +72,7 @@ struct DHT public Channel get (cstring channel_name) { - auto channel = channel_name in this.channels; + auto channel = channel_name in (&this).channels; if (channel is null) return null; return *channel; @@ -93,7 +93,7 @@ struct DHT public Channel getVerify ( cstring channel_name ) { - auto channel = channel_name in this.channels; + auto channel = channel_name in (&this).channels; enforce!(MissingChannelException)(channel !is null, idup(channel_name)); return *channel; } @@ -112,11 +112,11 @@ struct DHT public Channel getCreate (cstring channel_name) { - auto channel = channel_name in this.channels; + auto channel = channel_name in (&this).channels; if (channel is null) { - this.channels[idup(channel_name)] = new Channel; - channel = channel_name in this.channels; + (&this).channels[idup(channel_name)] = new Channel; + channel = channel_name in (&this).channels; } return *channel; } @@ -132,11 +132,11 @@ struct DHT public void remove (cstring channel_name) { - auto channel = this.get(channel_name); + auto channel = (&this).get(channel_name); if (channel !is null) { channel.listeners.trigger(DhtListener.Code.Finish, ""); - this.channels.remove(idup(channel_name)); + (&this).channels.remove(idup(channel_name)); } } @@ -148,10 +148,10 @@ struct DHT public void clear ( ) { - auto names = this.channels.keys; + auto names = (&this).channels.keys; foreach (name; names) { - auto channel = this.getVerify(name); + auto channel = (&this).getVerify(name); channel.data = null; } } @@ -167,7 +167,7 @@ struct DHT public void dropAllListeners ( ) { - foreach (channel; this.channels) + foreach (channel; (&this).channels) { channel.listeners = channel.new Listeners; } @@ -184,7 +184,7 @@ struct DHT { istring[] result; - foreach (key, value; this.channels) + foreach (key, value; (&this).channels) result ~= key; return result; diff --git a/src/fakedht/neo/SharedResources.d b/src/fakedht/neo/SharedResources.d index 7899a82a..bbade584 100644 --- a/src/fakedht/neo/SharedResources.d +++ b/src/fakedht/neo/SharedResources.d @@ -80,7 +80,7 @@ class SharedResources : IRequestResources ***************************************************************************/ - public MessageFiber getFiber ( void delegate ( ) fiber_method ) + public MessageFiber getFiber ( scope void delegate ( ) fiber_method ) { return new MessageFiber(fiber_method, 64 * 1024); } @@ -114,7 +114,7 @@ class SharedResources : IRequestResources ***************************************************************************/ public ITimer getTimer ( uint period_s, uint period_ms, - void delegate ( ) timer_dg ) + scope void delegate ( ) timer_dg ) { verify(period_ms < 1_000); verify(period_s > 0 || period_ms > 0); @@ -153,7 +153,7 @@ class SharedResources : IRequestResources ***********************************************************************/ - private this ( uint period_s, uint period_ms, void delegate ( ) timer_dg ) + private this ( uint period_s, uint period_ms, scope void delegate ( ) timer_dg ) { this.timer_dg = timer_dg; this.timer = new TimerEvent(&this.timerDg); diff --git a/src/fakedht/neo/request/Get.d b/src/fakedht/neo/request/Get.d index b27a0412..4e396ad4 100644 --- a/src/fakedht/neo/request/Get.d +++ b/src/fakedht/neo/request/Get.d @@ -72,7 +72,7 @@ public class GetImpl_v0 : GetProtocol_v0 ***************************************************************************/ override protected bool get ( cstring channel, hash_t key, - void delegate ( Const!(void)[] value ) dg ) + scope void delegate ( Const!(void)[] value ) dg ) { auto value_in_channel = global_storage.getCreate(channel).get(key); if ( value_in_channel !is null ) diff --git a/src/fakedht/neo/request/GetAll.d b/src/fakedht/neo/request/GetAll.d index 9ff7ad5e..d804df7b 100644 --- a/src/fakedht/neo/request/GetAll.d +++ b/src/fakedht/neo/request/GetAll.d @@ -121,7 +121,7 @@ public class GetAllImpl_v0 : GetAllProtocol_v0 ***************************************************************************/ override protected bool getNext ( - void delegate ( hash_t key, Const!(void)[] value ) dg ) + scope void delegate ( hash_t key, Const!(void)[] value ) dg ) { if ( this.iterate_keys.length == 0 ) return false; diff --git a/src/fakedht/neo/request/GetChannels.d b/src/fakedht/neo/request/GetChannels.d index 553a7744..a56be6ec 100644 --- a/src/fakedht/neo/request/GetChannels.d +++ b/src/fakedht/neo/request/GetChannels.d @@ -37,7 +37,7 @@ public class GetChannelsImpl_v0 : GetChannelsProtocol_v0 ***************************************************************************/ - override protected int opApply ( int delegate ( ref cstring ) dg ) + override protected int opApply ( scope int delegate ( ref cstring ) dg ) { int ret; foreach ( channel; global_storage.getChannelList() ) diff --git a/src/fakedht/neo/request/Update.d b/src/fakedht/neo/request/Update.d index 6183d8f9..e44e2a54 100644 --- a/src/fakedht/neo/request/Update.d +++ b/src/fakedht/neo/request/Update.d @@ -65,7 +65,7 @@ public class UpdateImpl_v0 : UpdateProtocol_v0 ***************************************************************************/ override protected bool get ( cstring channel, hash_t key, - void delegate ( Const!(void)[] value ) dg ) + scope void delegate ( Const!(void)[] value ) dg ) { auto value_in_channel = global_storage.getCreate(channel).get(key); if ( value_in_channel !is null ) diff --git a/src/turtle/env/Dht.d b/src/turtle/env/Dht.d index 039028e9..2e041a6e 100644 --- a/src/turtle/env/Dht.d +++ b/src/turtle/env/Dht.d @@ -134,7 +134,7 @@ public class Dht : Node!(DhtNode, "dht") unittest { struct NotVersioned { int x; } - struct Versioned { const StructVersion = 0; int x; } + struct Versioned { enum StructVersion = 0; int x; } // ensures compilation void stub ( ) @@ -347,7 +347,7 @@ public class Dht : Node!(DhtNode, "dht") ***************************************************************************/ public void expectRecordCondition ( cstring channel, hash_t key, - bool delegate ( in void[] record ) dg, + scope bool delegate ( in void[] record ) dg, double timeout = 1.0, double check_interval = 0.05 ) { char[Hash.HashDigits] str_key; @@ -435,7 +435,7 @@ public class Dht : Node!(DhtNode, "dht") ***************************************************************************/ private void waitForCondition ( double timeout, double check_interval, - bool delegate ( ) condition, lazy istring err_msg ) + scope bool delegate ( ) condition, lazy istring err_msg ) { auto total_wait = 0.0; @@ -668,7 +668,7 @@ unittest { struct Something { - const StructVersion = 1; + enum StructVersion = 1; int a, b; }