Skip to content

Commit

Permalink
Added configurable daemon timeout option.
Browse files Browse the repository at this point in the history
Renamed IMiningServerConfig.cs as IServerConfig.cs.
  • Loading branch information
bonesoul committed Sep 11, 2014
1 parent 0c22d66 commit 4e7b91c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
<Compile Include="Shares\ShareManager.cs" />
<Compile Include="Server\Mining\Service\IRpcService.cs" />
<Compile Include="Server\Mining\IMiningServer.cs" />
<Compile Include="Server\Mining\IMiningServerConfig.cs" />
<Compile Include="Server\IServerConfig.cs" />
<Compile Include="Server\Mining\Stratum\IStratumServerConfig.cs" />
<Compile Include="Server\Mining\Vanilla\IVanillaServerConfig.cs" />
<Compile Include="Server\Mining\Vanilla\VanillaMiner.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/CoiniumServ/Daemon/Config/DaemonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class DaemonConfig:IDaemonConfig

public string Password { get; private set; }

public int Timeout { get; private set; }

public DaemonConfig(dynamic config)
{
try
Expand All @@ -46,6 +48,7 @@ public DaemonConfig(dynamic config)
Port = config.port;
Username = config.username;
Password = config.password;
Timeout = config.timeout == 0 ? 5 : config.timeout;

Valid = true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/CoiniumServ/Daemon/Config/IDaemonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public interface IDaemonConfig:IConfig
/// password for rpc connection.
/// </summary>
string Password { get; }

/// <summary>
/// Timeout for daemon rpc connections in seconds.
/// </summary>
int Timeout { get; }
}
}
12 changes: 9 additions & 3 deletions src/CoiniumServ/Daemon/DaemonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ public class DaemonBase : IDaemonBase
public string RpcPassword { get; private set; }
public Int32 RequestCounter { get; private set; }

private readonly Int32 _timeout;

private readonly ILogger _logger;

public DaemonBase(IPoolConfig poolConfig)
{
_logger = LogManager.PacketLogger.ForContext<DaemonClient>().ForContext("Component", poolConfig.Coin.Name);

_timeout = poolConfig.Daemon.Timeout*1000; // set the daemon timeout.

RpcUrl = string.Format("http://{0}:{1}", poolConfig.Daemon.Host, poolConfig.Daemon.Port);
RpcUser = poolConfig.Daemon.Username;
RpcPassword = poolConfig.Daemon.Password;
RequestCounter = 0;
_logger = LogManager.PacketLogger.ForContext<DaemonClient>().ForContext("Component", poolConfig.Coin.Name);

RequestCounter = 0;
}

/// <summary>
Expand Down Expand Up @@ -118,7 +124,7 @@ private HttpWebRequest MakeHttpRequest(DaemonRequest walletRequest)
// Important, otherwise the service can't deserialse your request properly
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
webRequest.Timeout = 1000;
webRequest.Timeout = _timeout;

_logger.Verbose("tx: {0}", Encoding.UTF8.GetString(walletRequest.GetBytes()).PrettifyJson());

Expand Down
1 change: 0 additions & 1 deletion src/CoiniumServ/Daemon/DaemonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CoiniumServ.Daemon.Config;
using CoiniumServ.Daemon.Requests;
using CoiniumServ.Daemon.Responses;
/* This file is based on https://github.com/BitKoot/BitcoinRpcSharp */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion

using System;
using CoiniumServ.Configuration;
using Newtonsoft.Json;

namespace CoiniumServ.Server.Mining
namespace CoiniumServ.Server
{
[JsonObject(MemberSerialization.OptIn)]
public interface IServerConfig:IConfig
Expand Down
15 changes: 1 addition & 14 deletions src/CoiniumServ/Server/Web/IWebServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,11 @@
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion
using CoiniumServ.Configuration;

namespace CoiniumServ.Server.Web
{
public interface IWebServerConfig:IConfig
public interface IWebServerConfig : IServerConfig
{
bool Enabled { get; }

/// <summary>
/// interface to bind webserver.
/// </summary>
string BindInterface { get; }

/// <summary>
/// port to listen for http connections.
/// </summary>
int Port { get; }

IBackendConfig Backend { get; }
}
}
5 changes: 5 additions & 0 deletions src/CoiniumServ/Server/Web/WebServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ namespace CoiniumServ.Server.Web
public class WebServerConfig : IWebServerConfig
{
public bool Enabled { get; private set; }

public string BindInterface { get; private set; }

public int Port { get; private set; }

public IBackendConfig Backend { get; private set; }

public bool Valid { get; private set; }

public WebServerConfig(dynamic config)
{
try
Expand Down
4 changes: 3 additions & 1 deletion src/CoiniumServ/config/pools/advanced-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
# port: the port coin daemon is listening on.
# username: username for rpc connection.
# password: password for rpc connection.
# timeout: timeout for rpc connections in seconds.

"daemon": {
"host": "127.0.0.1",
"port": 9333,
"username": "user",
"password": "password"
"password": "password",
"timeout": 5
},

# -------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/CoiniumServ/config/pools/default-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
# -------------------------------

# host: ip/hostname of coin-daemon.
# timeout: timeout for rpc connections in seconds.

"daemon": {
"host": "127.0.0.1"
"host": "127.0.0.1",
"timeout": 5
},

# -------------------------------
Expand Down

0 comments on commit 4e7b91c

Please sign in to comment.