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

npub1pv…w75ht on Nostr: commit b344700411bb9ede3caecc60af9754f966f54d98 Author: @RandyMcMillan ...

commit b344700411bb9ede3caecc60af9754f966f54d98
Author: @RandyMcMillan <[email protected]>
Date: Thu Oct 19 21:09:46 2023 -0400

src/gnostr-pi.c:CMakeLists.txt:build/install

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 238b84827..f670444ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,81 +1,329 @@
+# 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.
+
if (MSVC)
cmake_minimum_required(VERSION 3.26)
else()
cmake_minimum_required(VERSION 3.15)
endif()
set(CMAKE_BUILD_TYPE Debug)
-project (nostril C)
+project (nostr_client_relay LANGUAGES CXX C)
+
+option(BUILD_RELEASE "BUILD_RELEASE" ON)
+
+if(BUILD_RELEASE)
+ set(CMAKE_BUILD_TYPE Release)
+endif()
+
+option(BUILD_STATIC "BUILD_STATIC" OFF)
+option(BUILD_GUI "BUILD_STATIC" OFF)
+option(BUILD_WEB "BUILD_WEB" OFF)
+option(USE_OPENSSL "set OFF to build without OpenSSL" ON)
+option(DEV_MODE "DEV_MODE" OFF)
+option(OPENSSL_BREW "OPENSSL_BREW" ON)
+
+if(MSVC)
+if(BUILD_STATIC)
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+endif()
+endif()
+
+message("-- nostr_client_relay static build: " ${BUILD_STATIC})
+message(STATUS "Source directory is " ${CMAKE_SOURCE_DIR})
+message(STATUS "Build directory is " ${CMAKE_CURRENT_BINARY_DIR})
+
+#//////////////////////////
+# external dependencies
+#//////////////////////////
+
+include_directories(${CMAKE_SOURCE_DIR}/ext/asio-1.18.1/include)
+include_directories(${CMAKE_SOURCE_DIR}/ext/json-3.11.2/single_include)
+include_directories(${CMAKE_SOURCE_DIR}/ext/secp256k1-0.3.2/include)
+add_subdirectory(${CMAKE_SOURCE_DIR}/ext/secp256k1-0.3.2)
+
+if(BUILD_WEB)
+if(MSVC)
+if(DEV_MODE)
+ set(BOOST_PREFIX ${CMAKE_SOURCE_DIR}/ext/boost_1_82_0)
+ add_subdirectory(${CMAKE_SOURCE_DIR}/ext/wt-4.10.0)
+ add_definitions(-DDEV_MODE)
+endif()
+endif()
+endif()
+
+#//////////////////////////
+# nostril
+#//////////////////////////
+
+add_subdirectory(${CMAKE_SOURCE_DIR}/src/nostril)
+include_directories(${CMAKE_SOURCE_DIR}/src/nostril)
+
+include_directories(src)

-include_directories(${CMAKE_SOURCE_DIR}/deps/secp256k1/include)
-add_subdirectory(${CMAKE_SOURCE_DIR}/deps/secp256k1)
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#//////////////////////////
-#windows.h header file has macros for min and max, nostril defines max
+# Asio definitions
#//////////////////////////

+set(CMAKE_CXX_STANDARD 17)
+add_definitions(-DASIO_STANDALONE)
+add_definitions(-DASIO_HAS_STD_ADDRESSOF)
+add_definitions(-DASIO_HAS_STD_ARRAY)
+add_definitions(-DASIO_HAS_CSTDINT)
+add_definitions(-DASIO_HAS_STD_SHARED_PTR)
+add_definitions(-DASIO_HAS_STD_TYPE_TRAITS)
+add_definitions(-DASIO_HAS_VARIADIC_TEMPLATES)
+add_definitions(-DASIO_HAS_STD_FUNCTION)
+add_definitions(-DASIO_HAS_STD_CHRONO)
+add_definitions(-DBOOST_ALL_NO_LIB)
if (MSVC)
- add_definitions(-DNOMINMAX)
+ add_definitions(-D_WIN32_WINNT=0x0501)
+ add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
endif()

#//////////////////////////
-#sources
+# Linux/Mac
#//////////////////////////

-set(src ${src})
-set(src ${src} hex.h)
-set(src ${src} proof.h)
-set(src ${src} cursor.h)
-set(src ${src} endian.h)
-set(src ${src} random.h)
-set(src ${src} sha256.h)
-set(src ${src} sha256.c)
-set(src ${src} base64.h)
-set(src ${src} base64.c)
-set(src ${src} aes.h)
-set(src ${src} aes.c)
-if (MSVC)
- set(src ${src} clock_gettime.h)
+if(UNIX AND NOT APPLE)
+ set(LINUX TRUE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations -Wno-nonnull -Wno-psabi")
+ message(STATUS "Compiler flags: ${CMAKE_CXX_FLAGS}")
+endif()
+
+if(UNIX AND APPLE)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations -Wno-nonnull")
+ message(STATUS "Compiler flags: ${CMAKE_CXX_FLAGS}")
endif()

+#//////////////////////////
+# Nostr library
+#//////////////////////////
+
+set(src ${src})
+set(src ${src} src/log.hh)
+set(src ${src} src/log.cc)
+set(src ${src} src/nostr.hh)
+set(src ${src} src/nostr.cc)
+set(src ${src} src/relay.hh)
+set(src ${src} src/relay.cc)
+set(src ${src} src/uuid.cc)
+set(src ${src} src/uuid.hh)
+set(src ${src} src/database.hh)
+set(src ${src} src/database.cc)
+
+add_library(nostr ${src})
+add_dependencies(nostr configurator)
+
##TODO:rename to gnostr-get-relays
## once tools are stable
add_executable(gnostr-get-relays-c src/gnostr-get-relays.c)

+add_executable(gnostr-pi src/gnostr-pi.c)
+
#//////////////////////////
-#link with libraries
-#lib_dep contains a cascade definition of all the libraries needed to link
+# link with libraries
+# lib_dep contains a cascade definition of all the libraries needed to link
#//////////////////////////

set(lib_dep ${lib_dep})
-set(lib_dep ${lib_dep} ${CMAKE_SOURCE_DIR}/deps/secp256k1/.libs/libsecp256k1.a)
+set(lib_dep ${lib_dep} nostr)
+set(lib_dep ${lib_dep} secp256k1)
+set(lib_dep ${lib_dep} nostri)
if (MSVC)
- set(lib_dep ${lib_dep} ${CMAKE_SOURCE_DIR}/deps/secp256k1/src/Debug/libsecp256k1.lib)
+ set(lib_dep ${lib_dep} Ws2_32.lib)
set(lib_dep ${lib_dep} Bcrypt.lib)
endif()

+#//////////////////////////
+# LINUX
+# order of the link libraries matters; pthread dl
+#//////////////////////////
+
+if(LINUX)
+ set(lib_dep ${lib_dep} pthread dl)
+ set(lib_dep ${lib_dep} stdc++fs)
+ find_program(LSB_RELEASE_EXEC lsb_release)
+ execute_process(COMMAND ${LSB_RELEASE_EXEC} -is OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message(STATUS "Building in " ${LSB_RELEASE_ID_SHORT})
+endif()
+
+#//////////////////////////
+#OpenSSL
+#//////////////////////////
+
+if(USE_OPENSSL)
+ include_directories(${CMAKE_SOURCE_DIR}/ext/Simple-WebSocket-Server-v2.0.2)
+ add_definitions(-DUSE_STANDALONE_ASIO)
+ set (ASIO_PATH ${CMAKE_SOURCE_DIR}/ext/asio-1.18.1)
+endif()
+
+if(USE_OPENSSL)
+
+ set(OPENSSL_ROOT_DIR "${CMAKE_SOURCE_DIR}/ext/openssl-3.0.5")
+ find_package(OpenSSL REQUIRED)
+ message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
+ message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
+ include_directories(${OPENSSL_INCLUDE_DIR})
+ set(lib_dep ${lib_dep} ${OPENSSL_LIBRARIES})
+
+ if (MSVC)
+ set(OPENSSL_ROOT_DIR "${CMAKE_SOURCE_DIR}/ext/openssl-3.0.5")
+ message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
+ endif()
+ find_package(OpenSSL REQUIRED)
+ message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
+ message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
+ include_directories(${OPENSSL_INCLUDE_DIR})
+ set(lib_dep ${lib_dep} ${OPENSSL_LIBRARIES})
+ if (MSVC)
+ set(lib_dep ${lib_dep} crypt32.lib)
+ endif()
+endif()
+
+
+#//////////////////////////
+# HTTP demo
+#//////////////////////////
+
+add_executable(http_client src/http/http.hh src/http/http.cc src/http/http_client.cc)
+add_executable(http_relay src/http/http.hh src/http/http.cc src/http/http_relay.cc)
+target_link_libraries (http_client ${lib_dep})
+target_link_libraries (http_relay ${lib_dep})
+
+#//////////////////////////
+# executables
+#//////////////////////////
+
+add_executable(gnostr-client src/wss_client.cc)
+add_executable(gnostr-req src/wss_req.cc)
+add_executable(gnostr-gnode src/wss_relay.cc)
+
+target_link_libraries (gnostr-client ${lib_dep})
+target_link_libraries (gnostr-req ${lib_dep})
+target_link_libraries (gnostr-gnode ${lib_dep})
+
+#//////////////////////////
+# tests
+#//////////////////////////
+
+add_executable(gnostr-tests test/tests.cc)
+target_link_libraries (gnostr-tests ${lib_dep})
+
+#//////////////////////////
+# examples
+#//////////////////////////
+if(UNIX AND NOT APPLE AND NOT LINUX)
+add_executable(examples examples/examples.cc)
+target_link_libraries (examples ${lib_dep})
+endif()
+
+#//////////////////////////
+# IDE project virtual folders
+#//////////////////////////
+
+set_target_properties(http_client PROPERTIES FOLDER "http")
+set_target_properties(http_relay PROPERTIES FOLDER "http")
+set_target_properties(nostri PROPERTIES FOLDER "nostril")
+set_target_properties(nostril PROPERTIES FOLDER "nostril")
+set_target_properties(configurator PROPERTIES FOLDER "nostril")
+set_target_properties(secp256k1 PROPERTIES FOLDER "nostril")
+set_target_properties(secp256k1_precomputed PROPERTIES FOLDER "nostril")
+
+if(BUILD_WEB)
+if(MSVC)
+if(DEV_MODE)
+ set_target_properties(wt PROPERTIES FOLDER "wt")
+ set_target_properties(wthttp PROPERTIES FOLDER "wt")
+ set_target_properties(wtisapi PROPERTIES FOLDER "wt")
+endif()
+endif()
+endif()
+
+message(STATUS "Copying data files to: ${CMAKE_BINARY_DIR}")
+file(COPY "${CMAKE_SOURCE_DIR}/test/list_01.txt" DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY "${CMAKE_SOURCE_DIR}/test/list_02.txt" DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY "${CMAKE_SOURCE_DIR}/resources/server.key" DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY "${CMAKE_SOURCE_DIR}/resources/server.crt" DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY "${CMAKE_SOURCE_DIR}/database/database.json" DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY "${CMAKE_SOURCE_DIR}/resources/wt_config.xml" DESTINATION ${CMAKE_BINARY_DIR}/web)
+
+#//////////////////////////
+# Wt desktop
+#//////////////////////////
+
+if (BUILD_GUI)
+ add_subdirectory(desktop)
+endif()

#//////////////////////////
-#executables
+# Wt web
#//////////////////////////

-# tool to generate file 'config.h' , generate from a shell with
-# configurator.exe > config.h
-add_executable(configurator configurator.c)
+if (BUILD_WEB)
+ add_subdirectory(web)
+endif()

-add_executable(nostril ${src} nostril.c)
-target_link_libraries (nostril ${lib_dep})

#//////////////////////////
-# generate config.h
+# Install
#//////////////////////////

-add_custom_command(
- TARGET configurator
- POST_BUILD
- COMMAND configurator > config.h
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/config.h" ${CMAKE_SOURCE_DIR}
- COMMENT "generating config.h"
-)
+install(TARGETS gnostr-gnode
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-gnode
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+
+install(TARGETS gnostr-client
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-client
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+
+install(TARGETS gnostr-pi
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-pi
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+
+install(TARGETS gnostr-req
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-req
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+
+install(TARGETS gnostr-get-relays-c
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-get-relays-c
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)

+install(TARGETS gnostr-tests
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-tests
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+
+if(BUILD_WEB)
+install(TARGETS gnostr-web
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
+install(TARGETS gnostr-web
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION /usr/local/bin)
+endif()
+
+if (BUILD_GUI)
+
+endif()
diff --git a/src/gnostr-pi.c b/src/gnostr-pi.c
new file mode 100644
index 000000000..243f6e06c
--- /dev/null
+++ b/src/gnostr-pi.c
@@ -0,0 +1,139 @@
+/* Print pi to n decimal places (default 1000): pi n */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void int2bin(int n, int* bin, int* bin_size, const int bits);
+
+void int2bin(int n, int* bin, int *bin_size, const int bits)
+{
+ int i = 0;
+ int temp[64];
+ for (int j = 0; j < 64; j++)
+ {
+ temp[j] = 0;
+ }
+ for (int l = 0; l < bits; l++)
+ {
+ bin[l] = 0;
+ }
+
+ while (n > 0)
+ {
+ temp[i] = n % 2;
+ n = n / 2;
+ i++;
+ }
+ *bin_size = i;
+
+ //reverse modulus values
+ for (int k = 0; k < *bin_size; k++)
+ {
+ bin[bits-*bin_size+k] = temp[*bin_size - 1 - k];
+ }
+}
+
+/* Print pi as an array of n digits in base 10000 */
+void print(unsigned short *pi, int n) {
+ int i;
+
+/* REF: https://en.wikipedia.org/wiki/Common_logarithm#Mantissa_and_characteristic
+ * REMOVE characteristic '3.'
+ * we are only concerned with mantissa
+ printf("%d.", pi[1]);
+*/
+ for (i=2; i<n-1; ++i)
+ printf("%04d", pi[i]);
+ printf("\n");
+}
+
+/* Compute pi to B bits precision by the Spigot algorithm given by
+Rabinowitz and Wagon, Am. Math. Monthly, March 1995, 195-203.
+
+ pi = 4;
+ for (i = B; i>0; --i)
+ pi = 2 + pi * i / (2*i+1)
+
+pi is represented by a base 10000 array of digits with 2 digits before
+the decimal point (pi[0], pi[1]), and one extra digit (pi[n-1]) at
+the end to allow for roundoff error, which is not printed. Note that a
+base 10 digit is equivalent to log(10)/log(2) = 3.322 bits.
+
+For shorter versions, see
+http://www1.physik.tu-muenchen.de/~gammel/matpack/html/Mathematics/Pi.html
+http://numbers.computation.free.fr/Constants/TinyPrograms/tinycodes.html
+
+and for an explanation of how they work, see
+Unbounded Spigot Algorithms for the Digits of Pi,
+Jeremy Gibbons, University of Oxford, 2004,
+http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/spigot.pdf
+
+*/
+
+int main(int argc, char** argv) {
+
+/*
+ input 0 4 8 12 16 20 24 28 etc...
+*/
+
+/*
+ begin int2bin
+*/
+
+ char ch;
+ ch = 'A';
+ int binary[32];
+ int binary_size = 0;
+
+/*
+ int2bin(int n, int* bin, int* bin_size, const int bits);
+*/
+ int2bin(1324, binary, &binary_size, 32);
+ //for (int i = 0; i < 32; i++){ printf("\n%d\n", binary[i]); }
+
+/*
+ end int2bin
+*/
+
+/*
+TODO:
+{A = 1, B = 0, C = 0, N!=0, x = 7/N^2, sqrt(343/N^6 + 7) = y}
+*/
+
+ int n = argc > 1 ? (atoi(argv[1])+3)/4+3 : 360; /* 360 default number of pi digits */
+
+ unsigned short *pi = (unsigned short*) malloc(n * sizeof(unsigned short));
+ div_t d;
+ int i, j, t;
+
+ /* pi = 4 */
+ memset(pi, 0, n*sizeof(unsigned short));
+ pi[1]=4;
+
+ /* for i = B down to 1 */
+ for (i=(int)(3.322*4*n); i>0; --i) {
+
+ /* pi *= i; */
+ t = 0;
+ for (j=n-1; j>=0; --j) { /* pi *= i; */
+ t += pi[j] * i;
+ pi[j] = t % 10000;
+ t /= 10000;
+ }
+
+ /* pi /= (2*i+1) */
+ d.quot = d.rem = 0;
+ for (j=0; j<n; ++j) { /* pi /= 2*i+1; */
+ d = div(pi[j]+d.rem*10000, i+i+1);
+ pi[j] = d.quot;
+ }
+
+ /* pi += 2 */
+ pi[1] += 2;
+ }
+
+ print(pi, n);
+ return 0;
+}
+
diff --git a/template/xor.sh b/template/xor.sh
new file mode 100755
index 000000000..44d675355
--- /dev/null
+++ b/template/xor.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+function help(){
+
+ printf "Usage:\n";
+ printf " xor.sh\n";
+ printf " Enter a string:\n";
+ printf " <string>\n";
+ exit;
+}
+[[ ! -z $1 ]] && help
+
+BASE=01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
+## echo -en "BASE=$BASE\n"
+
+echo -en "Enter a string:\c"
+read strval
+len=`expr "$strval" : '.*'`
+## echo "The length of the input string $strval is $len"
+## touch null
+
+type -P openssl >/tmp/xor.log && \
+ STR_HASH=$(echo $strval|openssl dgst -sha256 | \
+ sed 's/SHA2-256(stdin)= //' ) || echo "install openssl "
+
+## echo -en "STR_HASH=$STR_HASH\n"
+## printf "STR_HASH=$STR_HASH\n"
+## strhash_length=`expr "$STR_HASH" : '.*'`
+## echo "strhash_length=$strhash_length"
+
+type -P openssl >/tmp/xor.log && \
+ NULL_HASH=$(echo ""|openssl dgst -sha256 | \
+ sed 's/SHA2-256(stdin)= //' ) || echo "install openssl "
+
+## echo -en "$NULL_HASH\n"
+## null_hash_length=`expr "$NULL_HASH" : '.*'`
+## echo -en "null_hash_length=$null_hash_length\n"
+
+## echo -en "$(( 0x$BASE ^ 0x$BASE ))\n"
+## echo $(( 0x$BASE ^ 0x$BASE ))
+## echo eval $(( 0x$BASE ^ 0x$BASE ))
+#
+## echo -en "$(( 0x$BASE ^ 0x$STR_HASH ))\n"
+
+## echo eval $(( 0x$BASE ^ 0x$STR_HASH ))
+## echo eval $(( 0x$STR_HASH ^ 0x$BASE ))
+#
+## echo -en "$(( 0x$STR_HASH ^ 0x$BASE ))\n"
+#
+## echo -en "$(( 0x$STR_HASH ^ 0x$NULL_HASH ))\n"
+#
+## echo eval $(( 0x$NULL_HASH ^ 0x$STR_HASH ))
+
+delta_null_str=`expr $(( 0x$NULL_HASH ^ 0 ))`
+## echo -en "delta_null_str=$delta_null_str\n"
+
+delta_null_hash=`expr $(( 0 ^ 0x$NULL_HASH ))`
+## echo -en "delta_null_hash=$delta_null_hash\n"
+
+delta=`expr $(( 11 ^ 100 ))`
+## echo "assert delta=111=$delta"
+
+delta=`expr $(( 990 ^ 9900 ))`
+## echo "assert delta=9586=$delta"
+
+
+strhash_length=`expr "$STR_HASH" : '.*'`
+## echo "strhash_length=$strhash_length"
+printf "$strhash_length/$STR_HASH\n"
Author Public Key
npub1pvcu7r8gl4l4cvasjz0fxse53km0z82k7wqyfwkehnyrg03lg3xsgw75ht