├── .formatter.exs ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── Makefile ├── README.md ├── apps ├── erldist_filter │ ├── CHANGELOG.md │ ├── LICENSE.md │ ├── README.md │ ├── c_src │ │ ├── .clang-format │ │ ├── Makefile │ │ └── nif │ │ │ ├── action.c │ │ │ ├── action.h │ │ │ ├── avec.c │ │ │ ├── avec.h │ │ │ ├── channel │ │ │ ├── edf_atom_cache.c │ │ │ ├── edf_atom_cache.h │ │ │ ├── edf_atom_text.c │ │ │ ├── edf_atom_text.h │ │ │ ├── edf_channel.c │ │ │ ├── edf_channel.h │ │ │ ├── edf_channel_impl.c │ │ │ ├── edf_channel_impl.h │ │ │ ├── edf_channel_inspect.c │ │ │ ├── edf_channel_inspect.h │ │ │ ├── edf_channel_recv.c │ │ │ ├── edf_channel_recv.h │ │ │ ├── edf_channel_stats.c │ │ │ ├── edf_channel_stats.h │ │ │ ├── edf_external.c │ │ │ ├── edf_external.h │ │ │ ├── edf_external_recv.c │ │ │ ├── edf_external_recv.h │ │ │ ├── edf_external_sequence.c │ │ │ └── edf_external_sequence.h │ │ │ ├── config │ │ │ ├── edf_config.c │ │ │ ├── edf_config.h │ │ │ ├── edf_config_impl.c │ │ │ └── edf_config_impl.h │ │ │ ├── core │ │ │ ├── align.h │ │ │ ├── bool.h │ │ │ ├── c11threads.h │ │ │ ├── ipc.c │ │ │ ├── ipc.h │ │ │ ├── khashl.h │ │ │ ├── linklist.h │ │ │ ├── mutex.h │ │ │ ├── portable_endian.h │ │ │ ├── portable_hint.h │ │ │ ├── rwlock.h │ │ │ ├── simd.h │ │ │ ├── spinlock.h │ │ │ ├── spinrwlock.h │ │ │ ├── spinwait.h │ │ │ ├── unreachable.h │ │ │ ├── xnif_trace.c │ │ │ └── xnif_trace.h │ │ │ ├── edf_atoms.c │ │ │ ├── edf_atoms.h │ │ │ ├── edf_common.h │ │ │ ├── edf_mpid.h │ │ │ ├── erldist_filter_nif.c │ │ │ ├── erldist_filter_nif.h │ │ │ ├── erts │ │ │ ├── atom.h │ │ │ ├── dist.h │ │ │ ├── erl_rbtree.h │ │ │ └── external.h │ │ │ ├── etf │ │ │ ├── etf_common.h │ │ │ ├── etf_decode.h │ │ │ ├── etf_decode_dist_header.c │ │ │ ├── etf_decode_dist_header.h │ │ │ ├── etf_decode_term_length.c │ │ │ ├── etf_decode_term_length.h │ │ │ ├── etf_decode_udist.c │ │ │ ├── etf_decode_udist.h │ │ │ ├── etf_decode_vterm.c │ │ │ ├── etf_decode_vterm.h │ │ │ ├── etf_encode.h │ │ │ ├── etf_redirect_dop.c │ │ │ ├── etf_redirect_dop.h │ │ │ ├── etf_redirect_spawn_request.c │ │ │ ├── etf_redirect_spawn_request.h │ │ │ ├── etf_rewrite_as_drop.c │ │ │ ├── etf_rewrite_as_drop.h │ │ │ ├── etf_rewrite_fragment_header.c │ │ │ ├── etf_rewrite_fragment_header.h │ │ │ ├── etf_rollback_atom_cache.c │ │ │ └── etf_rollback_atom_cache.h │ │ │ ├── ioq.c │ │ │ ├── ioq.h │ │ │ ├── logger │ │ │ ├── edf_logger.c │ │ │ ├── edf_logger.h │ │ │ ├── edf_logger_impl.c │ │ │ ├── edf_logger_impl.h │ │ │ ├── edf_logger_queue_recv.c │ │ │ └── edf_logger_queue_recv.h │ │ │ ├── slice.h │ │ │ ├── trap │ │ │ ├── edf_trap.c │ │ │ ├── edf_trap.h │ │ │ ├── edf_trap_impl.c │ │ │ └── edf_trap_impl.h │ │ │ ├── udist │ │ │ ├── udist.c │ │ │ └── udist.h │ │ │ ├── uterm │ │ │ └── uterm.h │ │ │ ├── vdist │ │ │ ├── vdist.c │ │ │ └── vdist.h │ │ │ ├── vec.c │ │ │ ├── vec.h │ │ │ ├── vec_reader.h │ │ │ ├── vec_writer.h │ │ │ ├── vterm │ │ │ ├── vterm.c │ │ │ ├── vterm.h │ │ │ ├── vterm_common.h │ │ │ ├── vterm_debug_dump.c │ │ │ ├── vterm_encode.c │ │ │ ├── vterm_env.c │ │ │ ├── vterm_env.h │ │ │ ├── vterm_impl.c │ │ │ └── vterm_impl.h │ │ │ └── world │ │ │ ├── edf_world.c │ │ │ ├── edf_world.h │ │ │ ├── edf_world_impl.c │ │ │ └── edf_world_impl.h │ ├── include │ │ ├── erldist_filter.hrl │ │ ├── erldist_filter_erts_dist.hrl │ │ ├── erldist_filter_erts_external.hrl │ │ ├── erldist_filter_otp_25_2_3_dist.hrl │ │ ├── erldist_filter_otp_25_2_3_dist_util.hrl │ │ ├── erldist_filter_otp_25_2_3_net_address.hrl │ │ ├── erldist_filter_otp_26_0_2_dist.hrl │ │ ├── erldist_filter_otp_26_0_2_dist_util.hrl │ │ ├── erldist_filter_otp_26_0_2_net_address.hrl │ │ ├── udist.hrl │ │ ├── vdist.hrl │ │ ├── vedf.hrl │ │ └── vterm.hrl │ ├── lib │ │ ├── edf.ex │ │ └── edf │ │ │ └── record_extractor.ex │ ├── mix.exs │ ├── priv │ │ └── .keep │ ├── rebar.config │ ├── rebar.lock │ ├── src │ │ ├── edf.erl │ │ ├── erldist_filter.app.src │ │ ├── erldist_filter.erl │ │ ├── erldist_filter_app.erl │ │ ├── erldist_filter_handler.erl │ │ ├── erldist_filter_handler_sup.erl │ │ ├── erldist_filter_inet6_tcp_dist.erl │ │ ├── erldist_filter_inet_tcp_dist.erl │ │ ├── erldist_filter_logger.erl │ │ ├── erldist_filter_logger_sup.erl │ │ ├── erldist_filter_nif.erl │ │ ├── erldist_filter_otp_25_2_3_dist_util.erl │ │ ├── erldist_filter_otp_25_2_3_inet6_tcp_dist.erl │ │ ├── erldist_filter_otp_25_2_3_inet_tcp_dist.erl │ │ ├── erldist_filter_otp_26_0_2_dist_util.erl │ │ ├── erldist_filter_otp_26_0_2_inet6_tcp_dist.erl │ │ ├── erldist_filter_otp_26_0_2_inet_tcp_dist.erl │ │ ├── erldist_filter_router.erl │ │ ├── erldist_filter_router_sup.erl │ │ ├── erldist_filter_routers_sup.erl │ │ ├── erldist_filter_sup.erl │ │ ├── udist │ │ │ └── udist.erl │ │ ├── vdist │ │ │ ├── vdist.erl │ │ │ ├── vdist_atom_cache.erl │ │ │ ├── vdist_atom_cache_map.erl │ │ │ ├── vdist_atom_translation_table.erl │ │ │ ├── vdist_dop.erl │ │ │ ├── vdist_dop_alias_send.erl │ │ │ ├── vdist_dop_alias_send_tt.erl │ │ │ ├── vdist_dop_demonitor_p.erl │ │ │ ├── vdist_dop_exit.erl │ │ │ ├── vdist_dop_exit2.erl │ │ │ ├── vdist_dop_exit2_tt.erl │ │ │ ├── vdist_dop_exit_tt.erl │ │ │ ├── vdist_dop_group_leader.erl │ │ │ ├── vdist_dop_link.erl │ │ │ ├── vdist_dop_monitor_p.erl │ │ │ ├── vdist_dop_monitor_p_exit.erl │ │ │ ├── vdist_dop_payload_exit.erl │ │ │ ├── vdist_dop_payload_exit2.erl │ │ │ ├── vdist_dop_payload_exit2_tt.erl │ │ │ ├── vdist_dop_payload_exit_tt.erl │ │ │ ├── vdist_dop_payload_monitor_p_exit.erl │ │ │ ├── vdist_dop_reg_send.erl │ │ │ ├── vdist_dop_reg_send_tt.erl │ │ │ ├── vdist_dop_send.erl │ │ │ ├── vdist_dop_send_sender.erl │ │ │ ├── vdist_dop_send_sender_tt.erl │ │ │ ├── vdist_dop_send_tt.erl │ │ │ ├── vdist_dop_spawn_reply.erl │ │ │ ├── vdist_dop_spawn_reply_tt.erl │ │ │ ├── vdist_dop_spawn_request.erl │ │ │ ├── vdist_dop_spawn_request_tt.erl │ │ │ ├── vdist_dop_unlink.erl │ │ │ ├── vdist_dop_unlink_id.erl │ │ │ ├── vdist_dop_unlink_id_ack.erl │ │ │ ├── vdist_entry.erl │ │ │ ├── vdist_entry_decode.erl │ │ │ ├── vdist_entry_encode.erl │ │ │ ├── vdist_external.erl │ │ │ ├── vdist_fragment_cont.erl │ │ │ ├── vdist_fragment_header.erl │ │ │ ├── vdist_header_decode.erl │ │ │ ├── vdist_header_encode.erl │ │ │ ├── vdist_new_atom_cache_ref_entry.erl │ │ │ ├── vdist_normal_header.erl │ │ │ ├── vdist_old_atom_cache_ref_entry.erl │ │ │ └── vdist_pass_through_header.erl │ │ ├── vedf │ │ │ ├── vedf.erl │ │ │ └── vedf_channel.erl │ │ └── vterm │ │ │ ├── vterm.erl │ │ │ ├── vterm_atom.erl │ │ │ ├── vterm_atom_cache_ref.erl │ │ │ ├── vterm_atom_cache_ref_resolved.erl │ │ │ ├── vterm_atom_ext.erl │ │ │ ├── vterm_atom_utf8_ext.erl │ │ │ ├── vterm_binary_ext.erl │ │ │ ├── vterm_bit_binary_ext.erl │ │ │ ├── vterm_decode.erl │ │ │ ├── vterm_encode.erl │ │ │ ├── vterm_export_ext.erl │ │ │ ├── vterm_float_ext.erl │ │ │ ├── vterm_integer_ext.erl │ │ │ ├── vterm_large_big_ext.erl │ │ │ ├── vterm_large_tuple_ext.erl │ │ │ ├── vterm_lazy_term.erl │ │ │ ├── vterm_list_ext.erl │ │ │ ├── vterm_map_ext.erl │ │ │ ├── vterm_new_float_ext.erl │ │ │ ├── vterm_new_fun_ext.erl │ │ │ ├── vterm_new_pid_ext.erl │ │ │ ├── vterm_new_port_ext.erl │ │ │ ├── vterm_new_reference_ext.erl │ │ │ ├── vterm_newer_reference_ext.erl │ │ │ ├── vterm_nif_term.erl │ │ │ ├── vterm_nil_ext.erl │ │ │ ├── vterm_pid.erl │ │ │ ├── vterm_pid_ext.erl │ │ │ ├── vterm_port_ext.erl │ │ │ ├── vterm_reference.erl │ │ │ ├── vterm_reference_ext.erl │ │ │ ├── vterm_simplify.erl │ │ │ ├── vterm_small_atom_ext.erl │ │ │ ├── vterm_small_atom_utf8_ext.erl │ │ │ ├── vterm_small_big_ext.erl │ │ │ ├── vterm_small_integer_ext.erl │ │ │ ├── vterm_small_tuple_ext.erl │ │ │ ├── vterm_string_ext.erl │ │ │ ├── vterm_the_non_value.erl │ │ │ └── vterm_v4_port_ext.erl │ └── test │ │ └── erldist_filter_noop_SUITE.erl └── erldist_filter_test │ ├── rebar.config │ ├── src │ ├── erldist_filter_proper.erl │ ├── erldist_filter_proxy.erl │ ├── erldist_filter_test.app.src │ ├── proper_vdist.erl │ ├── proper_vterm.erl │ └── property_test │ │ ├── erldist_filter_nif_prop.erl │ │ ├── erldist_filter_nif_spbt_model_channel.erl │ │ ├── erldist_filter_nif_spbt_prop.erl │ │ ├── erldist_filter_nif_spbt_shim.erl │ │ ├── erldist_filter_nif_spbt_statem.erl │ │ ├── erldist_filter_peer_spbt_model.erl │ │ ├── erldist_filter_peer_spbt_prop.erl │ │ ├── erldist_filter_peer_spbt_shim.erl │ │ ├── erldist_filter_peer_spbt_statem.erl │ │ └── erldist_filter_peer_spbt_sup.erl │ └── test │ ├── erldist_filter_config_SUITE.erl │ ├── erldist_filter_conflict_SUITE.erl │ ├── erldist_filter_edge_cases_SUITE.erl │ ├── erldist_filter_edge_cases_SUITE_data │ └── counterexample8444249432900889_decode_length_trap_bug.config │ ├── erldist_filter_nif_SUITE.erl │ ├── erldist_filter_nif_spbt_SUITE.erl │ ├── erldist_filter_peer_spbt_SUITE.erl │ └── property_test │ └── erldist_filter_test_dummy_prop.erl ├── config └── config.exs ├── erlang.mk ├── mix.exs ├── mix.lock ├── rebar.config ├── rebar.lock └── test ├── peers_test.exs ├── support ├── peers.ex ├── queue_handler.ex └── queue_logger.ex ├── test_helper.exs └── untrusted_test.exs /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | # Used by "mix format" 8 | [ 9 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}", "apps/erldist_filter/{config,lib,test}/**/*.{ex,exs}"], 10 | line_length: 132 11 | ] 12 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | MIX_ENV: test 7 | 8 | jobs: 9 | test: 10 | name: Test 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | include: 17 | - elixir: 1.15.6 18 | otp: 26.1.1 19 | rebar3: 3.22.1 20 | lint: true 21 | 22 | - elixir: 1.14.5 23 | otp: 25.2.3 24 | rebar3: 3.22.0 25 | 26 | steps: 27 | - uses: actions/checkout@v3 28 | 29 | - name: Setup Beam 30 | uses: erlef/setup-beam@v1 31 | with: 32 | elixir-version: ${{ matrix.elixir }} 33 | otp-version: ${{ matrix.otp }} 34 | rebar3-version: ${{ matrix.rebar3 }} 35 | 36 | - name: Erlang Tests 37 | run: | 38 | rebar3 ct 39 | 40 | - name: Retrieve Mix Dependencies Cache 41 | uses: actions/cache@v3 42 | id: mix-cache 43 | with: 44 | path: deps 45 | key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} 46 | 47 | - name: Install Mix Dependencies 48 | if: steps.mix-cache.outputs.cache-hit != 'true' 49 | run: | 50 | mix local.rebar --force 51 | mix local.hex --force 52 | mix deps.get 53 | 54 | - name: Check Formatting 55 | if: ${{ matrix.lint }} 56 | run: mix format --check-formatted 57 | 58 | - name: Elixir Tests 59 | run: mix test --trace 60 | 61 | - name: Logs 62 | uses: actions/upload-artifact@v3 63 | if: failure() 64 | with: 65 | name: ct-logs-${{ matrix.otp }}-${{ matrix.elixir }} 66 | path: _build/test/logs/ 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | /apps/erldist_filter/_build/ 4 | /apps/erldist_filter_test/_build/ 5 | 6 | # If you run "mix test --cover", coverage assets end up here. 7 | /cover/ 8 | 9 | # The directory Mix downloads your dependencies sources to. 10 | /deps/ 11 | /apps/erldist_filter/deps/ 12 | /apps/erldist_filter_test/deps/ 13 | 14 | # Where third-party dependencies like ExDoc output generated docs. 15 | /doc/ 16 | /apps/erldist_filter/doc/ 17 | /apps/erldist_filter_test/doc/ 18 | 19 | # Ignore .fetch files in case you like to edit your project deps locally. 20 | /.fetch 21 | 22 | # If the VM crashes, it generates a dump, let's ignore it too. 23 | erl_crash.dump 24 | 25 | # Also ignore archive artifacts (built via "mix archive.build"). 26 | *.ez 27 | 28 | # Ignore package tarball (built via "mix hex.build"). 29 | erldist_filter-*.tar 30 | erldist_filter_test-*.tar 31 | 32 | # Temporary files, for example, from tests. 33 | /tmp/ 34 | 35 | # rebar3 and erlang.mk related files. 36 | .rebar3 37 | _* 38 | .eunit 39 | *.o 40 | *.beam 41 | *.plt 42 | *.swp 43 | *.swo 44 | .erlang.cookie 45 | ebin 46 | log 47 | erl_crash.dump 48 | .rebar 49 | logs 50 | _build 51 | .idea 52 | .vscode 53 | *.iml 54 | rebar3.crashdump 55 | *~ 56 | /.elixir_ls/ 57 | /.erlang.mk/ 58 | /apps/erldist_filter/c_src/env.mk 59 | /apps/erldist_filter/priv/*.dll 60 | /apps/erldist_filter/priv/*.dylib 61 | /apps/erldist_filter/priv/*.so 62 | /erlfmt 63 | /rebar3 64 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | apps/erldist_filter/CHANGELOG.md -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to `erldist_filter` 2 | 3 | We want to make contributing to this project as easy and transparent as possible. 4 | 5 | ## Our Development Process 6 | 7 | `erldist_filter` is currently developed in Meta's internal repositories and then exported out to GitHub by a Meta team member; however, we invite you to submit pull requests as described below. 8 | 9 | ## Pull Requests 10 | 11 | We actively welcome your pull requests. 12 | 13 | 1. Fork the repo and create your branch from `main`. 14 | 2. If you've added code that should be tested, add tests. 15 | 3. If you've changed APIs, update the documentation. 16 | 4. Ensure the test suite passes. 17 | 5. Make sure your code lints. 18 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 19 | 20 | ## Contributor License Agreement ("CLA") 21 | 22 | In order to accept your pull request, we need you to submit a CLA. You only need to do this once to work on any of Meta's open source projects. 23 | 24 | Complete your CLA here: 25 | 26 | ## Issues 27 | 28 | We use GitHub issues to track public bugs. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue. 29 | 30 | Meta has a [bounty program](https://www.facebook.com/whitehat/) for the safe disclosure of security bugs. In those cases, please go through the process outlined on that page and do not file a public issue. 31 | 32 | ## Coding Style 33 | 34 | Please run `make format` before submitting your changes. 35 | 36 | ## License 37 | 38 | By contributing to `erldist_filter`, you agree that your contributions will be licensed under the MIT license found in the LICENSE.md file in the root directory of this source tree. 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | =========== 3 | 4 | Copyright (c) Meta Platforms, Inc. and affiliates. 5 | 6 | Copyright (c) WhatsApp LLC 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `erldist_filter` 2 | 3 | [![Build Status](https://github.com/WhatsApp/erldist_filter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/WhatsApp/erldist_filter/actions) 4 | 5 | `erldist_filter` NIF for filtering and logging [Erlang Dist Protocol](https://www.erlang.org/doc/apps/erts/erl_dist_protocol.html) messages. 6 | 7 | See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out. 8 | 9 | ## License 10 | 11 | `erldist_filter` is MIT licensed, as found in the [LICENSE](LICENSE.md) file. 12 | -------------------------------------------------------------------------------- /apps/erldist_filter/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.1.0 (2023-10-04) 4 | 5 | * Added "fastpath" and "slowpath" branching for faster filtering of smaller messages. 6 | * I/O request and reply are dropped by default now (may be allowed by enabled `untrusted` mode with a custom handler). 7 | 8 | ## 1.0.0 (2023-09-07) 9 | 10 | * Initial release. 11 | -------------------------------------------------------------------------------- /apps/erldist_filter/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | =========== 3 | 4 | Copyright (c) Meta Platforms, Inc. and affiliates. 5 | 6 | Copyright (c) WhatsApp LLC 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /apps/erldist_filter/README.md: -------------------------------------------------------------------------------- 1 | # `erldist_filter` 2 | 3 | `erldist_filter` NIF for filtering and logging [Erlang Dist Protocol](https://www.erlang.org/doc/apps/erts/erl_dist_protocol.html) messages. 4 | 5 | ## License 6 | 7 | `erldist_filter` is MIT licensed, as found in the [LICENSE](LICENSE.md) file. 8 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/.clang-format: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | --- 7 | Language: Cpp 8 | BasedOnStyle: LLVM 9 | AllowShortFunctionsOnASingleLine: None 10 | AlwaysBreakAfterDefinitionReturnType: true 11 | BreakBeforeBraces: Linux 12 | ColumnLimit: 132 13 | IndentWidth: 4 14 | SortIncludes: false 15 | InsertNewlineAtEOF: true 16 | ... 17 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_IMPL_H 10 | #define EDF_CHANNEL_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_channel_open_5(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_channel_close_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_channel_inspect_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_channel_list_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_channel_list_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_channel_recv_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | extern ERL_NIF_TERM erldist_filter_nif_channel_set_controlling_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 33 | extern ERL_NIF_TERM erldist_filter_nif_channel_set_tracing_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 34 | 35 | /* Inline Function Definitions */ 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_inspect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_INSPECT_H 10 | #define EDF_CHANNEL_INSPECT_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern int edf_channel_inspect_atom_cache(ErlNifEnv *env, edf_atom_cache_t *cache, ERL_NIF_TERM *termp); 27 | extern int edf_channel_inspect_entry(ErlNifEnv *env, edf_channel_t *channel, ERL_NIF_TERM *termp); 28 | extern int edf_channel_inspect_rx(ErlNifEnv *env, edf_channel_t *channel, ERL_NIF_TERM *termp); 29 | extern int edf_channel_inspect_stats(ErlNifEnv *env, edf_channel_stats_t *stats, ERL_NIF_TERM *termp); 30 | 31 | /* Inline Function Definitions */ 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_channel_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CHANNEL_RECV_H 10 | #define EDF_CHANNEL_RECV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | #include "../trap/edf_trap.h" 18 | #include "../etf/etf_decode.h" 19 | #include "../etf/etf_encode.h" 20 | #include "../avec.h" 21 | 22 | /* Macro Definitions */ 23 | 24 | /* Type Definitions */ 25 | 26 | typedef struct edf_channel_recv_trap_s edf_channel_recv_trap_t; 27 | 28 | struct edf_channel_recv_trap_s { 29 | edf_trap_t super; 30 | edf_channel_resource_t *resource; 31 | edf_channel_t *channel; 32 | avec_t actions; 33 | edf_external_t *external; 34 | size_t fragment_index; 35 | size_t packet_count; 36 | }; 37 | 38 | /* Global Declarations */ 39 | 40 | /* Function Declarations */ 41 | 42 | extern ERL_NIF_TERM edf_channel_recv_trap_open(ErlNifEnv *env, edf_channel_resource_t *resource, edf_channel_t *channel, 43 | edf_channel_recv_trap_t **trapp); 44 | 45 | /* Inline Function Definitions */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_external_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_EXTERNAL_RECV_H 10 | #define EDF_EXTERNAL_RECV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_channel.h" 17 | #include "../trap/edf_trap.h" 18 | #include "../config/edf_config.h" 19 | #include "../etf/etf_decode.h" 20 | #include "../etf/etf_encode.h" 21 | #include "../vdist/vdist.h" 22 | 23 | /* Macro Definitions */ 24 | 25 | /* Type Definitions */ 26 | 27 | typedef struct edf_external_recv_trap_s edf_external_recv_trap_t; 28 | typedef enum edf_external_recv_trap_state_t edf_external_recv_trap_state_t; 29 | 30 | enum edf_external_recv_trap_state_t { 31 | EDF_EXTERNAL_RECV_TRAP_STATE_NONE = 0, 32 | EDF_EXTERNAL_RECV_TRAP_STATE_INIT, 33 | EDF_EXTERNAL_RECV_TRAP_STATE_COMPACT_REALLOC, 34 | EDF_EXTERNAL_RECV_TRAP_STATE_COMPACT_COPY, 35 | EDF_EXTERNAL_RECV_TRAP_STATE_MAYBE_INSPECT, 36 | EDF_EXTERNAL_RECV_TRAP_STATE_DECODE_PAYLOAD_LENGTH, 37 | EDF_EXTERNAL_RECV_TRAP_STATE_INSPECT, 38 | EDF_EXTERNAL_RECV_TRAP_STATE_MAYBE_LOG_EVENT, 39 | EDF_EXTERNAL_RECV_TRAP_STATE_LOG_EVENT, 40 | EDF_EXTERNAL_RECV_TRAP_STATE_MAYBE_REDIRECT, 41 | EDF_EXTERNAL_RECV_TRAP_STATE_REDIRECT_DOP, 42 | EDF_EXTERNAL_RECV_TRAP_STATE_REDIRECT_SPAWN_REQUEST, 43 | EDF_EXTERNAL_RECV_TRAP_STATE_EMIT, 44 | EDF_EXTERNAL_RECV_TRAP_STATE_DROP, 45 | EDF_EXTERNAL_RECV_TRAP_STATE_DONE, 46 | }; 47 | 48 | struct edf_external_recv_trap_s { 49 | edf_trap_t super; 50 | edf_external_recv_trap_state_t state; 51 | edf_external_t *external; 52 | size_t fragment_index; 53 | size_t old_frag_size; 54 | struct { 55 | size_t skip; 56 | size_t framing_length; 57 | size_t headers_length; 58 | size_t control_length; 59 | size_t payload_length; 60 | size_t total; 61 | } new_frag_size; 62 | }; 63 | 64 | /* Global Declarations */ 65 | 66 | /* Function Declarations */ 67 | 68 | extern ERL_NIF_TERM edf_external_recv_trap_open(ErlNifEnv *env, edf_external_t *external, edf_external_recv_trap_t **trapp); 69 | 70 | /* Inline Function Definitions */ 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/channel/edf_external_sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_EXTERNAL_SEQUENCE_H 10 | #define EDF_EXTERNAL_SEQUENCE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_external.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | static void edf_external_sequence_init_empty(edf_external_t *ext); 25 | static bool edf_external_sequence_is_linked(edf_external_t *ext); 26 | extern void edf_external_sequence_destroy_all(edf_external_t **root); 27 | extern edf_external_t *edf_external_sequence_lookup(edf_external_t *root, uint64_t sequence_id); 28 | extern edf_external_t *edf_external_sequence_lookup_insert(edf_external_t **root, edf_external_t *ext); 29 | extern void edf_external_sequence_unlink(edf_external_t **root, edf_external_t *ext); 30 | 31 | /* Inline Function Definitions */ 32 | 33 | inline void 34 | edf_external_sequence_init_empty(edf_external_t *ext) 35 | { 36 | ext->_sequence.parent = NULL; 37 | ext->_sequence.left = NULL; 38 | ext->_sequence.right = NULL; 39 | ext->_sequence.is_red = 0; 40 | ext->_sequence.is_linked = 0; 41 | return; 42 | } 43 | 44 | inline bool 45 | edf_external_sequence_is_linked(edf_external_t *ext) 46 | { 47 | if (ext == NULL || ext->_sequence.is_linked == 0) { 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/config/edf_config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #include "edf_config.h" 10 | 11 | #include "../core/xnif_trace.h" 12 | 13 | /* Global Variables */ 14 | 15 | static edf_config_t edf_config_internal = { 16 | .compact_fragments = false, 17 | .deep_packet_inspection = false, 18 | .logging = false, 19 | .redirect_dist_operations = false, 20 | .untrusted = false, 21 | }; 22 | edf_config_t *edf_config_global = &edf_config_internal; 23 | 24 | /* Function Definitions */ 25 | 26 | int 27 | edf_config_load(ErlNifEnv *env) 28 | { 29 | int retval = 0; 30 | (void)env; 31 | return retval; 32 | } 33 | 34 | void 35 | edf_config_unload(ErlNifEnv *env) 36 | { 37 | (void)env; 38 | return; 39 | } 40 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/config/edf_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CONFIG_H 10 | #define EDF_CONFIG_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../edf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct edf_config_s edf_config_t; 23 | 24 | struct edf_config_s { 25 | alignas(uintptr_t) bool compact_fragments; 26 | alignas(uintptr_t) bool deep_packet_inspection; 27 | alignas(uintptr_t) bool logging; 28 | alignas(uintptr_t) bool redirect_dist_operations; 29 | alignas(uintptr_t) bool untrusted; 30 | }; 31 | 32 | /* Global Declarations */ 33 | 34 | extern edf_config_t *edf_config_global; 35 | 36 | /* Function Declarations */ 37 | 38 | extern int edf_config_load(ErlNifEnv *env); 39 | extern void edf_config_unload(ErlNifEnv *env); 40 | 41 | static bool edf_config_is_compact_fragments_enabled(void); 42 | static bool edf_config_is_deep_packet_inspection_enabled(void); 43 | static bool edf_config_is_logging_enabled(void); 44 | static bool edf_config_is_redirect_dist_operations_enabled(void); 45 | static bool edf_config_is_untrusted_enabled(void); 46 | 47 | /* Inline Function Definitions */ 48 | 49 | inline bool 50 | edf_config_is_compact_fragments_enabled(void) 51 | { 52 | return (edf_config_global->compact_fragments); 53 | } 54 | 55 | inline bool 56 | edf_config_is_deep_packet_inspection_enabled(void) 57 | { 58 | return (edf_config_global->deep_packet_inspection); 59 | } 60 | 61 | inline bool 62 | edf_config_is_logging_enabled(void) 63 | { 64 | return (edf_config_global->logging); 65 | } 66 | 67 | inline bool 68 | edf_config_is_redirect_dist_operations_enabled(void) 69 | { 70 | return (edf_config_global->redirect_dist_operations); 71 | } 72 | 73 | inline bool 74 | edf_config_is_untrusted_enabled(void) 75 | { 76 | return (edf_config_global->untrusted); 77 | } 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/config/edf_config_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_CONFIG_IMPL_H 10 | #define EDF_CONFIG_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_config.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_config_get_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_config_get_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_config_set_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | 30 | /* Inline Function Definitions */ 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/align.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_ALIGN_H 10 | #define CORE_ALIGN_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | /* Darwin can be frustrating sometimes */ 19 | 20 | #ifndef alignas 21 | #define alignas(T) _Alignas(T) 22 | #endif 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/bool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_BOOL_H 10 | #define CORE_BOOL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | // bool, true, and false are now keywords as part of the C23 standard 17 | // See https://en.cppreference.com/w/c/language/bool_constant 18 | #include 19 | 20 | /* Darwin can be frustrating sometimes */ 21 | 22 | #ifndef bool 23 | #define bool _Bool 24 | #endif 25 | #ifndef false 26 | #define false 0 27 | #endif 28 | #ifndef true 29 | #define true 1 30 | #endif 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/linklist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef LINKLIST_H 10 | #define LINKLIST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | /* Type Definitions */ 20 | 21 | typedef struct linklist_s linklist_t; 22 | 23 | struct linklist_s { 24 | linklist_t *next; 25 | linklist_t *prev; 26 | }; 27 | 28 | /* Function Declarations */ 29 | 30 | static void linklist_init_anchor(linklist_t *anchor); 31 | static int linklist_is_empty(linklist_t *anchor); 32 | static int linklist_is_linked(linklist_t *node); 33 | static void linklist_insert(linklist_t *pos, linklist_t *node); 34 | static void linklist_insert_list(linklist_t *pos, linklist_t *list); 35 | static void linklist_unlink(linklist_t *node); 36 | 37 | /* Inline Function Definitions */ 38 | 39 | inline void 40 | linklist_init_anchor(linklist_t *anchor) 41 | { 42 | anchor->next = anchor->prev = anchor; 43 | } 44 | 45 | inline int 46 | linklist_is_linked(linklist_t *node) 47 | { 48 | return node->next != NULL; 49 | } 50 | 51 | inline int 52 | linklist_is_empty(linklist_t *anchor) 53 | { 54 | return anchor->next == anchor; 55 | } 56 | 57 | inline void 58 | linklist_insert(linklist_t *pos, linklist_t *node) 59 | { 60 | assert(!linklist_is_linked(node)); 61 | 62 | node->prev = pos->prev; 63 | node->next = pos; 64 | node->prev->next = node; 65 | node->next->prev = node; 66 | } 67 | 68 | inline void 69 | linklist_insert_list(linklist_t *pos, linklist_t *list) 70 | { 71 | if (linklist_is_empty(list)) 72 | return; 73 | list->next->prev = pos->prev; 74 | list->prev->next = pos; 75 | pos->prev->next = list->next; 76 | pos->prev = list->prev; 77 | (void)linklist_init_anchor(list); 78 | } 79 | 80 | inline void 81 | linklist_unlink(linklist_t *node) 82 | { 83 | node->next->prev = node->prev; 84 | node->prev->next = node->next; 85 | node->next = node->prev = NULL; 86 | } 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SPINLOCK_H 10 | #define SPINLOCK_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | #include "portable_hint.h" 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct spinlock_s spinlock_t; 23 | 24 | struct spinlock_s { 25 | atomic_flag value; 26 | }; 27 | 28 | /* Function Declarations */ 29 | 30 | static void spinlock_init(volatile spinlock_t *s); 31 | static void spinlock_lock(volatile spinlock_t *s); 32 | static void spinlock_unlock(volatile spinlock_t *s); 33 | 34 | /* Inline Function Definitions */ 35 | 36 | inline void 37 | spinlock_init(volatile spinlock_t *s) 38 | { 39 | atomic_flag value = ATOMIC_FLAG_INIT; 40 | s->value = value; 41 | } 42 | 43 | inline void 44 | spinlock_lock(volatile spinlock_t *s) 45 | { 46 | 47 | #if defined(__GNUC__) 48 | #define INTRINSICS_UNLIKELY(x) (__builtin_expect(!!(x), 0)) 49 | #else 50 | #define INTRINSICS_UNLIKELY(x) x 51 | #endif 52 | 53 | while (INTRINSICS_UNLIKELY(atomic_flag_test_and_set_explicit(&s->value, memory_order_relaxed))) { 54 | HINT_SPIN_LOOP(); 55 | } 56 | // (void)atomic_thread_fence(memory_order_acquire); 57 | (void)atomic_signal_fence(memory_order_acquire); 58 | return; 59 | 60 | #undef INTRINSICS_UNLIKELY 61 | } 62 | 63 | inline void 64 | spinlock_unlock(volatile spinlock_t *s) 65 | { 66 | (void)atomic_flag_clear_explicit(&s->value, memory_order_release); 67 | return; 68 | } 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/spinwait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SPINWAIT_H 10 | #define SPINWAIT_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #include "c11threads.h" 20 | #include "portable_hint.h" 21 | 22 | /* Type Definitions */ 23 | 24 | typedef struct spinwait_s spinwait_t; 25 | 26 | struct spinwait_s { 27 | uint32_t counter; 28 | }; 29 | 30 | /* Function Declarations */ 31 | 32 | static void spinwait_init(volatile spinwait_t *w); 33 | static bool spinwait_try_spin(volatile spinwait_t *w); 34 | static void spinwait_spin_no_yield(volatile spinwait_t *w); 35 | 36 | /* Inline Function Definitions */ 37 | 38 | inline void 39 | spinwait_init(volatile spinwait_t *w) 40 | { 41 | w->counter = 0; 42 | } 43 | 44 | inline bool 45 | spinwait_try_spin(volatile spinwait_t *w) 46 | { 47 | if (w->counter >= 10) { 48 | return false; 49 | } 50 | w->counter += 1; 51 | if (w->counter <= 3) { 52 | int i = (1 << ((int)(w->counter))); 53 | while (i--) { 54 | HINT_SPIN_LOOP(); 55 | } 56 | } else { 57 | (void)thrd_yield(); 58 | } 59 | return true; 60 | } 61 | 62 | inline void 63 | spinwait_spin_no_yield(volatile spinwait_t *w) 64 | { 65 | int i; 66 | w->counter += 1; 67 | if (w->counter > 10) { 68 | w->counter = 10; 69 | } 70 | i = (1 << ((int)(w->counter))); 71 | while (i--) { 72 | HINT_SPIN_LOOP(); 73 | } 74 | return; 75 | } 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/core/unreachable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef CORE_UNREACHABLE_H 10 | #define CORE_UNREACHABLE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | // unreachable() is part of the C23 standard 17 | // See https://en.cppreference.com/w/c/program/unreachable 18 | #include 19 | 20 | #if !defined(unreachable) 21 | // Uses compiler specific extensions if possible. 22 | #ifdef __GNUC__ // GCC, Clang, ICC 23 | #define unreachable() (__builtin_unreachable()) 24 | #elif defined(_MSC_VER) // MSVC 25 | #define unreachable() (__assume(false)) 26 | #else 27 | // Even if no extension is used, undefined behavior is still raised by 28 | // the empty function body and the noreturn attribute. 29 | // The external definition of unreachable_impl must be emitted in a separated TU 30 | // due to the rule for inline functions in C. 31 | [[noreturn]] inline void 32 | unreachable_impl() 33 | { 34 | } 35 | #define unreachable() (unreachable_impl()) 36 | #endif 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erldist_filter_nif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ERLDIST_FILTER_NIF_H 10 | #define ERLDIST_FILTER_NIF_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_common.h" 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/erts/atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * %CopyrightBegin% 3 | * 4 | * Copyright Ericsson AB 2015-2021. All Rights Reserved. 5 | * Copyright (c) Meta Platforms, Inc. and affiliates. 6 | * Copyright (c) WhatsApp LLC 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * %CopyrightEnd% 21 | */ 22 | 23 | #ifndef EDF_ERTS_ATOM_H 24 | #define EDF_ERTS_ATOM_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include 31 | 32 | #include 33 | 34 | /// See 35 | /// [erts/emulator/beam/atom.h](https://github.com/erlang/otp/blob/OTP-25.2.3/erts/emulator/beam/atom.h) 36 | /// in the Erlang/OTP source code. 37 | 38 | #define MAX_ATOM_CHARACTERS 255 39 | #define MAX_ATOM_SZ_FROM_LATIN1 (2 * MAX_ATOM_CHARACTERS) 40 | #define MAX_ATOM_SZ_LIMIT (4 * MAX_ATOM_CHARACTERS) /* theoretical byte limit */ 41 | 42 | typedef enum { 43 | ERTS_ATOM_ENC_7BIT_ASCII, 44 | ERTS_ATOM_ENC_LATIN1, 45 | ERTS_ATOM_ENC_UTF8, 46 | } ErtsAtomEncoding; 47 | 48 | extern ERL_NIF_TERM erts_atom_put(const uint8_t *name, signed int len, ErtsAtomEncoding enc, int trunc); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_COMMON_H 10 | #define ETF_DECODE_COMMON_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../edf_common.h" 17 | #include "../channel/edf_external.h" 18 | #include "../trap/edf_trap.h" 19 | #include "../vec.h" 20 | 21 | #include "../erts/dist.h" 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_H 10 | #define ETF_DECODE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_decode_dist_header.h" 17 | #include "etf_decode_term_length.h" 18 | #include "etf_decode_udist.h" 19 | #include "etf_decode_vterm.h" 20 | 21 | /* Macro Definitions */ 22 | 23 | /* Type Definitions */ 24 | 25 | /* Function Declarations */ 26 | 27 | /* Inline Function Definitions */ 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode_dist_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_DIST_HEADER_H 10 | #define ETF_DECODE_DIST_HEADER_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct etf_decode_dist_header_trap_s etf_decode_dist_header_trap_t; 23 | typedef enum etf_decode_dist_header_trap_state_t etf_decode_dist_header_trap_state_t; 24 | 25 | enum etf_decode_dist_header_trap_state_t { 26 | ETF_DECODE_DIST_HEADER_TRAP_STATE_INIT = 0, 27 | ETF_DECODE_DIST_HEADER_TRAP_STATE_READ_FLAGS, 28 | ETF_DECODE_DIST_HEADER_TRAP_STATE_DONE, 29 | }; 30 | 31 | struct etf_decode_dist_header_trap_s { 32 | edf_trap_t super; 33 | etf_decode_dist_header_trap_state_t state; 34 | edf_external_t *external; 35 | vec_t vec; 36 | size_t skip; 37 | uint8_t number_of_atom_cache_refs; 38 | size_t flags_size; 39 | const uint8_t *flagsp; 40 | bool long_atoms; 41 | int got_flags; 42 | int table_index; 43 | const uint8_t *head; 44 | const uint8_t *tail; 45 | }; 46 | 47 | /* Function Declarations */ 48 | 49 | extern ERL_NIF_TERM etf_decode_dist_header_trap_open(ErlNifEnv *env, edf_external_t *external, 50 | etf_decode_dist_header_trap_t **trapp); 51 | extern int etf_fast_decode_dist_header(ErlNifEnv *caller_env, edf_channel_t *channel, edf_atom_translation_table_t *attab, 52 | vec_reader_t *vr, int *external_flags, slice_t *headers, ERL_NIF_TERM *err_termp); 53 | 54 | /* Inline Function Definitions */ 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_decode_udist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_DECODE_UDIST_H 10 | #define ETF_DECODE_UDIST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | // Don't include "vterm_env.h", just reference the type here. 23 | typedef struct vterm_env_s vterm_env_t; 24 | 25 | /* Function Declarations */ 26 | 27 | extern int etf_decode_udist_control(ErlNifEnv *caller_env, vterm_env_t *vtenv, bool is_external, bool skip_slow_terms, vec_t *slice, 28 | udist_t *up, ERL_NIF_TERM *err_termp); 29 | 30 | /* Inline Function Definitions */ 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_ENCODE_H 10 | #define ETF_ENCODE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_redirect_dop.h" 17 | #include "etf_redirect_spawn_request.h" 18 | #include "etf_rewrite_as_drop.h" 19 | #include "etf_rewrite_fragment_header.h" 20 | #include "etf_rollback_atom_cache.h" 21 | 22 | /* Macro Definitions */ 23 | 24 | /* Type Definitions */ 25 | 26 | /* Function Declarations */ 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_redirect_dop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REDIRECT_DOP_H 10 | #define ETF_REDIRECT_DOP_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_redirect_dop(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | extern int etf_redirect_dop_resolve_node(ErlNifEnv *caller_env, edf_external_t *ext, vec_t *node_vec); 26 | 27 | /* Inline Function Definitions */ 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_redirect_spawn_request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REDIRECT_SPAWN_REQUEST_H 10 | #define ETF_REDIRECT_SPAWN_REQUEST_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_redirect_spawn_request(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | 26 | /* Inline Function Definitions */ 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rewrite_as_drop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REWRITE_AS_DROP_H 10 | #define ETF_REWRITE_AS_DROP_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Function Declarations */ 23 | 24 | extern int etf_rewrite_as_drop(ErlNifEnv *caller_env, edf_external_t *external, ERL_NIF_TERM *err_termp); 25 | 26 | /* Inline Function Definitions */ 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rewrite_fragment_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_REWRITE_FRAGMENT_HEADER_H 10 | #define ETF_REWRITE_FRAGMENT_HEADER_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct etf_rewrite_fragment_header_trap_s etf_rewrite_fragment_header_trap_t; 23 | typedef enum etf_rewrite_fragment_header_trap_state_t etf_rewrite_fragment_header_trap_state_t; 24 | 25 | enum etf_rewrite_fragment_header_trap_state_t { 26 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_INIT = 0, 27 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_FIND_CONFLICTS, 28 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_RESOLVE_ATOMS, 29 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_ALLOC, 30 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_ENCODE, 31 | ETF_REWRITE_FRAGMENT_HEADER_TRAP_STATE_DONE, 32 | }; 33 | 34 | struct etf_rewrite_fragment_header_trap_s { 35 | edf_trap_t super; 36 | etf_rewrite_fragment_header_trap_state_t state; 37 | edf_external_t *external; 38 | int internal_index; 39 | bool maybe_rewrite; 40 | size_t rewrite_size; 41 | }; 42 | 43 | /* Function Declarations */ 44 | 45 | extern ERL_NIF_TERM etf_rewrite_fragment_header_trap_open(ErlNifEnv *env, edf_external_t *external, 46 | etf_rewrite_fragment_header_trap_t **trapp); 47 | 48 | /* Inline Function Definitions */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/etf/etf_rollback_atom_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef ETF_ROLLBACK_ATOM_CACHE_H 10 | #define ETF_ROLLBACK_ATOM_CACHE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "etf_common.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | typedef struct etf_rollback_atom_cache_trap_s etf_rollback_atom_cache_trap_t; 23 | typedef enum etf_rollback_atom_cache_trap_state_t etf_rollback_atom_cache_trap_state_t; 24 | 25 | enum etf_rollback_atom_cache_trap_state_t { 26 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_INIT = 0, 27 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_ALLOC, 28 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_ENCODE, 29 | ETF_ROLLBACK_ATOM_CACHE_TRAP_STATE_DONE, 30 | }; 31 | 32 | struct etf_rollback_atom_cache_trap_s { 33 | edf_trap_t super; 34 | etf_rollback_atom_cache_trap_state_t state; 35 | edf_external_t *external; 36 | int internal_index; 37 | size_t rollback_size; 38 | }; 39 | 40 | /* Function Declarations */ 41 | 42 | extern ERL_NIF_TERM etf_rollback_atom_cache_trap_open(ErlNifEnv *env, edf_external_t *external, 43 | etf_rollback_atom_cache_trap_t **trapp); 44 | 45 | /* Inline Function Definitions */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/logger/edf_logger_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_LOGGER_IMPL_H 10 | #define EDF_LOGGER_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_logger.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_logger_open_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_logger_close_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_logger_inspect_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_logger_list_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_logger_recv_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_logger_set_capacity_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | extern ERL_NIF_TERM erldist_filter_nif_logger_set_controlling_process_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 33 | 34 | /* Inline Function Definitions */ 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/logger/edf_logger_queue_recv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_LOGGER_QUEUE_RECV_H 10 | #define EDF_LOGGER_QUEUE_RECV_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_logger.h" 17 | #include "../trap/edf_trap.h" 18 | 19 | /* Macro Definitions */ 20 | 21 | /* Type Definitions */ 22 | 23 | typedef struct edf_logger_queue_recv_trap_s edf_logger_queue_recv_trap_t; 24 | 25 | struct edf_logger_queue_recv_trap_s { 26 | edf_trap_t super; 27 | edf_logger_resource_t *resource; 28 | edf_logger_t *logger; 29 | ipc_batch_t *batch; 30 | }; 31 | 32 | /* Global Declarations */ 33 | 34 | /* Function Declarations */ 35 | 36 | extern int edf_logger_queue_recv(ErlNifEnv *env, edf_logger_resource_t *resource, edf_logger_t *logger, ipc_batch_t *batch, 37 | ERL_NIF_TERM *out_term); 38 | extern ERL_NIF_TERM edf_logger_queue_recv_trap_open(ErlNifEnv *env, edf_logger_resource_t *resource, edf_logger_t *logger, 39 | ipc_batch_t *batch, edf_logger_queue_recv_trap_t **trapp); 40 | 41 | /* Inline Function Definitions */ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/slice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef SLICE_H 10 | #define SLICE_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | /* Macro Definitions */ 20 | 21 | #define SLICE_INIT_EMPTY() \ 22 | { \ 23 | .head = NULL, .tail = NULL, \ 24 | } 25 | 26 | /* Type Definitions */ 27 | 28 | typedef struct slice_s slice_t; 29 | 30 | struct slice_s { 31 | const uint8_t *head; 32 | const uint8_t *tail; 33 | }; 34 | 35 | /* Function Declarations */ 36 | 37 | static int slice_is_empty(const slice_t *slice); 38 | static size_t slice_len(const slice_t *slice); 39 | 40 | /* Inline Function Definitions */ 41 | 42 | inline int 43 | slice_is_empty(const slice_t *slice) 44 | { 45 | return (slice == NULL || slice->head == NULL || slice->tail == NULL); 46 | } 47 | 48 | inline size_t 49 | slice_len(const slice_t *slice) 50 | { 51 | return (size_t)(slice->tail - slice->head); 52 | } 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/trap/edf_trap_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_TRAP_IMPL_H 10 | #define EDF_TRAP_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_trap.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_trap_2_continue(ErlNifEnv *caller_env, int argc, const ERL_NIF_TERM argv[]); 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/vterm/vterm_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef VTERM_COMMON_H 10 | #define VTERM_COMMON_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "../edf_common.h" 17 | #include "../channel/edf_atom_cache.h" 18 | #include "../vec.h" 19 | 20 | /* Macro Definitions */ 21 | 22 | /* Type Definitions */ 23 | 24 | typedef uintptr_t vword_t; 25 | 26 | typedef struct __vterm_s __vterm_t; 27 | typedef enum __vterm_tag_t __vterm_tag_t; 28 | 29 | typedef __vterm_t *vterm_t; 30 | typedef vword_t vterm_tag_t; 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/vterm/vterm_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef VTERM_IMPL_H 10 | #define VTERM_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "vterm.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vdist_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vterm_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 28 | extern ERL_NIF_TERM erldist_filter_nif_dist_ext_to_vterm_3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 29 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vdist_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 30 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vterm_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 31 | extern ERL_NIF_TERM erldist_filter_nif_dist_int_to_vterm_3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 32 | 33 | /* Inline Function Definitions */ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /apps/erldist_filter/c_src/nif/world/edf_world_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * Copyright (c) WhatsApp LLC 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE.md file in the root directory of this source tree. 7 | */ 8 | 9 | #ifndef EDF_WORLD_IMPL_H 10 | #define EDF_WORLD_IMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "edf_world.h" 17 | 18 | /* Macro Definitions */ 19 | 20 | /* Type Definitions */ 21 | 22 | /* Global Declarations */ 23 | 24 | /* Function Declarations */ 25 | 26 | extern ERL_NIF_TERM erldist_filter_nif_world_stats_get_0(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]); 27 | 28 | /* Inline Function Definitions */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter.hrl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 20 Sep 2022 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | %% @oncall whatsapp_clr 17 | -ifndef(ERLDIST_FILTER_HRL). 18 | 19 | -define(ERLDIST_FILTER_HRL, 1). 20 | 21 | -include_lib("erldist_filter/include/vdist.hrl"). 22 | -include_lib("erldist_filter/include/vedf.hrl"). 23 | -include_lib("erldist_filter/include/vterm.hrl"). 24 | 25 | -endif. 26 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter_otp_25_2_3_net_address.hrl: -------------------------------------------------------------------------------- 1 | %% NOTE: This file is imported from https://raw.githubusercontent.com/erlang/otp/OTP-25.2.3/lib/kernel/include/net_address.hrl 2 | %% @oncall whatsapp_clr 3 | 4 | %% 5 | %% %CopyrightBegin% 6 | %% 7 | %% Copyright Ericsson AB 1997-2016. All Rights Reserved. 8 | %% Copyright (c) Meta Platforms, Inc. and affiliates. 9 | %% Copyright (c) WhatsApp LLC 10 | %% 11 | %% Licensed under the Apache License, Version 2.0 (the "License"); 12 | %% you may not use this file except in compliance with the License. 13 | %% You may obtain a copy of the License at 14 | %% 15 | %% http://www.apache.org/licenses/LICENSE-2.0 16 | %% 17 | %% Unless required by applicable law or agreed to in writing, software 18 | %% distributed under the License is distributed on an "AS IS" BASIS, 19 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | %% See the License for the specific language governing permissions and 21 | %% limitations under the License. 22 | %% 23 | %% %CopyrightEnd% 24 | %% 25 | 26 | %% Generic address format 27 | 28 | -record(net_address, 29 | { 30 | address, %% opaque address 31 | host, %% host name 32 | protocol, %% protocol 33 | family %% address family 34 | }). 35 | -------------------------------------------------------------------------------- /apps/erldist_filter/include/erldist_filter_otp_26_0_2_net_address.hrl: -------------------------------------------------------------------------------- 1 | %% NOTE: This file is imported from https://raw.githubusercontent.com/erlang/otp/OTP-26.0.2/lib/kernel/include/net_address.hrl 2 | %% @oncall whatsapp_clr 3 | 4 | %% 5 | %% %CopyrightBegin% 6 | %% 7 | %% Copyright Ericsson AB 1997-2016. All Rights Reserved. 8 | %% Copyright (c) Meta Platforms, Inc. and affiliates. 9 | %% Copyright (c) WhatsApp LLC 10 | %% 11 | %% Licensed under the Apache License, Version 2.0 (the "License"); 12 | %% you may not use this file except in compliance with the License. 13 | %% You may obtain a copy of the License at 14 | %% 15 | %% http://www.apache.org/licenses/LICENSE-2.0 16 | %% 17 | %% Unless required by applicable law or agreed to in writing, software 18 | %% distributed under the License is distributed on an "AS IS" BASIS, 19 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | %% See the License for the specific language governing permissions and 21 | %% limitations under the License. 22 | %% 23 | %% %CopyrightEnd% 24 | %% 25 | 26 | %% Generic address format 27 | 28 | -record(net_address, 29 | { 30 | address, %% opaque address 31 | host, %% host name 32 | protocol, %% protocol 33 | family %% address family 34 | }). -------------------------------------------------------------------------------- /apps/erldist_filter/include/vedf.hrl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 19 Jun 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | %% @oncall whatsapp_clr 17 | -ifndef(VEDF_HRL). 18 | 19 | -define(VEDF_HRL, 1). 20 | 21 | -record(vedf_channel, { 22 | packet_size = 0 :: 0 | 1 | 2 | 4 | 8, 23 | dflags = 0 :: vterm:u64(), 24 | rx_sequences = maps:new() :: #{vdist:sequence_id() => vdist_external:t()}, 25 | rx_atom_cache = undefined :: undefined | vdist_atom_cache:t(), 26 | rx_logger_time = 0 :: non_neg_integer(), 27 | rx_router_name :: atom(), 28 | rx_sort = 0 :: non_neg_integer(), 29 | compact_fragments = false :: boolean(), 30 | deep_packet_inspection = false :: boolean(), 31 | logging = false :: boolean(), 32 | redirect_dist_operations = false :: boolean(), 33 | sysname = undefined :: undefined | erldist_filter_nif:sysname(), 34 | untrusted = false :: boolean() 35 | }). 36 | 37 | -endif. 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/mix.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | defmodule ErldistFilter.MixProject do 8 | use Mix.Project 9 | 10 | def project() do 11 | {app, desc} = load_app() 12 | [ 13 | app: app, 14 | version: to_string(Keyword.fetch!(desc, :vsn)), 15 | description: to_string(Keyword.fetch!(desc, :description)), 16 | elixir: "~> 1.14", 17 | compilers: [:elixir_make] ++ Mix.compilers(), 18 | make_args: ["-j"], 19 | make_env: %{"MIX_ENV" => to_string(Mix.env())}, 20 | make_clean: ["clean"], 21 | make_cwd: "c_src", 22 | deps: deps(), 23 | elixirc_paths: elixirc_paths(Mix.env()), 24 | package: package() 25 | ] 26 | end 27 | 28 | def application() do 29 | {_app, desc} = load_app() 30 | [mod: Keyword.fetch!(desc, :mod)] 31 | end 32 | 33 | # Run "mix help deps" to learn about dependencies. 34 | defp deps() do 35 | [ 36 | {:elixir_make, "~> 0.7", runtime: false} 37 | ] 38 | end 39 | 40 | defp elixirc_paths(:test), do: ["lib", "test/support"] 41 | defp elixirc_paths(_), do: ["lib"] 42 | 43 | defp package() do 44 | {_app, desc} = load_app() 45 | [ 46 | build_tools: ["mix", "rebar3"], 47 | description: to_string(Keyword.fetch!(desc, :description)), 48 | exclude_patterns: Enum.map(Keyword.fetch!(desc, :exclude_patterns), fn pattern -> 49 | Regex.compile!(to_string(pattern)) 50 | end), 51 | files: Enum.map(Keyword.fetch!(desc, :files), &to_string/1), 52 | licenses: Enum.map(Keyword.fetch!(desc, :licenses), &to_string/1), 53 | links: Enum.into(Keyword.fetch!(desc, :links), Map.new(), fn {key, value} -> 54 | {to_string(key), to_string(value)} 55 | end) 56 | ] 57 | end 58 | 59 | defp load_app() do 60 | {:ok, [{:application, name, desc}]} = :file.consult('src/erldist_filter.app.src') 61 | {name, desc} 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /apps/erldist_filter/priv/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WhatsApp/erldist_filter/34a9cbe5a3cb011756fd20a77ecbe60fc0155ed5/apps/erldist_filter/priv/.keep -------------------------------------------------------------------------------- /apps/erldist_filter/rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, []}. 10 | 11 | {pre_hooks, [ 12 | {"(linux|darwin|solaris)", compile, "make -j -C c_src"}, 13 | {"(freebsd)", compile, "gmake -j -C c_src"}, 14 | {"(win32)", compile, "cd c_src && nmake /F Makefile.win"} 15 | ]}. 16 | 17 | {post_hooks, [ 18 | {"(linux|darwin|solaris)", clean, "make -C c_src clean distclean"}, 19 | {"(freebsd)", clean, "gmake -C c_src clean distclean"}, 20 | {"(win32)", compile, "cd c_src && nmake /F Makefile.win clean distclean"} 21 | ]}. 22 | 23 | {shell, 24 | % {config, "config/sys.config"}, 25 | [{apps, [erldist_filter]}]}. 26 | 27 | {ex_doc, [ 28 | {source_url, <<"https://github.com/WhatsApp/erldist_filter">>}, 29 | {extras, [ 30 | <<"README.md">>, 31 | <<"LICENSE.md">>, 32 | <<"../../CHANGELOG.md">>, 33 | <<"../../CODE_OF_CONDUCT.md">>, 34 | <<"../../CONTRIBUTING.md">> 35 | ]}, 36 | {main, <<"readme">>} 37 | ]}. 38 | 39 | {hex, [{doc, ex_doc}]}. 40 | -------------------------------------------------------------------------------- /apps/erldist_filter/rebar.lock: -------------------------------------------------------------------------------- 1 | []. 2 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/edf.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 17 Jun 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(edf). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include_lib("erldist_filter/include/udist.hrl"). 22 | 23 | %% Internal API 24 | -export([ 25 | req/3 26 | ]). 27 | 28 | %%%============================================================================= 29 | %%% Internal API functions 30 | %%%============================================================================= 31 | 32 | -spec req(Sysname, {Module, FunctionName, Arity}, Arguments) -> no_return() | eqwalizer:dynamic() when 33 | Sysname :: node(), 34 | Module :: module(), 35 | FunctionName :: atom(), 36 | Arity :: non_neg_integer(), 37 | Arguments :: [eqwalizer:dynamic()]. 38 | req(Sysname, {Module, FunctionName, Arity}, Arguments) when length(Arguments) =:= Arity -> 39 | case erldist_filter:handler_get() of 40 | undefined -> 41 | erlang:apply(Module, FunctionName, Arguments); 42 | Handler when is_atom(Handler) -> 43 | Handler:spawn_request_init(Sysname, Module, FunctionName, Arguments) 44 | end. 45 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter.app.src: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% % @format 8 | {application, erldist_filter, [ 9 | {description, "erldist_filter: Erlang distribution filtering"}, 10 | {vsn, "1.1.0"}, 11 | {mod, {erldist_filter_app, []}}, 12 | {modules, []}, 13 | {registered, []}, 14 | %% NOTE: Remember to sync changes to `applications` to 15 | %% the BUCK file in the application's base folder 16 | {applications, [ 17 | kernel, 18 | stdlib, 19 | inets, 20 | ssl 21 | ]}, 22 | {env, []}, 23 | {doc, "doc"}, 24 | {exclude_patterns, [ 25 | %% emacs temp files 26 | "~$", 27 | %% c object files 28 | "\\.o$", 29 | %% compiled NIF libraries 30 | "\\.dll$", 31 | "\\.dylib$", 32 | "\\.so$", 33 | %% make temp files 34 | "env\\.mk$", 35 | %% vim swap files 36 | "\\.swp$" 37 | ]}, 38 | {files, [ 39 | "c_src", 40 | "CHANGELOG*", 41 | "include", 42 | "lib", 43 | "LICENSE*", 44 | "mix.exs", 45 | "priv", 46 | "README*", 47 | "rebar.config", 48 | "src" 49 | ]}, 50 | {licenses, ["MIT"]}, 51 | {links, #{ 52 | "GitHub" => "https://github.com/WhatsApp/erldist_filter" 53 | }} 54 | ]}. 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/erldist_filter_app.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 10 Aug 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(erldist_filter_app). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(application). 22 | 23 | %% application callbacks 24 | -export([ 25 | start/2, 26 | stop/1 27 | ]). 28 | 29 | %%%============================================================================= 30 | %%% application callbacks 31 | %%%============================================================================= 32 | 33 | -spec start(StartType, StartArgs) -> {ok, Pid} | {ok, Pid, State} | {error, Reason} when 34 | StartType :: application:start_type(), 35 | StartArgs :: term(), 36 | Pid :: pid(), 37 | State :: term(), 38 | Reason :: term(). 39 | start(_StartType, _StartArgs) -> 40 | {ok, SupPid} = erldist_filter_sup:start_link(), 41 | {ok, SupPid}. 42 | 43 | -spec stop(State) -> Ignored when 44 | State :: term(), 45 | Ignored :: term(). 46 | stop(_State) -> 47 | ok. 48 | 49 | %%%----------------------------------------------------------------------------- 50 | %%% Internal functions 51 | %%%----------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_alias_send.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_alias_send). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_alias_send{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, Alias) -> T when 44 | FromPid :: vterm:pid_t(), Alias :: vterm:reference_t(), T :: t(). 45 | new(FromPid, Alias) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_reference_t(Alias) 47 | -> 48 | #vdist_dop_alias_send{from_pid = FromPid, alias = Alias}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_alias_send{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_alias_send{from_pid = FromPid, alias = Alias}) -> 56 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_ALIAS_SEND), FromPid, Alias]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_alias_send{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_alias_send_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_alias_send_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_alias_send_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, Alias, Token) -> T when 44 | FromPid :: vterm:pid_t(), Alias :: vterm:reference_t(), Token :: vterm:t(), T :: t(). 45 | new(FromPid, Alias, Token) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_reference_t(Alias) andalso ?is_vterm_t(Token) 47 | -> 48 | #vdist_dop_alias_send_tt{from_pid = FromPid, alias = Alias, token = Token}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_alias_send_tt{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_alias_send_tt{from_pid = FromPid, alias = Alias, token = Token}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_ALIAS_SEND_TT), FromPid, Alias, Token]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_alias_send_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_demonitor_p.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_demonitor_p). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_demonitor_p{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToProc, Ref) -> T when 44 | FromPid :: vterm:pid_t(), ToProc :: vterm:pid_t() | vterm:atom_t(), Ref :: vterm:reference_t(), T :: t(). 45 | new(FromPid, ToProc, Ref) when 46 | ?is_vterm_pid_t(FromPid) andalso (?is_vterm_pid_t(ToProc) orelse ?is_vterm_atom_t(ToProc)) andalso 47 | ?is_vterm_reference_t(Ref) 48 | -> 49 | #vdist_dop_demonitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}. 50 | 51 | -spec has_payload(T) -> boolean() when T :: t(). 52 | has_payload(#vdist_dop_demonitor_p{}) -> 53 | false. 54 | 55 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 56 | into_control_message_vterm(#vdist_dop_demonitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}) -> 57 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_DEMONITOR_P), FromPid, ToProc, Ref]). 58 | 59 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 60 | sequence_id(#vdist_dop_demonitor_p{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 61 | vterm_pid:sequence_id(FromPid). 62 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_exit). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_exit{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, Reason) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), Reason :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, Reason) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(Reason) -> 46 | #vdist_dop_exit{from_pid = FromPid, to_pid = ToPid, reason = Reason}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_exit{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_exit{from_pid = FromPid, to_pid = ToPid, reason = Reason}) -> 54 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_EXIT), FromPid, ToPid, Reason]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_exit{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit2.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_exit2). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_exit2{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, Reason) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), Reason :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, Reason) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(Reason) -> 46 | #vdist_dop_exit2{from_pid = FromPid, to_pid = ToPid, reason = Reason}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_exit2{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_exit2{from_pid = FromPid, to_pid = ToPid, reason = Reason}) -> 54 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_EXIT2), FromPid, ToPid, Reason]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_exit2{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit2_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_exit2_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/4, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_exit2_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, TraceToken, Reason) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), Reason :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, TraceToken, Reason) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) andalso ?is_vterm_t(Reason) 47 | -> 48 | #vdist_dop_exit2_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_exit2_tt{}) -> 52 | false. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_exit2_tt{ 56 | from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason 57 | }) -> 58 | vterm_small_tuple_ext:new(5, [vterm_small_integer_ext:new(?DOP_EXIT2_TT), FromPid, ToPid, TraceToken, Reason]). 59 | 60 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 61 | sequence_id(#vdist_dop_exit2_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 62 | vterm_pid:sequence_id(FromPid). 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_exit_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_exit_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/4, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_exit_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, TraceToken, Reason) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), Reason :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, TraceToken, Reason) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) andalso ?is_vterm_t(Reason) 47 | -> 48 | #vdist_dop_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_exit_tt{}) -> 52 | false. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_exit_tt{ 56 | from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken, reason = Reason 57 | }) -> 58 | vterm_small_tuple_ext:new(5, [vterm_small_integer_ext:new(?DOP_EXIT_TT), FromPid, ToPid, TraceToken, Reason]). 59 | 60 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 61 | sequence_id(#vdist_dop_exit_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 62 | vterm_pid:sequence_id(FromPid). 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_group_leader.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_group_leader). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_group_leader{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 46 | #vdist_dop_group_leader{from_pid = FromPid, to_pid = ToPid}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_group_leader{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_group_leader{from_pid = FromPid, to_pid = ToPid}) -> 54 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_GROUP_LEADER), FromPid, ToPid]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_group_leader{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_link.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_link). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_link{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 46 | #vdist_dop_link{from_pid = FromPid, to_pid = ToPid}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_link{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_link{from_pid = FromPid, to_pid = ToPid}) -> 54 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_LINK), FromPid, ToPid]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_link{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_monitor_p.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_monitor_p). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_monitor_p{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToProc, Ref) -> T when 44 | FromPid :: vterm:pid_t(), ToProc :: vterm:pid_t() | vterm:atom_t(), Ref :: vterm:reference_t(), T :: t(). 45 | new(FromPid, ToProc, Ref) when 46 | ?is_vterm_pid_t(FromPid) andalso (?is_vterm_pid_t(ToProc) orelse ?is_vterm_atom_t(ToProc)) andalso 47 | ?is_vterm_reference_t(Ref) 48 | -> 49 | #vdist_dop_monitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}. 50 | 51 | -spec has_payload(T) -> boolean() when T :: t(). 52 | has_payload(#vdist_dop_monitor_p{}) -> 53 | false. 54 | 55 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 56 | into_control_message_vterm(#vdist_dop_monitor_p{from_pid = FromPid, to_proc = ToProc, ref = Ref}) -> 57 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_MONITOR_P), FromPid, ToProc, Ref]). 58 | 59 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 60 | sequence_id(#vdist_dop_monitor_p{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 61 | vterm_pid:sequence_id(FromPid). 62 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_payload_exit). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_payload_exit{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 47 | -> 48 | #vdist_dop_payload_exit{from_pid = FromPid, to_pid = ToPid}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_payload_exit{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_payload_exit{from_pid = FromPid, to_pid = ToPid}) -> 56 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT), FromPid, ToPid]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_payload_exit{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit2.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_payload_exit2). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_payload_exit2{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 47 | -> 48 | #vdist_dop_payload_exit2{from_pid = FromPid, to_pid = ToPid}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_payload_exit2{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_payload_exit2{from_pid = FromPid, to_pid = ToPid}) -> 56 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT2), FromPid, ToPid]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_payload_exit2{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit2_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_payload_exit2_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_payload_exit2_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, TraceToken) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, TraceToken) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 47 | -> 48 | #vdist_dop_payload_exit2_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_payload_exit2_tt{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_payload_exit2_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT2_TT), FromPid, ToPid, TraceToken]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_payload_exit2_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_exit_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_payload_exit_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_payload_exit_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, TraceToken) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, TraceToken) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 47 | -> 48 | #vdist_dop_payload_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_payload_exit_tt{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_payload_exit_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_PAYLOAD_EXIT_TT), FromPid, ToPid, TraceToken]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_payload_exit_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_payload_monitor_p_exit.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_payload_monitor_p_exit). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_payload_monitor_p_exit{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromProc, ToPid, Ref) -> T when 44 | FromProc :: vterm:pid_t() | vterm:atom_t(), 45 | ToPid :: vterm:pid_t() | vterm:atom_t(), 46 | Ref :: vterm:reference_t(), 47 | T :: t(). 48 | new(FromProc, ToPid, Ref) when 49 | (?is_vterm_pid_t(FromProc) orelse ?is_vterm_atom_t(FromProc)) andalso ?is_vterm_pid_t(ToPid) andalso 50 | ?is_vterm_reference_t(Ref) 51 | -> 52 | #vdist_dop_payload_monitor_p_exit{from_proc = FromProc, to_pid = ToPid, ref = Ref}. 53 | 54 | -spec has_payload(T) -> boolean() when T :: t(). 55 | has_payload(#vdist_dop_payload_monitor_p_exit{}) -> 56 | true. 57 | 58 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 59 | into_control_message_vterm(#vdist_dop_payload_monitor_p_exit{from_proc = FromProc, to_pid = ToPid, ref = Ref}) -> 60 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_PAYLOAD_MONITOR_P_EXIT), FromProc, ToPid, Ref]). 61 | 62 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 63 | sequence_id(#vdist_dop_payload_monitor_p_exit{from_proc = FromProc}) when ?is_vterm_atom_t(FromProc) -> 64 | vterm_atom:sequence_id(FromProc); 65 | sequence_id(#vdist_dop_payload_monitor_p_exit{from_proc = FromProc}) when ?is_vterm_pid_t(FromProc) -> 66 | vterm_pid:sequence_id(FromProc). 67 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_reg_send.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_reg_send). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_reg_send{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, Unused, ToName) -> T when 44 | FromPid :: vterm:pid_t(), Unused :: vterm:t(), ToName :: vterm:atom_t(), T :: t(). 45 | new(FromPid, Unused, ToName) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_t(Unused) andalso ?is_vterm_atom_t(ToName) 47 | -> 48 | #vdist_dop_reg_send{from_pid = FromPid, unused = Unused, to_name = ToName}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_reg_send{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_reg_send{from_pid = FromPid, unused = Unused, to_name = ToName}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_REG_SEND), FromPid, Unused, ToName]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_reg_send{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_reg_send_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_reg_send_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/4, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_reg_send_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, Unused, ToName, TraceToken) -> T when 44 | FromPid :: vterm:pid_t(), Unused :: vterm:t(), ToName :: vterm:atom_t(), TraceToken :: vterm:t(), T :: t(). 45 | new(FromPid, Unused, ToName, TraceToken) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_t(Unused) andalso ?is_vterm_atom_t(ToName) andalso 47 | ?is_vterm_t(TraceToken) 48 | -> 49 | #vdist_dop_reg_send_tt{from_pid = FromPid, unused = Unused, to_name = ToName, trace_token = TraceToken}. 50 | 51 | -spec has_payload(T) -> boolean() when T :: t(). 52 | has_payload(#vdist_dop_reg_send_tt{}) -> 53 | true. 54 | 55 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 56 | into_control_message_vterm(#vdist_dop_reg_send_tt{ 57 | from_pid = FromPid, unused = Unused, to_name = ToName, trace_token = TraceToken 58 | }) -> 59 | vterm_small_tuple_ext:new(5, [vterm_small_integer_ext:new(?DOP_REG_SEND_TT), FromPid, Unused, ToName, TraceToken]). 60 | 61 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 62 | sequence_id(#vdist_dop_reg_send_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 63 | vterm_pid:sequence_id(FromPid). 64 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_send). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_send{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Unused, ToPid) -> T when 44 | Unused :: vterm:t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(Unused, ToPid) when 46 | ?is_vterm_t(Unused) andalso ?is_vterm_pid_t(ToPid) 47 | -> 48 | #vdist_dop_send{unused = Unused, to_pid = ToPid}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_send{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_send{unused = Unused, to_pid = ToPid}) -> 56 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_SEND), Unused, ToPid]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_send{}) -> 60 | 0. 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_sender.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_send_sender). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_send_sender{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) 47 | -> 48 | #vdist_dop_send_sender{from_pid = FromPid, to_pid = ToPid}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_send_sender{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_send_sender{from_pid = FromPid, to_pid = ToPid}) -> 56 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_SEND_SENDER), FromPid, ToPid]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_send_sender{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_sender_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_send_sender_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_send_sender_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid, TraceToken) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 45 | new(FromPid, ToPid, TraceToken) when 46 | ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 47 | -> 48 | #vdist_dop_send_sender_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_send_sender_tt{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_send_sender_tt{from_pid = FromPid, to_pid = ToPid, trace_token = TraceToken}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_SEND_SENDER_TT), FromPid, ToPid, TraceToken]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_send_sender_tt{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 60 | vterm_pid:sequence_id(FromPid). 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_send_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_send_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_send_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Unused, ToPid, TraceToken) -> T when 44 | Unused :: vterm:t(), ToPid :: vterm:pid_t(), TraceToken :: vterm:t(), T :: t(). 45 | new(Unused, ToPid, TraceToken) when 46 | ?is_vterm_t(Unused) andalso ?is_vterm_pid_t(ToPid) andalso ?is_vterm_t(TraceToken) 47 | -> 48 | #vdist_dop_send_tt{unused = Unused, to_pid = ToPid, trace_token = TraceToken}. 49 | 50 | -spec has_payload(T) -> boolean() when T :: t(). 51 | has_payload(#vdist_dop_send_tt{}) -> 52 | true. 53 | 54 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 55 | into_control_message_vterm(#vdist_dop_send_tt{unused = Unused, to_pid = ToPid, trace_token = TraceToken}) -> 56 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_SEND_TT), Unused, ToPid, TraceToken]). 57 | 58 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 59 | sequence_id(#vdist_dop_send_tt{}) -> 60 | 0. 61 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_spawn_reply.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_spawn_reply). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/4, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_spawn_reply{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(ReqId, To, Flags, Result) -> T when 44 | ReqId :: vterm:reference_t(), 45 | To :: vterm:pid_t(), 46 | Flags :: vterm:fixed_integer_t(), 47 | Result :: vterm:atom_t() | vterm:pid_t(), 48 | T :: t(). 49 | new(ReqId, To, Flags, Result) when 50 | ?is_vterm_reference_t(ReqId) andalso ?is_vterm_pid_t(To) andalso ?is_vterm_fixed_integer_t(Flags) andalso 51 | (?is_vterm_atom_t(Result) orelse ?is_vterm_pid_t(Result)) 52 | -> 53 | #vdist_dop_spawn_reply{req_id = ReqId, to = To, flags = Flags, result = Result}. 54 | 55 | -spec has_payload(T) -> boolean() when T :: t(). 56 | has_payload(#vdist_dop_spawn_reply{}) -> 57 | false. 58 | 59 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 60 | into_control_message_vterm(#vdist_dop_spawn_reply{ 61 | req_id = ReqId, to = To, flags = Flags, result = Result 62 | }) -> 63 | vterm_small_tuple_ext:new(5, [vterm_small_integer_ext:new(?DOP_SPAWN_REPLY), ReqId, To, Flags, Result]). 64 | 65 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 66 | sequence_id(#vdist_dop_spawn_reply{req_id = ReqId}) when ?is_vterm_reference_t(ReqId) -> 67 | vterm_reference:sequence_id(ReqId). 68 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_spawn_reply_tt.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_spawn_reply_tt). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/5, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_spawn_reply_tt{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(ReqId, To, Flags, Result, Token) -> T when 44 | ReqId :: vterm:reference_t(), 45 | To :: vterm:pid_t(), 46 | Flags :: vterm:fixed_integer_t(), 47 | Result :: vterm:atom_t() | vterm:pid_t(), 48 | Token :: vterm:t(), 49 | T :: t(). 50 | new(ReqId, To, Flags, Result, Token) when 51 | ?is_vterm_reference_t(ReqId) andalso ?is_vterm_pid_t(To) andalso ?is_vterm_fixed_integer_t(Flags) andalso 52 | (?is_vterm_atom_t(Result) orelse ?is_vterm_pid_t(Result)) andalso ?is_vterm_t(Token) 53 | -> 54 | #vdist_dop_spawn_reply_tt{req_id = ReqId, to = To, flags = Flags, result = Result, token = Token}. 55 | 56 | -spec has_payload(T) -> boolean() when T :: t(). 57 | has_payload(#vdist_dop_spawn_reply_tt{}) -> 58 | false. 59 | 60 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 61 | into_control_message_vterm(#vdist_dop_spawn_reply_tt{ 62 | req_id = ReqId, to = To, flags = Flags, result = Result, token = Token 63 | }) -> 64 | vterm_small_tuple_ext:new(6, [vterm_small_integer_ext:new(?DOP_SPAWN_REPLY_TT), ReqId, To, Flags, Result, Token]). 65 | 66 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 67 | sequence_id(#vdist_dop_spawn_reply_tt{req_id = ReqId}) when ?is_vterm_reference_t(ReqId) -> 68 | vterm_reference:sequence_id(ReqId). 69 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_unlink). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/2, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_unlink{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(FromPid, ToPid) -> T when 44 | FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(FromPid, ToPid) when ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 46 | #vdist_dop_unlink{from_pid = FromPid, to_pid = ToPid}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_unlink{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_unlink{from_pid = FromPid, to_pid = ToPid}) -> 54 | vterm_small_tuple_ext:new(3, [vterm_small_integer_ext:new(?DOP_UNLINK), FromPid, ToPid]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_unlink{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink_id.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_unlink_id). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_unlink_id{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Id, FromPid, ToPid) -> T when 44 | Id :: vterm:integer_t(), FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(Id, FromPid, ToPid) when ?is_vterm_integer_t(Id) andalso ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 46 | #vdist_dop_unlink_id{id = Id, from_pid = FromPid, to_pid = ToPid}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_unlink_id{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_unlink_id{id = Id, from_pid = FromPid, to_pid = ToPid}) -> 54 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_UNLINK_ID), Id, FromPid, ToPid]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_unlink_id{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_dop_unlink_id_ack.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_dop_unlink_id_ack). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_dist.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/3, 27 | has_payload/1, 28 | into_control_message_vterm/1, 29 | sequence_id/1 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vdist_dop_unlink_id_ack{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Id, FromPid, ToPid) -> T when 44 | Id :: vterm:integer_t(), FromPid :: vterm:pid_t(), ToPid :: vterm:pid_t(), T :: t(). 45 | new(Id, FromPid, ToPid) when ?is_vterm_integer_t(Id) andalso ?is_vterm_pid_t(FromPid) andalso ?is_vterm_pid_t(ToPid) -> 46 | #vdist_dop_unlink_id_ack{id = Id, from_pid = FromPid, to_pid = ToPid}. 47 | 48 | -spec has_payload(T) -> boolean() when T :: t(). 49 | has_payload(#vdist_dop_unlink_id_ack{}) -> 50 | false. 51 | 52 | -spec into_control_message_vterm(T) -> vterm:tuple_t() when T :: t(). 53 | into_control_message_vterm(#vdist_dop_unlink_id_ack{id = Id, from_pid = FromPid, to_pid = ToPid}) -> 54 | vterm_small_tuple_ext:new(4, [vterm_small_integer_ext:new(?DOP_UNLINK_ID_ACK), Id, FromPid, ToPid]). 55 | 56 | -spec sequence_id(T) -> vdist:sequence_id() when T :: t(). 57 | sequence_id(#vdist_dop_unlink_id_ack{from_pid = FromPid}) when ?is_vterm_pid_t(FromPid) -> 58 | vterm_pid:sequence_id(FromPid). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_fragment_cont.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_fragment_cont). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vdist_header_encode). 22 | 23 | -include("erldist_filter.hrl"). 24 | % -include("erldist_filter_erts_dist.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | encode_header/1 31 | ]). 32 | 33 | %% Types 34 | -type t() :: #vdist_fragment_cont{}. 35 | 36 | -export_type([ 37 | t/0 38 | ]). 39 | 40 | %%%============================================================================= 41 | %%% API functions 42 | %%%============================================================================= 43 | 44 | -spec new(SequenceId, FragmentId) -> T when 45 | SequenceId :: vdist:sequence_id(), FragmentId :: vdist:fragment_id(), T :: t(). 46 | new(SequenceId, FragmentId) when ?is_u64(SequenceId) andalso ?is_u64(FragmentId) -> 47 | #vdist_fragment_cont{sequence_id = SequenceId, fragment_id = FragmentId}. 48 | 49 | -spec encode_header(T) -> binary() when T :: t(). 50 | encode_header(#vdist_fragment_cont{sequence_id = SequenceId, fragment_id = FragmentId}) -> 51 | <>. 52 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_header_encode.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_header_encode). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | 23 | -callback encode_header(T :: vdist:header_t()) -> binary(). 24 | 25 | -export([ 26 | encode_header/1 27 | ]). 28 | 29 | %%%============================================================================= 30 | %%% API functions 31 | %%%============================================================================= 32 | 33 | -spec encode_header(T :: vdist:header_t()) -> binary(). 34 | encode_header(T = #vdist_fragment_cont{}) -> 35 | vdist_fragment_cont:encode_header(T); 36 | encode_header(T = #vdist_fragment_header{}) -> 37 | vdist_fragment_header:encode_header(T); 38 | encode_header(T = #vdist_normal_header{}) -> 39 | vdist_normal_header:encode_header(T); 40 | encode_header(T = #vdist_pass_through_header{}) -> 41 | vdist_pass_through_header:encode_header(T). 42 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_old_atom_cache_ref_entry.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_old_atom_cache_ref_entry). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | -include("erldist_filter_erts_external.hrl"). 23 | 24 | %% API 25 | -export([ 26 | new/1, 27 | encode_header_flag/1, 28 | encode_header_reference/2 29 | ]). 30 | 31 | %% Types 32 | -type t() :: #vdist_old_atom_cache_ref_entry{}. 33 | 34 | -export_type([ 35 | t/0 36 | ]). 37 | 38 | %%%============================================================================= 39 | %%% API functions 40 | %%%============================================================================= 41 | 42 | -spec new(AtomCacheIndex) -> T when AtomCacheIndex :: vdist:atom_cache_index(), T :: t(). 43 | new(AtomCacheIndex) when ?is_atom_cache_index(AtomCacheIndex) -> 44 | #vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}. 45 | 46 | -spec encode_header_flag(T) -> bitstring() when T :: t(). 47 | encode_header_flag(#vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}) -> 48 | SegmentIndex = ((AtomCacheIndex bsr 8) band 7), 49 | <<0:1, SegmentIndex:3>>. 50 | 51 | -spec encode_header_reference(T, LongAtoms) -> bitstring() when T :: t(), LongAtoms :: boolean(). 52 | encode_header_reference(#vdist_old_atom_cache_ref_entry{atom_cache_index = AtomCacheIndex}, _LongAtoms) -> 53 | InternalSegmentIndex = (AtomCacheIndex band 16#FF), 54 | <>. 55 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vdist/vdist_pass_through_header.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vdist_pass_through_header). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vdist_header_encode). 22 | 23 | -include("erldist_filter.hrl"). 24 | % -include("erldist_filter_erts_dist.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/0, 30 | encode_header/1 31 | ]). 32 | 33 | %% Types 34 | -type t() :: #vdist_pass_through_header{}. 35 | 36 | -export_type([ 37 | t/0 38 | ]). 39 | 40 | %%%============================================================================= 41 | %%% API functions 42 | %%%============================================================================= 43 | 44 | -spec new() -> T when T :: t(). 45 | new() -> 46 | #vdist_pass_through_header{}. 47 | 48 | -spec encode_header(T) -> binary() when T :: t(). 49 | encode_header(#vdist_pass_through_header{}) -> 50 | <>. 51 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom.erl: -------------------------------------------------------------------------------- 1 | %%%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_atom). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | 23 | -export([ 24 | sequence_id/1 25 | ]). 26 | 27 | -spec sequence_id(T) -> non_neg_integer() when T :: vterm:atom_t(). 28 | sequence_id(#vterm_atom_cache_ref_resolved{term = Term}) -> 29 | sequence_id(vterm:expand_atom(Term)); 30 | sequence_id(#vterm_atom_ext{len = Len, name = Name}) -> 31 | hash_u64(Len, Name); 32 | sequence_id(#vterm_atom_utf8_ext{len = Len, name = Name}) -> 33 | hash_u64(Len, Name); 34 | sequence_id(#vterm_small_atom_ext{len = Len, name = Name}) -> 35 | hash_u64(Len, Name); 36 | sequence_id(#vterm_small_atom_utf8_ext{len = Len, name = Name}) -> 37 | hash_u64(Len, Name). 38 | 39 | %% @private 40 | -spec hash_u64(Len, Name) -> Hash when Len :: non_neg_integer(), Name :: binary(), Hash :: non_neg_integer(). 41 | hash_u64(Len, Name) -> 42 | ((erlang:phash2({Name, Len}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Len, Name}, 16#FFFFFFFF)) band 43 | 16#FFFFFFFFFFFFFFFF. 44 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_cache_ref.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_atom_cache_ref). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | 23 | -include("erldist_filter.hrl"). 24 | -include("erldist_filter_erts_external.hrl"). 25 | 26 | %% API 27 | -export([ 28 | new/1, 29 | internal_vterm_to_binary/2 30 | ]). 31 | 32 | %% Types 33 | -type t() :: #vterm_atom_cache_ref{}. 34 | 35 | -export_type([ 36 | t/0 37 | ]). 38 | 39 | %%%============================================================================= 40 | %%% API functions 41 | %%%============================================================================= 42 | 43 | -spec new(Index) -> T when Index :: vterm:u8(), T :: t(). 44 | new(Index) when ?is_u8(Index) -> 45 | #vterm_atom_cache_ref{index = Index}. 46 | 47 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 48 | internal_vterm_to_binary(#vterm_atom_cache_ref{index = Index}, #{allow_atom_cache_refs := true}) -> 49 | <>. 50 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_cache_ref_resolved.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_atom_cache_ref_resolved). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_atom_cache_ref_resolved{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Index, Term) -> T when Index :: vterm:u8(), Term :: atom(), T :: t(). 46 | new(Index, Term) when ?is_u8(Index) andalso is_atom(Term) -> 47 | #vterm_atom_cache_ref_resolved{index = Index, term = Term}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_atom_cache_ref_resolved{index = Index}, #{allow_atom_cache_refs := true}) -> 51 | <>; 52 | internal_vterm_to_binary(#vterm_atom_cache_ref_resolved{term = Term}, _Opts) when is_atom(Term) -> 53 | vterm_encode:internal_term_to_binary(Term). 54 | 55 | -spec simplify(t()) -> atom(). 56 | simplify(#vterm_atom_cache_ref_resolved{term = Term}) when is_atom(Term) -> 57 | Term. 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_atom_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_atom_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Name) -> T when Len :: vterm:u16(), Name :: binary(), T :: t(). 46 | new(Len, Name) when ?is_u16(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 47 | #vterm_atom_ext{len = Len, name = Name}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_atom_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 51 | <>. 52 | 53 | -spec simplify(t()) -> atom(). 54 | simplify(#vterm_atom_ext{name = Name}) -> 55 | erlang:binary_to_atom(Name, latin1). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_atom_utf8_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_atom_utf8_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_atom_utf8_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Name) -> T when Len :: vterm:u16(), Name :: binary(), T :: t(). 46 | new(Len, Name) when ?is_u16(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 47 | #vterm_atom_utf8_ext{len = Len, name = Name}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_atom_utf8_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 51 | <>. 52 | 53 | -spec simplify(T) -> A when T :: t(), A :: atom(). 54 | simplify(#vterm_atom_utf8_ext{name = Name}) -> 55 | erlang:binary_to_atom(Name, utf8). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_binary_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_binary_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_binary_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Data) -> T when Len :: vterm:u32(), Data :: binary(), T :: t(). 46 | new(Len, Data) when ?is_u32(Len) andalso is_binary(Data) andalso Len =:= byte_size(Data) -> 47 | #vterm_binary_ext{len = Len, data = Data}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_binary_ext{len = Len, data = Data}, _Opts) when Len =:= byte_size(Data) -> 51 | <>. 52 | 53 | -spec simplify(T) -> Data when T :: t(), Data :: binary(). 54 | simplify(#vterm_binary_ext{data = Data}) -> 55 | Data. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_bit_binary_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_bit_binary_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_bit_binary_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Bits, Data) -> T when Len :: vterm:u32(), Bits :: 1..8, Data :: binary(), T :: t(). 46 | new(Len, Bits, Data) when 47 | ?is_u32(Len) andalso (is_integer(Bits) andalso Bits >= 1 andalso Bits =< 8) andalso is_binary(Data) andalso 48 | Len =:= byte_size(Data) 49 | -> 50 | #vterm_bit_binary_ext{len = Len, bits = Bits, data = Data}. 51 | 52 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 53 | internal_vterm_to_binary(#vterm_bit_binary_ext{len = Len, bits = Bits, data = Data}, _Opts) when 54 | Len =:= byte_size(Data) 55 | -> 56 | <>. 57 | 58 | -spec simplify(T) -> Data when T :: t(), Data :: bitstring(). 59 | simplify(#vterm_bit_binary_ext{bits = Bits, data = Data}) -> 60 | BitSize = bit_size(Data) - (8 - Bits), 61 | <> = Data, 62 | BitBinary. 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_export_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_export_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_export_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Module, Function, Arity) -> T when 46 | Module :: vterm:atom_t(), Function :: vterm:atom_t(), Arity :: vterm:small_integer_t(), T :: t(). 47 | new(Module, Function, Arity) when 48 | ?is_vterm_atom_t(Module) andalso ?is_vterm_atom_t(Function) andalso ?is_vterm_small_integer_t(Arity) 49 | -> 50 | #vterm_export_ext{module = Module, function = Function, arity = Arity}. 51 | 52 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 53 | internal_vterm_to_binary(#vterm_export_ext{module = Module0, function = Function0, arity = Arity0}, Opts) -> 54 | Module = vterm_encode:internal_vterm_to_binary(Module0, Opts), 55 | Function = vterm_encode:internal_vterm_to_binary(Function0, Opts), 56 | Arity = vterm_encode:internal_vterm_to_binary(Arity0, Opts), 57 | <>. 58 | 59 | -spec simplify(t()) -> fun(). 60 | simplify(#vterm_export_ext{module = Module0, function = Function0, arity = Arity0}) -> 61 | Module = vterm:simplify(Module0), 62 | Function = vterm:simplify(Function0), 63 | Arity = vterm:simplify(Arity0), 64 | fun Module:Function/Arity. 65 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_float_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_float_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/1, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_float_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(FloatString) -> T when FloatString :: <<_:248>>, T :: t(). 46 | new(FloatString) when is_binary(FloatString) andalso byte_size(FloatString) =:= 31 -> 47 | #vterm_float_ext{float_string = FloatString}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_float_ext{float_string = FloatString}, _Opts) when byte_size(FloatString) =:= 31 -> 51 | <>. 52 | 53 | -spec simplify(T) -> term() when T :: t(). 54 | simplify(VTerm = #vterm_float_ext{}) -> 55 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 56 | Term. 57 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_integer_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_integer_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/1, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_integer_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Value) -> T when Value :: vterm:i32(), T :: t(). 46 | new(Value) when ?is_i32(Value) -> 47 | #vterm_integer_ext{value = Value}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_integer_ext{value = Value}, _Opts) -> 51 | <>. 52 | 53 | -spec simplify(T) -> Value when T :: t(), Value :: vterm:i32(). 54 | simplify(#vterm_integer_ext{value = Value}) -> 55 | Value. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_large_big_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_large_big_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_large_big_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(N, Sign, D) -> T when N :: vterm:u32(), Sign :: 0..1, D :: binary(), T :: t(). 46 | new(N, Sign, D) when ?is_u32(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) -> 47 | #vterm_large_big_ext{n = N, sign = Sign, d = D}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_large_big_ext{n = N, sign = Sign, d = D}, _Opts) when 51 | ?is_u32(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) 52 | -> 53 | <>. 54 | 55 | -spec simplify(T) -> term() when T :: t(). 56 | simplify(VTerm = #vterm_large_big_ext{}) -> 57 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 58 | Term. 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_large_tuple_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_large_tuple_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_large_tuple_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Arity, Elements) -> T when Arity :: vterm:u32(), Elements :: list(vterm:t()), T :: t(). 46 | new(Arity, Elements) when ?is_u32(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) -> 47 | #vterm_large_tuple_ext{arity = Arity, elements = Elements}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_large_tuple_ext{arity = Arity, elements = Elements}, Opts) when 51 | ?is_u32(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) 52 | -> 53 | EncodedElements = vterm_encode:internal_vterm_elements_to_binary(Elements, Opts), 54 | <>. 55 | 56 | -spec simplify(T) -> Data when T :: t(), Data :: tuple(). 57 | simplify(#vterm_large_tuple_ext{elements = Elements}) -> 58 | erlang:list_to_tuple([vterm:simplify(Element) || Element <- Elements]). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_lazy_term.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_lazy_term). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | 26 | %% API 27 | -export([ 28 | new/1, 29 | internal_vterm_to_binary/2, 30 | simplify/1 31 | ]). 32 | 33 | %% Types 34 | -type t() :: #vterm_lazy_term{}. 35 | 36 | -export_type([ 37 | t/0 38 | ]). 39 | 40 | %%%============================================================================= 41 | %%% API functions 42 | %%%============================================================================= 43 | 44 | -spec new(Slice) -> T when Slice :: binary(), T :: t(). 45 | new(Slice) -> 46 | #vterm_lazy_term{slice = Slice}. 47 | 48 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 49 | internal_vterm_to_binary(#vterm_lazy_term{slice = Slice}, Opts) -> 50 | {ok, VTerm, <<>>} = vterm_decode:internal_binary_to_vterm(Slice), 51 | Slice = vterm_encode:internal_vterm_to_binary(VTerm, Opts), 52 | Slice. 53 | 54 | -spec simplify(T) -> term() when T :: t(). 55 | simplify(#vterm_lazy_term{slice = Slice}) -> 56 | {ok, VTerm, <<>>} = vterm_decode:internal_binary_to_vterm(Slice), 57 | vterm:simplify(VTerm). 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_map_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_map_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_map_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Arity, Pairs) -> T when Arity :: vterm:u32(), Pairs :: list({vterm:t(), vterm:t()}), T :: t(). 46 | new(Arity, Pairs) when ?is_u32(Arity) andalso is_list(Pairs) andalso Arity =:= length(Pairs) -> 47 | #vterm_map_ext{arity = Arity, pairs = Pairs}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_map_ext{arity = Arity, pairs = Pairs}, Opts) when 51 | ?is_u32(Arity) andalso is_list(Pairs) andalso Arity =:= length(Pairs) 52 | -> 53 | % EncodedPairs = vterm_encode:internal_vterm_pairs_to_binary(Pairs, Opts), 54 | EncodedPairs = erlang:iolist_to_binary([ 55 | [vterm_encode:internal_vterm_to_binary(K, Opts), vterm_encode:internal_vterm_to_binary(V, Opts)] 56 | || {K, V} <- Pairs 57 | ]), 58 | <>. 59 | 60 | -spec simplify(T) -> Data when T :: t(), Data :: map(). 61 | simplify(#vterm_map_ext{pairs = Pairs}) -> 62 | SimplePairs = [{vterm:simplify(K), vterm:simplify(V)} || {K, V} <- Pairs], 63 | maps:from_list(SimplePairs). 64 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_new_float_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_new_float_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/1, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_new_float_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(IEEEFloat) -> T when IEEEFloat :: <<_:64>>, T :: t(). 46 | new(IEEEFloat) when is_binary(IEEEFloat) andalso bit_size(IEEEFloat) =:= 64 -> 47 | #vterm_new_float_ext{ieee_float = IEEEFloat}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_new_float_ext{ieee_float = IEEEFloat}, _Opts) when bit_size(IEEEFloat) =:= 64 -> 51 | <>. 52 | 53 | -spec simplify(t()) -> term(). 54 | simplify(VTerm = #vterm_new_float_ext{}) -> 55 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 56 | Term. 57 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_new_pid_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_new_pid_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/4, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_new_pid_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Node, Id, Serial, Creation) -> T when 46 | Node :: vterm:atom_t(), Id :: vterm:u32(), Serial :: vterm:u32(), Creation :: vterm:u32(), T :: t(). 47 | new(Node, Id, Serial, Creation) when 48 | ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_u32(Serial) andalso ?is_u32(Creation) 49 | -> 50 | #vterm_new_pid_ext{node = Node, id = Id, serial = Serial, creation = Creation}. 51 | 52 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 53 | internal_vterm_to_binary(#vterm_new_pid_ext{node = Node0, id = Id, serial = Serial, creation = Creation}, Opts) when 54 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_u32(Serial) andalso ?is_u32(Creation) 55 | -> 56 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 57 | <>. 58 | 59 | -spec simplify(t()) -> term(). 60 | simplify(VTerm = #vterm_new_pid_ext{}) -> 61 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 62 | Term. 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_new_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_new_port_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_new_port_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: vterm:u32(), T :: t(). 46 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_u32(Creation) -> 47 | #vterm_new_port_ext{node = Node, id = Id, creation = Creation}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_new_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 51 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_u32(Creation) 52 | -> 53 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 54 | <>. 55 | 56 | -spec simplify(t()) -> term(). 57 | simplify(VTerm = #vterm_new_port_ext{}) -> 58 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 59 | Term. 60 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_nif_term.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_nif_term). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/1, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_nif_term{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Term) -> T when Term :: vterm:t() | term(), T :: t(). 46 | new(Term) -> 47 | #vterm_nif_term{term = Term}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_nif_term{term = VTerm}, _Opts) when ?is_vterm_the_non_value_t(VTerm) -> 51 | erlang:error(notsup); 52 | internal_vterm_to_binary(#vterm_nif_term{term = VTerm}, Opts) when ?is_vterm_t(VTerm) -> 53 | vterm_encode:internal_vterm_to_binary(VTerm, Opts); 54 | internal_vterm_to_binary(#vterm_nif_term{term = Term}, _Opts) -> 55 | vterm_encode:internal_term_to_binary(Term). 56 | 57 | -spec simplify(T) -> term() when T :: t(). 58 | simplify(#vterm_nif_term{term = VTerm}) when ?is_vterm_the_non_value_t(VTerm) -> 59 | erlang:error(notsup); 60 | simplify(#vterm_nif_term{term = VTerm}) when ?is_vterm_t(VTerm) -> 61 | vterm:simplify(VTerm); 62 | simplify(#vterm_nif_term{term = Term}) -> 63 | Term. 64 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_nil_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_nil_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/0, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_nil_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new() -> T when T :: t(). 46 | new() -> 47 | #vterm_nil_ext{}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_nil_ext{}, _Opts) -> 51 | <>. 52 | 53 | -spec simplify(T) -> [] when T :: t(). 54 | simplify(#vterm_nil_ext{}) -> 55 | []. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_pid.erl: -------------------------------------------------------------------------------- 1 | %%%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_pid). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | 23 | -export([ 24 | sequence_id/1 25 | ]). 26 | 27 | -spec sequence_id(vterm:pid_t()) -> non_neg_integer(). 28 | sequence_id(#vterm_new_pid_ext{id = Id, serial = Serial, creation = Creation}) -> 29 | hash_u64(Id, Serial, Creation); 30 | sequence_id(#vterm_pid_ext{id = Id, serial = Serial, creation = Creation}) -> 31 | hash_u64(Id, Serial, Creation). 32 | 33 | %% @private 34 | -spec hash_u64(non_neg_integer(), non_neg_integer(), non_neg_integer()) -> non_neg_integer(). 35 | hash_u64(Id, Serial, Creation) -> 36 | ((erlang:phash2({Creation, Serial, Id}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Id, Serial, Creation}, 16#FFFFFFFF)) band 37 | 16#FFFFFFFFFFFFFFFF. 38 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_pid_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_pid_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/4, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_pid_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %% Macros 42 | -define(is_creation(X), (is_integer(X) andalso (X) >= 0 andalso (X) =< 3)). 43 | 44 | %%%============================================================================= 45 | %%% API functions 46 | %%%============================================================================= 47 | 48 | -spec new(Node, Id, Serial, Creation) -> T when 49 | Node :: vterm:atom_t(), Id :: vterm:u32(), Serial :: vterm:u32(), Creation :: 0..3, T :: t(). 50 | new(Node, Id, Serial, Creation) when 51 | ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_u32(Serial) andalso ?is_creation(Creation) 52 | -> 53 | #vterm_pid_ext{node = Node, id = Id, serial = Serial, creation = Creation}. 54 | 55 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 56 | internal_vterm_to_binary(#vterm_pid_ext{node = Node0, id = Id, serial = Serial, creation = Creation}, Opts) when 57 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_u32(Serial) andalso ?is_creation(Creation) 58 | -> 59 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 60 | <>. 61 | 62 | -spec simplify(t()) -> term(). 63 | simplify(VTerm = #vterm_pid_ext{}) -> 64 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 65 | Term. 66 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_port_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_port_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %% Macros 42 | -define(is_creation(X), (is_integer(X) andalso (X) >= 0 andalso (X) =< 3)). 43 | 44 | %%%============================================================================= 45 | %%% API functions 46 | %%%============================================================================= 47 | 48 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: 0..3, T :: t(). 49 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_creation(Creation) -> 50 | #vterm_port_ext{node = Node, id = Id, creation = Creation}. 51 | 52 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 53 | internal_vterm_to_binary(#vterm_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 54 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_creation(Creation) 55 | -> 56 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 57 | <>. 58 | 59 | -spec simplify(t()) -> term(). 60 | simplify(VTerm = #vterm_port_ext{}) -> 61 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 62 | Term. 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_reference.erl: -------------------------------------------------------------------------------- 1 | %%%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_reference). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | 23 | -export([ 24 | sequence_id/1 25 | ]). 26 | 27 | -spec sequence_id(vterm:reference_t()) -> non_neg_integer(). 28 | sequence_id(#vterm_newer_reference_ext{creation = Creation, ids = Ids}) -> 29 | hash_u64(Ids, Creation); 30 | sequence_id(#vterm_new_reference_ext{creation = Creation, ids = Ids}) -> 31 | hash_u64(Ids, Creation); 32 | sequence_id(#vterm_reference_ext{id = Id, creation = Creation}) -> 33 | hash_u64([Id], Creation). 34 | 35 | %% @private 36 | -spec hash_u64(Ids, Creation) -> Hash when 37 | Ids :: [non_neg_integer()], Creation :: non_neg_integer(), Hash :: non_neg_integer(). 38 | hash_u64(Ids, Creation) -> 39 | ((erlang:phash2({Creation, Ids}, 16#FFFFFFFF) bsl 32) bor erlang:phash2({Ids, Creation}, 16#FFFFFFFF)) band 40 | 16#FFFFFFFFFFFFFFFF. 41 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_reference_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_reference_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_reference_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %% Macros 42 | -define(is_creation(X), (is_integer(X) andalso (X) >= 0 andalso (X) =< 3)). 43 | 44 | %%%============================================================================= 45 | %%% API functions 46 | %%%============================================================================= 47 | 48 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u32(), Creation :: 0..3, T :: t(). 49 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u32(Id) andalso ?is_creation(Creation) -> 50 | #vterm_reference_ext{node = Node, id = Id, creation = Creation}. 51 | 52 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 53 | internal_vterm_to_binary(#vterm_reference_ext{node = Node0, id = Id, creation = Creation}, Opts) when 54 | ?is_vterm_atom_t(Node0) andalso ?is_u32(Id) andalso ?is_creation(Creation) 55 | -> 56 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 57 | <>. 58 | 59 | -spec simplify(t()) -> term(). 60 | simplify(VTerm = #vterm_reference_ext{}) -> 61 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 62 | Term. 63 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_simplify.erl: -------------------------------------------------------------------------------- 1 | %%%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_simplify). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | %% Callbacks 22 | -callback simplify(T :: vterm:t()) -> term(). 23 | 24 | %%%============================================================================= 25 | %%% API functions 26 | %%%============================================================================= 27 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_atom_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_small_atom_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_small_atom_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Name) -> T when Len :: vterm:u8(), Name :: binary(), T :: t(). 46 | new(Len, Name) when ?is_u8(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 47 | #vterm_small_atom_ext{len = Len, name = Name}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_small_atom_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 51 | <>. 52 | 53 | -spec simplify(T) -> A when T :: t(), A :: atom(). 54 | simplify(#vterm_small_atom_ext{name = Name}) -> 55 | erlang:binary_to_atom(Name, latin1). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_atom_utf8_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_small_atom_utf8_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_small_atom_utf8_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Name) -> T when Len :: vterm:u8(), Name :: binary(), T :: t(). 46 | new(Len, Name) when ?is_u8(Len) andalso is_binary(Name) andalso Len =:= byte_size(Name) -> 47 | #vterm_small_atom_utf8_ext{len = Len, name = Name}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_small_atom_utf8_ext{len = Len, name = Name}, _Opts) when Len =:= byte_size(Name) -> 51 | <>. 52 | 53 | -spec simplify(t()) -> atom(). 54 | simplify(#vterm_small_atom_utf8_ext{name = Name}) -> 55 | erlang:binary_to_atom(Name, utf8). 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_big_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_small_big_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_small_big_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(N, Sign, D) -> T when N :: vterm:u8(), Sign :: 0..1, D :: binary(), T :: t(). 46 | new(N, Sign, D) when ?is_u8(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) -> 47 | #vterm_small_big_ext{n = N, sign = Sign, d = D}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_small_big_ext{n = N, sign = Sign, d = D}, _Opts) when 51 | ?is_u8(N) andalso (Sign =:= 0 orelse Sign =:= 1) andalso N =:= byte_size(D) 52 | -> 53 | <>. 54 | 55 | -spec simplify(t()) -> term(). 56 | simplify(VTerm = #vterm_small_big_ext{}) -> 57 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 58 | Term. 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_integer_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_small_integer_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/1, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_small_integer_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Value) -> T when Value :: vterm:u8(), T :: t(). 46 | new(Value) when ?is_u8(Value) -> 47 | #vterm_small_integer_ext{value = Value}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_small_integer_ext{value = Value}, _Opts) -> 51 | <>. 52 | 53 | -spec simplify(T) -> Value when T :: t(), Value :: vterm:u8(). 54 | simplify(#vterm_small_integer_ext{value = Value}) -> 55 | Value. 56 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_small_tuple_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_small_tuple_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_small_tuple_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Arity, Elements) -> T when Arity :: vterm:u8(), Elements :: list(vterm:t()), T :: t(). 46 | new(Arity, Elements) when ?is_u8(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) -> 47 | #vterm_small_tuple_ext{arity = Arity, elements = Elements}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_small_tuple_ext{arity = Arity, elements = Elements}, Opts) when 51 | ?is_u8(Arity) andalso is_list(Elements) andalso Arity =:= length(Elements) 52 | -> 53 | EncodedElements = vterm_encode:internal_vterm_elements_to_binary(Elements, Opts), 54 | <>. 55 | 56 | -spec simplify(t()) -> tuple(). 57 | simplify(#vterm_small_tuple_ext{elements = Elements}) -> 58 | erlang:list_to_tuple([vterm:simplify(Element) || Element <- Elements]). 59 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_string_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_string_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/2, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_string_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Len, Characters) -> T when Len :: vterm:u16(), Characters :: binary(), T :: t(). 46 | new(Len, Characters) when ?is_u16(Len) andalso is_binary(Characters) andalso Len =:= byte_size(Characters) -> 47 | #vterm_string_ext{len = Len, characters = Characters}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_string_ext{len = Len, characters = Characters}, _Opts) when 51 | Len =:= byte_size(Characters) 52 | -> 53 | <>. 54 | 55 | -spec simplify(t()) -> string(). 56 | simplify(#vterm_string_ext{characters = Characters}) -> 57 | erlang:binary_to_list(Characters). 58 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_the_non_value.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_the_non_value). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include("erldist_filter.hrl"). 22 | 23 | %% API 24 | -export([ 25 | new/0 26 | ]). 27 | 28 | %% Types 29 | -type t() :: #vterm_the_non_value{}. 30 | 31 | -export_type([ 32 | t/0 33 | ]). 34 | 35 | %%%============================================================================= 36 | %%% API functions 37 | %%%============================================================================= 38 | 39 | -spec new() -> T when T :: t(). 40 | new() -> 41 | #vterm_the_non_value{}. 42 | -------------------------------------------------------------------------------- /apps/erldist_filter/src/vterm/vterm_v4_port_ext.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Mar 2023 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(vterm_v4_port_ext). 17 | -compile(warn_missing_spec_all). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -behaviour(vterm_encode). 22 | -behaviour(vterm_simplify). 23 | 24 | -include("erldist_filter.hrl"). 25 | -include("erldist_filter_erts_external.hrl"). 26 | 27 | %% API 28 | -export([ 29 | new/3, 30 | internal_vterm_to_binary/2, 31 | simplify/1 32 | ]). 33 | 34 | %% Types 35 | -type t() :: #vterm_v4_port_ext{}. 36 | 37 | -export_type([ 38 | t/0 39 | ]). 40 | 41 | %%%============================================================================= 42 | %%% API functions 43 | %%%============================================================================= 44 | 45 | -spec new(Node, Id, Creation) -> T when Node :: vterm:atom_t(), Id :: vterm:u64(), Creation :: vterm:u32(), T :: t(). 46 | new(Node, Id, Creation) when ?is_vterm_atom_t(Node) andalso ?is_u64(Id) andalso ?is_u32(Creation) -> 47 | #vterm_v4_port_ext{node = Node, id = Id, creation = Creation}. 48 | 49 | -spec internal_vterm_to_binary(T, Opts) -> binary() when T :: t(), Opts :: term(). 50 | internal_vterm_to_binary(#vterm_v4_port_ext{node = Node0, id = Id, creation = Creation}, Opts) when 51 | ?is_vterm_atom_t(Node0) andalso ?is_u64(Id) andalso ?is_u32(Creation) 52 | -> 53 | Node = vterm_encode:internal_vterm_to_binary(Node0, Opts), 54 | <>. 55 | 56 | -spec simplify(t()) -> term(). 57 | simplify(VTerm = #vterm_v4_port_ext{}) -> 58 | {ok, Term, <<>>} = vterm_decode:external_binary_to_term(vterm_encode:external_vterm_to_binary(VTerm, #{})), 59 | Term. 60 | -------------------------------------------------------------------------------- /apps/erldist_filter/test/erldist_filter_noop_SUITE.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc A test suite designed to load the `erldist_filter_nif' and do nothing 11 | %%% else. 12 | %%% 13 | %%% @end 14 | %%% Created : 16 Dec 2022 by Andrew Bennett 15 | %%%----------------------------------------------------------------------------- 16 | %%% % @format 17 | -module(erldist_filter_noop_SUITE). 18 | -author("potatosaladx@meta.com"). 19 | -oncall("whatsapp_clr"). 20 | 21 | -include_lib("common_test/include/ct.hrl"). 22 | -include_lib("stdlib/include/assert.hrl"). 23 | 24 | %% ct callbacks 25 | -export([ 26 | all/0, 27 | groups/0, 28 | init_per_suite/1, 29 | end_per_suite/1, 30 | init_per_group/2, 31 | end_per_group/2, 32 | init_per_testcase/2, 33 | end_per_testcase/2 34 | ]). 35 | 36 | %% Test Cases 37 | -export([ 38 | test_that_the_nif_loads/0, 39 | test_that_the_nif_loads/1 40 | ]). 41 | 42 | %%%============================================================================= 43 | %%% ct callbacks 44 | %%%============================================================================= 45 | 46 | all() -> 47 | [ 48 | {group, noop} 49 | ]. 50 | 51 | groups() -> 52 | [ 53 | {noop, [parallel], [ 54 | test_that_the_nif_loads 55 | ]} 56 | ]. 57 | 58 | init_per_suite(Config) -> 59 | Config. 60 | 61 | end_per_suite(_Config) -> 62 | ok. 63 | 64 | init_per_group(_Group, Config) -> 65 | Config. 66 | 67 | end_per_group(_Group, _Config) -> 68 | ok. 69 | 70 | init_per_testcase(_TestCase, Config) -> 71 | Config. 72 | 73 | end_per_testcase(_TestCase, _Config) -> 74 | ok. 75 | 76 | %%%============================================================================= 77 | %%% Test Cases 78 | %%%============================================================================= 79 | 80 | test_that_the_nif_loads() -> 81 | [ 82 | {doc, "Loads the `erldist_filter_nif' and verifies that `distribution_flags/0' returns a map."}, 83 | {timetrap, {seconds, 60}} 84 | ]. 85 | 86 | test_that_the_nif_loads(_Config) -> 87 | ?assert(is_map(erldist_filter_nif:distribution_flags())). 88 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, [ 10 | erldist_filter, 11 | {proper, {git, "https://github.com/proper-testing/proper.git", {branch, "master"}}} 12 | ]}. 13 | 14 | {shell, 15 | % {config, "config/sys.config"}, 16 | [{apps, [erldist_filter, erldist_filter_test]}]}. 17 | 18 | {project_plugins, [{rebar3_proper, "0.12.1"}]}. 19 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/erldist_filter_test.app.src: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% % @format 8 | {application, erldist_filter_test, [ 9 | {description, "erldist_filter_test: test modules for Erlang distribution filtering"}, 10 | {vsn, "1.1.0"}, 11 | {modules, []}, 12 | {registered, []}, 13 | %% NOTE: Remember to sync changes to `applications` to 14 | %% the BUCK file in the application's base folder 15 | {applications, [ 16 | kernel, 17 | stdlib, 18 | common_test, 19 | proper, 20 | erldist_filter 21 | ]}, 22 | {env, []} 23 | ]}. 24 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/property_test/erldist_filter_nif_spbt_prop.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 27 Sep 2022 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(erldist_filter_nif_spbt_prop). 17 | -author("potatosaladx@meta.com"). 18 | -oncall("whatsapp_clr"). 19 | -compile(warn_missing_spec_all). 20 | 21 | -include_lib("proper/include/proper.hrl"). 22 | 23 | %% Properties 24 | -export([ 25 | prop_serial_statem/1, 26 | prop_parallel_statem/1 27 | ]). 28 | 29 | %% Macros 30 | -define(STATEM, erldist_filter_nif_spbt_statem). 31 | 32 | %%%============================================================================= 33 | %%% Properties 34 | %%%============================================================================= 35 | 36 | -spec prop_serial_statem(ct_suite:ct_config()) -> proper:test(). 37 | prop_serial_statem(Config) -> 38 | ?FORALL( 39 | Commands, 40 | commands(?STATEM), 41 | begin 42 | RunResult = {_History, _State, _Result} = run_commands(?STATEM, Commands), 43 | ct_property_test:present_result(?MODULE, Commands, RunResult, Config) 44 | end 45 | ). 46 | 47 | -spec prop_parallel_statem(ct_suite:ct_config()) -> proper:test(). 48 | prop_parallel_statem(Config) -> 49 | ?FORALL( 50 | Commands, 51 | parallel_commands(?STATEM), 52 | begin 53 | RunResult = {_History, _State, _Result} = run_parallel_commands(?STATEM, Commands), 54 | ct_property_test:present_result(?MODULE, Commands, RunResult, Config) 55 | end 56 | ). 57 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/src/property_test/erldist_filter_peer_spbt_prop.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 22 Sep 2022 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(erldist_filter_peer_spbt_prop). 17 | -author("potatosaladx@meta.com"). 18 | -oncall("whatsapp_clr"). 19 | -compile(warn_missing_spec_all). 20 | 21 | -include_lib("proper/include/proper.hrl"). 22 | 23 | %% Properties 24 | -export([ 25 | prop_serial_statem/1, 26 | prop_parallel_statem/1 27 | ]). 28 | 29 | %% Macros 30 | -define(MODEL, erldist_filter_peer_spbt_model). 31 | -define(STATEM, erldist_filter_peer_spbt_statem). 32 | 33 | %%%============================================================================= 34 | %%% Properties 35 | %%%============================================================================= 36 | 37 | -spec prop_serial_statem(ct_suite:ct_config()) -> proper:test(). 38 | prop_serial_statem(Config) -> 39 | UPeer = test_server:lookup_config(upeer, Config), 40 | VPeer = test_server:lookup_config(vpeer, Config), 41 | ?FORALL( 42 | Commands, 43 | commands(?STATEM, ?MODEL:initial_state(#{upeer => UPeer, vpeer => VPeer})), 44 | begin 45 | RunResult = {_History, _State, _Result} = run_commands(?STATEM, Commands), 46 | ct_property_test:present_result(?MODULE, Commands, RunResult, Config) 47 | end 48 | ). 49 | 50 | -spec prop_parallel_statem(ct_suite:ct_config()) -> proper:test(). 51 | prop_parallel_statem(Config) -> 52 | UPeer = test_server:lookup_config(upeer, Config), 53 | VPeer = test_server:lookup_config(vpeer, Config), 54 | ?FORALL( 55 | Commands, 56 | parallel_commands(?STATEM, ?MODEL:initial_state(#{upeer => UPeer, vpeer => VPeer})), 57 | begin 58 | RunResult = {_History, _State, _Result} = run_parallel_commands(?STATEM, Commands), 59 | ct_property_test:present_result(?MODULE, Commands, RunResult, Config) 60 | end 61 | ). 62 | -------------------------------------------------------------------------------- /apps/erldist_filter_test/test/property_test/erldist_filter_test_dummy_prop.erl: -------------------------------------------------------------------------------- 1 | %%%----------------------------------------------------------------------------- 2 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 3 | %%% Copyright (c) WhatsApp LLC 4 | %%% 5 | %%% This source code is licensed under the MIT license found in the 6 | %%% LICENSE.md file in the root directory of this source tree. 7 | %%% 8 | %%% @author Andrew Bennett 9 | %%% @copyright (c) Meta Platforms, Inc. and affiliates. 10 | %%% @doc 11 | %%% 12 | %%% @end 13 | %%% Created : 16 Dec 2022 by Andrew Bennett 14 | %%%----------------------------------------------------------------------------- 15 | %%% % @format 16 | -module(erldist_filter_test_dummy_prop). 17 | -author("potatosaladx@meta.com"). 18 | -oncall("whatsapp_clr"). 19 | 20 | -include_lib("proper/include/proper.hrl"). 21 | 22 | %% Properties 23 | -export([ 24 | prop_noop/1 25 | ]). 26 | 27 | %%%============================================================================= 28 | %%% Properties 29 | %%%============================================================================= 30 | 31 | prop_noop(_Config) -> 32 | ?FORALL( 33 | Integer, 34 | integer(), 35 | begin 36 | Integer =:= Integer 37 | end 38 | ). 39 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | import Config 8 | 9 | # config(:logger, 10 | # level: :debug, 11 | # handle_otp_reports: true, 12 | # handle_sasl_reports: true 13 | # ) 14 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | defmodule ErldistFilterElixirTests.MixProject do 8 | use Mix.Project 9 | 10 | def project() do 11 | [ 12 | app: :erldist_filter_elixir_tests, 13 | version: "1.0.0", 14 | elixir: "~> 1.14", 15 | deps: deps(), 16 | elixirc_paths: elixirc_paths(Mix.env()) 17 | ] 18 | end 19 | 20 | def application() do 21 | [extra_applications: [:logger, :observer, :runtime_tools, :erldist_filter]] 22 | end 23 | 24 | # Run "mix help deps" to learn about dependencies. 25 | defp deps() do 26 | [ 27 | {:erldist_filter, path: "apps/erldist_filter", only: :test, override: true}, 28 | {:erldist_filter_test, path: "apps/erldist_filter_test", only: :test, override: true} 29 | ] 30 | end 31 | 32 | defp elixirc_paths(:test), do: ["lib", "test/support"] 33 | defp elixirc_paths(_), do: ["lib"] 34 | end 35 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "elixir_make": {:hex, :elixir_make, "0.7.7", "7128c60c2476019ed978210c245badf08b03dbec4f24d05790ef791da11aa17c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bc19fff950fad52bbe5f211b12db9ec82c6b34a9647da0c2224b8b8464c7e6c"}, 3 | "proper": {:git, "https://github.com/proper-testing/proper.git", "a5ae5669f01143b0828fc21667d4f5e344aa760b", [branch: "master"]}, 4 | } 5 | -------------------------------------------------------------------------------- /rebar.config: -------------------------------------------------------------------------------- 1 | %%% Copyright (c) Meta Platforms, Inc. and affiliates. 2 | %%% Copyright (c) WhatsApp LLC 3 | %%% 4 | %%% This source code is licensed under the MIT license found in the 5 | %%% LICENSE.md file in the root directory of this source tree. 6 | %%% % @format 7 | {erl_opts, [debug_info]}. 8 | 9 | {deps, [ 10 | {eqwalizer_support, 11 | {git_subdir, "https://github.com/WhatsApp/eqwalizer.git", {branch, "main"}, "eqwalizer_support"}} 12 | ]}. 13 | 14 | {shell, 15 | % {config, "config/sys.config"}, 16 | [{apps, [erldist_filter, erldist_filter_test]}]}. 17 | 18 | {project_plugins, [ 19 | {eqwalizer_rebar3, {git_subdir, "https://github.com/WhatsApp/eqwalizer.git", {branch, "main"}, "eqwalizer_rebar3"}} 20 | ]}. 21 | -------------------------------------------------------------------------------- /rebar.lock: -------------------------------------------------------------------------------- 1 | {"1.2.0", 2 | [{<<"eqwalizer_support">>, 3 | {git_subdir,"https://github.com/WhatsApp/eqwalizer.git", 4 | {ref,"a12f4fa1f0db971b54dfa9ff6cdf5240040579b1"}, 5 | "eqwalizer_support"}, 6 | 0}, 7 | {<<"proper">>, 8 | {git,"https://github.com/proper-testing/proper.git", 9 | {ref,"bfd7d862dd5082eeca65c192a7021d0e4de5973e"}}, 10 | 0}, 11 | {<<"rebar3_proper">>,{pkg,<<"rebar3_proper">>,<<"0.12.1">>},0}]}. 12 | [ 13 | {pkg_hash,[ 14 | {<<"rebar3_proper">>, <<"5DDB0FE2B118844A96F868660516F78A6DEA4C777FF19DE225CCC313310B9F1B">>}]}, 15 | {pkg_hash_ext,[ 16 | {<<"rebar3_proper">>, <<"6691C4D1883543578240D157EAA9D49F3EBB3156892F7C320F070868962327B8">>}]} 17 | ]. 18 | -------------------------------------------------------------------------------- /test/support/queue_logger.ex: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | defmodule ErldistFilterElixirTests.QueueLogger do 8 | @behaviour :erldist_filter_logger 9 | 10 | @spec child_spec() :: :supervisor.child_spec() 11 | def child_spec() do 12 | :erldist_filter_logger_sup.child_spec(__MODULE__, %{}, 1) 13 | end 14 | 15 | def export() do 16 | server_ref = :erldist_filter_logger.child_name(__MODULE__, 1) 17 | {:ok, reply} = :gen.call(server_ref, :"$erldist_filter_logger_call", :export) 18 | reply 19 | end 20 | 21 | @impl :erldist_filter_logger 22 | def init(_handler_options, _worker_number) do 23 | state = :queue.new() 24 | {:ok, state} 25 | end 26 | 27 | @impl :erldist_filter_logger 28 | def handle_batch(_batch_size, _batch_drop, batch_events, state) do 29 | {:handle_events, batch_events, state} 30 | end 31 | 32 | @impl :erldist_filter_logger 33 | def handle_control_event(time, sysname, control, state) do 34 | control = :udist.cast_to_dop(control) 35 | state = :queue.in({time, sysname, control}, state) 36 | {:cont, state} 37 | end 38 | 39 | @impl :erldist_filter_logger 40 | def handle_payload_event(time, sysname, control, payload, state) do 41 | control = :udist.cast_to_dop(control) 42 | state = :queue.in({time, sysname, control, payload}, state) 43 | {:cont, state} 44 | end 45 | 46 | @impl :erldist_filter_logger 47 | def handle_info({:"$erldist_filter_logger_call", from, :export}, state) do 48 | reply = :queue.to_list(state) 49 | :ok = :gen.reply(from, reply) 50 | state = :queue.new() 51 | {:cont, state} 52 | end 53 | 54 | def handle_info(_info, state) do 55 | {:cont, state} 56 | end 57 | 58 | @impl :erldist_filter_logger 59 | def terminate(_reason, _state) do 60 | :ok 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # Copyright (c) WhatsApp LLC 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE.md file in the root directory of this source tree. 6 | 7 | # :ok = :logger.set_primary_config(:level, :debug) 8 | # :ok = :lists.foreach(&:logger.remove_handler/1, :logger.get_handler_ids) 9 | # :ok = :logger.add_handler(:debug_output, :logger_std_h, %{ 10 | # config: %{type: :standard_error}, 11 | # formatter: {:logger_formatter, %{legacy_header: false, single_line: true}}, 12 | # level: :debug 13 | # }) 14 | 15 | ExUnit.start(max_cases: 1) 16 | --------------------------------------------------------------------------------