Skip to content

Commit

Permalink
Merge pull request #536 from CoiniumServ/develop
Browse files Browse the repository at this point in the history
mining.subscribe fix.
  • Loading branch information
Hüseyin Uslu committed Oct 4, 2014
2 parents 7ed3d94 + 48574ca commit 2d4c862
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "deps/csredis"]
path = deps/csredis
url = https://github.com/CoiniumServ/csredis.git
[submodule "deps/json-rpc"]
path = deps/json-rpc
url = https://github.com/CoiniumServ/JSON-RPC.NET.git
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ Even better multi-pool & auto-exchange module is being developed which once comp

CoiniumServ was created to be used for [Coinium.org](http://www.coinium.org) mining pool network at first hand. You can check [some of pools](https://github.com/CoiniumServ/CoiniumServ/wiki/Pools) of the pools running CoiniumServ.

### Screenshots

##### Console

![CoiniumServ running over mono & ubuntu](http://i.imgur.com/HvaPVrZ.png)

##### Embedded web frontend

![Embedded web frontend](http://i.imgur.com/oOF8lQ0.png)

### Status

Latest release: [v0.2.0 alpha](https://github.com/CoiniumServ/CoiniumServ/releases/tag/v0.2.0-beta)
Expand Down
22 changes: 21 additions & 1 deletion build/CoiniumServ.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{02E410C9-83C5-4D63-8902-5AD041EBEB6C}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSRedis", "..\deps\csredis\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libCoiniumServ", "..\src\libCoiniumServ\libCoiniumServ.csproj", "{F908636C-BC75-4B93-A774-E4878F3D39AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "..\deps\json-rpc\Json-Rpc\AustinHarris.JsonRpc.csproj", "{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -107,6 +109,24 @@ Global
{F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|Mixed Platforms.ActiveCfg = Release|Any CPU
{F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|Mixed Platforms.Build.0 = Release|Any CPU
{F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|x86.ActiveCfg = Release|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.Build.0 = Debug|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.ActiveCfg = Debug|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.Build.0 = Debug|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.Build.0 = Release|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.ActiveCfg = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Any CPU.ActiveCfg = Release|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Any CPU.Build.0 = Release|Any CPU
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Mixed Platforms.ActiveCfg = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Mixed Platforms.Build.0 = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|x86.ActiveCfg = Release|x86
{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions deps/json-rpc
Submodule json-rpc added at 6669fa
20 changes: 10 additions & 10 deletions src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
<ApplicationIcon>Coinium.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="AustinHarris.JsonRpc, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\AustinHarris.JsonRpc.1.0.4.18\lib\net40\AustinHarris.JsonRpc.dll</HintPath>
</Reference>
<Reference Include="BouncyCastle.Crypto, Version=1.7.4137.9688, Culture=neutral, PublicKeyToken=a4292a325f69b123, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
Expand Down Expand Up @@ -120,11 +116,11 @@
</Reference>
<Reference Include="Serilog, Version=1.4.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\Serilog.1.4.9\lib\net45\Serilog.dll</HintPath>
<HintPath>..\..\build\packages\Serilog.1.4.10\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="Serilog.FullNetFx, Version=1.4.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\Serilog.1.4.9\lib\net45\Serilog.FullNetFx.dll</HintPath>
<HintPath>..\..\build\packages\Serilog.1.4.10\lib\net45\Serilog.FullNetFx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -440,18 +436,18 @@
<Compile Include="Server\Mining\Getwork\GetworkMiner.cs" />
<Compile Include="Pools\PoolConfig.cs" />
<Compile Include="Pools\PoolManager.cs" />
<Compile Include="Server\Mining\Getwork\Service\HttpServiceContext.cs" />
<Compile Include="Server\Mining\Getwork\GetworkContext.cs" />
<Compile Include="Server\Mining\Getwork\GetworkServer.cs" />
<Compile Include="Server\Mining\Getwork\GetworkServerConfig.cs" />
<Compile Include="Server\Mining\Getwork\Service\GetworkService.cs" />
<Compile Include="Server\Mining\Getwork\GetworkService.cs" />
<Compile Include="Mining\IMiner.cs" />
<Compile Include="Server\Mining\Stratum\Service\SocketServiceContext.cs" />
<Compile Include="Server\Mining\Stratum\StratumContext.cs" />
<Compile Include="Server\Commands\Server.cs" />
<Compile Include="Server\Commands\Stats.cs" />
<Compile Include="Server\Commands\Uptime.cs" />
<Compile Include="Server\Commands\Version.cs" />
<Compile Include="Server\Mining\Stratum\StratumMiner.cs" />
<Compile Include="Server\Mining\Stratum\Service\StratumService.cs" />
<Compile Include="Server\Mining\Stratum\StratumService.cs" />
<Compile Include="Daemon\Responses\Getwork.cs" />
<Compile Include="Container\Context\IApplicationContext.cs" />
<Compile Include="Server\Mining\Getwork\HttpServer.cs" />
Expand Down Expand Up @@ -957,6 +953,10 @@
<Project>{d35e185e-a7e1-41e1-846c-21944f56074f}</Project>
<Name>CSRedis</Name>
</ProjectReference>
<ProjectReference Include="..\..\deps\json-rpc\Json-Rpc\AustinHarris.JsonRpc.csproj">
<Project>{24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307}</Project>
<Name>AustinHarris.JsonRpc</Name>
</ProjectReference>
<ProjectReference Include="..\libCoiniumServ\libCoiniumServ.csproj">
<Project>{f908636c-bc75-4b93-a774-e4878f3d39af}</Project>
<Name>libCoiniumServ</Name>
Expand Down
2 changes: 0 additions & 2 deletions src/CoiniumServ/Container/Registries/ServerRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
using CoiniumServ.Container.Context;
using CoiniumServ.Server.Mining;
using CoiniumServ.Server.Mining.Getwork;
using CoiniumServ.Server.Mining.Getwork.Service;
using CoiniumServ.Server.Mining.Service;
using CoiniumServ.Server.Mining.Stratum;
using CoiniumServ.Server.Mining.Stratum.Service;
using CoiniumServ.Server.Web;

namespace CoiniumServ.Container.Registries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
#endregion

using System.Net;
using CoiniumServ.Mining;

namespace CoiniumServ.Server.Mining.Getwork.Service
namespace CoiniumServ.Server.Mining.Getwork
{
public class HttpServiceContext
public class GetworkContext
{
public IMiner Miner { get; private set; }
public IGetworkMiner Miner { get; private set; }

public HttpListenerResponse Response { get; private set; }

public HttpServiceContext(IMiner miner, HttpListenerContext context)
public GetworkContext(IGetworkMiner miner, HttpListenerContext context)
{
Miner = miner;
Response = context.Response;
Expand Down
5 changes: 2 additions & 3 deletions src/CoiniumServ/Server/Mining/Getwork/GetworkMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using CoiniumServ.Logging;
using CoiniumServ.Mining;
using CoiniumServ.Pools;
using CoiniumServ.Server.Mining.Getwork.Service;
using CoiniumServ.Utils.Extensions;
using Newtonsoft.Json;
using Serilog;
Expand Down Expand Up @@ -97,7 +96,7 @@ public GetworkMiner(int id, IPool pool, IMinerManager minerManager)
var asyncData = ((JsonRpcStateAsync) callback);
var result = asyncData.Result;
var response = Encoding.UTF8.GetBytes(result);
var context = (HttpServiceContext) asyncData.AsyncState;
var context = (GetworkContext) asyncData.AsyncState;
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
Expand Down Expand Up @@ -125,7 +124,7 @@ public void Parse(HttpListenerContext httpContext)
using (var reader = new StreamReader(httpRequest.InputStream, Encoding.UTF8))
{
var line = reader.ReadToEnd();
var rpcContext = new HttpServiceContext(this, httpContext);
var rpcContext = new GetworkContext(this, httpContext);

_packetLogger.Verbose("rx: {0}", line.PrettifyJson());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using CoiniumServ.Shares;
using Serilog;

namespace CoiniumServ.Server.Mining.Getwork.Service
namespace CoiniumServ.Server.Mining.Getwork
{
/// <summary>
/// Getwork protocol implementation.
Expand Down Expand Up @@ -56,9 +56,6 @@ public class GetworkService : JsonRpcService, IRpcService
[JsonRpcMethod("getwork")]
public Daemon.Responses.Getwork Getwork(string data = null)
{
var context = (HttpServiceContext) JsonRpcContext.Current().Value;
var miner = (IGetworkMiner) (context.Miner);

// TODO: fixme! instead use jobmanager and sharemanager.

if (data == null) // if miner supplied no data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
//
#endregion

using CoiniumServ.Mining;

namespace CoiniumServ.Server.Mining.Stratum.Service
namespace CoiniumServ.Server.Mining.Stratum
{
public class SocketServiceContext
public class StratumContext
{
public IMiner Miner { get; private set; }
public IStratumMiner Miner { get; private set; }

public SocketServiceContext(IMiner miner)
public StratumContext(IStratumMiner miner)
{
Miner = miner;
}
Expand Down
3 changes: 1 addition & 2 deletions src/CoiniumServ/Server/Mining/Stratum/StratumMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
using CoiniumServ.Persistance.Layers;
using CoiniumServ.Pools;
using CoiniumServ.Server.Mining.Stratum.Errors;
using CoiniumServ.Server.Mining.Stratum.Service;
using CoiniumServ.Server.Mining.Stratum.Sockets;
using CoiniumServ.Utils.Buffers;
using CoiniumServ.Utils.Extensions;
Expand Down Expand Up @@ -227,7 +226,7 @@ private void ProcessRequest(string line)
{
try
{
var rpcContext = new SocketServiceContext(this); // set the context.
var rpcContext = new StratumContext(this); // set the context.

_packetLogger.Verbose("rx: {0}", line.PrettifyJson());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using CoiniumServ.Server.Mining.Stratum.Responses;
using CoiniumServ.Shares;

namespace CoiniumServ.Server.Mining.Stratum.Service
namespace CoiniumServ.Server.Mining.Stratum
{
/// <summary>
/// Stratum protocol implementation.
Expand All @@ -46,20 +46,20 @@ public class StratumService : JsonRpcService, IRpcService
/// <summary>
/// Subscribes a Miner to allow it to recieve work to begin hashing and submitting shares.
/// </summary>
/// <param name="signature">Miner Connection</param>
/// <param name="signature">software signature</param>
/// <param name="sessionId">optional parameter supplied by miners whom wants to reconnect and continue their old session</param>
[JsonRpcMethod("mining.subscribe")]
public SubscribeResponse SubscribeMiner(string signature)
public SubscribeResponse SubscribeMiner(string signature = null, string sessionId = null)
{
var context = (SocketServiceContext) JsonRpcContext.Current().Value;
var miner = (IStratumMiner)(context.Miner);
var context = (StratumContext) JsonRpcContext.Current().Value;

var response = new SubscribeResponse
{
ExtraNonce1 = miner.ExtraNonce.ToString("x8"), // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
ExtraNonce1 = context.Miner.ExtraNonce.ToString("x8"), // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
};

miner.Subscribe(signature);
context.Miner.Subscribe(signature);

return response;
}
Expand All @@ -72,10 +72,8 @@ public SubscribeResponse SubscribeMiner(string signature)
[JsonRpcMethod("mining.authorize")]
public bool AuthorizeMiner(string user, string password)
{
var context = (SocketServiceContext)JsonRpcContext.Current().Value;
var miner = (IStratumMiner)(context.Miner);

return miner.Authenticate(user, password);
var context = (StratumContext)JsonRpcContext.Current().Value;
return context.Miner.Authenticate(user, password);
}

/// <summary>
Expand All @@ -89,10 +87,8 @@ public bool AuthorizeMiner(string user, string password)
[JsonRpcMethod("mining.submit")]
public bool SubmitWork(string user, string jobId, string extraNonce2, string nTime, string nonce)
{
var context = (SocketServiceContext)JsonRpcContext.Current().Value;
var miner = (IStratumMiner)(context.Miner);

return _shareManager.ProcessShare(miner, jobId, extraNonce2, nTime, nonce).IsValid;
var context = (StratumContext)JsonRpcContext.Current().Value;
return _shareManager.ProcessShare(context.Miner, jobId, extraNonce2, nTime, nonce).IsValid;
}
}
}
10 changes: 10 additions & 0 deletions src/CoiniumServ/config/coins/mooncoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Mooncoin",
"symbol": "MOON",
"algorithm": "scrypt",
"site": "https://bitcointalk.org/index.php?topic=389403.0",
"blockExplorer": {
"block": "http://moonchain.net/block/",
"tx": "http://moonchain.net/tx/"
}
}
10 changes: 10 additions & 0 deletions src/CoiniumServ/config/coins/noblecoin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Noblecoin",
"symbol": "NOBL",
"algorithm": "scrypt",
"site": "https://www.noblemovement.com/",
"blockExplorer": {
"block": "https://chainz.cryptoid.info/nobl/block.dws?",
"tx": "https://chainz.cryptoid.info/nobl/tx.dws?"
}
}
10 changes: 10 additions & 0 deletions src/CoiniumServ/config/coins/usde.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "USDE",
"symbol": "USDE",
"algorithm": "scrypt",
"site": "http://usd-e.com/",
"blockExplorer": {
"block": "https://altexplorer.net/block/",
"tx": "https://altexplorer.net/tx/"
}
}
3 changes: 1 addition & 2 deletions src/CoiniumServ/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AustinHarris.JsonRpc" version="1.0.4.18" targetFramework="net45" />
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
<package id="CryptSharpOfficial" version="2.0.0.0" targetFramework="net45" />
<package id="Dapper" version="1.34" targetFramework="net45" />
Expand All @@ -19,5 +18,5 @@
<package id="Nancy.Viewengines.Razor" version="0.23.2" targetFramework="net45" />
<package id="NancyFx.Metrics" version="0.2.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Serilog" version="1.4.9" targetFramework="net45" />
<package id="Serilog" version="1.4.10" targetFramework="net45" />
</packages>
5 changes: 2 additions & 3 deletions src/Tests/Banning/BanConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ namespace CoiniumServ.Tests.Banning
{
public class BanConfigTests
{
private readonly IConfigFactory _configFactory;
private readonly IJsonConfigReader _jsonConfigReader;

public BanConfigTests()
{
var kernel = TinyIoCContainer.Current;
new Bootstrapper(kernel);
_configFactory = kernel.Resolve<IConfigFactory>();
_jsonConfigReader = _configFactory.GetJsonConfigReader();
var configFactory = kernel.Resolve<IConfigFactory>();
_jsonConfigReader = configFactory.GetJsonConfigReader();
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Tests/CoiniumServ.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="Blocks\BlockProcessorTests.cs" />
<Compile Include="Coin\Coinbase\SerializersTests.cs" />
<Compile Include="Daemon\BlockTemplateTests.cs" />
<Compile Include="Server\Mining\Stratum\StratumServiceTests.cs" />
<Compile Include="Utils\Extensions\ArrayExtensionsTests.cs" />
<Compile Include="Utils\Extensions\StringExtensionsTests.cs" />
<Compile Include="Shares\ShareTests.cs" />
Expand Down Expand Up @@ -101,6 +102,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\deps\json-rpc\Json-Rpc\AustinHarris.JsonRpc.csproj">
<Project>{24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307}</Project>
<Name>AustinHarris.JsonRpc</Name>
</ProjectReference>
<ProjectReference Include="..\CoiniumServ\CoiniumServ.csproj">
<Project>{5fca1e48-0751-4625-9532-cb804df55db5}</Project>
<Name>CoiniumServ</Name>
Expand Down

0 comments on commit 2d4c862

Please sign in to comment.