Initial multiple pools support [1/2].
This commit is contained in:
parent
faf793b0aa
commit
952017ae7a
6 changed files with 162 additions and 111 deletions
|
@ -45,8 +45,8 @@ Network::Network(const Options *options) :
|
|||
m_agent = userAgent();
|
||||
|
||||
addPool(std::make_unique<Url>().get());
|
||||
addPool(m_options->url());
|
||||
addPool(m_options->backupUrl());
|
||||
// addPool(m_options->url());
|
||||
// addPool(m_options->backupUrl());
|
||||
|
||||
m_timer.data = this;
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
|
@ -120,7 +120,7 @@ void Network::onJobResult(const JobResult &result)
|
|||
|
||||
void Network::onLoginCredentialsRequired(Client *client)
|
||||
{
|
||||
client->login(m_options->user(), m_options->pass(), m_agent);
|
||||
// client->login(m_options->user(), m_options->pass(), m_agent);
|
||||
}
|
||||
|
||||
|
||||
|
|
105
src/net/Url.cpp
105
src/net/Url.cpp
|
@ -35,8 +35,12 @@
|
|||
|
||||
|
||||
Url::Url() :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_port(3333)
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,40 +57,22 @@ Url::Url() :
|
|||
* @param url
|
||||
*/
|
||||
Url::Url(const char *url) :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_port(3333)
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
const char *p = strstr(url, "://");
|
||||
const char *base = url;
|
||||
|
||||
if (p) {
|
||||
if (strncasecmp(url, "stratum+tcp://", 14)) {
|
||||
return;
|
||||
}
|
||||
|
||||
base = url + 14;
|
||||
}
|
||||
|
||||
if (!strlen(base) || *base == '/') {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *port = strchr(base, ':');
|
||||
if (!port) {
|
||||
m_host = strdup(base);
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t size = port++ - base + 1;
|
||||
m_host = static_cast<char*>(malloc(size));
|
||||
memcpy(m_host, base, size - 1);
|
||||
m_host[size - 1] = '\0';
|
||||
|
||||
m_port = strtol(port, nullptr, 10);
|
||||
parse(url);
|
||||
}
|
||||
|
||||
|
||||
Url::Url(const char *host, uint16_t port) :
|
||||
Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash) :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_port(port)
|
||||
{
|
||||
m_host = strdup(host);
|
||||
|
@ -96,10 +82,67 @@ Url::Url(const char *host, uint16_t port) :
|
|||
Url::~Url()
|
||||
{
|
||||
free(m_host);
|
||||
free(m_password);
|
||||
free(m_user);
|
||||
}
|
||||
|
||||
|
||||
bool Url::isNicehash() const
|
||||
{
|
||||
return isValid() && strstr(m_host, ".nicehash.com");
|
||||
return isValid() && (m_nicehash || strstr(m_host, ".nicehash.com"));
|
||||
}
|
||||
|
||||
|
||||
bool Url::parse(const char *url)
|
||||
{
|
||||
const char *p = strstr(url, "://");
|
||||
const char *base = url;
|
||||
|
||||
if (p) {
|
||||
if (strncasecmp(url, "stratum+tcp://", 14)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
base = url + 14;
|
||||
}
|
||||
|
||||
if (!strlen(base) || *base == '/') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *port = strchr(base, ':');
|
||||
if (!port) {
|
||||
m_host = strdup(base);
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t size = port++ - base + 1;
|
||||
m_host = static_cast<char*>(malloc(size));
|
||||
memcpy(m_host, base, size - 1);
|
||||
m_host[size - 1] = '\0';
|
||||
|
||||
m_port = strtol(port, nullptr, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Url::setPassword(const char *password, bool force)
|
||||
{
|
||||
if (m_password != nullptr && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(m_password);
|
||||
m_password = strdup(password);
|
||||
}
|
||||
|
||||
|
||||
void Url::setUser(const char *user, bool force)
|
||||
{
|
||||
if (m_user != nullptr && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(m_user);
|
||||
m_user = strdup(user);
|
||||
}
|
||||
|
|
|
@ -31,19 +31,35 @@
|
|||
class Url
|
||||
{
|
||||
public:
|
||||
constexpr static const char *kDefaultPassword = "x";
|
||||
constexpr static const char *kDefaultUser = "x";
|
||||
constexpr static uint16_t kDefaultPort = 3333;
|
||||
|
||||
Url();
|
||||
Url(const char *url);
|
||||
Url(const char *host, uint16_t port);
|
||||
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false );
|
||||
~Url();
|
||||
|
||||
bool isNicehash() const;
|
||||
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||
inline bool isValid() const { return m_host && m_port > 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
inline const char *password() const { return m_password ? m_password : kDefaultPassword; }
|
||||
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
|
||||
inline bool isValid() const { return m_host && m_port > 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
bool isNicehash() const;
|
||||
bool parse(const char *url);
|
||||
void setPassword(const char *password, bool force = true);
|
||||
void setUser(const char *user, bool force = true);
|
||||
|
||||
private:
|
||||
bool m_keepAlive;
|
||||
bool m_nicehash;
|
||||
char *m_host;
|
||||
char *m_password;
|
||||
char *m_user;
|
||||
uint16_t m_port;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue