Skip to content

Commit

Permalink
Linux compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonano614 committed Dec 7, 2018
1 parent ed53eea commit 695bce5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 51 deletions.
2 changes: 1 addition & 1 deletion client/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ enum xdag_field_type g_block_header_type = XDAG_FIELD_HEAD;
struct xdag_stats g_xdag_stats;
struct xdag_ext_stats g_xdag_extstats;
int g_disable_mining = 0;
int g_xdag_type = 0;
enum xdag_type g_xdag_type = 0;
char *g_coinname, *g_progname;
19 changes: 11 additions & 8 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include "network.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "json-rpc/rpc_service.h"
#include "xdag_config.h"
#include "json-rpc/rpc_service.h"
#include "../dnet/dnet_crypt.h"

#define ARG_EQUAL(a,b,c) strcmp(c, "") == 0 ? strcmp(a, b) == 0 : (strcmp(a, b) == 0 || strcmp(a, c) == 0)

Expand All @@ -54,9 +55,12 @@ time_t g_xdag_xfer_last = 0;
int(*g_xdag_show_state)(const char *state, const char *balance, const char *address) = 0;

int parse_startup_parameters(int argc, char **argv, struct startup_parameters *parameters);
int pre_init(void);
int setup_miner(struct startup_parameters *parameters);
int setup_pool(struct startup_parameters *parameters);
int dnet_key_init(void);
void printUsage(char* appName);
void set_xdag_name();
void set_xdag_name(void);

int xdag_init(int argc, char **argv, int isGui)
{
Expand Down Expand Up @@ -248,7 +252,7 @@ int parse_startup_parameters(int argc, char **argv, struct startup_parameters *p
return 1; // 1 - continue execution
}

int pre_init()
int pre_init(void)
{
if(!xdag_time_init()) {
printf("Cannot initialize time module\n");
Expand Down Expand Up @@ -333,9 +337,11 @@ int setup_pool(struct startup_parameters *parameters)
xdag_mess("Starting pool engine...");
if(xdag_initialize_mining(parameters->pool_arg, parameters->miner_address)) return -1;
}

return 0;
}

int dnet_key_init()
int dnet_key_init(void)
{
int err = dnet_crypt_init();
if(err < 0)
Expand All @@ -346,7 +352,7 @@ int dnet_key_init()
return 0;
}

void set_xdag_name()
void set_xdag_name(void)
{
g_progname = "xdag";
g_coinname = "XDAG";
Expand Down Expand Up @@ -392,6 +398,3 @@ void printUsage(char* appName)
" -tag - tag for pool to distingush pools. Max length is 32 chars\n"
, appName);
}



26 changes: 9 additions & 17 deletions client/xdag_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <stdio.h>
#include "xdag_config.h"


#ifndef true
#define true (1)
#endif
Expand All @@ -14,6 +13,7 @@

#if defined(_WIN32) || defined(_WIN64)
#define strkscmp _stricmp
#define strdup _strdup
#else
#define strkscmp strcasecmp
#endif
Expand All @@ -38,10 +38,6 @@ static char *trim(char *str)
return str;
}





typedef struct {
char *name;
char *value;
Expand All @@ -54,16 +50,13 @@ typedef struct {
char **key_names;
} NODE;



typedef struct {
char *path;
int number_nodes;
NODE **nodes;
char **node_names;
} CFG;


static const char COMMENT_MARK[] = { '#', '*' };
typedef enum {
TYPE_EMPTYLINE,
Expand Down Expand Up @@ -100,7 +93,6 @@ static char *readline(FILE *fp)
return line;
}


static int strn(const char *p, const char chr)
{
int count = 0;
Expand Down Expand Up @@ -255,7 +247,7 @@ static char *xdag_config_read_node_name(FILE *fp)
} else if(type == TYPE_KEY) {
free(line);
fseek(fp, offset, SEEK_SET);
return _strdup("");
return strdup("");
} else {
free(line);
offset = ftell(fp);
Expand Down Expand Up @@ -288,15 +280,15 @@ static int xdag_config_add_node(CFG *config, NODE *s)
}
if(!isEmpty(s->name)) {
config->nodes[config->number_nodes - 1] = s;
config->node_names[config->number_nodes - 1] = _strdup(s->name);
config->node_names[config->number_nodes - 1] = strdup(s->name);
} else {
int i;
for(i = config->number_nodes - 1; i > 0; i--) {
config->nodes[i] = config->nodes[i - 1];
config->node_names[i] = config->node_names[i - 1];
}
config->nodes[0] = s;
config->node_names[0] = _strdup(s->name);
config->node_names[0] = strdup(s->name);
}
return 0;
}
Expand All @@ -308,7 +300,7 @@ static NODE *xdag_add_node(const char *name)
printf("Configuration:add node memory initialization failed\n");
return NULL;
}
node->name = _strdup(name);
node->name = strdup(name);
node->number_keys = 0;
node->keys = NULL;
node->key_names = NULL;
Expand All @@ -322,7 +314,7 @@ static KEY *xdag_add_key(const char *name)
printf("Configuration:add key memory initialization failed\n");
return NULL;
}
k->name = _strdup(name);
k->name = strdup(name);
k->value = NULL;
return k;
}
Expand All @@ -341,7 +333,7 @@ static int xdag_config_add_key(NODE *node, KEY *key)
printf("Configuration:add key names memory initialization failed\n");
return -1;
}
node->key_names[node->number_keys - 1] = _strdup(key->name);
node->key_names[node->number_keys - 1] = strdup(key->name);
return 0;
}

Expand All @@ -363,7 +355,7 @@ static KEY *xdag_config_read_key(FILE *fp)
if(key == NULL) {
return NULL;
}
key->value = trim(_strdup(p + 1));
key->value = trim(strdup(p + 1));
free(line);
return key;
} else if(type == TYPE_NODE) {
Expand Down Expand Up @@ -429,7 +421,7 @@ static CFG *xdag_config_init(const char *path)
return NULL;
}
if(path != NULL) {
cfg->path = _strdup(path);
cfg->path = strdup(path);
} else {
cfg->path = NULL;
}
Expand Down
38 changes: 19 additions & 19 deletions dnet/dnet_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static struct dfslib_crypt *g_dnet_user_crypt = 0;

struct dnet_session {
struct dnet_key key;
uint32_t sector_write[SECTOR_SIZE / 4];
uint32_t sector_read[SECTOR_SIZE / 4];
uint32_t sector_write[CRYPT_SECTOR_SIZE / 4];
uint32_t sector_read[CRYPT_SECTOR_SIZE / 4];
struct dfslib_crypt crypt_write;
struct dfslib_crypt crypt_read;
uint64_t pos_write, pos_read;
Expand Down Expand Up @@ -93,33 +93,33 @@ static int dnet_rsa_crypt(dfsrsa_t *data, int datalen, dfsrsa_t *key, int keylen

#define dfsrsa_crypt dnet_rsa_crypt

static void dnet_sector_to_password(uint32_t sector[SECTOR_SIZE / 4], char password[PWDLEN + 1])
static void dnet_sector_to_password(uint32_t sector[CRYPT_SECTOR_SIZE / 4], char password[PWDLEN + 1])
{
for(int i = 0; i < PWDLEN / 8; ++i) {
unsigned crc = crc_of_array((unsigned char *)(sector + i * SECTOR_SIZE / 4 / (PWDLEN / 8)), SECTOR_SIZE / (PWDLEN / 8));
unsigned crc = crc_of_array((unsigned char *)(sector + i * CRYPT_SECTOR_SIZE / 4 / (PWDLEN / 8)), CRYPT_SECTOR_SIZE / (PWDLEN / 8));
sprintf(password + 8 * i, "%08X", crc);
}
}

static void dnet_random_sector(uint32_t sector[SECTOR_SIZE / 4])
static void dnet_random_sector(uint32_t sector[CRYPT_SECTOR_SIZE / 4])
{
char password[PWDLEN + 1] = "Iyf&%d#$jhPo_t|3fgd+hf(s@;)F5D7gli^kjtrd%.kflP(7*5gt;Y1sYRC4VGL&";
for(int i = 0; i < 3; ++i) {
struct dfslib_string str;
dfslib_utf8_string(&str, password, PWDLEN);
dfslib_random_sector(sector, 0, &str, &str);
for(int j = KEYLEN_MIN / 8; j <= SECTOR_SIZE / 4; j += KEYLEN_MIN / 8) {
for(int j = KEYLEN_MIN / 8; j <= CRYPT_SECTOR_SIZE / 4; j += KEYLEN_MIN / 8) {
sector[j - 1] &= 0x7FFFFFFF;
}
if(i == 2) break;
dfsrsa_crypt((dfsrsa_t *)sector, SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN);
dfsrsa_crypt((dfsrsa_t *)sector, CRYPT_SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN);
dnet_sector_to_password(sector, password);
}
}

int dnet_generate_random_array(void *array, unsigned long size)
{
uint32_t sector[SECTOR_SIZE / 4];
uint32_t sector[CRYPT_SECTOR_SIZE / 4];
unsigned long i;
if(size < 4 || size & (size - 1)) return -1;
if(size >= 512) {
Expand All @@ -142,16 +142,16 @@ void dnet_generate_stream_id(struct dnet_stream_id *id)

static int dnet_test_keys(void)
{
uint32_t src[SECTOR_SIZE / 4], dest[SECTOR_SIZE / 4];
uint32_t src[CRYPT_SECTOR_SIZE / 4], dest[CRYPT_SECTOR_SIZE / 4];
dnet_random_sector(src);
memcpy(dest, src, SECTOR_SIZE);
if(dfsrsa_crypt((dfsrsa_t *)dest, SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN)) return 1;
if(dfsrsa_crypt((dfsrsa_t *)dest, SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->pub.key, DNET_KEYLEN)) return 2;
if(memcmp(dest, src, SECTOR_SIZE)) return 3;
memcpy(dest, src, SECTOR_SIZE);
if(dfsrsa_crypt((dfsrsa_t *)dest, SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->pub.key, DNET_KEYLEN)) return 4;
if(dfsrsa_crypt((dfsrsa_t *)dest, SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN)) return 5;
if(memcmp(dest, src, SECTOR_SIZE)) return 6;
memcpy(dest, src, CRYPT_SECTOR_SIZE);
if(dfsrsa_crypt((dfsrsa_t *)dest, CRYPT_SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN)) return 1;
if(dfsrsa_crypt((dfsrsa_t *)dest, CRYPT_SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->pub.key, DNET_KEYLEN)) return 2;
if(memcmp(dest, src, CRYPT_SECTOR_SIZE)) return 3;
memcpy(dest, src, CRYPT_SECTOR_SIZE);
if(dfsrsa_crypt((dfsrsa_t *)dest, CRYPT_SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->pub.key, DNET_KEYLEN)) return 4;
if(dfsrsa_crypt((dfsrsa_t *)dest, CRYPT_SECTOR_SIZE / sizeof(dfsrsa_t), g_dnet_keys->priv.key, DNET_KEYLEN)) return 5;
if(memcmp(dest, src, CRYPT_SECTOR_SIZE)) return 6;
return 0;
}

Expand Down Expand Up @@ -236,7 +236,7 @@ int dnet_user_crypt_action(unsigned *data, unsigned long long data_id, unsigned
return 0;
}

int dnet_crypt_init()
int dnet_crypt_init(void)
{
g_dnet_keys = malloc(sizeof(struct dnet_keys));
if(!g_dnet_keys) return 1;
Expand Down Expand Up @@ -313,7 +313,7 @@ int dnet_crypt_init()
return -dnet_test_keys();
}

void dnet_session_init_crypt(struct dfslib_crypt *crypt, uint32_t sector[SECTOR_SIZE / 4])
void dnet_session_init_crypt(struct dfslib_crypt *crypt, uint32_t sector[CRYPT_SECTOR_SIZE / 4])
{
char password[PWDLEN + 1];
struct dfslib_string str;
Expand Down
10 changes: 4 additions & 6 deletions dnet/dnet_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define DNET_KEY_SIZE 4096
#define DNET_KEYLEN ((DNET_KEY_SIZE * 2) / (sizeof(dfsrsa_t) * 8))

#define SECTOR_LOG 9
#define SECTOR_SIZE (1 << SECTOR_LOG)
#define CRYPT_SECTOR_LOG 9
#define CRYPT_SECTOR_SIZE (1 << CRYPT_SECTOR_LOG)

struct dnet_key {
dfsrsa_t key[DNET_KEYLEN];
Expand All @@ -25,15 +25,13 @@ struct dnet_stream_id {
extern "C" {
#endif

extern int dnet_crypt_init();
extern int dnet_crypt_init(void);

extern void dnet_generate_stream_id(struct dnet_stream_id *id);
extern void dnet_session_init_crypt(struct dfslib_crypt *crypt, uint32_t sector[SECTOR_SIZE / 4]);
extern void dnet_session_init_crypt(struct dfslib_crypt *crypt, uint32_t sector[CRYPT_SECTOR_SIZE / 4]);

#ifdef __cplusplus
};
#endif

#endif


0 comments on commit 695bce5

Please sign in to comment.