Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# trystero's CI: the superproject's reusable workflow, which builds this commit inside a checkout of
# webcpp, on every lane trystero declares and its own lanes, oracle and interop, with libsecp256k1,
# libdatachannel and OpenSSL, which the workflow's actions install, its page, the lint and the test
# matrix.
# libdatachannel and OpenSSL, all built from the superproject's pinned sources, its page, the lint
# and the test matrix.
name: CI

on:
Expand Down
17 changes: 8 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ holds only what is specific to trystero.
alone in a call of their own, without it, so the lint analyses the timer,
the sealer and the WebSockets without exceptions too. trystero raises
nothing of its own; a raise would go through `boost::throw_exception`.
- **The dependencies.** libsecp256k1 (every room) remains an external
installation, found through `webcpp.external` and `webcpp.external-found`
at `-sSECP256K1_ROOT=<dir>` or `-sSECP256K1_EMSCRIPTEN_ROOT=<dir>`, then
`.local/secp256k1-native` or `.local/secp256k1-emscripten`. Native system
fallback outside Windows is allowed only for this dependency. A missing
installation leaves trystero out unless `webcpp-require-external=on`.
MSVC links its static `libsecp256k1.lib` with `SECP256K1_STATIC`.
The native backend instead names `/webcpp/third_party//libdatachannel`,
- **The dependencies.** libsecp256k1 (every room) is webcpp's own build,
`/third_party//secp256k1` (v0.8.0, from `third_party/libs/secp256k1`), which
`/webcpp/trystero//trystero` names; its tables come from
`webcpp-secp256k1-tables` (see `doc/building.adoc`). Nothing is installed
outside the checkout, once the pinned submodules are initialised.
The native backend also names `/webcpp/third_party//libdatachannel`,
which builds pinned libdatachannel 0.24.6, libjuice, usrsctp and libsrtp as
separate static archives against `/webcpp/third_party//openssl` and its
matching generated headers. These are the same OpenSSL target used by
Asio and Beast, so a combined application has one provider. No
`LIBDATACHANNEL_ROOT`, `OPENSSL_ROOT` or installed binary is consulted.
Initialize their sources with `git submodule update --init --recursive
third_party/libs/libdatachannel third_party/libs/openssl`. Native builds
third_party/libs/libdatachannel third_party/libs/openssl
third_party/libs/secp256k1`. Native builds
need CMake 3.21 or newer in addition to OpenSSL's Perl and Make/nmake.
B2 forwards the configured compiler, C++ ABI, runtime and optimization
flags, and isolates artifacts by their effective configuration. The
Expand Down
56 changes: 12 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,19 @@ send a wrong room proof, reported by the lower id only.

trystero is developed inside the webcpp superproject, as a Boost library is
developed inside Boost. Its TLS and WebRTC dependencies are built from
pinned sources; only libsecp256k1 needs an external installation:
pinned sources, and so is libsecp256k1:

| Library | Needed by | Found where |
| --- | --- | --- |
| libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules | every room: it signs the Nostr events peers meet through | `-sSECP256K1_ROOT=<dir>` natively, `-sSECP256K1_EMSCRIPTEN_ROOT=<dir>` for its emscripten build, else `.local/secp256k1-native` and `.local/secp256k1-emscripten` |
| libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules | every room: it signs the Nostr events peers meet through | `/third_party//secp256k1`, from `third_party/libs/secp256k1` |
| libdatachannel 0.24.6 | the native backend | `/webcpp/third_party//libdatachannel`, from pinned source submodules |
| OpenSSL 3.5.9 | the native backend | `/webcpp/third_party//openssl`, also used by Asio and Beast |

The libsecp256k1 `-s` option, on b2's command line, names a directory with the library's
`include/` and `lib/`; the environment is never read. Without it, the library
is looked for in the superproject's `.local/` directory the table names,
where webcpp's CI installs it, and else, natively outside Windows, in
`/usr/include` or `/usr/local/include`, where a system install is
legitimate; a relative `-s` is read from b2's working directory. A `-s` that names a directory
without the library's header stops the build, naming it. A library found
nowhere leaves trystero out: its tests and examples are skipped, b2 says so
once, naming the library and where it looked, and every other library
builds; `webcpp-require-external=on`, which the CI gives, stops the build
instead. With them found,
The tables of libsecp256k1 follow `webcpp-secp256k1-tables`: `auto` is window 15 and
comb 11x6 natively (a larger program, faster signing and verification) and window 2 and
comb 2x5 on emscripten (the same signing, verification a little slower than window 4, a
smaller program). A program that wants otherwise asks for `<webcpp-secp256k1-tables>small`
or `large`. With the pinned source submodules initialized,

b2 libs/trystero/test libs/trystero/example
b2 toolset=emscripten libs/trystero/test libs/trystero/example
Expand Down Expand Up @@ -241,34 +235,13 @@ git clone https://github.com/emscripten-core/emsdk.git
git clone --recurse-submodules https://github.com/webcpporg/webcpp.git
```

### 5. Build libsecp256k1

libsecp256k1 is built twice: natively, and with Emscripten for the browser.

```sh
git clone --branch v0.8.0 https://github.com/bitcoin-core/secp256k1.git
options="-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=ON \
-DSECP256K1_ECMULT_WINDOW_SIZE=4 -DSECP256K1_ECMULT_GEN_KB=2 \
-DSECP256K1_BUILD_TESTS=OFF -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \
-DSECP256K1_BUILD_BENCHMARK=OFF"

cmake -S secp256k1 -B build-secp256k1-native $options \
-DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-native
cmake --build build-secp256k1-native && cmake --install build-secp256k1-native

./emsdk/upstream/emscripten/emcmake cmake -S secp256k1 -B build-secp256k1-emscripten $options \
-DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-emscripten
cmake --build build-secp256k1-emscripten && cmake --install build-secp256k1-emscripten
```

### 6. Initialize the native dependencies
### 5. Initialize the native dependencies

The recursive checkout already includes pinned OpenSSL, libdatachannel,
libjuice, usrsctp, plog and libsrtp sources. For an existing checkout:

```sh
git -C webcpp submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel
git -C webcpp submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel third_party/libs/secp256k1
```

B2 builds them with the selected compiler, runtime and C++ ABI when the
Expand All @@ -279,7 +252,7 @@ combined application; no system OpenSSL or installed libdatachannel is used.
Native Trystero targets declare `<threading>multi` because WebRTC runs
worker threads. The supplied examples and tests declare it already.

### 7. Tell b2 its compilers and Boost
### 6. Tell b2 its compilers and Boost

```sh
cat > user-config.jam <<EOF
Expand All @@ -290,7 +263,7 @@ using emscripten : : $PWD/emsdk/upstream/emscripten/em++
EOF
```

### 8. Build the native quick start and the chat page
### 7. Build the native quick start and the chat page

```sh
cd webcpp
Expand All @@ -304,7 +277,7 @@ The second command ends by printing the chat site's directory,
`bin/libs/trystero/example/chat/emscripten-6.0.11/debug/address-model-32/cxxstd-20-iso/link-static/target-os-none/site`,
which holds `index.html`, `chat-program.js` and `chat-program.wasm`.

### 9. Run them
### 8. Run them

In a terminal, from `webcpp`, start the native quick start. It runs until you
stop it with Ctrl-C:
Expand Down Expand Up @@ -334,11 +307,6 @@ Every browser tab that joins the same app and room joins the same chat.

### When something goes wrong

- **b2 says trystero is left out**: a library is not in the directory of
`webcpp/.local/` it names; install it there as steps 5 and 6 do, or give
b2 `-s<VARIABLE>=<dir>` with the directory that `cmake --install` wrote.
- **b2 stops naming a `-s`**: it names a directory without the library's
header; give the directory that `cmake --install` wrote.
- **b2 prints `node: bad option: --experimental-wasm-threads`** when it
configures the emscripten toolset: b2's toolset probes node with a flag that
recent Node removed. It is harmless.
Expand Down
36 changes: 7 additions & 29 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,12 @@

project /webcpp/trystero ;

# Only libsecp256k1 is externally installed. Native WebRTC and OpenSSL are
# pinned source dependencies, built together for the consumer's B2 variant.
# libsecp256k1 (every room) is webcpp's build of it, /third_party//secp256k1:
# v0.8.0 from the submodule third_party/libs/secp256k1, with the tables the
# feature webcpp-secp256k1-tables chooses (small on emscripten, large natively;
# CODING-GUIDELINES.md chapter 5). Native WebRTC and OpenSSL are pinned source
# dependencies too, built together for the consumer's B2 variant.
import errors ;
import webcpp ;

# tag::dependencies[]
local secp256k1-root = [ webcpp.external trystero : libsecp256k1
: SECP256K1_ROOT : secp256k1-native : secp256k1.h : native ] ;
local secp256k1-emscripten-root = [ webcpp.external trystero : libsecp256k1
: SECP256K1_EMSCRIPTEN_ROOT : secp256k1-emscripten : secp256k1.h : emscripten ] ;
lib secp256k1 : : <name>secp256k1 <toolset>emscripten
<search>$(secp256k1-emscripten-root)/lib
: : <include>$(secp256k1-emscripten-root)/include ;
lib secp256k1 : : <name>libsecp256k1 <toolset>msvc
<search>$(secp256k1-root)/lib
: : <include>$(secp256k1-root)/include <define>SECP256K1_STATIC ;
lib secp256k1 : : <name>secp256k1 <search>$(secp256k1-root)/lib
: : <include>$(secp256k1-root)/include ;
# Searched libraries are used only through usage requirements.
explicit secp256k1 ;
# end::dependencies[]

# The dependencies of the rooms: libsecp256k1, the emscripten build of it on
# emscripten. Checked only when a target that uses trystero is built.
rule trystero-dependencies ( properties * )
{
return [ webcpp.external-found trystero : libsecp256k1 : $(properties) ] ;
}

# The native backend's own dependencies, checked only when a target that
# uses it is built.
Expand All @@ -55,9 +33,9 @@ rule native-dependencies ( properties * )
# program then fails to link, undefined _embind_register_function), since
# b2 takes only free features from usage requirements.
# tag::trystero[]
alias trystero : : <conditional>@trystero-dependencies
alias trystero : :
: : <include>include <library>/boost//headers <library>/webcpp//boost_json
<library>/webcpp/config//config <library>secp256k1
<library>/webcpp/config//config <library>/third_party//secp256k1
<toolset>emscripten:<define>BOOST_ASIO_DISABLE_THREADS
<toolset>emscripten:<linkflags>-lembind ;
# end::trystero[]
Expand Down
62 changes: 11 additions & 51 deletions doc/building.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@

trystero is header-only, and is developed inside the webcpp superproject, as
a Boost library is developed inside Boost. Its native TLS and WebRTC
dependencies are built from pinned sources. Only libsecp256k1 needs an
external installation:
dependencies, and libsecp256k1, are built from pinned sources:

[cols="2,2,3",options="header"]
|===
| Library | Needed by | Found where

| libsecp256k1 0.8.0, with its `schnorrsig` and `extrakeys` modules
| every room: it signs the Nostr events peers meet through
| `-sSECP256K1_ROOT=<dir>` natively, else `.local/secp256k1-native`;
`-sSECP256K1_EMSCRIPTEN_ROOT=<dir>` for its emscripten build, else
`.local/secp256k1-emscripten`
| `/third_party//secp256k1`, built from `third_party/libs/secp256k1`

| libdatachannel 0.24.6
| the native backend
Expand All @@ -31,26 +28,12 @@ external installation:
| `/webcpp/third_party//openssl`, shared by the Asio, Beast and Trystero build graphs
|===

The libsecp256k1 `-s` option names a directory with the library's `include/` and `lib/`, on b2's
command line; the environment is never read, so that a variable a shell keeps
from another day never replaces `.local/` without a word. Without it, the
library is looked for in the directory of `.local/` that the table names,
where webcpp's continuous integration installs it, when that directory holds
the library's header, and else, natively outside Windows, in `/usr/include`
or `/usr/local/include`, where a system install is legitimate. A relative
`-s` is read from b2's working directory. A `-s` that names a directory without the library's
header stops the build, naming it. A library found nowhere leaves trystero
out: its tests and examples are skipped, the build says so once, naming the
library and where it looked, and every other library builds; with
`webcpp-require-external=on`, as the continuous integration builds, it stops
the build instead. With MSVC, libsecp256k1 uses CMake's
`libsecp256k1.lib`, linked statically with `SECP256K1_STATIC` defined.
trystero's `build.jam` declares that external dependency so:

[listing]
----
include::{library-root}/build.jam[tag=dependencies]
----
The tables of libsecp256k1 are chosen by the feature
`webcpp-secp256k1-tables`. With `auto`, the default, natively they are window 15
and comb 11x6: a larger program, and faster signing and verification. On emscripten
they are window 2 and comb 2x5: the same signing, verification a little slower than
window 4, and a smaller program. A program that wants otherwise asks for
`<webcpp-secp256k1-tables>small` or `<webcpp-secp256k1-tables>large`.

[#trystero-building-project]
=== In a b2 project
Expand Down Expand Up @@ -120,7 +103,7 @@ include::{webcpp-root}/tools/ci/emsdk.jam[tag=emsdk]
include::{webcpp-root}/tools/ci/emsdk.jam[tag=emscripten]
----

With it, libsecp256k1 installed and the pinned source submodules initialized, from the root of a webcpp checkout,
With it and the pinned source submodules initialized, from the root of a webcpp checkout,
these build the tests and the examples, natively and on emscripten:

[source,bash]
Expand All @@ -132,35 +115,12 @@ b2 toolset=emscripten libs/trystero/test libs/trystero/example
[#trystero-building-dependencies]
=== Preparing the dependencies

libsecp256k1 is built twice: natively, and with Emscripten for the browser.
Its small tables keep the browser's download small:

[source,bash]
----
git clone --branch v0.8.0 https://github.com/bitcoin-core/secp256k1.git
options="-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=ON \
-DSECP256K1_ECMULT_WINDOW_SIZE=4 -DSECP256K1_ECMULT_GEN_KB=2 \
-DSECP256K1_BUILD_TESTS=OFF -DSECP256K1_BUILD_EXHAUSTIVE_TESTS=OFF \
-DSECP256K1_BUILD_BENCHMARK=OFF"

cmake -S secp256k1 -B build-secp256k1-native $options \
-DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-native
cmake --build build-secp256k1-native && cmake --install build-secp256k1-native

emcmake cmake -S secp256k1 -B build-secp256k1-emscripten $options \
-DCMAKE_INSTALL_PREFIX=$PWD/webcpp/.local/secp256k1-emscripten
cmake --build build-secp256k1-emscripten && cmake --install build-secp256k1-emscripten
----

where `webcpp` is the checkout of the superproject: each is installed in the
directory of `.local/` where the build looks for it.

Initialize the native dependencies from the superproject root:

[source,bash]
----
git submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel
git submodule update --init --recursive third_party/libs/openssl third_party/libs/libdatachannel \
third_party/libs/secp256k1
----

Install CMake 3.21 or newer, Perl and Make (native Windows Perl and nmake
Expand Down
3 changes: 3 additions & 0 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ of every version are on webcpp's index page.
=== Unreleased

// tag::unreleased[]
* Changed libsecp256k1 to come from `/third_party//secp256k1`, not an external
installation: `-sSECP256K1_ROOT` and `-sSECP256K1_EMSCRIPTEN_ROOT` are gone, and
`webcpp-secp256k1-tables` chooses its tables.
// end::unreleased[]

[#trystero-changelog-0-1-0]
Expand Down
3 changes: 2 additions & 1 deletion doc/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace `webcpp::trystero`.
System; and Beast for the native backend.
* https://github.com/bitcoin-core/secp256k1[libsecp256k1] 0.8.0, with its
`schnorrsig` and `extrakeys` modules, for the BIP-340 signatures of Nostr
events: every room needs it.
events: every room needs it. webcpp builds it from its pinned
source, `/third_party//secp256k1`.
* In the browser: Emscripten 6.0.11, the version webcpp pins, and a page
served from a secure context (https, or http on `localhost`), where
`crypto.subtle` exists.
Expand Down
4 changes: 0 additions & 4 deletions doc/roadmap.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ echoes the offerer's `msid` into the answer.
. *Trystero's other features.* Request actions (`kind: 'request'`),
decisions on incoming transfers and their progress, the application's own
handshake, passive rooms, and the other strategies, among them MQTT and BitTorrent trackers.
. *libsecp256k1 from webcpp's own build.* libsecp256k1 is still found where
b2's command line or the superproject's `.local/` says. Native OpenSSL and
libdatachannel already build from pinned `third_party/` sources
(<<trystero-building>>).
5 changes: 2 additions & 3 deletions doc/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ and run the unit tests with GCC 14 and with clang 18 against
`libstdc{plus}{plus}` in a Linux container, Ubuntu 24.04, with `docker run`
and the network `none`, which leaves the loopback alone: every test passes,
which shows that none reaches beyond the machine
(<<trystero-invariant-6,guarantee 6>>). libsecp256k1 is installed before
running the container. B2 builds the pinned OpenSSL, libdatachannel and
nested source dependencies inside the container with the lane's compiler,
(<<trystero-invariant-6,guarantee 6>>). B2 builds the pinned libsecp256k1, OpenSSL,
libdatachannel and nested source dependencies inside the container with the lane's compiler,
runtime and static link configuration. These builds need no network access.

[#trystero-testing-provider]
Expand Down
1 change: 0 additions & 1 deletion test/provider/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import webcpp ;
webcpp.targets native ;
webcpp.original python3 ;

# Keep ownership with Trystero so CI provisions its external secp256k1.
# The common executable names all three public dependency aliases.
webcpp.drive combined : ../../../../tools/openssl/test//combined_provider
: <variant>release <threading>multi <exception-handling>on
Expand Down
Loading