Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0.21.todo' into feature/events
Browse files Browse the repository at this point in the history
  • Loading branch information
lostystyg committed Apr 25, 2022
2 parents af71bdf + b049782 commit dbea23e
Show file tree
Hide file tree
Showing 19 changed files with 572 additions and 1,098 deletions.
2 changes: 1 addition & 1 deletion src/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/httprpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ void StopHTTPRPC();
* Precondition; HTTP and RPC has been started.
*/
void StartREST(const util::Ref& context);
void StartSTATIC(const util::Ref& context);
/** Interrupt RPC REST subsystem.
*/
void InterruptREST();
/** Stop HTTP REST subsystem.
* Precondition; HTTP and RPC has been stopped.
*/
void StopREST();
void StopSTATIC();

#endif
10 changes: 6 additions & 4 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,17 @@ bool InitHTTPServer(const util::Ref& context)
#endif

// Additional pocketnet seocket
if (gArgs.GetBoolArg("-api", true))
if (gArgs.GetBoolArg("-api", DEFAULT_API_ENABLE))
{
g_webSocket = new HTTPWebSocket(eventBase, timeout, workQueuePublicDepth, workQueuePostDepth, true);
RegisterPocketnetWebRPCCommands(g_webSocket->m_table_rpc, g_webSocket->m_table_post_rpc);
}

// Additional pocketnet static files socket
g_staticSocket = new HTTPSocket(eventBase, timeout, workQueueStaticDepth, true);
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE))
g_restSocket = new HTTPSocket(eventBase, timeout, workQueueRestDepth, true);
}

if (gArgs.GetBoolArg("-static", DEFAULT_STATIC_ENABLE))
g_staticSocket = new HTTPSocket(eventBase, timeout, workQueueStaticDepth, true);

if (!HTTPBindAddresses())
{
Expand Down
4 changes: 4 additions & 0 deletions src/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ static const int DEFAULT_HTTP_STATIC_WORKQUEUE = 16;
static const int DEFAULT_HTTP_REST_WORKQUEUE = 16;
static const int DEFAULT_HTTP_SERVER_TIMEOUT = 30;

static const bool DEFAULT_API_ENABLE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_STATIC_ENABLE = false;

struct evhttp_request;

class CService;
Expand Down
30 changes: 24 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@

static bool fFeeEstimatesInitialized = false;
static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_API_ENABLE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;

Statistic::RequestStatEngine gStatEngineInstance;
Expand Down Expand Up @@ -229,6 +227,7 @@ void Shutdown(NodeContext& node)

StopHTTPRPC();
StopREST();
StopSTATIC();
StopRPC();
StopHTTPServer();

Expand Down Expand Up @@ -628,6 +627,11 @@ void SetupServerArgs(NodeContext& node)

argsman.AddArg("-api", strprintf("Enable Public RPC api server (default: %u)", DEFAULT_API_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);

argsman.AddArg("-static", strprintf("Accept public requests to static resources (default: %u)", DEFAULT_STATIC_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-staticpath", "Path to static resources (default: GetDataDir()/wwwroot", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);


argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcauth=<userpw>", "Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcauth. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
Expand Down Expand Up @@ -661,6 +665,7 @@ void SetupServerArgs(NodeContext& node)
argsman.AddArg("-sqltimeout", strprintf("Timeout for ReadOnly sql querys (default: %ds)", 10), ArgsManager::ALLOW_ANY, OptionsCategory::SQLITE);
argsman.AddArg("-sqlsharedcache", strprintf("Experimental: enable shared cache for sqlite connections (default: disabled)"), ArgsManager::ALLOW_ANY, OptionsCategory::SQLITE);
argsman.AddArg("-sqlcachesize", strprintf("Experimental: Cache size for SQLite connection in megabytes (default: %d mb)", 5), ArgsManager::ALLOW_ANY, OptionsCategory::SQLITE);
argsman.AddArg("-withoutweb", strprintf("Disable WEB part of database (default: %u)", false), ArgsManager::ALLOW_ANY, OptionsCategory::SQLITE);


#if HAVE_DECL_DAEMON
Expand Down Expand Up @@ -866,7 +871,7 @@ static void ThreadImport(ChainstateManager& chainman, const util::Ref& context,
}

// .. only web DB
if (fReindex == 5 && args.GetBoolArg("-api", true))
if (fReindex == 5 && args.GetBoolArg("-api", DEFAULT_API_ENABLE))
{
LogPrintf("Building a Web database: 0%%\n");

Expand Down Expand Up @@ -971,14 +976,25 @@ static bool AppInitServers(const util::Ref& context, NodeContext& node)
const ArgsManager& args = *Assert(node.args);
RPCServer::OnStarted(&OnRPCStarted);
RPCServer::OnStopped(&OnRPCStopped);

if (!InitHTTPServer(context))
return false;

StartRPC();

node.rpc_interruption_point = RpcInterruptionPoint;

if (!StartHTTPRPC(context))
return false;
if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) StartREST(context);

if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE))
StartREST(context);

if (gArgs.GetBoolArg("-static", DEFAULT_STATIC_ENABLE))
StartSTATIC(context);

StartHTTPServer();

return true;
}

Expand Down Expand Up @@ -1626,7 +1642,8 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA

PocketWeb::PocketFrontendInst.Init();

if (args.GetBoolArg("-api", true))
// Always start WEB DB building thread
if (!args.GetBoolArg("-withoutweb", false))
PocketServices::WebPostProcessorInst.Start(threadGroup);

// ********************************************************* Step 4b: Additional settings
Expand Down Expand Up @@ -2297,7 +2314,8 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
// ********************************************************* Step 13: finished

// Start WebSocket server
if (args.GetBoolArg("-api", true)) InitWS();
if (args.GetBoolArg("-api", DEFAULT_API_ENABLE))
InitWS();

gStatEngineInstance.Run(threadGroup, context);

Expand Down
4 changes: 2 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static const int TIMEOUT_INTERVAL = 20 * 60;
static const int FEELER_INTERVAL = 120;
/** The maximum number of addresses from our addrman to return in response to a getaddr message. */
static constexpr size_t MAX_ADDR_TO_SEND = 1000;
/** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
/** Maximum length of incoming protocol messages (no message over 16 MB is currently acceptable). */
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 16000000;
/** Maximum length of the user agent string in `version` message */
static const unsigned int MAX_SUBVERSION_LENGTH = 256;
/** Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) */
Expand Down
4 changes: 2 additions & 2 deletions src/pocketdb/consensus/Reputation.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ namespace PocketConsensus
{ 1180000, 0, [](int height) { return make_shared<ReputationConsensus_checkpoint_1180000>(height); }},
{ 1324655, 65000, [](int height) { return make_shared<ReputationConsensus_checkpoint_1324655>(height); }},
{ 1324655, 75000, [](int height) { return make_shared<ReputationConsensus_checkpoint_1324655_2>(height); }},
{ 1680000, 761000, [](int height) { return make_shared<ReputationConsensus_checkpoint_scores_content_author_reducing_impact>(height); }},
{ 1680000, 772000, [](int height) { return make_shared<ReputationConsensus_checkpoint_scores_comment_author_disable_impact>(height); }},
{ 1700000, 761000, [](int height) { return make_shared<ReputationConsensus_checkpoint_scores_content_author_reducing_impact>(height); }},
{ 1700000, 772000, [](int height) { return make_shared<ReputationConsensus_checkpoint_scores_comment_author_disable_impact>(height); }},
};
public:
shared_ptr<ReputationConsensus> Instance(int height)
Expand Down
2 changes: 1 addition & 1 deletion src/pocketdb/consensus/moderation/Flag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace PocketConsensus
private:
const vector<ConsensusCheckpoint<ModerationFlagConsensus>> m_rules = {
{ 0, -1, [](int height) { return make_shared<ModerationFlagConsensus>(height); }},
{ 1680000, 761000, [](int height) { return make_shared<ModerationFlagConsensus_checkpoint_enable>(height); }},
{ 1700000, 761000, [](int height) { return make_shared<ModerationFlagConsensus_checkpoint_enable>(height); }},
};
public:
shared_ptr<ModerationFlagConsensus> Instance(int height)
Expand Down
Loading

0 comments on commit dbea23e

Please sign in to comment.