Why Nostr? What is Njump?
2024-07-03 00:54:19

npub1sz…8t5st on Nostr: commit e7e7f3882bfc97be0b9620051f9691317c28fe41 Author: @RandyMcMillan ...

commit e7e7f3882bfc97be0b9620051f9691317c28fe41
Author: @RandyMcMillan <[email protected]>
Date: Tue Jan 9 00:03:14 2024 -0500

src

diff --git a/src/gnostr-get-relays.c b/src/gnostr-get-relays.c
index 6869ee524..beafc1a70 100755
--- a/src/gnostr-get-relays.c
+++ b/src/gnostr-get-relays.c
@@ -3,11 +3,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+void help(){
+ printf("help");
+ exit(0);
+}
+void version(){
+ printf("v0.0.0");
+ exit(0);
+}
int main(int argc, const char **argv) {
+ //printf("%d",argc);//exit(0);
+ if (argc >= 2){
+ if (argv[0]){
+ //printf(" %s",argv[0]);
+ }
+ if (argv[1]){
+ //printf(" %s",argv[1]);
+ }
+ if (!strcmp(argv[1], "-h")){
+ //printf("argv[1]: %s",argv[1]);
+ help();
+ }
+ if (!strcmp(argv[1], "--help")){
+ //printf("argv[1]: %s",argv[1]);
+ help();
+ }
+ if (!strcmp(argv[1], "-v")){
+ version();
+ }
+ if (!strcmp(argv[1], "--version")){
+ version();
+ }
+ exit(0);
+ }
char command[128];
strcpy(command, "curl -sS 'https://api.nostr.watch/v1/online'; > /tmp/gnostr.relays ");
system(command);
- strcpy(command, "cat /tmp/gnostr.relays ");
+ strcpy(command, "echo $(cat /tmp/gnostr.relays | sed 's/\\[//' | sed 's/\\]//' | sed 's/\"//g')");
system(command);
return 0;
}
diff --git a/src/gnostr-pi.c b/src/gnostr-pi.c
index 243f6e06c..a95311984 100644
--- a/src/gnostr-pi.c
+++ b/src/gnostr-pi.c
@@ -3,6 +3,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
+#include <time.h>
+
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
+#ifdef _OPENMP
+ #include <omp.h> // This line won't add the library if you don't compile with -fopenmp option.
+ #ifdef _MSC_VER
+ // For Microsoft compiler
+ #define OMP_FOR(n) __pragma(omp parallel for if(n>10))
+ #else // assuming "__GNUC__" is defined
+ // For GCC compiler
+ #define OMP_FOR(n) _Pragma("omp parallel for if(n>10)")
+ #endif
+#else
+ #define omp_get_thread_num() 0
+ #define OMP_FOR(n)
+#endif
+
+
+#ifdef _OPENMP
+#define N 20000
+#define THREADS_NB omp_get_max_threads()
+
+void init_arrays(double *a, double *b) {
+ memset(a, 0, sizeof(a));
+ memset(b, 0, sizeof(b));
+ for (int i = 0; i < N; i++) {
+ a[i] += 1.0;
+ b[i] += 1.0;
+ }
+}
+
+double func2(double i, double j) {
+ double res = 0.0;
+
+ while (i / j > 0.0) {
+ res += i / j;
+ i -= 0.1;
+ j -= 0.000003;
+ }
+ return res;
+}
+
+double single_thread(double *a, double *b) {
+ double res = 0;
+ int i, j;
+ for (i = 0; i < N; i++) {
+ for (j = 0; j < N; j++) {
+ if (i == j) continue;
+ res += func2(a[i], b[j]);
+ }
+ }
+ return res;
+}
+
+double multi_threads(double *a, double *b) {
+ double res = 0;
+ int i, j;
+ #pragma omp parallel for private(j) num_threads(THREADS_NB) reduction(+:res)
+ for (i = 0; i < N; i++) {
+ for (j = 0; j < N; j++) {
+ if (i == j) continue;
+ res += func2(a[i], b[j]);
+ }
+ }
+ return res;
+}
+
+int bench(void) {
+ double *a, *b;
+ a = (double *)calloc(N, sizeof(double));
+ b = (double *)calloc(N, sizeof(double));
+ init_arrays(a, b);
+
+ clock_t start_time = clock();
+ double res = single_thread(a, b);
+ double elapsed_time = (double)(clock() - start_time) / CLOCKS_PER_SEC;
+ printf("Default: Done with %f in %f sd\n", res, elapsed_time);
+
+ start_time = clock();
+ res = multi_threads(a, b);
+ elapsed_time = (double)(clock() - start_time) / CLOCKS_PER_SEC;
+ printf("With OMP: Done with %f in %f sd\n", res, elapsed_time / THREADS_NB);
+
+ return elapsed_time;
+}
+#endif

void int2bin(int n, int* bin, int* bin_size, const int bits);

@@ -73,6 +163,131 @@ http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/spigot.pdf

int main(int argc, char** argv) {

+if (DEBUG) { printf("main:%x\n",argc); }
+
+if (argc == 1) {
+
+ if (DEBUG) { printf("==1:%x\n",argc); }
+
+}
+if (argc == 2) {
+
+ if (DEBUG) { printf("==2:%x\n",argc); }
+
+}
+if (argc == 3) {
+
+ if (DEBUG) { printf("==3:%x\n",argc); }
+
+}
+if (argc >= 3) {
+
+ if (DEBUG) { printf(">=3:%x\n",argc); }
+
+}
+if (argc >= 2) {
+
+ if (DEBUG) {
+
+ printf(">=2:%x\n",argc);
+
+ }
+
+ #ifdef _OPENMP
+
+ if (!strcmp(argv[1], "--bench")) {
+
+ if (DEBUG) {
+
+ printf("BENCH:DEBUG:%x\n",argc);
+ printf("strcmp(argv[1],\"--bench\") = %x\n", !strcmp(argv[1], "--bench"));
+
+ } else {
+
+ printf("BENCH:ELSE:DEBUG:%x\n",argc);
+ printf("strcmp(argv[1],\"--bench\") = %x\n", !strcmp(argv[1], "--bench"));
+
+ }
+
+ }
+
+ #endif
+
+ if (!strcmp(argv[1], "--test")) {
+
+ if (DEBUG) {
+
+ printf("TEST:%x\n",argc);
+ printf("strcmp(argv[1],\"--test\") = %x\n", !strcmp(argv[1], "--test"));
+
+ }
+
+ }
+ if (!strcmp(argv[1], "-t")) {
+
+ if (DEBUG) {
+
+ printf("T:%x\n",argc);
+ printf("strcmp(argv[1],\"-t\") = %x\n", !strcmp(argv[1], "-t"));
+
+ };
+
+ }
+ if (!strcmp(argv[1], "--help")) {
+
+ if (DEBUG) {
+
+ printf("HELP:%x\n",argc);
+ printf("strcmp(argv[1],\"--help\") = %x\n", !strcmp(argv[1], "--help"));
+
+ }
+
+ }
+ if (!strcmp(argv[1], "-h")) {
+
+ if (DEBUG) {
+
+ printf("H:%x\n",argc);
+ printf("strcmp(argv[1],\"-h\") = %x\n", !strcmp(argv[1], "-h"));
+
+ }
+
+ }
+ if (!strcmp(argv[1], "--version")) {
+
+ if (DEBUG) {
+
+ printf("VERSION:%x\n",argc);
+ printf("strcmp(argv[1],\"--version\") = %x\n", !strcmp(argv[1], "--version"));
+
+ }
+
+ }
+ if (!strcmp(argv[1], "-v")) {
+
+ if (DEBUG) {
+
+ printf("V:%x\n",argc);
+ printf("strcmp(argv[1],\"-v\") = %x\n", !strcmp(argv[1], "-v"));
+
+ }
+
+ }
+
+ } else {
+
+ if (DEBUG) {
+
+ printf("ELSE:DEBUG:%x\n",argc);
+
+ } else {
+
+ //printf("ELSE:ELSE:%x\n",argc);
+
+ }
+
+}
+
/*
input 0 4 8 12 16 20 24 28 etc...
*/
@@ -80,7 +295,6 @@ int main(int argc, char** argv) {
/*
begin int2bin
*/
-
char ch;
ch = 'A';
int binary[32];
diff --git a/src/log.cc b/src/log.cc
index dc9fe7b3d..4a859fde4 100644
--- a/src/log.cc
+++ b/src/log.cc
@@ -1,4 +1,4 @@
-// This file is part of 'Nostr_client_relay'
+// This file is part of 'Nostr_client_relay'
// Copyright (c) 2023, Space Research Software LLC, Pedro Vicente. All rights reserved.
// See file LICENSE for full license details.

@@ -24,7 +24,7 @@ extern std::string log_program_name;

void comm::start_log()
{
- ofs_log.open(log_program_name + ".log.txt", std::ofstream::trunc);
+ ofs_log.open("/tmp/" + log_program_name + ".log", std::ofstream::trunc);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/wss_client.cc b/src/wss_client.cc
index 086486442..e227399d0 100644
--- a/src/wss_client.cc
+++ b/src/wss_client.cc
@@ -1,4 +1,4 @@
-// This file is part of 'Nostr_client_relay'
+// This file is part of 'gnostr-client'
// Copyright (c) 2023, Space Research Software LLC, Pedro Vicente. All rights reserved.
// See file LICENSE for full license details.

@@ -13,7 +13,7 @@
#include "uuid.hh"

using WssClient = SimpleWeb::SocketClient<SimpleWeb::WSS>;
-std::string log_program_name("nostro");
+std::string log_program_name("gnostr-client");
std::vector<std::string> store;

/////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -25,7 +25,7 @@ std::vector<std::string> store;

void usage()
{
- std::cout << "./nostro [OPTIONS]" << std::endl;
+ std::cout << "gnostr-client [OPTIONS]" << std::endl;
std::cout << "[OPTIONS]:" << std::endl;
std::cout << " --uri <wss URI> Wss URI to send" << std::endl;
std::cout << " --req message is a request (REQ). EVENT parameters are ignored" << std::endl;
@@ -37,6 +37,11 @@ void usage()
std::cout << " --sec <hex seckey> set the secret key for signing, otherwise one will be randomly generated" << std::endl;
exit(0);
}
+void version()
+{
+ std::cout << "v0.0.0" << std::endl;
+ exit(0);
+}

/////////////////////////////////////////////////////////////////////////////////////////////////////
// main
@@ -59,11 +64,16 @@ int main(int argc, const char* argv[])
for (int i = 1; i < argc; ++i)
{
std::string arg = argv[i];
- if (arg == "--help")
+ if (arg == "--help" || arg == "-h")
{
usage();
return 0;
}
+ else if (arg == "--version" || arg == "-v")
+ {
+ version();
+ return 0;
+ }
else if (arg == "--req")
{
is_req = 1;
diff --git a/src/wss_req.cc b/src/wss_req.cc
index 511c66390..e87d6a7b8 100644
--- a/src/wss_req.cc
+++ b/src/wss_req.cc
@@ -64,6 +64,11 @@ int main(int argc, const char* argv[])
usage();
return 0;
}
+ if (arg == "--version")
+ {
+ printf("v0.0.0");
+ return 0;
+ }
else if (arg == "--req")
{
is_req = 1;
Author Public Key
npub1sz79j4cuw4qzalp9txrxemxp88sfjh7tspupcsu5egdm65yfda5qx8t5st