nxducominer
A multithreaded DUCO miner for the Nintendo Switch
 
Loading...
Searching...
No Matches
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <switch.h>
#include <curl/curl.h>
#include <pthread.h>
#include <errno.h>
#include <stdatomic.h>
#include "dashboard.h"
#include "switch/crypto/sha1.h"
#include "jsmn.h"

Go to the source code of this file.

Data Structures

struct  MiningResults
 aggregated mining results of all threads More...
 
struct  ThreadData
 thread-specific mining data and state More...
 
struct  WebDashboard
 web dashboard server information More...
 
struct  ResourceManager
 resource manager for system-wide state More...
 
struct  MiningConfig
 mining configuration from config file More...
 
struct  MemoryStruct
 memory buffer for CURL operation More...
 

Macros

#define CONFIG_FILE   "config.txt"
 config file/path
 
#define SOFTWARE   "nxducominer"
 software identifier
 
#define GET_POOL   "https://server.duinocoin.com/getPool"
 pool server url
 
#define DUCO_ORANGE   CONSOLE_ESC(38;2;252;104;3m)
 duinocoin branding https://github.com/revoxhere/duino-coin/tree/useful-tools#branding
 
#define ERROR_RED   CONSOLE_ESC(31m)
 
#define NOTICE_BLUE   CONSOLE_ESC(38;2;135;206;235m)
 
#define DARK_GREY   CONSOLE_ESC(38;2;90;90;90m)
 
#define LIGHT_GREY   CONSOLE_ESC(38;2;135;135;135m)
 
#define RESET   CONSOLE_ESC(0m)
 
#define CONSOLE_ESC_NSTR(fmt)   "\033[" fmt
 console escape helper, does not stringify.
 

Functions

void cleanup (char *msg)
 clean up resources and exit
 
const char * get_psm_charger_type (PsmChargerType type)
 string representation of charger type
 
void get_time_string (char *buffer, int size)
 get current time as formatted string
 
void * safe_malloc (size_t size)
 safe malloc with zero-initialization
 
char * safe_strdup (const char *src)
 safe strdup
 
void set_dynamic_string (char **field, const char *value)
 set dynamic string field with memory management
 
ssize_t safe_write (int fd, const char *buf, size_t len)
 safe socket write with retry
 
static size_t write_memory_callback (void *contents, size_t size, size_t nmemb, void *userp)
 CURL write callback for memory buffer.
 
void replace_placeholder (char **str, const char *placeholder, const char *value)
 replace all occurrences of placeholder in string (html) with value
 
void parse_config_file (MiningConfig *config)
 parse configuration file
 
void get_node (char **ip, int *port, char **name)
 get mining node from DuinoCoin server
 
void * do_mining_work (void *arg)
 mining thread worker function
 
void * web_dashboard (void *arg)
 web dashboard server thread
 
int main ()
 entry point
 

Variables

MiningResults mr
 
WebDashboard web
 
ResourceManager res
 
MiningConfig mc
 

Macro Definition Documentation

◆ CONFIG_FILE

#define CONFIG_FILE   "config.txt"

config file/path

Definition at line 19 of file main.c.

◆ CONSOLE_ESC_NSTR

#define CONSOLE_ESC_NSTR (   fmt)    "\033[" fmt

console escape helper, does not stringify.

Definition at line 31 of file main.c.

◆ DARK_GREY

#define DARK_GREY   CONSOLE_ESC(38;2;90;90;90m)

Definition at line 27 of file main.c.

◆ DUCO_ORANGE

#define DUCO_ORANGE   CONSOLE_ESC(38;2;252;104;3m)

duinocoin branding https://github.com/revoxhere/duino-coin/tree/useful-tools#branding

Definition at line 24 of file main.c.

◆ ERROR_RED

#define ERROR_RED   CONSOLE_ESC(31m)

Definition at line 25 of file main.c.

◆ GET_POOL

#define GET_POOL   "https://server.duinocoin.com/getPool"

pool server url

Definition at line 21 of file main.c.

◆ LIGHT_GREY

#define LIGHT_GREY   CONSOLE_ESC(38;2;135;135;135m)

Definition at line 28 of file main.c.

◆ NOTICE_BLUE

#define NOTICE_BLUE   CONSOLE_ESC(38;2;135;206;235m)

Definition at line 26 of file main.c.

◆ RESET

#define RESET   CONSOLE_ESC(0m)

Definition at line 29 of file main.c.

◆ SOFTWARE

#define SOFTWARE   "nxducominer"

software identifier

Definition at line 20 of file main.c.

Function Documentation

◆ cleanup()

void cleanup ( char *  msg)

clean up resources and exit

Parameters
msgoptional error message to display before exiting
Note
This function terminates the program

Definition at line 165 of file main.c.

◆ do_mining_work()

void * do_mining_work ( void *  arg)

mining thread worker function

Parameters
argThreadData structure for this thread
Returns
NULL

Definition at line 570 of file main.c.

◆ get_node()

void get_node ( char **  ip,
int *  port,
char **  name 
)

get mining node from DuinoCoin server

Parameters
ipoutput parameter for node IP
portoutput parameter for node port
Note
calls cleanup() on error

Definition at line 469 of file main.c.

◆ main()

int main ( )

entry point

Returns
exit status
Note
initializes systems, starts threads, and manages main loop

< this is to combine multithreaded workloads to appear as one single device in the wallet.

Definition at line 806 of file main.c.

◆ parse_config_file()

void parse_config_file ( MiningConfig config)

parse configuration file

Parameters
configpopulates MiningConfig
Note
calls cleanup() on error

Definition at line 391 of file main.c.

◆ web_dashboard()

void * web_dashboard ( void *  arg)

web dashboard server thread

Parameters
argWebDashboard struct
Returns
NULL

Definition at line 727 of file main.c.