Skip to content

Commit

Permalink
Initial commit for public release of swarm v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanja-boric-sociomantic committed Apr 6, 2017
1 parent 3606123 commit 1d2695e
Show file tree
Hide file tree
Showing 64 changed files with 2,174 additions and 158 deletions.
5 changes: 1 addition & 4 deletions Build.mak
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
override DFLAGS += -w
override LDFLAGS += -lebtree -llzo2 -lrt -lgcrypt -lgpg-error -lglib-2.0

ifeq ($(DVER),1)
override DFLAGS += -v2 -v2=-static-arr-params -v2=-volatile
Expand All @@ -9,9 +10,5 @@ endif
# Remove deprecated modules from testing:
TEST_FILTER_OUT += \


# Add link flags for unittests
$O/%unittests: override LDFLAGS += -lebtree -llzo2 -lrt -lgcrypt -lgpg-error -lglib-2.0

.PHONY: d2conv
d2conv: $O/d2conv.stamp
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ An overview of the features of the legacy and neo client architecture can be
found here

`Legacy client documentation
<https://github.com/sociomantic-tsunami/swarm/blob/v3.x.x/src/swarm/README_client.rst>`_.
<https://github.com/sociomantic-tsunami/swarm/blob/v4.x.x/src/swarm/README_client.rst>`_.

`Neo client documentation
<https://github.com/sociomantic-tsunami/swarm/blob/v3.x.x/src/swarm/README_client_neo.rst>`_.
<https://github.com/sociomantic-tsunami/swarm/blob/v4.x.x/src/swarm/README_client_neo.rst>`_.

Example
-------

A simple example of how to construct a client and node using the neo protocol
can be found `here
<https://github.com/sociomantic-tsunami/swarm/blob/v4.x.x/test/neo/>`_.

Build / Use
===========
Expand All @@ -54,7 +61,7 @@ Dependencies
========== =======
Dependency Version
========== =======
ocean v2.5.x
ocean v3.1.x
makd v1.5.x
========== =======

Expand Down
2 changes: 0 additions & 2 deletions docker/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ apt-get install -y \
libgcrypt-dev \
libglib2.0-dev \
libgpg-error-dev


Empty file modified src/swarm/README_client.rst
100755 → 100644
Empty file.
Empty file modified src/swarm/client/request/model/INodeInfo.d
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions src/swarm/client/request/params/IRequestParams.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import ocean.core.Traits;

import ocean.io.select.EpollSelectDispatcher;

import ocean.io.serialize.SimpleSerializer;
import ocean.io.serialize.SimpleStreamSerializer;

import ocean.io.model.IConduit: IOStream, InputStream, OutputStream;

Expand Down Expand Up @@ -89,7 +89,7 @@ public abstract class IRequestParams
protected alias .IOStream IOStream;
protected alias .InputStream InputStream;
protected alias .OutputStream OutputStream;
protected alias .SimpleSerializer SimpleSerializer;
protected alias .SimpleStreamSerializer SimpleStreamSerializer;
protected alias .copyFields copyFields;
protected alias .SizeofTuple SizeofTuple;

Expand Down
Empty file modified src/swarm/neo/IPAddress.d
100755 → 100644
Empty file.
Empty file modified src/swarm/neo/authentication/Credentials.d
100755 → 100644
Empty file.
24 changes: 13 additions & 11 deletions src/swarm/neo/authentication/CredentialsFile.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern (C) private int g_ascii_xdigit_value ( char c ); // glib-2.0
class CredentialsFile
{
import swarm.neo.authentication.Credentials;
import HmacDef = swarm.neo.authentication.HmacDef;

import ocean.io.device.File;

Expand All @@ -66,7 +67,7 @@ class CredentialsFile
***************************************************************************/

private Credentials.Key[istring] credentials_;
private HmacDef.Key[istring] credentials_;

/***************************************************************************
Expand Down Expand Up @@ -105,7 +106,7 @@ class CredentialsFile
***************************************************************************/

public Const!(Credentials.Key[istring])* credentials ( )
public Const!(HmacDef.Key[istring])* credentials ( )
{
return &this.credentials_;
}
Expand Down Expand Up @@ -175,8 +176,8 @@ class CredentialsFile
***************************************************************************/

private static Credentials.Key[istring] parse ( istring content,
cstring filepath = null )
private static HmacDef.Key[istring] parse ( istring content,
cstring filepath = null )
{
int line = 0; // The current line in the input file.

Expand All @@ -199,7 +200,7 @@ class CredentialsFile

scope parser = new QueryParams('\n', ':');

Credentials.Key[istring] keys;
HmacDef.Key[istring] keys;

foreach (name, hex_key; parser.set(content))
{
Expand All @@ -222,7 +223,7 @@ class CredentialsFile

size_t i = 0;

Credentials.Key key;
HmacDef.Key key;

foreach (ref b; key.content)
{
Expand Down Expand Up @@ -296,6 +297,7 @@ class CredentialsFile
version ( UnitTest )
{
import swarm.neo.authentication.Credentials;
import HmacDef = swarm.neo.authentication.HmacDef;
import ocean.core.Test;
import ocean.core.ByteSwap;

Expand All @@ -312,7 +314,7 @@ version ( UnitTest )
***************************************************************************/

void registryTest ( istring name, istring file_content, Credentials.Key[istring] expected )
void registryTest ( istring name, istring file_content, HmacDef.Key[istring] expected )
{
auto t = new NamedTest(name);
auto reg = CredentialsFile.parse(file_content, name);
Expand All @@ -339,14 +341,14 @@ version ( UnitTest )
***************************************************************************/

Credentials.Key makeKey ( ulong[] words ... )
HmacDef.Key makeKey ( ulong[] words ... )
in
{
assert(words.length == Credentials.Key.length / words[0].sizeof);
assert(words.length == HmacDef.Key.length / words[0].sizeof);
}
body
{
Credentials.Key key;
HmacDef.Key key;
(cast(ulong[])key.content)[] = words;
ByteSwap.swap64(key.content);
return key;
Expand All @@ -364,7 +366,7 @@ version ( UnitTest )
unittest
{
// Empty
registryTest("Empty", [], (Credentials.Key[istring]).init);
registryTest("Empty", [], (HmacDef.Key[istring]).init);

// One entry then EOF
registryTest(
Expand Down
7 changes: 4 additions & 3 deletions src/swarm/neo/authentication/HmacAuthCode.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ struct HmacAuthCode
import swarm.neo.authentication.HmacDef: Key, Code, Nonce;

import ocean.util.cipher.gcrypt.HMAC;
import ocean.util.cipher.gcrypt.c.random;
import ocean.util.cipher.gcrypt.c.gpgerror;
import ocean.util.cipher.gcrypt.c.md;
import ocean.util.cipher.gcrypt.c.random;

import core.stdc.time: time_t;

Expand All @@ -49,7 +50,7 @@ struct HmacAuthCode
***************************************************************************/

const hash_algoritm = HMAC.gcry_md_algos.GCRY_MD_SHA512;
const hash_algoritm = gcry_md_algos.GCRY_MD_SHA512;

private HMAC hmac;

Expand Down Expand Up @@ -203,7 +204,7 @@ struct HmacAuthCode
***********************************************************************/

ulong timestamp;

Nonce nonce;

char[] name;
Expand Down
Empty file modified src/swarm/neo/authentication/HmacDef.d
100755 → 100644
Empty file.
Empty file modified src/swarm/neo/client/ClientSocket.d
100755 → 100644
Empty file.
9 changes: 3 additions & 6 deletions src/swarm/neo/client/Connection.d
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class Connection: ConnectionBase
import swarm.neo.client.RetryTimer;

import ocean.core.Enforce;
import ocean.io.select.EpollSelectDispatcher;
import ocean.transition;

debug ( SwarmConn ) import ocean.io.Stdout;
Expand Down Expand Up @@ -448,13 +449,9 @@ public final class Connection: ConnectionBase

case this.status_.Disconnected:
/*
* If the shutdown was requested during startup, report that
* we are now stopping further connection attempts.
* Shutdown was requested during startup, stopping further
* connection attempts.
*/
// TODO: do we need to notify the user at this stage?
// they are probably the one who requested the shutdown...
//~ if (this.startup_notifier !is null)
//~ this.startup_notifier(this);
return false;

default:
Expand Down
48 changes: 40 additions & 8 deletions src/swarm/neo/client/ConnectionSet.d
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import swarm.neo.client.RequestOnConn;
/// ditto
public final class ConnectionSet : RequestOnConn.IConnectionGetter
{
import ocean.core.Exception_tango;
import ocean.core.ExceptionDefinitions;
import ocean.core.SmartUnion;

import swarm.neo.client.Connection;
import swarm.neo.client.RequestSet;
import swarm.neo.client.NotifierTypes;
import swarm.neo.IPAddress;
import swarm.neo.authentication.Credentials;
import ocean.io.select.EpollSelectDispatcher;
Expand Down Expand Up @@ -100,22 +102,42 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter

private uint n_nodes_starting = 0;

/***************************************************************************
Union of notifications about a connection.
***************************************************************************/

private union ConnNotificationUnion
{
/// The connection has been successfully established.
NodeInfo connected;

/// An error (indicated by the `e` field) occurred while connecting. The
/// connection attempt will automatically be retried.
NodeExceptionInfo error_while_connecting;
}

/***************************************************************************
Smart-union of notifications about a connection.
***************************************************************************/

public alias SmartUnion!(ConnNotificationUnion) ConnNotification;

/***************************************************************************
User callback to be notified when a connection, which was added with
`start()`,
1. finished connecting, because either the connection was established
or because it was removed with `stop()` while connecting, or
1. the connection was established, or
2. detected an error -- for example, the node is unreachable or a
socket I/O error, but also a failed protocol handshake or
authentication -- and will try connecting again.
In case 1 `e is null`, in case 2 it reflects the error.
***************************************************************************/

public alias void delegate ( IPAddress node_address, Exception e )
ConnectionNotifier;
public alias void delegate ( ConnNotification info ) ConnectionNotifier;

/// ditto
private ConnectionNotifier conn_notifier;
Expand Down Expand Up @@ -416,10 +438,20 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter
private void notifyConnectResult ( Connection connection,
Exception e = null )
{
ConnNotification info;

if (e is null)
{
this.n_nodes_starting--;
info.connected = NodeInfo(connection.remote_address);
}
else
{
info.error_while_connecting =
NodeExceptionInfo(connection.remote_address, e);
}

this.conn_notifier(connection.remote_address, e);
this.conn_notifier(info);
}
}

Expand Down
Empty file modified src/swarm/neo/client/IRequestSet.d
100755 → 100644
Empty file.
Loading

0 comments on commit 1d2695e

Please sign in to comment.