boinc icon indicating copy to clipboard operation
boinc copied to clipboard

Move random_int() to util.cpp

Open computezrmle opened this issue 1 year ago • 8 comments

random_int() can easily be used as seed for srand() from various functions if it is in util.cpp. This is not possible if it is in crypt_prog.cpp since crypt_prog.cpp is not included in the standard build process. Instead, tools/makefile_sign_executable must be used to build it.

See: https://boinc.berkeley.edu/trac/wiki/KeySetup#Filesigningutilities

computezrmle avatar Mar 26 '24 21:03 computezrmle

@computezrmle, please fix the failed build. Thank you

AenBleidd avatar Mar 26 '24 22:03 AenBleidd

As for Release-x64-msbuild 2024-03-26T21:24:45.8536712Z D:\a\boinc\boinc\win_build\vcpkg_3rdparty_dependencies.vcxproj(182,5): error MSB3073: The command "vcpkg.exe install --x-manifest-root=D:\a\boinc\boinc\win_build\..\3rdParty\vcpkg_ports\configs\msbuild/x64 --x-install-root=D:\a\boinc\boinc\win_build\..\3rdParty\Windows\vcpkg/installed/ --overlay-ports=../../vcpkg_ports/ports --overlay-triplets=../../vcpkg_ports/triplets/ci --triplet x64-windows-static --clean-after-build" exited with code -1. Is it caused by a missing entry in win_build\vcpkg_3rdparty_dependencies.vcxproj? If so, I would need a hint since I'm not familiar with the syntax.

As for Release-ARM64-msbuild 2024-03-26T21:25:11.3790575Z D:\a\boinc\boinc\lib\util.cpp(552,18): error C2664: 'HINSTANCE LoadLibrary(LPCWSTR)': cannot convert argument 1 from 'const char [13]' to 'LPCWSTR' [D:\a\boinc\boinc\win_build\boincmgr.vcxproj] Could this be a multi-byte/unicode issue? If so, could it be solved using LoadLibrary(L"ADVAPI32.DLL")?

computezrmle avatar Mar 27 '24 08:03 computezrmle

Is it caused by a missing entry in win_build\vcpkg_3rdparty_dependencies.vcxproj?

This was an unrelated issue, now fixed by build rerun. Others are still here, so please fix them

AenBleidd avatar Mar 27 '24 10:03 AenBleidd

Is there a need for this outside of crypt_prog? You can call srand() with, e.g. the time of day in microseconds.

davidpanderson avatar Mar 27 '24 21:03 davidpanderson

Can the recent build issues be solved without too much effort?

1st idea to get a random number was to use the standard library functions from C++11. Looks like certain C++11 functions (including those) don't work for BOINC.

Next idea was to use rand() which needs srand(seed). Since seed is expected to be an unsigned int random_int() from crypt_prog seemed to be a good idea as

  • it is available in the source tree
  • it delivers an unsigned int
  • it uses a "natural" random source like /dev/random.

As random_int() has build issues for the client when used from crypt_prog the next idea was to move it to lib/util which would make it globally available. The build issues for the server it has now came unexpected. If they can be solved, why not leave random_int() in lib/util?

Other sources for seed appear to be less "natural". A seed base on daytime may deliver a good seed if it is not too coarse.

Can you confirm that dtime() from lib/util returns a double like 86345.123456? I'm sure it does on Linux. What about Windows or GCL_SIMULATOR?

If yes, this may be fine enough to cover concurrently starting processes: seed = (unsigned int)(100000 * dtime())

or, to avoid seed becomes greater than 32-bit max unsigned int: seed = (unsigned int)(1000 * dtime()) This would give a granularity of 0.1 ms.

computezrmle avatar Mar 28 '24 08:03 computezrmle

Is there a need for this outside of crypt_prog? You can call srand() with, e.g. the time of day in microseconds.

I think, having this as a generally available function won't hurt and could be helpful.

AenBleidd avatar Mar 28 '24 13:03 AenBleidd

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 10.79%. Comparing base (b2af307) to head (d60cab9). Report is 2 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5555      +/-   ##
============================================
- Coverage     10.80%   10.79%   -0.01%     
  Complexity     1068     1068              
============================================
  Files           279      279              
  Lines         36294    36303       +9     
  Branches       8409     8412       +3     
============================================
  Hits           3920     3920              
- Misses        31980    31989       +9     
  Partials        394      394              
Files Coverage Δ
lib/util.h 40.00% <ø> (ø)
lib/util.cpp 32.50% <0.00%> (-2.33%) :arrow_down:
lib/crypt_prog.cpp 0.00% <0.00%> (ø)

codecov[bot] avatar Mar 28 '24 15:03 codecov[bot]

Sorry, but I don't see a use case for this.

davidpanderson avatar Apr 01 '24 06:04 davidpanderson