diff --git a/src/ckpool.c b/src/ckpool.c index 010f4a2a..72965287 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -23,7 +23,6 @@ #include "stratifier.h" #include "connector.h" -/* Only global variable, to be used only by sighandler */ ckpool_t *global_ckp; static void *listener(void *arg) diff --git a/src/ckpool.h b/src/ckpool.h index 11f50af1..6756df9b 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -12,113 +12,57 @@ #include "config.h" -#include - -#if HAVE_BYTESWAP_H -# include -#endif - -#if HAVE_ENDIAN_H -# include -#elif HAVE_SYS_ENDIAN_H -# include -#endif - -#ifndef bswap_16 - #define bswap_16 __builtin_bswap16 - #define bswap_32 __builtin_bswap32 - #define bswap_64 __builtin_bswap64 -#endif - -/* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then - * htobe64 also won't exist */ -#ifndef htobe32 -# if __BYTE_ORDER == __LITTLE_ENDIAN -# define htole16(x) (x) -# define le16toh(x) (x) -# define htole32(x) (x) -# define htole64(x) (x) -# define le32toh(x) (x) -# define le64toh(x) (x) -# define be32toh(x) bswap_32(x) -# define be64toh(x) bswap_64(x) -# define htobe16(x) bswap_16(x) -# define htobe32(x) bswap_32(x) -# define htobe64(x) bswap_64(x) -# elif __BYTE_ORDER == __BIG_ENDIAN -# define htole16(x) bswap_16(x) -# define le16toh(x) bswap_16(x) -# define htole32(x) bswap_32(x) -# define le32toh(x) bswap_32(x) -# define le64toh(x) bswap_64(x) -# define htole64(x) bswap_64(x) -# define be32toh(x) (x) -# define be64toh(x) (x) -# define htobe16(x) (x) -# define htobe32(x) (x) -# define htobe64(x) (x) -# endif -#endif - -#define unlikely(expr) (__builtin_expect(!!(expr), 0)) -#define likely(expr) (__builtin_expect(!!(expr), 1)) -#define __maybe_unused __attribute__((unused)) -#define uninitialised_var(x) x = x - -/* Typedefs are evil but we use this one so often... */ -typedef unsigned char uchar; - -typedef struct timeval tv_t; -typedef struct timespec ts_t; - -static inline void swap_256(void *dest_p, const void *src_p) -{ - uint32_t *dest = dest_p; - const uint32_t *src = src_p; - - dest[0] = src[7]; - dest[1] = src[6]; - dest[2] = src[5]; - dest[3] = src[4]; - dest[4] = src[3]; - dest[5] = src[2]; - dest[6] = src[1]; - dest[7] = src[0]; -} - -static inline void bswap_256(void *dest_p, const void *src_p) -{ - uint32_t *dest = dest_p; - const uint32_t *src = src_p; - - dest[0] = bswap_32(src[7]); - dest[1] = bswap_32(src[6]); - dest[2] = bswap_32(src[5]); - dest[3] = bswap_32(src[4]); - dest[4] = bswap_32(src[3]); - dest[5] = bswap_32(src[2]); - dest[6] = bswap_32(src[1]); - dest[7] = bswap_32(src[0]); -} - -static inline void flip_32(void *dest_p, const void *src_p) -{ - uint32_t *dest = dest_p; - const uint32_t *src = src_p; - int i; - - for (i = 0; i < 8; i++) - dest[i] = bswap_32(src[i]); -} - -static inline void flip_80(void *dest_p, const void *src_p) -{ - uint32_t *dest = dest_p; - const uint32_t *src = src_p; - int i; - - for (i = 0; i < 20; i++) - dest[i] = bswap_32(src[i]); -} +#include "libckpool.h" + +struct proc_instance; +typedef struct proc_instance proc_instance_t; +struct ckpool_instance; +typedef struct ckpool_instance ckpool_t; + +struct proc_instance { + ckpool_t *ckp; + unixsock_t us; + char *processname; + char *sockname; + int pid; + int (*process)(proc_instance_t *); +}; + +struct ckpool_instance { + /* Main process name */ + char *name; + /* Directory where sockets are created */ + char *socket_dir; + /* Filename of config file */ + char *config; + /* Logging level */ + int loglevel; + + /* Process instance data of parent/child processes */ + proc_instance_t main; + proc_instance_t generator; + proc_instance_t stratifier; + proc_instance_t connector; + + /* Threads of main process */ + pthread_t pth_listener; + pthread_t pth_watchdog; + + /* Bitcoind data */ + char *btcdurl; + char *btcdauth; + char *btcdpass; + int blockpoll; // How frequently in ms to poll bitcoind for block updates + + /* Coinbase data */ + char *btcaddress; // Address to mine to + char *btcsig; // Optional signature to add to coinbase + + /* Stratum options */ + int update_interval; // Seconds between stratum updates + char *serverurl; +}; + +ckpool_t *global_ckp; #endif /* CKPOOL_H */ diff --git a/src/libckpool.h b/src/libckpool.h index b3759e5b..d1b3e272 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -17,9 +17,116 @@ #include #include #include +#include #include #include +#if HAVE_BYTESWAP_H +# include +#endif + +#if HAVE_ENDIAN_H +# include +#elif HAVE_SYS_ENDIAN_H +# include +#endif + +#ifndef bswap_16 + #define bswap_16 __builtin_bswap16 + #define bswap_32 __builtin_bswap32 + #define bswap_64 __builtin_bswap64 +#endif + +/* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then + * htobe64 also won't exist */ +#ifndef htobe32 +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define htole16(x) (x) +# define le16toh(x) (x) +# define htole32(x) (x) +# define htole64(x) (x) +# define le32toh(x) (x) +# define le64toh(x) (x) +# define be32toh(x) bswap_32(x) +# define be64toh(x) bswap_64(x) +# define htobe16(x) bswap_16(x) +# define htobe32(x) bswap_32(x) +# define htobe64(x) bswap_64(x) +# elif __BYTE_ORDER == __BIG_ENDIAN +# define htole16(x) bswap_16(x) +# define le16toh(x) bswap_16(x) +# define htole32(x) bswap_32(x) +# define le32toh(x) bswap_32(x) +# define le64toh(x) bswap_64(x) +# define htole64(x) bswap_64(x) +# define be32toh(x) (x) +# define be64toh(x) (x) +# define htobe16(x) (x) +# define htobe32(x) (x) +# define htobe64(x) (x) +# endif +#endif + +#define unlikely(expr) (__builtin_expect(!!(expr), 0)) +#define likely(expr) (__builtin_expect(!!(expr), 1)) +#define __maybe_unused __attribute__((unused)) +#define uninitialised_var(x) x = x + +typedef unsigned char uchar; + +typedef struct timeval tv_t; +typedef struct timespec ts_t; + +static inline void swap_256(void *dest_p, const void *src_p) +{ + uint32_t *dest = dest_p; + const uint32_t *src = src_p; + + dest[0] = src[7]; + dest[1] = src[6]; + dest[2] = src[5]; + dest[3] = src[4]; + dest[4] = src[3]; + dest[5] = src[2]; + dest[6] = src[1]; + dest[7] = src[0]; +} + +static inline void bswap_256(void *dest_p, const void *src_p) +{ + uint32_t *dest = dest_p; + const uint32_t *src = src_p; + + dest[0] = bswap_32(src[7]); + dest[1] = bswap_32(src[6]); + dest[2] = bswap_32(src[5]); + dest[3] = bswap_32(src[4]); + dest[4] = bswap_32(src[3]); + dest[5] = bswap_32(src[2]); + dest[6] = bswap_32(src[1]); + dest[7] = bswap_32(src[0]); +} + +static inline void flip_32(void *dest_p, const void *src_p) +{ + uint32_t *dest = dest_p; + const uint32_t *src = src_p; + int i; + + for (i = 0; i < 8; i++) + dest[i] = bswap_32(src[i]); +} + +static inline void flip_80(void *dest_p, const void *src_p) +{ + uint32_t *dest = dest_p; + const uint32_t *src = src_p; + int i; + + for (i = 0; i < 20; i++) + dest[i] = bswap_32(src[i]); +} + #define mutex_lock(_lock) _mutex_lock(_lock, __FILE__, __func__, __LINE__) #define mutex_unlock_noyield(_lock) _mutex_unlock_noyield(_lock, __FILE__, __func__, __LINE__) #define mutex_unlock(_lock) _mutex_unlock(_lock, __FILE__, __func__, __LINE__) @@ -141,54 +248,7 @@ struct unixsock { typedef struct unixsock unixsock_t; -struct proc_instance; typedef struct proc_instance proc_instance_t; -struct ckpool_instance; -typedef struct ckpool_instance ckpool_t; - -struct proc_instance { - ckpool_t *ckp; - unixsock_t us; - char *processname; - char *sockname; - int pid; - int (*process)(proc_instance_t *); -}; - -struct ckpool_instance { - /* Main process name */ - char *name; - /* Directory where sockets are created */ - char *socket_dir; - /* Filename of config file */ - char *config; - /* Logging level */ - int loglevel; - - /* Process instance data of parent/child processes */ - proc_instance_t main; - proc_instance_t generator; - proc_instance_t stratifier; - proc_instance_t connector; - - /* Threads of main process */ - pthread_t pth_listener; - pthread_t pth_watchdog; - - /* Bitcoind data */ - char *btcdurl; - char *btcdauth; - char *btcdpass; - int blockpoll; // How frequently in ms to poll bitcoind for block updates - - /* Coinbase data */ - char *btcaddress; // Address to mine to - char *btcsig; // Optional signature to add to coinbase - - /* Stratum options */ - int update_interval; // Seconds between stratum updates - char *serverurl; -}; void rename_proc(const char *name); void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg); diff --git a/src/stratifier.c b/src/stratifier.c index 559694a3..8cb04c7c 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -743,8 +743,6 @@ static void add_submit_fail(stratum_instance_t *client, int diff) add_submit(client, diff); } -extern ckpool_t *global_ckp; - /* We should already be holding the workbase_lock */ static void test_blocksolve(workbase_t *wb, const uchar *data, double diff, const char *coinbase, int cblen)