├── .gitignore ├── .readthedocs.yaml ├── .semaphore ├── README.md ├── deploy-development.yml ├── deploy-production.yml ├── deploy-staging.yml ├── happy-path.yml ├── semaphore.yml ├── test.yml ├── update-golang-cache.yml ├── upload-artifacts.yml ├── upload-config.yml └── upload-relay.yml ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── api │ └── api.go ├── client │ └── client.cpp ├── func_backend │ └── func_backend.go ├── func_client │ └── func_client.cpp ├── func_server │ └── func_server.cpp ├── func_test_api │ └── func_test_api.go ├── func_test_backend │ └── func_test_backend.go ├── func_test_database │ └── func_test_database.go ├── func_test_portal │ └── func_test_portal.go ├── func_test_relay │ └── func_test_relay.go ├── func_test_sdk │ └── func_test_sdk.go ├── func_test_terraform │ └── func_test_terraform.go ├── ip2location │ └── ip2location.go ├── load_test_relays │ └── load_test_relays.go ├── load_test_servers │ └── load_test_servers.go ├── load_test_sessions │ └── load_test_sessions.go ├── magic_backend │ └── magic_backend.go ├── raspberry_backend │ └── raspberry_backend.go ├── raspberry_client │ └── raspberry_client.cpp ├── raspberry_server │ └── raspberry_server.cpp ├── relay_backend │ ├── relay_backend.go │ ├── relay_to_relay_ping.json │ ├── relay_update.json │ └── route_matrix_update.json ├── relay_gateway │ └── relay_gateway.go ├── server │ └── server.cpp ├── server_backend │ ├── client_relay_ping.json │ ├── server_backend.go │ ├── server_init.json │ ├── server_relay_ping.json │ ├── server_update.json │ ├── session_summary.json │ └── session_update.json ├── server_cruncher │ └── server_cruncher.go ├── session_cruncher │ └── session_cruncher.go └── soak_test_relay │ └── soak_test_relay.go ├── config.json ├── config ├── akamai.txt ├── amazon.txt ├── google.txt └── multiplay.txt ├── deploy ├── app.service ├── bootstrap.sh └── nginx.conf ├── docker-compose.yml ├── docker ├── api.Dockerfile ├── base.Dockerfile ├── client.Dockerfile ├── magic_backend.Dockerfile ├── portal.Dockerfile ├── postgres.Dockerfile ├── raspberry_backend.Dockerfile ├── raspberry_client.Dockerfile ├── raspberry_server.Dockerfile ├── relay.Dockerfile ├── relay_backend.Dockerfile ├── relay_gateway.Dockerfile ├── server.Dockerfile ├── server_backend.Dockerfile ├── server_cruncher.Dockerfile └── session_cruncher.Dockerfile ├── docs ├── bigquery_table_schemas.md ├── configure_network_next.md ├── connect_a_client_to_the_test_server.md ├── create_google_cloud_projects_with_terraform.md ├── create_your_own_buyer.md ├── datacenter_and_relay_naming_conventions.md ├── deploy_to_development.md ├── deploy_to_production.md ├── deploy_to_staging.md ├── disable_the_raspberry_clients.md ├── enable_acceleration_to_sao_paulo.md ├── fork_next_repository.md ├── getting_production_ready_for_your_game.md ├── glossary_of_common_terms.md ├── integrate_with_your_game.md ├── modify_route_shader_for_test_buyer.md ├── modify_set_of_akamai_relays.md ├── modify_set_of_amazon_relays.md ├── modify_set_of_google_relays.md ├── move_test_server_to_sao_paulo.md ├── network_next_terraform_provider.md ├── next_tool_user_guide.md ├── planning_your_production_relay_fleet.md ├── portal_user_guide.md ├── run_a_test_client.md ├── run_local_instance_with_docker_compose.md ├── run_your_own_client_and_server.md ├── setup_prerequisites.md ├── setup_semaphore_ci_to_build_and_deploy_artifacts.md ├── setup_your_local_machine_for_development.md ├── spin_dev_back_up.md ├── spin_up_other_relays_in_sao_paulo.md ├── spin_up_relays_near_you.md ├── tear_down_dev_staging_and_production.md ├── test_acceleration_to_sao_paolo.md └── unreal_engine_plugin.md ├── envs ├── dev.env ├── docker.bin ├── empty.bin ├── local.bin ├── local.env ├── prod.env ├── staging.bin └── staging.env ├── go.mod ├── go.sum ├── modules ├── admin │ └── admin.go ├── common │ ├── client_relays.go │ ├── client_relays_test.go │ ├── cost_matrix.go │ ├── cost_matrix_test.go │ ├── file_system.go │ ├── google_bigquery.go │ ├── google_pubsub.go │ ├── misc.go │ ├── redis_counters.go │ ├── redis_leader_election.go │ ├── redis_time_series.go │ ├── relay_manager.go │ ├── relay_manager_test.go │ ├── route_matrix.go │ ├── route_matrix_test.go │ ├── service.go │ └── udp_server.go ├── constants │ └── constants.go ├── core │ ├── core.go │ └── core_test.go ├── crypto │ ├── crypto.go │ └── crypto_test.go ├── database │ └── database.go ├── encoding │ ├── bitpacker.go │ ├── bitpacker_test.go │ ├── encoding.go │ ├── read_stream.go │ ├── stream.go │ ├── stream_test.go │ └── write_stream.go ├── envvar │ └── envvar.go ├── handlers │ ├── sdk_handlers.go │ ├── sdk_handlers_test.go │ ├── session_update.go │ └── session_update_test.go ├── ip2location │ └── ip2location.go ├── messages │ ├── analytics.go │ ├── analytics_test.go │ └── portal.go ├── packets │ ├── packet.go │ ├── packets_test.go │ ├── relay_packets.go │ ├── sdk_constants.go │ ├── sdk_packets.go │ └── sdk_version.go └── portal │ ├── portal.go │ └── portal_test.go ├── next ├── portal ├── .env.dev ├── .env.local ├── .env.prod ├── .env.staging ├── README.md ├── babel.config.js ├── jsconfig.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── .gitignore │ ├── App.vue │ ├── assets │ │ ├── logo_black.png │ │ ├── logo_white.png │ │ └── n_black.png │ ├── components │ │ └── SessionCounts.vue │ ├── main.js │ ├── mitt.js │ ├── router │ │ └── index.js │ ├── update.js │ ├── utils.js │ └── views │ │ ├── AdminView.vue │ │ ├── BuyerView.vue │ │ ├── BuyersView.vue │ │ ├── DatacenterView.vue │ │ ├── DatacentersView.vue │ │ ├── MapView.vue │ │ ├── RelayView.vue │ │ ├── RelaysView.vue │ │ ├── SellerView.vue │ │ ├── SellersView.vue │ │ ├── ServerView.vue │ │ ├── ServersView.vue │ │ ├── SessionView.vue │ │ ├── SessionsView.vue │ │ └── UserView.vue └── vue.config.js ├── redis ├── 10000 │ └── redis.conf ├── 10001 │ └── redis.conf ├── 10002 │ └── redis.conf ├── 10003 │ └── redis.conf ├── 10004 │ └── redis.conf └── 10005 │ └── redis.conf ├── relay ├── client │ ├── client.go │ ├── go.mod │ └── go.sum ├── module │ ├── Makefile │ └── relay_module.c ├── reference │ ├── Makefile │ ├── reference_relay.cpp │ ├── relay.h │ ├── relay_linux.cpp │ ├── relay_linux.h │ ├── relay_mac.cpp │ ├── relay_mac.h │ └── relay_version.h └── xdp │ ├── Makefile │ ├── relay.c │ ├── relay.h │ ├── relay_base64.c │ ├── relay_base64.h │ ├── relay_bpf.c │ ├── relay_bpf.h │ ├── relay_config.c │ ├── relay_config.h │ ├── relay_constants.h │ ├── relay_debug.c │ ├── relay_debug.h │ ├── relay_encoding.h │ ├── relay_hash.h │ ├── relay_main.c │ ├── relay_main.h │ ├── relay_manager.c │ ├── relay_manager.h │ ├── relay_messages.h │ ├── relay_ping.c │ ├── relay_ping.h │ ├── relay_ping_history.c │ ├── relay_ping_history.h │ ├── relay_ping_stats.h │ ├── relay_platform.c │ ├── relay_platform.h │ ├── relay_queue.h │ ├── relay_set.h │ ├── relay_shared.h │ ├── relay_version.h │ └── relay_xdp.c ├── run ├── schemas ├── bigquery │ ├── client_relay_ping.json │ ├── relay_to_relay_ping.json │ ├── relay_update.json │ ├── route_matrix_update.json │ ├── server_init.json │ ├── server_relay_ping.json │ ├── server_update.json │ ├── session_summary.json │ └── session_update.json ├── pubsub │ ├── client_relay_ping.json │ ├── relay_to_relay_ping.json │ ├── relay_update.json │ ├── route_matrix_update.json │ ├── server_init.json │ ├── server_relay_ping.json │ ├── server_update.json │ ├── session_summary.json │ └── session_update.json └── sql │ ├── create.sql │ ├── destroy.sql │ ├── docker.sql │ ├── local.sql │ ├── staging.sql │ └── test.sql ├── scripts ├── all_commands.sh ├── init_relay.sh ├── setup_relay.sh └── tabs2spaces.sh ├── sdk ├── .gitignore ├── .semaphore │ └── semaphore.yml ├── README.md ├── build │ ├── gdk │ │ ├── Icon-150.png │ │ ├── Icon-44.png │ │ ├── Icon-480.png │ │ ├── MicrosoftGame.Config │ │ ├── SplashScreen.png │ │ ├── StoreLogo.png │ │ ├── WideLogo.png │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── gdk.sln │ │ ├── next.vcxproj │ │ ├── pch.cpp │ │ └── pch.h │ ├── ps4 │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── next.vcxproj │ │ └── ps4.sln │ ├── ps5 │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── next.vcxproj │ │ └── ps5.sln │ ├── switch │ │ ├── Application.aarch64.lp64.nmeta │ │ ├── ImportNintendoSdk.props │ │ ├── NintendoSDK_Application.bmp │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── next.vcxproj │ │ └── switch.sln │ ├── win32 │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── next.vcxproj │ │ └── win32.sln │ └── win64 │ │ ├── client.cpp │ │ ├── client.vcxproj │ │ ├── next.vcxproj │ │ ├── test.cpp │ │ ├── test.vcxproj │ │ └── win64.sln ├── docs │ └── source │ │ ├── building_the_sdk.rst │ │ ├── complex_client_example.rst │ │ ├── complex_server_example.rst │ │ ├── conf.py │ │ ├── contents.rst │ │ ├── env.rst │ │ ├── globals.rst │ │ ├── images │ │ ├── client_server.png │ │ ├── downloads.png │ │ ├── get_access.png │ │ ├── map.png │ │ ├── public_key.png │ │ ├── session_drill_in.png │ │ ├── sessions.png │ │ └── settings.png │ │ ├── index.rst │ │ ├── next_address_t.rst │ │ ├── next_client_t.rst │ │ ├── next_server_t.rst │ │ ├── reference.rst │ │ ├── requirements.txt │ │ ├── simple_client_example.rst │ │ ├── simple_server_example.rst │ │ ├── upgraded_client_example.rst │ │ └── upgraded_server_example.rst ├── examples │ ├── complex_client.cpp │ ├── complex_server.cpp │ ├── simple_client.cpp │ ├── simple_server.cpp │ ├── upgraded_client.cpp │ └── upgraded_server.cpp ├── include │ ├── next.h │ ├── next_address.h │ ├── next_autodetect.h │ ├── next_bandwidth_limiter.h │ ├── next_base64.h │ ├── next_bitpacker.h │ ├── next_client.h │ ├── next_config.h │ ├── next_constants.h │ ├── next_continue_token.h │ ├── next_crypto.h │ ├── next_hash.h │ ├── next_header.h │ ├── next_internal_config.h │ ├── next_jitter_tracker.h │ ├── next_memory_checks.h │ ├── next_out_of_order_tracker.h │ ├── next_packet_filter.h │ ├── next_packet_loss_tracker.h │ ├── next_packets.h │ ├── next_pending_session_manager.h │ ├── next_ping_history.h │ ├── next_platform.h │ ├── next_platform_gdk.h │ ├── next_platform_linux.h │ ├── next_platform_mac.h │ ├── next_platform_ps4.h │ ├── next_platform_ps5.h │ ├── next_platform_switch.h │ ├── next_platform_windows.h │ ├── next_proxy_session_manager.h │ ├── next_queue.h │ ├── next_read_write.h │ ├── next_relay_manager.h │ ├── next_replay_protection.h │ ├── next_route_manager.h │ ├── next_route_token.h │ ├── next_serialize.h │ ├── next_server.h │ ├── next_session_manager.h │ ├── next_stream.h │ ├── next_tests.h │ ├── next_upgrade_token.h │ └── next_util.h ├── keygen │ └── keygen.go ├── premake5.lua ├── soak.cpp ├── sodium │ ├── sodium.h │ ├── sodium_aead_chacha20poly1305.c │ ├── sodium_aead_xchacha20poly1305.c │ ├── sodium_blake2.h │ ├── sodium_blake2b-compress-avx2.c │ ├── sodium_blake2b-compress-avx2.h │ ├── sodium_blake2b-compress-ref.c │ ├── sodium_blake2b-compress-sse41.c │ ├── sodium_blake2b-compress-sse41.h │ ├── sodium_blake2b-compress-ssse3.c │ ├── sodium_blake2b-compress-ssse3.h │ ├── sodium_blake2b-load-avx2.h │ ├── sodium_blake2b-load-sse2.h │ ├── sodium_blake2b-load-sse41.h │ ├── sodium_blake2b-ref.c │ ├── sodium_box_curve25519xchacha20poly1305.c │ ├── sodium_box_curve25519xsalsa20poly1305.c │ ├── sodium_box_seal_curve25519xchacha20poly1305.c │ ├── sodium_chacha20-ref.c │ ├── sodium_chacha20-ref.h │ ├── sodium_codecs.c │ ├── sodium_common.h │ ├── sodium_core.c │ ├── sodium_core.h │ ├── sodium_core_ed25519.c │ ├── sodium_core_hchacha20.c │ ├── sodium_core_hsalsa20.c │ ├── sodium_core_hsalsa20_ref2.c │ ├── sodium_core_salsa_ref.c │ ├── sodium_crypto_aead_chacha20poly1305.h │ ├── sodium_crypto_aead_xchacha20poly1305.h │ ├── sodium_crypto_auth.h │ ├── sodium_crypto_auth_hmacsha512.h │ ├── sodium_crypto_auth_hmacsha512256.h │ ├── sodium_crypto_box.c │ ├── sodium_crypto_box.h │ ├── sodium_crypto_box_curve25519xchacha20poly1305.h │ ├── sodium_crypto_box_curve25519xsalsa20poly1305.h │ ├── sodium_crypto_box_easy.c │ ├── sodium_crypto_core_ed25519.h │ ├── sodium_crypto_core_hchacha20.h │ ├── sodium_crypto_core_hsalsa20.h │ ├── sodium_crypto_core_salsa20.h │ ├── sodium_crypto_core_salsa2012.h │ ├── sodium_crypto_core_salsa208.h │ ├── sodium_crypto_generichash.c │ ├── sodium_crypto_generichash.h │ ├── sodium_crypto_generichash_blake2b.h │ ├── sodium_crypto_hash.h │ ├── sodium_crypto_hash_sha256.c │ ├── sodium_crypto_hash_sha256.h │ ├── sodium_crypto_hash_sha256_cp.c │ ├── sodium_crypto_hash_sha512.h │ ├── sodium_crypto_kx.c │ ├── sodium_crypto_kx.h │ ├── sodium_crypto_onetimeauth.h │ ├── sodium_crypto_onetimeauth_poly1305.h │ ├── sodium_crypto_scalarmult.c │ ├── sodium_crypto_scalarmult.h │ ├── sodium_crypto_scalarmult_curve25519.h │ ├── sodium_crypto_scalarmult_ed25519.h │ ├── sodium_crypto_secretbox.c │ ├── sodium_crypto_secretbox.h │ ├── sodium_crypto_secretbox_easy.c │ ├── sodium_crypto_secretbox_xchacha20poly1305.h │ ├── sodium_crypto_secretbox_xsalsa20poly1305.h │ ├── sodium_crypto_secretstream_xchacha20poly1305.h │ ├── sodium_crypto_shorthash.h │ ├── sodium_crypto_shorthash_siphash24.h │ ├── sodium_crypto_sign.c │ ├── sodium_crypto_sign.h │ ├── sodium_crypto_sign_ed25519.h │ ├── sodium_crypto_sign_edwards25519sha512batch.h │ ├── sodium_crypto_stream.h │ ├── sodium_crypto_stream_chacha20.h │ ├── sodium_crypto_stream_salsa20.h │ ├── sodium_crypto_stream_salsa2012.h │ ├── sodium_crypto_stream_salsa208.h │ ├── sodium_crypto_stream_xchacha20.h │ ├── sodium_crypto_stream_xsalsa20.h │ ├── sodium_crypto_verify_16.h │ ├── sodium_crypto_verify_32.h │ ├── sodium_crypto_verify_64.h │ ├── sodium_dolbeau_chacha20-avx2.c │ ├── sodium_dolbeau_chacha20-avx2.h │ ├── sodium_dolbeau_chacha20-ssse3.c │ ├── sodium_dolbeau_chacha20-ssse3.h │ ├── sodium_dolbeau_u0.h │ ├── sodium_dolbeau_u1.h │ ├── sodium_dolbeau_u4.h │ ├── sodium_dolbeau_u8.h │ ├── sodium_export.h │ ├── sodium_fe_25_5_base.h │ ├── sodium_fe_25_5_base2.h │ ├── sodium_fe_25_5_constants.h │ ├── sodium_fe_25_5_fe.h │ ├── sodium_fe_51_base.h │ ├── sodium_fe_51_base2.h │ ├── sodium_fe_51_constants.h │ ├── sodium_fe_51_fe.h │ ├── sodium_generichash_blake2.c │ ├── sodium_generichash_blake2b.c │ ├── sodium_hash_sha512.c │ ├── sodium_hash_sha512_cp.c │ ├── sodium_onetimeauth_poly1305.c │ ├── sodium_onetimeauth_poly1305.h │ ├── sodium_poly1305-sse2.c │ ├── sodium_poly1305-sse2.h │ ├── sodium_poly1305_donna.c │ ├── sodium_poly1305_donna.h │ ├── sodium_poly1305_donna32.h │ ├── sodium_poly1305_donna64.h │ ├── sodium_private_chacha20_ietf_ext.h │ ├── sodium_private_common.h │ ├── sodium_private_ed25519_ref10.h │ ├── sodium_private_ed25519_ref10_fe_25_5.h │ ├── sodium_private_ed25519_ref10_fe_51.h │ ├── sodium_private_implementations.h │ ├── sodium_private_mutex.h │ ├── sodium_private_sse2_64_32.h │ ├── sodium_randombytes.c │ ├── sodium_randombytes.h │ ├── sodium_randombytes_nativeclient.h │ ├── sodium_randombytes_salsa20_random.c │ ├── sodium_randombytes_salsa20_random.h │ ├── sodium_randombytes_sysrandom.c │ ├── sodium_randombytes_sysrandom.h │ ├── sodium_ref10_ed25519.c │ ├── sodium_ref10_keypair.c │ ├── sodium_ref10_open.c │ ├── sodium_ref10_scalarmult_ed25519_ref10.c │ ├── sodium_ref10_sign.c │ ├── sodium_ref10_sign_ed25519.h │ ├── sodium_ref10_x25519.c │ ├── sodium_ref10_x25519.h │ ├── sodium_runtime.c │ ├── sodium_runtime.h │ ├── sodium_salsa20-ref.c │ ├── sodium_salsa20-ref.h │ ├── sodium_salsa20-xmm6.c │ ├── sodium_salsa20-xmm6.h │ ├── sodium_salsa20-xmm6_asm.S │ ├── sodium_sandy2x.S │ ├── sodium_sandy2x_consts.S │ ├── sodium_sandy2x_consts_namespace.h │ ├── sodium_sandy2x_curve25519.c │ ├── sodium_sandy2x_curve25519.h │ ├── sodium_sandy2x_fe.h │ ├── sodium_sandy2x_fe51.h │ ├── sodium_sandy2x_fe51_invert.c │ ├── sodium_sandy2x_fe51_mul.S │ ├── sodium_sandy2x_fe51_namespace.h │ ├── sodium_sandy2x_fe51_nsquare.S │ ├── sodium_sandy2x_fe51_pack.S │ ├── sodium_sandy2x_fe_frombytes.c │ ├── sodium_sandy2x_ladder.S │ ├── sodium_sandy2x_ladder.h │ ├── sodium_sandy2x_ladder_base.S │ ├── sodium_sandy2x_ladder_base.h │ ├── sodium_sandy2x_ladder_base_namespace.h │ ├── sodium_sandy2x_ladder_namespace.h │ ├── sodium_scalarmult_curve25519.c │ ├── sodium_scalarmult_curve25519.h │ ├── sodium_secretbox_xchacha20poly1305.c │ ├── sodium_secretbox_xsalsa20poly1305.c │ ├── sodium_sign_ed25519.c │ ├── sodium_stream_chacha20.c │ ├── sodium_stream_chacha20.h │ ├── sodium_stream_salsa20.c │ ├── sodium_stream_salsa20.h │ ├── sodium_stream_xchacha20.c │ ├── sodium_stream_xsalsa20.c │ ├── sodium_utils.c │ ├── sodium_utils.h │ ├── sodium_verify.c │ ├── sodium_version.c │ ├── sodium_version.h │ ├── sodium_xmm6int_salsa20-avx2.c │ ├── sodium_xmm6int_salsa20-avx2.h │ ├── sodium_xmm6int_salsa20-sse2.c │ ├── sodium_xmm6int_salsa20-sse2.h │ ├── sodium_xmm6int_u0.h │ ├── sodium_xmm6int_u1.h │ ├── sodium_xmm6int_u4.h │ └── sodium_xmm6int_u8.h ├── source │ ├── next.cpp │ ├── next_address.cpp │ ├── next_autodetect.cpp │ ├── next_base64.cpp │ ├── next_client.cpp │ ├── next_config.cpp │ ├── next_crypto.cpp │ ├── next_hash.cpp │ ├── next_packet_filter.cpp │ ├── next_packets.cpp │ ├── next_platform_gdk.cpp │ ├── next_platform_linux.cpp │ ├── next_platform_mac.cpp │ ├── next_platform_ps4.cpp │ ├── next_platform_ps5.cpp │ ├── next_platform_switch.cpp │ ├── next_platform_windows.cpp │ ├── next_route_manager.cpp │ ├── next_server.cpp │ └── next_tests.cpp ├── test.Dockerfile └── test.cpp ├── sellers ├── akamai.go ├── amazon.go └── google.go ├── terraform ├── dev │ ├── backend │ │ ├── main.tf │ │ └── terraform.tfvars │ └── relays │ │ ├── amazon │ │ ├── generated.tf │ │ ├── main.tf │ │ ├── region │ │ │ └── main.tf │ │ └── relay │ │ │ └── main.tf │ │ ├── main.tf │ │ └── terraform.tfvars ├── modules │ ├── external_http_service │ │ └── main.tf │ ├── external_http_service_autoscale │ │ └── main.tf │ ├── external_mig_without_health_check │ │ └── main.tf │ ├── external_udp_service │ │ └── main.tf │ ├── external_udp_service_autoscale │ │ └── main.tf │ ├── internal_http_service │ │ └── main.tf │ ├── internal_http_service_autoscale │ │ └── main.tf │ ├── internal_mig_with_health_check │ │ └── main.tf │ ├── internal_mig_with_health_check_autoscale │ │ └── main.tf │ ├── nginx │ │ └── main.tf │ └── redis_stack │ │ └── main.tf ├── prod │ ├── backend │ │ ├── main.tf │ │ └── terraform.tfvars │ └── relays │ │ ├── amazon │ │ ├── generated.tf │ │ ├── main.tf │ │ ├── region │ │ │ └── main.tf │ │ └── relay │ │ │ └── main.tf │ │ ├── main.tf │ │ └── terraform.tfvars ├── projects │ └── main.tf ├── sellers │ ├── akamai │ │ ├── generated.tf │ │ └── main.tf │ ├── bare_metal │ │ └── main.tf │ ├── colocrossing │ │ └── main.tf │ ├── datapacket │ │ └── main.tf │ ├── equinix │ │ └── main.tf │ ├── gcore │ │ └── main.tf │ ├── google │ │ ├── generated.tf │ │ └── main.tf │ ├── hivelocity │ │ └── main.tf │ ├── i3d │ │ └── main.tf │ ├── latitude │ │ └── main.tf │ ├── oneqode │ │ └── main.tf │ ├── phoenixnap │ │ └── main.tf │ ├── serversdotcom │ │ └── main.tf │ ├── velia │ │ └── main.tf │ └── zenlayer │ │ └── main.tf └── staging │ └── backend │ ├── main.tf │ └── terraform.tfvars └── tools ├── artifact └── artifact.go ├── build_portal └── build_portal.go ├── extract_database └── extract_database.go ├── generate_staging_sql └── generate_staging_sql.go ├── happy_path └── happy_path.go ├── load_relay_manager └── load_relay_manager.go ├── load_test_crypto_box └── load_test_crypto_box.go ├── load_test_crypto_sign └── load_test_crypto_sign.go ├── load_test_optimize └── load_test_optimize.go ├── load_test_portal └── load_test_portal.go ├── load_test_redis_counters └── load_test_redis_counters.go ├── load_test_redis_data └── load_test_redis_data.go ├── load_test_redis_time_series └── load_test_redis_time_series.go ├── load_test_relay_manager └── load_test_relay_manager.go ├── load_test_route_matrix └── load_test_route_matrix.go ├── load_test_server_update └── load_test_server_update.go ├── load_test_session_update └── load_test_session_update.go ├── next └── next.go ├── redis_cluster └── redis_cluster.go └── run └── run.go /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .DS_Store 3 | dist 4 | .idea 5 | .vscode 6 | cover.out 7 | *.swp 8 | *.o 9 | *.d 10 | .ycm_extra_conf.py 11 | .env 12 | *.rdb 13 | *.csv 14 | 15 | # next tool output 16 | cost.bin 17 | optimize.bin 18 | database.bin* 19 | 20 | # happy path output 21 | logs 22 | 23 | # test files 24 | *.mmdb 25 | 26 | # terraform 27 | .terraform 28 | .terraform.* 29 | terraform.tfstate 30 | terraform.tfstate.* 31 | 32 | # cache 33 | cache/* 34 | 35 | # portal 36 | node_modules 37 | yarn.lock 38 | 39 | # redis cluster 40 | appendonlydir 41 | nodes.conf 42 | *.rdb 43 | 44 | # fun times 45 | .a 46 | sdk/build/ps4/client 47 | sdk/build/ps4/test 48 | Gaming.Xbox.* -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.7" 13 | 14 | # Build documentation in the docs/ directory with Sphinx 15 | sphinx: 16 | configuration: sdk/docs/source/conf.py 17 | 18 | # Explicitly set the version of Python and its requirements 19 | python: 20 | install: 21 | - requirements: sdk/docs/source/requirements.txt -------------------------------------------------------------------------------- /.semaphore/README.md: -------------------------------------------------------------------------------- 1 | # Semaphore 2 | 3 | Semaphore is our CI/CD tool. It is responsible for: 4 | 5 | 1. Running unit tests for Pull Requests. 6 | 2. Building and publishing artifacts to Google Cloud environments for deployments. 7 | 8 | To understand Semaphore's YAML syntax, refer to their [documentation](https://docs.semaphoreci.com/reference/pipeline-yaml-reference/). 9 | 10 | ## Docker 11 | 12 | Semaphore runs unit tests inside a Docker container. This is more efficient than downloading the necessary packages each time. 13 | However, the container size greatly impacts the time it takes to run the unit tests because the Semaphore instance has to pull 14 | the container (see Semaphore's suggestions for optimizations [here](https://docs.semaphoreci.com/ci-cd-environment/custom-ci-cd-environment-with-docker/#optimizing-docker-images-for-fast-cicd)). 15 | This is why the Dockerfile is based on Alpine with the minimum number of installs. 16 | 17 | ### Updating Docker Image 18 | 19 | Update the Docker image when the following occurs: 20 | 21 | 1. New package dependencies for the backend are required 22 | 2. New google cloud emulator is required 23 | 3. Changes to go.mod or go.sum 24 | 25 | 26 | To update the Docker image, make sure you have Docker installed and are a collaborator for the `nbopardi/networknext` docker repo. 27 | Then run the following from the root of the backend repo: 28 | 29 | 1. `go mod tidy` 30 | 2. `docker build -f ./.semaphore/Dockerfile -t nbopardi/networknext:backend .` 31 | 3. `docker history nbopardi/networknext:backend` 32 | - This is to verify the size of each layer of the Docker image. 33 | - Make sure the total image size is relatively small (under 3 GB). 34 | 4. `docker push nbopardi/networknext:backend` 35 | 36 | Once complete, Semaphore will now use the latest Docker image. 37 | -------------------------------------------------------------------------------- /.semaphore/deploy-development.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: "Deploy to Development" 4 | 5 | agent: 6 | machine: 7 | type: e1-standard-2 8 | os_image: ubuntu2004 9 | 10 | global_job_config: 11 | secrets: 12 | - name: secrets 13 | 14 | blocks: 15 | 16 | - name: "Deploy to Development" 17 | 18 | task: 19 | 20 | jobs: 21 | - name: "Deploy" 22 | commands: 23 | - tar xzf /home/semaphore/secrets/secrets.tar.gz -C /home/semaphore/secrets 24 | - export GOOGLE_APPLICATION_CREDENTIALS=/home/semaphore/secrets/terraform-dev.json 25 | - gcloud auth activate-service-account --key-file=/home/semaphore/secrets/terraform-dev.json 26 | - echo $SEMAPHORE_GIT_TAG_NAME 27 | - echo $SEMAPHORE_GIT_BRANCH 28 | - echo $SEMAPHORE_WORKFLOW_NUMBER 29 | - checkout 30 | - cd terraform/dev/backend 31 | - terraform init 32 | - terraform apply -var="tag=${SEMAPHORE_GIT_TAG_NAME}" -var="extra=-${SEMAPHORE_WORKFLOW_NUMBER}" -auto-approve -lock=false 33 | -------------------------------------------------------------------------------- /.semaphore/deploy-production.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: "Deploy to Production" 4 | 5 | agent: 6 | machine: 7 | type: e1-standard-2 8 | os_image: ubuntu2004 9 | 10 | global_job_config: 11 | secrets: 12 | - name: secrets 13 | 14 | blocks: 15 | 16 | - name: "Deploy to Production" 17 | 18 | task: 19 | 20 | jobs: 21 | - name: "Deploy" 22 | commands: 23 | - tar xzf /home/semaphore/secrets/secrets.tar.gz -C /home/semaphore/secrets 24 | - export GOOGLE_APPLICATION_CREDENTIALS=/home/semaphore/secrets/terraform-prod.json 25 | - gcloud auth activate-service-account --key-file=/home/semaphore/secrets/terraform-prod.json 26 | - echo $SEMAPHORE_GIT_TAG_NAME 27 | - echo $SEMAPHORE_GIT_BRANCH 28 | - echo $SEMAPHORE_WORKFLOW_NUMBER 29 | - checkout 30 | - cd terraform/prod/backend 31 | - terraform init 32 | - terraform apply -var="tag=${SEMAPHORE_GIT_TAG_NAME}" -var="extra=-${SEMAPHORE_WORKFLOW_NUMBER}" -auto-approve -lock=false 33 | -------------------------------------------------------------------------------- /.semaphore/deploy-staging.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: "Deploy to Staging" 4 | 5 | agent: 6 | machine: 7 | type: e1-standard-2 8 | os_image: ubuntu2004 9 | 10 | global_job_config: 11 | secrets: 12 | - name: secrets 13 | 14 | blocks: 15 | 16 | - name: "Deploy to Staging" 17 | 18 | task: 19 | 20 | jobs: 21 | - name: "Deploy" 22 | commands: 23 | - tar xzf /home/semaphore/secrets/secrets.tar.gz -C /home/semaphore/secrets 24 | - export GOOGLE_APPLICATION_CREDENTIALS=/home/semaphore/secrets/terraform-staging.json 25 | - gcloud auth activate-service-account --key-file=/home/semaphore/secrets/terraform-staging.json 26 | - echo $SEMAPHORE_GIT_TAG_NAME 27 | - echo $SEMAPHORE_GIT_BRANCH 28 | - echo $SEMAPHORE_WORKFLOW_NUMBER 29 | - checkout 30 | - cd terraform/staging/backend 31 | - terraform init 32 | - terraform apply -var="tag=${SEMAPHORE_GIT_TAG_NAME}" -var="extra=-${SEMAPHORE_WORKFLOW_NUMBER}" -auto-approve -lock=false 33 | -------------------------------------------------------------------------------- /.semaphore/happy-path.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: Happy Path 4 | 5 | agent: 6 | machine: 7 | type: f1-standard-4 8 | os_image: ubuntu2004 9 | 10 | global_job_config: 11 | secrets: 12 | - name: secrets 13 | 14 | blocks: 15 | 16 | - name: "Happy Path" 17 | dependencies: [] 18 | task: 19 | 20 | jobs: 21 | - name: "run happy-path-no-wait" 22 | commands: 23 | - tar xzf /home/semaphore/secrets/secrets.tar.gz -C /home/semaphore/secrets 24 | - ls /home/semaphore/secrets 25 | - sem-service start redis 7 26 | - sem-service start postgres 14 27 | - sem-service status postgres 28 | - psql -U postgres -h localhost -c "CREATE USER developer;" 29 | - psql -U postgres -h localhost -c "ALTER USER developer WITH SUPERUSER;" 30 | - cache restore golang 31 | - checkout 32 | - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libsodium-dev 33 | - cd ~/next 34 | - make rebuild 35 | - ./next select local 36 | - ./run happy-path-no-wait 37 | 38 | epilogue: 39 | commands: 40 | - killall api || true 41 | - killall magic_backend || true 42 | - killall relay_gateway || true 43 | - killall relay_backend || true 44 | - killall relay-debug || true 45 | - killall server_backend || true 46 | - killall session_cruncher || true 47 | - killall server_cruncher || true 48 | - killall client || true 49 | - killall server || true 50 | -------------------------------------------------------------------------------- /.semaphore/update-golang-cache.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: Update Golang Cache 4 | 5 | agent: 6 | machine: 7 | type: f1-standard-4 8 | os_image: ubuntu2004 9 | 10 | blocks: 11 | 12 | - name: "Update Golang Cache" 13 | dependencies: [] 14 | task: 15 | jobs: 16 | - name: "rebuild everything and update golang cache" 17 | commands: 18 | - checkout 19 | - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libsodium-dev redis-server 20 | - cd ~/next 21 | - make rebuild 22 | - ./next select local 23 | - ./run test 24 | - cache delete golang 25 | - cache store golang /home/semaphore/go/pkg/mod 26 | -------------------------------------------------------------------------------- /.semaphore/upload-config.yml: -------------------------------------------------------------------------------- 1 | version: v1.0 2 | 3 | name: "Config Deploy" 4 | 5 | agent: 6 | machine: 7 | type: e1-standard-2 8 | os_image: ubuntu2004 9 | 10 | global_job_config: 11 | secrets: 12 | - name: secrets 13 | 14 | blocks: 15 | 16 | - name: "Publish Config" 17 | 18 | task: 19 | 20 | prologue: 21 | commands: 22 | - tar xzf /home/semaphore/secrets/secrets.tar.gz -C /home/semaphore/secrets 23 | - gcloud auth activate-service-account --key-file=/home/semaphore/secrets/terraform-storage.json 24 | - export SDK_CONFIG_BUCKET=gs://next_network_next_sdk_config 25 | 26 | jobs: 27 | 28 | - name: "Config" 29 | commands: 30 | - artifact pull workflow google.txt 31 | - artifact pull workflow amazon.txt 32 | - artifact pull workflow akamai.txt 33 | - artifact pull workflow multiplay.txt 34 | - gsutil cp google.txt $SDK_CONFIG_BUCKET 35 | - gsutil cp amazon.txt $SDK_CONFIG_BUCKET 36 | - gsutil cp akamai.txt $SDK_CONFIG_BUCKET 37 | - gsutil cp multiplay.txt $SDK_CONFIG_BUCKET 38 | -------------------------------------------------------------------------------- /cmd/ip2location/ip2location.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/networknext/next/modules/common" 9 | "github.com/networknext/next/modules/core" 10 | "github.com/networknext/next/modules/envvar" 11 | "github.com/networknext/next/modules/ip2location" 12 | ) 13 | 14 | var licenseKey string 15 | var bucketName string 16 | 17 | func main() { 18 | 19 | service := common.CreateService("ip2location") 20 | 21 | licenseKey = envvar.GetString("MAXMIND_LICENSE_KEY", "") 22 | 23 | bucketName = envvar.GetString("IP2LOCATION_BUCKET_NAME", "") 24 | 25 | if licenseKey == "" { 26 | core.Error("you must supply a license key") 27 | os.Exit(1) 28 | } 29 | 30 | go downloadDatabases() 31 | 32 | service.WaitForShutdown() 33 | } 34 | 35 | func downloadDatabases() { 36 | for { 37 | core.Debug("---------------------------------------------------") 38 | err := ip2location.DownloadDatabases_MaxMind(licenseKey) 39 | if err != nil { 40 | core.Error("failed to download databases: %v", err) 41 | goto sleep 42 | } 43 | if bucketName != "" { 44 | core.Debug("uploading database files to google cloud bucket") 45 | err := ip2location.Bash(fmt.Sprintf("gsutil cp GeoIP2-*.mmdb gs://%s", bucketName)) 46 | if err != nil { 47 | core.Error("failed to upload database files: %v", err) 48 | goto sleep 49 | } 50 | core.Debug("success!") 51 | } 52 | sleep: 53 | core.Debug("sleeping...") 54 | core.Debug("---------------------------------------------------") 55 | time.Sleep(time.Hour) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /cmd/relay_backend/relay_to_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "relay_to_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "source_relay_id", "type": "long"}, 8 | {"name": "destination_relay_id", "type": "long"}, 9 | {"name": "rtt", "type": "int"}, 10 | {"name": "jitter", "type": "int"}, 11 | {"name": "packet_loss", "type": "float"} 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /cmd/relay_backend/relay_update.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "relay_update", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "relay_id", "type": "long"}, 8 | {"name": "session_count", "type": "int"}, 9 | {"name": "max_sessions", "type": "int"}, 10 | {"name": "envelope_bandwidth_up_kbps", "type": "long"}, 11 | {"name": "envelope_bandwidth_down_kbps", "type": "long"}, 12 | {"name": "packets_sent_per_second", "type": "float"}, 13 | {"name": "packets_received_per_second", "type": "float"}, 14 | {"name": "bandwidth_sent_kbps", "type": "float"}, 15 | {"name": "bandwidth_received_kbps", "type": "float"}, 16 | {"name": "client_pings_per_second", "type": "float"}, 17 | {"name": "server_pings_per_second", "type": "float"}, 18 | {"name": "relay_pings_per_second", "type": "float"}, 19 | {"name": "relay_flags", "type": "long"}, 20 | {"name": "num_routable", "type": "int"}, 21 | {"name": "num_unroutable", "type": "int"}, 22 | {"name": "start_time", "type": "long"}, 23 | {"name": "current_time", "type": "long"}, 24 | {"name": "relay_counters", "type": {"type": "array", "items": "long"}} 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /cmd/server_backend/client_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "client_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "buyer_id", "type": "long"}, 8 | {"name": "session_id", "type": "long"}, 9 | {"name": "user_hash", "type": "long"}, 10 | {"name": "latitude", "type": "float"}, 11 | {"name": "longitude", "type": "float"}, 12 | {"name": "client_address", "type": "string"}, 13 | {"name": "connection_type", "type": "int"}, 14 | {"name": "platform_type", "type": "int"}, 15 | {"name": "client_relay_id", "type": "long"}, 16 | {"name": "client_relay_rtt", "type": "int"}, 17 | {"name": "client_relay_jitter", "type": "int"}, 18 | {"name": "client_relay_packet_loss", "type": "float"} 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /cmd/server_backend/server_init.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_init", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "sdk_version_major", "type": "int"}, 8 | {"name": "sdk_version_minor", "type": "int"}, 9 | {"name": "sdk_version_patch", "type": "int"}, 10 | {"name": "buyer_id", "type": "long"}, 11 | {"name": "datacenter_id", "type": "long"}, 12 | {"name": "datacenter_name", "type": "string"}, 13 | {"name": "server_address", "type": "string"} 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /cmd/server_backend/server_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "buyer_id", "type": "long"}, 8 | {"name": "session_id", "type": "long"}, 9 | {"name": "datacenter_id", "type": "long"}, 10 | {"name": "server_address", "type": "string"}, 11 | {"name": "server_relay_id", "type": "long"}, 12 | {"name": "server_relay_rtt", "type": "int"}, 13 | {"name": "server_relay_jitter", "type": "int"}, 14 | {"name": "server_relay_packet_loss", "type": "float"} 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /cmd/server_backend/server_update.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_update", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "sdk_version_major", "type": "int"}, 8 | {"name": "sdk_version_minor", "type": "int"}, 9 | {"name": "sdk_version_patch", "type": "int"}, 10 | {"name": "buyer_id", "type": "long"}, 11 | {"name": "datacenter_id", "type": "long"}, 12 | {"name": "num_sessions", "type": "int"}, 13 | {"name": "server_address", "type": "string"} 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "company_name": "next", 3 | "vpn_address": "45.79.157.168", 4 | "cloudflare_zone_id": "eba5d882ea2aa23f92dfb50fbf7e3cf4", 5 | "cloudflare_domain": "virtualgo.net", 6 | "google_billing_account": "018C15-D3C7AC-4722E8", 7 | "google_org_id": "434699063105", 8 | "ssh_key": "~/secrets/next_ssh" 9 | } 10 | -------------------------------------------------------------------------------- /config/akamai.txt: -------------------------------------------------------------------------------- 1 | ap-west,akamai.mumbai.1 2 | ca-central,akamai.toronto 3 | ap-southeast,akamai.sydney 4 | us-iad,akamai.washington 5 | us-ord,akamai.chicago 6 | fr-par,akamai.paris 7 | us-sea,akamai.seattle 8 | br-gru,akamai.saopaulo 9 | nl-ams,akamai.amsterdam 10 | se-sto,akamai.stockholm 11 | es-mad,akamai.madrid 12 | in-maa,akamai.chennai 13 | jp-osa,akamai.osaka 14 | it-mil,akamai.milan 15 | us-mia,akamai.miami 16 | id-cgk,akamai.jakarta 17 | us-lax,akamai.losangeles 18 | gb-lon,akamai.london 19 | au-mel,akamai.melbourne 20 | in-bom-2,akamai.mumbai.2 21 | sg-sin-2,akamai.singapore.2 22 | us-central,akamai.dallas 23 | us-west,akamai.fremont 24 | us-southeast,akamai.atlanta 25 | us-east,akamai.newyork 26 | eu-west,akamai.london 27 | ap-south,akamai.singapore.1 28 | eu-central,akamai.frankfurt 29 | ap-northeast,akamai.tokyo 30 | -------------------------------------------------------------------------------- /config/multiplay.txt: -------------------------------------------------------------------------------- 1 | uk2group,100tb 2 | UK2,100tb 3 | Midphase,100tb 4 | WestHost,100tb 5 | VELIA,velia 6 | Maxihost,maxihost 7 | MaxiHost,maxihost 8 | maxihost,maxihost 9 | latitude.sh,maxihost 10 | Zenlayer,zenlayer 11 | ZENLAYER,zenlayer 12 | zenlayer,zenlayer 13 | Total server solutions,totalserversolutions 14 | Total Server Solutions,totalserversolutions 15 | totalserversolutions.com,totalserversolutions 16 | TOTAL-SERVER-SOLUTIONS,totalserversolutions 17 | TSS-LONDON,totalserversolutions 18 | Performive,totalserversolutions 19 | Vultr,vultr 20 | vultr,vultr 21 | CHOOP,vultr 22 | Servers.com,serversdotcom 23 | servers.com,serversdotcom 24 | servers.ru,serversdotcom 25 | SERVERS-COM,serversdotcom 26 | Psychz,psychz 27 | Profuse,psychz 28 | PSINet,psychz 29 | Servers Australia,serversaustralia 30 | Datacamp,datapacket 31 | DataCamp,datapacket 32 | DATACAMP,datapacket 33 | HIVELOCITY,hivelocity 34 | Hivelocity,hivelocity 35 | hivelocity,hivelocity 36 | Leaseweb,leaseweb 37 | GoDaddy,godaddy 38 | iWeb Technologies Inc,iweb 39 | G-Core,gcore 40 | G-Core Labs,gcore 41 | -------------------------------------------------------------------------------- /deploy/app.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Network Next App Server 3 | 4 | [Service] 5 | ExecStart=/app/app -race 6 | EnvironmentFile=/app/app.env 7 | Restart=always 8 | RestartSec=30 9 | TimeoutStopSec=90 10 | -------------------------------------------------------------------------------- /deploy/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tag= 4 | bucket= 5 | artifact= 6 | 7 | print_usage() { 8 | printf "Usage: bootstrap.sh -t tag -b bucket_name -a artifact\n\n" 9 | printf "t [string]\tGit tag of release\n" 10 | printf "b [string]\tBucket name on GCP Storage\n" 11 | printf "a [string]\tArtifact name on GCP Storage\n" 12 | 13 | printf "Example:\n\n" 14 | printf "> bootstrap.sh -t dev-007 -b gs://test_network_next_artifacts -a server_backend.tar.gz\n" 15 | } 16 | 17 | while getopts 't:b:a:h' flag; do 18 | case "${flag}" in 19 | t) tag="${OPTARG}" ;; 20 | b) bucket="${OPTARG}" ;; 21 | a) artifact="${OPTARG}" ;; 22 | h) print_usage 23 | exit 1 ;; 24 | *) print_usage 25 | exit 1 ;; 26 | esac 27 | done 28 | 29 | # Create /app dir 30 | rm -rf /app 31 | mkdir -p /app 32 | cd /app 33 | 34 | # Copy libsodium from GCP Storage 35 | gsutil cp "$bucket/$tag/libsodium.so" '/usr/local/lib' 36 | 37 | # Refresh the known libs on the system 38 | ldconfig 39 | 40 | # Copy the required files for the service from GCP Storage 41 | gsutil cp "$bucket/$tag/$artifact" artifact.tar.gz 42 | 43 | # Uncompress the artifact files 44 | tar -xvf artifact.tar.gz 45 | 46 | # Set the app service binary to executable 47 | chmod +x app 48 | 49 | # Copy the Systemd service definition to the right location 50 | cp app.service /etc/systemd/system/app.service 51 | 52 | # Bump up the max socket read and write buffer sizes 53 | sysctl -w net.core.rmem_max=1000000000 54 | sysctl -w net.core.wmem_max=1000000000 55 | 56 | # Reload services 57 | systemctl daemon-reload 58 | -------------------------------------------------------------------------------- /deploy/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes auto; 3 | pid /run/nginx.pid; 4 | include /etc/nginx/modules-enabled/*.conf; 5 | 6 | events { 7 | worker_connections 768; 8 | } 9 | 10 | http { 11 | 12 | sendfile on; 13 | tcp_nopush on; 14 | types_hash_max_size 2048; 15 | 16 | include /etc/nginx/mime.types; 17 | default_type application/octet-stream; 18 | 19 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE 20 | ssl_prefer_server_ciphers on; 21 | 22 | access_log /var/log/nginx/access.log; 23 | error_log /var/log/nginx/error.log; 24 | 25 | gzip on; 26 | 27 | server { 28 | listen 80; 29 | location / { 30 | root /var/www/html; 31 | index index.html; 32 | try_files $uri $uri/ /index.html; 33 | } 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /docker/api.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/api/ /app/cmd/api/ 9 | COPY /envs/docker.bin /app/database.bin 10 | 11 | RUN go build -o api /app/cmd/api/*.go 12 | 13 | EXPOSE 80 14 | 15 | ENV ENV docker 16 | ENV ALLOWED_ORIGIN * 17 | ENV DEBUG_LOGS 1 18 | 19 | CMD [ "/app/api" ] 20 | -------------------------------------------------------------------------------- /docker/base.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM ubuntu:22.04 4 | 5 | WORKDIR /app 6 | 7 | RUN apt update -y && apt upgrade -y && apt install libsodium-dev ca-certificates build-essential curl libcurl4-openssl-dev wget pkg-config -y 8 | 9 | RUN if lscpu | grep -q x86_64 ; then wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz ; else wget https://go.dev/dl/go1.21.4.linux-arm64.tar.gz ; fi 10 | 11 | RUN tar -C /usr/local -xzf go1.21.4.linux-*.tar.gz 12 | 13 | ENV PATH="${PATH}:/usr/local/go/bin" 14 | 15 | RUN go version 16 | 17 | COPY ./go.mod /app/go.mod 18 | COPY ./go.sum /app/go.sum 19 | 20 | RUN go mod download 21 | -------------------------------------------------------------------------------- /docker/client.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY sdk/ /app/sdk/ 8 | COPY cmd/client/ /app/cmd/client/ 9 | 10 | RUN g++ -o libnext.so -Isdk/include sdk/source/*.cpp -shared -fPIC -lsodium -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 11 | RUN g++ -o client -Isdk/include cmd/client/client.cpp libnext.so -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 12 | RUN mv /app/libnext.so /usr/local/lib && ldconfig 13 | 14 | CMD [ "/app/client" ] 15 | -------------------------------------------------------------------------------- /docker/magic_backend.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/magic_backend/ /app/cmd/magic_backend/ 9 | 10 | RUN go build -o magic_backend /app/cmd/magic_backend/*.go 11 | 12 | EXPOSE 80 13 | 14 | ENV ENV docker 15 | 16 | CMD [ "/app/magic_backend" ] 17 | -------------------------------------------------------------------------------- /docker/portal.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM node 4 | 5 | WORKDIR /app 6 | 7 | COPY portal/package*.json ./ 8 | 9 | RUN npm install 10 | 11 | COPY portal/*.js ./ 12 | COPY portal/*.json ./ 13 | COPY portal/.env.* ./ 14 | COPY portal/src ./src 15 | COPY portal/public ./public 16 | 17 | EXPOSE 8080 18 | 19 | CMD [ "yarn", "serve-local" ] 20 | -------------------------------------------------------------------------------- /docker/postgres.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:14-alpine 2 | 3 | ENV POSTGRES_DB postgres 4 | 5 | COPY schemas/sql/create.sql /docker-entrypoint-initdb.d/a.sql 6 | COPY schemas/sql/docker.sql /docker-entrypoint-initdb.d/b.sql 7 | -------------------------------------------------------------------------------- /docker/raspberry_backend.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/raspberry_backend/ /app/cmd/raspberry_backend/ 9 | 10 | RUN go build -o raspberry_backend /app/cmd/raspberry_backend/*.go 11 | 12 | EXPOSE 80 13 | 14 | ENV ENV docker 15 | 16 | CMD [ "/app/raspberry_backend" ] 17 | -------------------------------------------------------------------------------- /docker/raspberry_client.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY sdk/ /app/sdk/ 8 | COPY cmd/raspberry_client/ /app/cmd/raspberry_client/ 9 | 10 | RUN g++ -o libnext.so -Isdk/include sdk/source/*.cpp -shared -fPIC -lsodium -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 11 | RUN g++ -o raspberry_client -Isdk/include cmd/raspberry_client/raspberry_client.cpp libnext.so -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 12 | RUN mv /app/libnext.so /usr/local/lib && ldconfig 13 | 14 | CMD [ "/app/raspberry_client" ] 15 | -------------------------------------------------------------------------------- /docker/raspberry_server.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY sdk/ /app/sdk/ 8 | COPY cmd/raspberry_server/ /app/cmd/raspberry_server/ 9 | 10 | RUN g++ -o libnext.so -Isdk/include sdk/source/*.cpp -shared -fPIC -lsodium -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 11 | RUN g++ -o raspberry_server -Isdk/include cmd/raspberry_server/raspberry_server.cpp libnext.so -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 12 | RUN mv /app/libnext.so /usr/local/lib && ldconfig 13 | 14 | EXPOSE 40000/udp 15 | 16 | CMD [ "/app/raspberry_server" ] 17 | -------------------------------------------------------------------------------- /docker/relay.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY relay/reference /app 8 | 9 | RUN g++ -o relay *.cpp -lsodium -lcurl -lpthread -lm 10 | 11 | EXPOSE 40000/udp 12 | 13 | CMD [ "/app/relay" ] 14 | -------------------------------------------------------------------------------- /docker/relay_backend.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/relay_backend /app/cmd/relay_backend/ 9 | COPY /envs/docker.bin /app/database.bin 10 | 11 | RUN go build -o relay_backend /app/cmd/relay_backend/*.go 12 | 13 | EXPOSE 80 14 | 15 | ENV ENV docker 16 | 17 | CMD [ "/app/relay_backend" ] 18 | -------------------------------------------------------------------------------- /docker/relay_gateway.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/relay_gateway /app/cmd/relay_gateway 9 | COPY /envs/docker.bin /app/database.bin 10 | 11 | RUN go build -o relay_gateway /app/cmd/relay_gateway/*.go 12 | 13 | EXPOSE 80 14 | 15 | ENV ENV docker 16 | 17 | CMD [ "/app/relay_gateway" ] 18 | -------------------------------------------------------------------------------- /docker/server.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY sdk/ /app/sdk/ 8 | COPY cmd/server/ /app/cmd/server/ 9 | 10 | RUN g++ -o libnext.so -Isdk/include sdk/source/*.cpp -shared -fPIC -lsodium -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 11 | RUN g++ -o server -Isdk/include cmd/server/server.cpp libnext.so -lcurl -lpthread -lm -DNEXT_DEVELOPMENT=1 12 | RUN mv /app/libnext.so /usr/local/lib && ldconfig 13 | 14 | EXPOSE 30000/udp 15 | 16 | CMD [ "/app/server" ] 17 | -------------------------------------------------------------------------------- /docker/server_backend.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/server_backend /app/cmd/server_backend 9 | 10 | RUN go build -o server_backend /app/cmd/server_backend/*.go 11 | 12 | EXPOSE 80 13 | 14 | ENV ENV docker 15 | 16 | CMD [ "/app/server_backend" ] 17 | -------------------------------------------------------------------------------- /docker/server_cruncher.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/server_cruncher/ /app/cmd/server_cruncher/ 9 | COPY /envs/docker.bin /app/database.bin 10 | 11 | RUN go build -o server_cruncher /app/cmd/server_cruncher/*.go 12 | 13 | EXPOSE 80 14 | 15 | ENV ENV docker 16 | 17 | CMD [ "/app/server_cruncher" ] 18 | -------------------------------------------------------------------------------- /docker/session_cruncher.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM network_next_base 4 | 5 | WORKDIR /app 6 | 7 | COPY /modules/ /app/modules/ 8 | COPY /cmd/session_cruncher/ /app/cmd/session_cruncher/ 9 | COPY /envs/docker.bin /app/database.bin 10 | 11 | RUN go build -o session_cruncher /app/cmd/session_cruncher/*.go 12 | 13 | EXPOSE 80 14 | 15 | ENV ENV docker 16 | 17 | CMD [ "/app/session_cruncher" ] 18 | -------------------------------------------------------------------------------- /docs/datacenter_and_relay_naming_conventions.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | # Datacenter and relay naming conventions 6 | 7 | A full production system has thousands of datacenters and hundreds of relays. 8 | 9 | Let's keep them all organized with a clear naming convention :) 10 | 11 | ## 1. Datacenter naming convention 12 | 13 | Each datacenter must be named: 14 | 15 | * `[seller].[cityname].[number]` 16 | 17 | For example: 18 | 19 | * google.losangeles.1 20 | * google.losangeles.2 21 | * amazon.virginia.5 22 | 23 | In cases where there is only one datacenter in a city for that seller, the number may be omitted. 24 | 25 | * i3d.istanbul 26 | 27 | When chosing a city name, prefer a cityname as already used for existing relays. This makes it easier to find other relays in the same city, which is a common operation when you are building your relay fleet. 28 | 29 | # Relay naming convention 30 | 31 | Relays must include the datacenter name, followed by a,b,c etc. for each relay in that datacenter. 32 | 33 | * `[datacenter].[a|b|c...]` 34 | 35 | For example: 36 | 37 | * google.losangeles.2.a 38 | * google.losangeles.2.b 39 | * google.losangeles.2.c 40 | * amazon.virginia.1.a 41 | * amazon.virginia.1.b 42 | * i3d.istanbul.a 43 | * i3d.istanbul.b 44 | 45 | In cases where there is only one relay in a datacenter, it is OK to omit the a,b,c if you wish, and then the relay is named the same as the datacenter: 46 | 47 | * google.losangeles.1 48 | 49 | [Back to main documentation](../README.md) 50 | -------------------------------------------------------------------------------- /docs/fork_next_repository.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | # Fork the Network Next repository on github 6 | 7 | To get started you need to fork the 'next' repository to create your own version of the Network Next codebase. 8 | 9 | 1. Create your own github account and organization at http://github.com 10 | 11 | sign up 12 | 13 | 2. Get access to the network next repository. 14 | 15 | Send us an email at support@networknext.com and let us know your github id. 16 | 17 | We will add your github id to the list of accounts authorized to access the network next github repository. 18 | 19 | 3. Navigate to http://github.com/networknext/next 20 | 21 | Screenshot 2023-08-05 at 8 43 04 AM 22 | 23 | 4. Fork the repository to your own github account 24 | 25 | It's OK to fork only the "main" branch. You'll create your own branches in your fork. 26 | 27 | 5. Clone the forked repository into your home directory 28 | 29 | It will create a subdirectory called "next". You can change to this directory at the console with `cd ~/next` at any time. 30 | 31 | Next step: [run a local instance with docker compose](run_local_instance_with_docker_compose.md). 32 | -------------------------------------------------------------------------------- /docs/network_next_terraform_provider.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | # Network Next Terraform provider 6 | 7 | Network Next is configured via a Terraform provider. This provider talks with your REST API running in your environment to query and mutate the contents of the Postgres SQL database that configures Network Next. 8 | 9 | You can see examples of the Network Next Terraform provider in action in the following files: 10 | 11 | * `~/next/terraform/dev/relays/main.tf` 12 | * `~/next/terraform/prod/relays/main.tf` 13 | 14 | And you can read the Network Next Terrafrom provider docs here: https://registry.terraform.io/providers/networknext/networknext/latest/docs 15 | 16 | After you make changes with terraform, always remember to _commit_ your changes to the backend runtime: 17 | 18 | ```console 19 | (terraform changes) 20 | cd ~/next 21 | next database 22 | next commit 23 | ``` 24 | 25 | This extracts the configuration data defined in Postgres and _commits_ it to the backend runtime. This way the essential runtime backend that plans and executes routing is able to operate independently from Postgres, and continues to function even if it is down. 26 | 27 | [Back to main documentation](../README.md) 28 | -------------------------------------------------------------------------------- /docs/run_local_instance_with_docker_compose.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | # Run a local instance with Docker Compose 6 | 7 | You can run a Network Next test environment locally with docker compose on any OS. This lets you quickly get a test instance of the whole system up and running locally, which you can interact with via a web browser. 8 | 9 | 1. Install Docker from http://docker.com 10 | 11 | 2. Change into the directory where you cloned the source 12 | 13 | `cd ~/next` 14 | 15 | 3. Build the system 16 | 17 | `docker compose build` 18 | 19 | 4. Bring the system up 20 | 21 | `docker compose up` 22 | 23 | 5. View the portal 24 | 25 | Navigate to the network next portal at http://127.0.0.1:8080 26 | 27 | It will take a few minutes for the system to fully initialize. Once everything has started up, you should see something like this: 28 | 29 | image 30 | 31 | Congratulations! Network Next up is up and running in docker! 32 | 33 | 6. Take the system down 34 | 35 | `docker compose down` 36 | 37 | Next step: [setup your local machine for development](setup_your_local_machine_for_development.md). 38 | -------------------------------------------------------------------------------- /docs/test_acceleration_to_sao_paolo.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | # Test acceleration to Sao Paulo 6 | 7 | Now we can just go `run client` and it should be accelerated. 8 | 9 | Here is the acceleration I see from New York, over Wi-Fi on Spectrum Cable internet: 10 | 11 | acceleration to sao paulo 12 | 13 | How much acceleration do you see from your location? 14 | 15 | Up next: [Back to main documentation](../README.md). 16 | -------------------------------------------------------------------------------- /envs/dev.env: -------------------------------------------------------------------------------- 1 | # dev environment 2 | 3 | ENV=dev 4 | 5 | NEXT_LOG_LEVEL=4 6 | NEXT_SERVER_BACKEND_HOSTNAME="server-dev.virtualgo.net" 7 | NEXT_BUYER_PUBLIC_KEY="OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 8 | NEXT_BUYER_PRIVATE_KEY="OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 9 | NEXT_RELAY_BACKEND_PUBLIC_KEY="XMZGJsM6tHP2vFBXQZBmXguSNa9Czs8V/pcCfhF2KhU=" 10 | NEXT_SERVER_BACKEND_PUBLIC_KEY="9ShrWyUWRm+twHzd5xJuO3kpH1j9hGuxK2MlfI44x38=" 11 | 12 | API_URL="https://api-dev.virtualgo.net" 13 | 14 | VPN_ADDRESS="45.79.157.168" 15 | 16 | SSH_KEY_FILE="~/secrets/next_ssh" 17 | 18 | RELAY_ARTIFACTS_BUCKET_NAME="next_network_next_relay_artifacts" 19 | 20 | IP2LOCATION_BUCKET_NAME="next_network_next_dev" 21 | 22 | PORTAL_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.SyPxLYb8c4oeneNHi8j1JhxxRjLBJT4oo0lOZeU38i4" 23 | 24 | RELAY_BACKEND_URL="https://relay-dev.virtualgo.net" 25 | 26 | RELAY_BACKEND_PUBLIC_KEY="XMZGJsM6tHP2vFBXQZBmXguSNa9Czs8V/pcCfhF2KhU=" 27 | 28 | SERVER_BACKEND_PUBLIC_KEY="9ShrWyUWRm+twHzd5xJuO3kpH1j9hGuxK2MlfI44x38=" 29 | 30 | RASPBERRY_BACKEND_URL="https://raspberry-dev.virtualgo.net" 31 | -------------------------------------------------------------------------------- /envs/docker.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/envs/docker.bin -------------------------------------------------------------------------------- /envs/empty.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/envs/empty.bin -------------------------------------------------------------------------------- /envs/local.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/envs/local.bin -------------------------------------------------------------------------------- /envs/local.env: -------------------------------------------------------------------------------- 1 | # local environment 2 | 3 | ENV=local 4 | 5 | DEBUG_LOGS=1 6 | 7 | NEXT_LOG_LEVEL=4 8 | NEXT_DATACENTER=local 9 | NEXT_SERVER_BACKEND_HOSTNAME="127.0.0.1" 10 | NEXT_SERVER_BACKEND_PUBLIC_KEY="kbkPE9qsGhseamPgi9R5NWV7iQL1Ekav0P0vVgLzXnY=" 11 | NEXT_RELAY_BACKEND_PUBLIC_KEY="LSSu6JW+6nx9FZ8yf5eu2g3S7NxqIzZEq0AUaRfLrh4=" 12 | NEXT_BUYER_PUBLIC_KEY="OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 13 | NEXT_BUYER_PRIVATE_KEY="OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 14 | 15 | RELAY_NAME=local 16 | RELAY_DEBUG=1 17 | 18 | RELAY_BACKEND_URL="http://127.0.0.1:30000" 19 | 20 | MAGIC_URL=http://127.0.0.1:41007/magic 21 | 22 | ROUTE_MATRIX_URL=http://127.0.0.1:30001/route_matrix 23 | 24 | API_URL="http://127.0.0.1:50000" 25 | 26 | SSH_KEY_FILE="~/secrets/next_ssh" 27 | 28 | ALLOWED_ORIGIN="*" 29 | 30 | PORTAL_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.AQLOiTtd4CSaLkr10PmCGQeWqKu9u_kTKlMn0fKHEEw" 31 | 32 | RELAY_PUBLIC_KEY="peLF27fnP8pXz6AqgH6SM7s90iCOgEI+2rjGrACgGCU=" 33 | RELAY_PRIVATE_KEY="ACQytjHVJca67Tp5RFCe9f/IKEwQLCxjr8xSymqu09E=" 34 | 35 | PING_KEY="27vFfmCMWpdFkXDAHRtDRaeMstAdUcaJM+fMHrY2ZI4=" 36 | 37 | RELAY_BACKEND_PUBLIC_KEY="LSSu6JW+6nx9FZ8yf5eu2g3S7NxqIzZEq0AUaRfLrh4=" 38 | RELAY_BACKEND_PRIVATE_KEY="+IA2a0tW7lnrnq0KThYPX1SZXh7kZAgSsKKjLQTOBoA=" 39 | 40 | SERVER_BACKEND_PUBLIC_KEY="kbkPE9qsGhseamPgi9R5NWV7iQL1Ekav0P0vVgLzXnY=" 41 | SERVER_BACKEND_PRIVATE_KEY="dyM7hpYZ7JTR4oXZSrS4xGrDdW7NOt2v9nki7xx8uW+RuQ8T2qwaGx5qY+CL1Hk1ZXuJAvUSRq/Q/S9WAvNedg==" 42 | 43 | RASPBERRY_BACKEND_URL="http://127.0.0.1:40100" 44 | -------------------------------------------------------------------------------- /envs/prod.env: -------------------------------------------------------------------------------- 1 | # production environment 2 | 3 | ENV=prod 4 | 5 | NEXT_SERVER_BACKEND_HOSTNAME="server.virtualgo.net" 6 | NEXT_RELAY_BACKEND_PUBLIC_KEY="unH/Yxm0C6JCZ1dTGZH2BTBOFhGMcYsOEDURd9qY72w=" 7 | NEXT_SERVER_BACKEND_PUBLIC_KEY="Uycn3KibCfXJo1uM+NNWgCySRzM2Ti3bhvom9XBkxfE=" 8 | NEXT_BUYER_PUBLIC_KEY="OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 9 | NEXT_BUYER_PRIVATE_KEY="OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 10 | 11 | API_URL="https://api.virtualgo.net" 12 | 13 | SSH_KEY_FILE="~/secrets/next_ssh" 14 | 15 | VPN_ADDRESS="45.79.157.168" 16 | 17 | RELAY_ARTIFACTS_BUCKET_NAME="next_network_next_relay_artifacts" 18 | 19 | IP2LOCATION_BUCKET_NAME="next_network_next_prod" 20 | 21 | PORTAL_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.RTbZ1D9G7mRj0kt1HqpEGx9S_lao5-sJnUDgBG0bbIE" 22 | 23 | RELAY_BACKEND_URL="https://relay.virtualgo.net" 24 | 25 | RELAY_BACKEND_PUBLIC_KEY="unH/Yxm0C6JCZ1dTGZH2BTBOFhGMcYsOEDURd9qY72w=" 26 | 27 | SERVER_BACKEND_PUBLIC_KEY="Uycn3KibCfXJo1uM+NNWgCySRzM2Ti3bhvom9XBkxfE=" 28 | -------------------------------------------------------------------------------- /envs/staging.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/envs/staging.bin -------------------------------------------------------------------------------- /envs/staging.env: -------------------------------------------------------------------------------- 1 | # staging environment 2 | 3 | ENV=staging 4 | 5 | NEXT_SERVER_BACKEND_HOSTNAME="server-staging.virtualgo.net" 6 | NEXT_RELAY_BACKEND_PUBLIC_KEY="GwcGxScFxwc6pipXazWOQlz3aTVaNseThiNYtIyd10k=" 7 | NEXT_SERVER_BACKEND_PUBLIC_KEY="P3/d3jmPGQof1jjmF7/1aBd6ytd3bJ8rBp4qdkPlr/M=" 8 | NEXT_BUYER_PUBLIC_KEY="OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 9 | NEXT_BUYER_PRIVATE_KEY="OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 10 | 11 | API_URL="https://api-staging.virtualgo.net" 12 | 13 | SSH_KEY_FILE="~/secrets/next_ssh" 14 | 15 | VPN_ADDRESS="45.79.157.168" 16 | 17 | RELAY_ARTIFACTS_BUCKET_NAME="next_network_next_relay_artifacts" 18 | 19 | IP2LOCATION_BUCKET_NAME="next_network_next_staging" 20 | 21 | PORTAL_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.6rg3er5XroWR54xN7nUWfR6vTwes0qcyR3cld8mjBN0" 22 | 23 | RELAY_BACKEND_URL="https://relay-staging.virtualgo.net" 24 | 25 | RELAY_BACKEND_PUBLIC_KEY="GwcGxScFxwc6pipXazWOQlz3aTVaNseThiNYtIyd10k=" 26 | 27 | SERVER_BACKEND_PUBLIC_KEY="P3/d3jmPGQof1jjmF7/1aBd6ytd3bJ8rBp4qdkPlr/M=" 28 | -------------------------------------------------------------------------------- /modules/common/cost_matrix_test.go: -------------------------------------------------------------------------------- 1 | package common_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/networknext/next/modules/common" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func CostMatrixReadWriteTest(writeMessage *common.CostMatrix, readMessage *common.CostMatrix, t *testing.T) { 12 | 13 | buffer, err := writeMessage.Write() 14 | assert.Nil(t, err) 15 | 16 | err = readMessage.Read(buffer) 17 | assert.Nil(t, err) 18 | 19 | assert.Equal(t, writeMessage, readMessage) 20 | } 21 | 22 | func TestCostMatrixReadWrite(t *testing.T) { 23 | t.Parallel() 24 | writeMessage := common.GenerateRandomCostMatrix(32) 25 | readMessage := common.CostMatrix{} 26 | CostMatrixReadWriteTest(&writeMessage, &readMessage, t) 27 | } 28 | -------------------------------------------------------------------------------- /modules/common/route_matrix_test.go: -------------------------------------------------------------------------------- 1 | package common_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/networknext/next/modules/common" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func RouteMatrixReadWriteTest(writeMessage *common.RouteMatrix, readMessage *common.RouteMatrix, t *testing.T) { 12 | 13 | buffer, err := writeMessage.Write() 14 | assert.Nil(t, err) 15 | 16 | err = readMessage.Read(buffer) 17 | assert.Nil(t, err) 18 | 19 | assert.Equal(t, writeMessage, readMessage) 20 | } 21 | 22 | func TestRouteMatrixReadWrite(t *testing.T) { 23 | t.Parallel() 24 | writeMessage := common.GenerateRandomRouteMatrix(32) 25 | readMessage := common.RouteMatrix{} 26 | RouteMatrixReadWriteTest(&writeMessage, &readMessage, t) 27 | } 28 | -------------------------------------------------------------------------------- /modules/encoding/stream.go: -------------------------------------------------------------------------------- 1 | package encoding 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | type Stream interface { 8 | IsWriting() bool 9 | IsReading() bool 10 | SerializeInteger(value *int32, min int32, max int32) 11 | SerializeBits(value *uint32, bits int) 12 | SerializeUint32(value *uint32) 13 | SerializeBool(value *bool) 14 | SerializeFloat32(value *float32) 15 | SerializeUint64(value *uint64) 16 | SerializeFloat64(value *float64) 17 | SerializeBytes(data []byte) 18 | SerializeString(value *string, maxSize int) 19 | SerializeAlign() 20 | SerializeAddress(addr *net.UDPAddr) 21 | GetAlignBits() int 22 | GetBytesProcessed() int 23 | GetBitsProcessed() int 24 | Error() error 25 | Flush() 26 | } 27 | -------------------------------------------------------------------------------- /modules/packets/packet.go: -------------------------------------------------------------------------------- 1 | package packets 2 | 3 | import ( 4 | "github.com/networknext/next/modules/encoding" 5 | ) 6 | 7 | type Packet interface { 8 | Serialize(stream encoding.Stream) error 9 | } 10 | 11 | func WritePacket[P Packet](packetData []byte, packetObject P) ([]byte, error) { 12 | writeStream := encoding.CreateWriteStream(packetData) 13 | err := packetObject.Serialize(writeStream) 14 | writeStream.Flush() 15 | return packetData[:writeStream.GetBytesProcessed()], err 16 | } 17 | 18 | func ReadPacket[P Packet](packetData []byte, packetObject P) error { 19 | readStream := encoding.CreateReadStream(packetData) 20 | return packetObject.Serialize(readStream) 21 | } 22 | -------------------------------------------------------------------------------- /modules/packets/sdk_version.go: -------------------------------------------------------------------------------- 1 | package packets 2 | 3 | import ( 4 | "fmt" 5 | "github.com/networknext/next/modules/encoding" 6 | ) 7 | 8 | const ( 9 | SDKVersionEqual = iota 10 | SDKVersionOlder 11 | SDKVersionNewer 12 | ) 13 | 14 | type SDKVersion struct { 15 | Major int32 16 | Minor int32 17 | Patch int32 18 | } 19 | 20 | func (version *SDKVersion) Serialize(stream encoding.Stream) error { 21 | stream.SerializeInteger(&version.Major, 0, 255) 22 | stream.SerializeInteger(&version.Minor, 0, 255) 23 | stream.SerializeInteger(&version.Patch, 0, 255) 24 | return stream.Error() 25 | } 26 | 27 | func (a SDKVersion) Compare(b SDKVersion) int { 28 | 29 | if a.Major > b.Major { 30 | return SDKVersionNewer 31 | } else if a.Major < b.Major { 32 | return SDKVersionOlder 33 | } 34 | 35 | if a.Minor > b.Minor { 36 | return SDKVersionNewer 37 | } else if a.Minor < b.Minor { 38 | return SDKVersionOlder 39 | } 40 | 41 | if a.Patch > b.Patch { 42 | return SDKVersionNewer 43 | } else if a.Patch < b.Patch { 44 | return SDKVersionOlder 45 | } 46 | 47 | return SDKVersionEqual 48 | } 49 | 50 | func (a SDKVersion) AtLeast(b SDKVersion) bool { 51 | return a.Compare(b) != SDKVersionOlder 52 | } 53 | 54 | func (v SDKVersion) String() string { 55 | if v.Major == 255 { 56 | return "internal" 57 | } else { 58 | return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /next: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | unset -v latest 4 | for file in tools/next/*.go; do 5 | [[ $file -nt $latest ]] && latest=$file 6 | done 7 | 8 | if [ ! -f ./dist/next ] || [ $latest -nt ./dist/next ]; then 9 | mkdir -p ./dist 10 | go build -o ./dist/next tools/next/*.go || { echo 'failed to build next.go' ; exit 1; } 11 | fi 12 | 13 | ./dist/next "$@" 14 | -------------------------------------------------------------------------------- /portal/.env.dev: -------------------------------------------------------------------------------- 1 | VUE_APP_API_URL=https://api-dev.virtualgo.net 2 | VUE_APP_PORTAL_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.SyPxLYb8c4oeneNHi8j1JhxxRjLBJT4oo0lOZeU38i4 3 | -------------------------------------------------------------------------------- /portal/.env.local: -------------------------------------------------------------------------------- 1 | VUE_APP_API_URL=http://127.0.0.1:50000 2 | VUE_APP_PORTAL_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.AQLOiTtd4CSaLkr10PmCGQeWqKu9u_kTKlMn0fKHEEw 3 | -------------------------------------------------------------------------------- /portal/.env.prod: -------------------------------------------------------------------------------- 1 | VUE_APP_API_URL=https://api.virtualgo.net 2 | VUE_APP_PORTAL_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.RTbZ1D9G7mRj0kt1HqpEGx9S_lao5-sJnUDgBG0bbIE 3 | -------------------------------------------------------------------------------- /portal/.env.staging: -------------------------------------------------------------------------------- 1 | VUE_APP_API_URL=https://api-staging.virtualgo.net 2 | VUE_APP_PORTAL_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsInBvcnRhbCI6dHJ1ZSwiaXNzIjoibmV4dCBrZXlnZW4iLCJpYXQiOjE3NDkyNDcyOTB9.6rg3er5XroWR54xN7nUWfR6vTwes0qcyR3cld8mjBN0 3 | -------------------------------------------------------------------------------- /portal/README.md: -------------------------------------------------------------------------------- 1 | # portal 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | yarn lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /portal/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /portal/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "esnext", 5 | "baseUrl": "./", 6 | "moduleResolution": "node", 7 | "paths": { 8 | "@/*": [ 9 | "src/*" 10 | ] 11 | }, 12 | "lib": [ 13 | "esnext", 14 | "dom", 15 | "dom.iterable", 16 | "scripthost" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /portal/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/portal/public/favicon.ico -------------------------------------------------------------------------------- /portal/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Network Next 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /portal/src/.gitignore: -------------------------------------------------------------------------------- 1 | yarn.lock 2 | .DS_Store 3 | node_modules 4 | -------------------------------------------------------------------------------- /portal/src/assets/logo_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/portal/src/assets/logo_black.png -------------------------------------------------------------------------------- /portal/src/assets/logo_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/portal/src/assets/logo_white.png -------------------------------------------------------------------------------- /portal/src/assets/n_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/portal/src/assets/n_black.png -------------------------------------------------------------------------------- /portal/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | import "bootstrap/dist/css/bootstrap.min.css" 4 | import "bootstrap" 5 | import 'bootstrap-icons/font/bootstrap-icons.css'; 6 | import router from './router' 7 | import 'uplot/dist/uPlot.min.css'; 8 | 9 | createApp(App).use(router).mount('#app') 10 | -------------------------------------------------------------------------------- /portal/src/mitt.js: -------------------------------------------------------------------------------- 1 | import mitt from 'mitt'; 2 | 3 | const emitter = mitt(); 4 | 5 | export default emitter; 6 | -------------------------------------------------------------------------------- /portal/src/views/MapView.vue: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------- 2 | 3 | 14 | 15 | // ---------------------------------------------------- 16 | 17 | 54 | 55 | // ---------------------------------------------------- 56 | 57 | 77 | 78 | // ---------------------------------------------------- 79 | -------------------------------------------------------------------------------- /portal/vue.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('@vue/cli-service') 2 | module.exports = defineConfig({ 3 | transpileDependencies: true 4 | }) 5 | -------------------------------------------------------------------------------- /redis/10000/redis.conf: -------------------------------------------------------------------------------- 1 | port 10000 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /redis/10001/redis.conf: -------------------------------------------------------------------------------- 1 | port 10001 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /redis/10002/redis.conf: -------------------------------------------------------------------------------- 1 | port 10002 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /redis/10003/redis.conf: -------------------------------------------------------------------------------- 1 | port 10003 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /redis/10004/redis.conf: -------------------------------------------------------------------------------- 1 | port 10004 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /redis/10005/redis.conf: -------------------------------------------------------------------------------- 1 | port 10005 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | maxmemory 1gb 6 | maxmemory-policy allkeys-lru 7 | appendonly no 8 | save "" 9 | -------------------------------------------------------------------------------- /relay/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/networknext/relay/client 2 | 3 | go 1.21.7 4 | toolchain go1.24.1 5 | 6 | require golang.org/x/crypto v0.35.0 7 | 8 | require golang.org/x/sys v0.30.0 // indirect 9 | -------------------------------------------------------------------------------- /relay/client/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= 2 | golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= 3 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 4 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 5 | -------------------------------------------------------------------------------- /relay/module/Makefile: -------------------------------------------------------------------------------- 1 | 2 | KERNEL = $(shell uname -r) 3 | 4 | obj-m += relay_module.o 5 | 6 | module: relay_module.c 7 | @echo building relay module 8 | make -C /lib/modules/$(KERNEL)/build M=$(shell pwd) modules 9 | sudo modprobe chacha20 10 | sudo modprobe poly1305 11 | sudo insmod relay_module.ko; echo 12 | -------------------------------------------------------------------------------- /relay/reference/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: all 3 | all: debug 4 | 5 | .PHONY: clean 6 | clean: 7 | rm -f relay 8 | 9 | build: *.h *.cpp 10 | g++ -g *.cpp -lsodium -lcurl -o relay 11 | 12 | build-debug: *.h *.cpp 13 | g++ -DRELAY_DEBUG=1 -g *.cpp -lsodium -lcurl -o relay 14 | 15 | .PHONY: debug 16 | debug: build-debug 17 | RELAY_NAME=debug RELAY_PUBLIC_ADDRESS=192.168.1.40:40000 RELAY_PUBLIC_KEY=XBIAwHE0CppjvPMmtX3TT3QnvmhMbU0KxDpsaFBo+nE= RELAY_PRIVATE_KEY=qlUNbQoc3amdkfNrLflO0Z9/2XJai6zV880AS9cInDc= RELAY_PING_KEY=ANXbw47AaWuu7sidkuw0Cq5cIXU4e8xoqJbSsFC+MT0= RELAY_BACKEND_PUBLIC_KEY=osFv1SPtMkhezNPuLbNbjp/F8ks5I1Y1QVqD0yLd+0o= ./relay 18 | -------------------------------------------------------------------------------- /relay/reference/relay_linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "relay.h" 8 | 9 | #ifndef RELAY_LINUX_H 10 | #define RELAY_LINUX_H 11 | 12 | #if RELAY_PLATFORM == RELAY_PLATFORM_LINUX 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #define RELAY_PLATFORM_HAS_IPV6 1 19 | #define RELAY_PLATFORM_SOCKET_NON_BLOCKING 0 20 | #define RELAY_PLATFORM_SOCKET_BLOCKING 1 21 | 22 | // ------------------------------------- 23 | 24 | typedef int relay_platform_socket_handle_t; 25 | 26 | struct relay_platform_socket_t 27 | { 28 | int type; 29 | relay_platform_socket_handle_t handle; 30 | }; 31 | 32 | // ------------------------------------- 33 | 34 | struct relay_platform_thread_t 35 | { 36 | pthread_t handle; 37 | }; 38 | 39 | typedef void * relay_platform_thread_return_t; 40 | 41 | #define RELAY_PLATFORM_THREAD_RETURN() do { return NULL; } while ( 0 ) 42 | 43 | #define RELAY_PLATFORM_THREAD_FUNC 44 | 45 | typedef relay_platform_thread_return_t (RELAY_PLATFORM_THREAD_FUNC relay_platform_thread_func_t)(void*); 46 | 47 | // ------------------------------------- 48 | 49 | struct relay_platform_mutex_t 50 | { 51 | pthread_mutex_t handle; 52 | }; 53 | 54 | // ------------------------------------- 55 | 56 | #endif // #if RELAY_PLATFORM == RELAY_PLATFORM_LINUX 57 | 58 | #endif // #ifndef RELAY_LINUX_H 59 | -------------------------------------------------------------------------------- /relay/reference/relay_mac.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "relay.h" 8 | 9 | #ifndef RELAY_MAC_H 10 | #define RELAY_MAC_H 11 | 12 | #if RELAY_PLATFORM == RELAY_PLATFORM_MAC 13 | 14 | #include 15 | #include 16 | 17 | #define RELAY_PLATFORM_HAS_IPV6 1 18 | #define RELAY_PLATFORM_SOCKET_NON_BLOCKING 0 19 | #define RELAY_PLATFORM_SOCKET_BLOCKING 1 20 | 21 | // ------------------------------------- 22 | 23 | typedef int relay_platform_socket_handle_t; 24 | 25 | struct relay_platform_socket_t 26 | { 27 | relay_platform_socket_handle_t handle; 28 | }; 29 | 30 | // ------------------------------------- 31 | 32 | struct relay_platform_thread_t 33 | { 34 | pthread_t handle; 35 | }; 36 | 37 | typedef void * relay_platform_thread_return_t; 38 | 39 | #define RELAY_PLATFORM_THREAD_RETURN() do { return NULL; } while ( 0 ) 40 | 41 | #define RELAY_PLATFORM_THREAD_FUNC 42 | 43 | typedef relay_platform_thread_return_t (RELAY_PLATFORM_THREAD_FUNC relay_platform_thread_func_t)(void*); 44 | 45 | // ------------------------------------- 46 | 47 | struct relay_platform_mutex_t 48 | { 49 | pthread_mutex_t handle; 50 | }; 51 | 52 | // ------------------------------------- 53 | 54 | #endif // #if RELAY_PLATFORM == RELAY_PLATFORM_MAC 55 | 56 | #endif // #ifndef RELAY_MAC_H -------------------------------------------------------------------------------- /relay/reference/relay_version.h: -------------------------------------------------------------------------------- 1 | #define RELAY_VERSION "1.0.0" -------------------------------------------------------------------------------- /relay/xdp/relay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #include "relay_constants.h" 6 | #include "relay_version.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef RELAY_DEBUG 14 | #define RELAY_DEBUG 0 15 | #endif // #ifndef RELAY_DEBUG 16 | -------------------------------------------------------------------------------- /relay/xdp/relay_base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_BASE64_H 6 | #define RELAY_BASE64_H 7 | 8 | #include "relay.h" 9 | 10 | int relay_base64_decode_data( const char * input, uint8_t * output, size_t output_size ); 11 | 12 | int relay_base64_decode_string( const char * input, char * output, size_t output_size ); 13 | 14 | #endif // #ifndef RELAY_BASE64_H 15 | -------------------------------------------------------------------------------- /relay/xdp/relay_bpf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_BPF_H 6 | #define RELAY_BPF_H 7 | 8 | #include "relay.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | struct bpf_t 15 | { 16 | #ifdef COMPILE_WITH_BPF 17 | int interface_index; 18 | struct xdp_program * program; 19 | bool attached_native; 20 | bool attached_skb; 21 | int config_fd; 22 | int state_fd; 23 | int stats_fd; 24 | int relay_map_fd; 25 | int session_map_fd; 26 | #endif // #ifdef COMPILE_WITH_BPF 27 | }; 28 | 29 | int bpf_init( struct bpf_t * bpf, uint32_t relay_public_address, uint32_t relay_internal_address ); 30 | 31 | void bpf_shutdown( struct bpf_t * bpf ); 32 | 33 | #endif // #ifndef RELAY_BPF_H 34 | -------------------------------------------------------------------------------- /relay/xdp/relay_config.h: -------------------------------------------------------------------------------- 1 | #ifndef RELAY_CONFIG_H 2 | #define RELAY_CONFIG_H 3 | 4 | #include "relay.h" 5 | 6 | struct config_t 7 | { 8 | char relay_name[256]; 9 | uint16_t relay_port; 10 | uint32_t relay_public_address; 11 | uint32_t relay_internal_address; 12 | uint8_t relay_public_key[RELAY_PUBLIC_KEY_BYTES]; 13 | uint8_t relay_private_key[RELAY_PRIVATE_KEY_BYTES]; 14 | uint8_t relay_backend_public_key[RELAY_BACKEND_PUBLIC_KEY_BYTES]; 15 | uint8_t relay_secret_key[RELAY_SECRET_KEY_BYTES]; 16 | char relay_backend_url[256]; 17 | }; 18 | 19 | int read_config( struct config_t * config ); 20 | 21 | #endif // #ifndef RELAY_CONFIG_H 22 | -------------------------------------------------------------------------------- /relay/xdp/relay_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_DEBUG_H 6 | #define RELAY_DEBUG_H 7 | 8 | #include "relay.h" 9 | 10 | struct debug_t 11 | { 12 | int config_fd; 13 | int state_fd; 14 | int stats_fd; 15 | int relay_map_fd; 16 | int session_map_fd; 17 | uint8_t relay_ping_key[RELAY_PING_KEY_BYTES]; 18 | uint8_t relay_secret_key[RELAY_SECRET_KEY_BYTES]; 19 | }; 20 | 21 | struct config_t; 22 | struct bpf_t; 23 | 24 | int debug_init( struct debug_t * debug, struct config_t * config, struct bpf_t * bpf ); 25 | 26 | int debug_run( struct debug_t * debug ); 27 | 28 | void debug_shutdown( struct debug_t * debug ); 29 | 30 | #endif // #ifndef RELAY_DEBUG_H 31 | -------------------------------------------------------------------------------- /relay/xdp/relay_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_MANAGER_H 6 | #define RELAY_MANAGER_H 7 | 8 | #include "relay.h" 9 | #include "relay_set.h" 10 | #include "relay_ping_stats.h" 11 | 12 | struct relay_manager_t 13 | { 14 | int num_relays; 15 | uint64_t relay_ids[MAX_RELAYS]; 16 | double relay_last_ping_time[MAX_RELAYS]; 17 | uint32_t relay_addresses[MAX_RELAYS]; 18 | uint16_t relay_ports[MAX_RELAYS]; 19 | uint8_t relay_internal[MAX_RELAYS]; 20 | struct relay_ping_history_t * relay_ping_history[MAX_RELAYS]; 21 | }; 22 | 23 | struct relay_manager_t * relay_manager_create(); 24 | 25 | void relay_manager_reset( struct relay_manager_t * manager ); 26 | 27 | void relay_manager_update( struct relay_manager_t * manager, struct relay_set * new_relays, struct relay_set * delete_relays ); 28 | 29 | bool relay_manager_process_pong( struct relay_manager_t * manager, uint32_t from_address, uint16_t from_port, uint64_t sequence ); 30 | 31 | void relay_manager_get_ping_stats( struct relay_manager_t * manager, struct relay_ping_stats_t * ping_stats ); 32 | 33 | void relay_manager_destroy( struct relay_manager_t * manager ); 34 | 35 | #endif // #ifndef RELAY_MANAGER_H 36 | -------------------------------------------------------------------------------- /relay/xdp/relay_messages.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_MESSAGES_H 6 | #define RELAY_MESSAGES_H 7 | 8 | #include "relay.h" 9 | #include "relay_set.h" 10 | #include "relay_ping_stats.h" 11 | 12 | struct relay_control_message 13 | { 14 | uint64_t current_timestamp; 15 | uint8_t current_magic[8]; 16 | uint8_t ping_key[RELAY_PING_KEY_BYTES]; 17 | struct relay_set new_relays; 18 | struct relay_set delete_relays; 19 | }; 20 | 21 | struct relay_stats_message 22 | { 23 | uint64_t pings_sent; 24 | uint64_t bytes_sent; 25 | struct relay_ping_stats_t ping_stats; 26 | }; 27 | 28 | #endif // #ifndef RELAY_MESSAGES_H 29 | -------------------------------------------------------------------------------- /relay/xdp/relay_ping.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_PING_H 6 | #define RELAY_PING_H 7 | 8 | #include "relay.h" 9 | 10 | struct ping_t 11 | { 12 | int relay_port; 13 | uint32_t relay_public_address; 14 | uint32_t relay_internal_address; 15 | struct relay_platform_socket_t * socket; 16 | struct relay_manager_t * relay_manager; 17 | uint64_t current_timestamp; 18 | uint8_t current_magic[8]; 19 | bool has_ping_key; 20 | uint8_t ping_key[RELAY_PING_KEY_BYTES]; 21 | uint64_t pings_sent; 22 | uint64_t bytes_sent; 23 | struct relay_queue_t * control_queue; 24 | struct relay_platform_mutex_t * control_mutex; 25 | struct relay_queue_t * stats_queue; 26 | struct relay_platform_mutex_t * stats_mutex; 27 | int relay_map_fd; 28 | struct relay_platform_thread_t * thread; 29 | }; 30 | 31 | struct config_t; 32 | struct main_t; 33 | struct bpf_t; 34 | 35 | int ping_init( struct ping_t * ping, struct config_t * config, struct main_t * main, struct bpf_t * bpf ); 36 | 37 | void ping_shutdown( struct ping_t * ping ); 38 | 39 | int ping_start_thread( struct ping_t * ping ); 40 | 41 | void ping_join_thread( struct ping_t * ping ); 42 | 43 | void * ping_thread_function( void * context ); 44 | 45 | #endif // #ifndef RELAY_PING_H 46 | -------------------------------------------------------------------------------- /relay/xdp/relay_ping_history.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_PING_HISTORY_H 6 | #define RELAY_PING_HISTORY_H 7 | 8 | #include "relay.h" 9 | 10 | struct relay_ping_history_stats_t 11 | { 12 | float rtt; 13 | float jitter; 14 | float packet_loss; 15 | }; 16 | 17 | struct relay_ping_history_entry_t 18 | { 19 | uint64_t sequence; 20 | double time_ping_sent; 21 | double time_pong_received; 22 | }; 23 | 24 | struct relay_ping_history_t 25 | { 26 | uint64_t sequence; 27 | struct relay_ping_history_entry_t entries[RELAY_PING_HISTORY_SIZE]; 28 | }; 29 | 30 | void relay_ping_history_clear( struct relay_ping_history_t * history ); 31 | 32 | uint64_t relay_ping_history_ping_sent( struct relay_ping_history_t * history, double time ); 33 | 34 | void relay_ping_history_pong_received( struct relay_ping_history_t * history, uint64_t sequence, double time ); 35 | 36 | void relay_ping_history_get_stats( const struct relay_ping_history_t * history, double start, double end, struct relay_ping_history_stats_t * stats, double ping_safety ); 37 | 38 | #endif // #ifndef RELAY_PING_HISTORY_H 39 | -------------------------------------------------------------------------------- /relay/xdp/relay_ping_stats.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_PING_STATS_H 6 | #define RELAY_PING_STATS_H 7 | 8 | #include "relay.h" 9 | 10 | struct relay_ping_stats_t 11 | { 12 | int num_relays; 13 | uint64_t relay_ids[MAX_RELAYS]; 14 | float relay_rtt[MAX_RELAYS]; 15 | float relay_jitter[MAX_RELAYS]; 16 | float relay_packet_loss[MAX_RELAYS]; 17 | }; 18 | 19 | #endif // #ifndef RELAY_PING_STATS_H 20 | -------------------------------------------------------------------------------- /relay/xdp/relay_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_SET_H 6 | #define RELAY_SET_H 7 | 8 | #include "relay.h" 9 | 10 | struct relay_set 11 | { 12 | int num_relays; 13 | uint64_t id[MAX_RELAYS]; 14 | uint32_t address[MAX_RELAYS]; 15 | uint16_t port[MAX_RELAYS]; 16 | uint8_t internal[MAX_RELAYS]; 17 | }; 18 | 19 | #endif // #ifndef RELAY_SET_H 20 | -------------------------------------------------------------------------------- /relay/xdp/relay_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next XDP Relay 3 | */ 4 | 5 | #ifndef RELAY_VERSION_H 6 | #define RELAY_VERSION_H 7 | 8 | #define RELAY_VERSION "1.0.0" 9 | 10 | #define RELAY_VERSION_LENGTH 32 11 | 12 | #endif // #ifndef RELAY_VERSION_H 13 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | unset -v latest 4 | for file in tools/run/*.go; do 5 | [[ $file -nt $latest ]] && latest=$file 6 | done 7 | 8 | if [ ! -f ./dist/run ] || [ $latest -nt ./dist/run ]; then 9 | mkdir -p ./dist 10 | go build -o ./dist/run tools/run/*.go || { echo 'failed to build run.go' ; exit 1; } 11 | fi 12 | 13 | ./dist/run "$@" 14 | -------------------------------------------------------------------------------- /schemas/bigquery/relay_to_relay_ping.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "timestamp", 4 | "type": "TIMESTAMP", 5 | "mode": "REQUIRED", 6 | "description": "The timestamp when the relay ping occurred" 7 | }, 8 | { 9 | "name": "source_relay_id", 10 | "type": "INT64", 11 | "mode": "REQUIRED", 12 | "description": "The id of the source relay" 13 | }, 14 | { 15 | "name": "destination_relay_id", 16 | "type": "INT64", 17 | "mode": "REQUIRED", 18 | "description": "The id of the destination relay" 19 | }, 20 | { 21 | "name": "rtt", 22 | "type": "INT64", 23 | "mode": "REQUIRED", 24 | "description": "Round trip latency between the two relays (milliseconds)" 25 | }, 26 | { 27 | "name": "jitter", 28 | "type": "INT64", 29 | "mode": "REQUIRED", 30 | "description": "Time variance in latency between the two relays (milliseconds)" 31 | }, 32 | 33 | { 34 | "name": "packet_loss", 35 | "type": "FLOAT64", 36 | "mode": "REQUIRED", 37 | "description": "The packet loss between the two relays (%)" 38 | } 39 | ] 40 | -------------------------------------------------------------------------------- /schemas/bigquery/server_init.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "timestamp", 4 | "type": "TIMESTAMP", 5 | "mode": "REQUIRED", 6 | "description": "The timestamp when the server init occurred" 7 | }, 8 | { 9 | "name": "sdk_version_major", 10 | "type": "INT64", 11 | "mode": "REQUIRED", 12 | "description": "The major SDK version number on the server" 13 | }, 14 | { 15 | "name": "sdk_version_minor", 16 | "type": "INT64", 17 | "mode": "REQUIRED", 18 | "description": "The minor SDK version number on the server" 19 | }, 20 | { 21 | "name": "sdk_version_patch", 22 | "type": "INT64", 23 | "mode": "REQUIRED", 24 | "description": "The patch SDK version number on the server" 25 | }, 26 | { 27 | "name": "buyer_id", 28 | "type": "INT64", 29 | "mode": "REQUIRED", 30 | "description": "The buyer this server belongs to" 31 | }, 32 | { 33 | "name": "datacenter_id", 34 | "type": "INT64", 35 | "mode": "REQUIRED", 36 | "description": "The datacenter this server is in" 37 | }, 38 | { 39 | "name": "datacenter_name", 40 | "type": "STRING", 41 | "mode": "REQUIRED", 42 | "description": "The name of the datacenter, for example: 'google.iowa.1'" 43 | }, 44 | { 45 | "name": "server_address", 46 | "type": "STRING", 47 | "mode": "REQUIRED", 48 | "description": "The address and port of the server, for example: '123.254.10.5:40000'" 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /schemas/bigquery/server_relay_ping.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "timestamp", 4 | "type": "TIMESTAMP", 5 | "mode": "REQUIRED", 6 | "description": "The timestamp when the server relay pings occurred" 7 | }, 8 | { 9 | "name": "buyer_id", 10 | "type": "INT64", 11 | "mode": "REQUIRED", 12 | "description": "The buyer the server belongs to" 13 | }, 14 | { 15 | "name": "session_id", 16 | "type": "INT64", 17 | "mode": "REQUIRED", 18 | "description": "Unique id for the session" 19 | }, 20 | { 21 | "name": "datacenter_id", 22 | "type": "INT64", 23 | "mode": "REQUIRED", 24 | "description": "The datacenter the server is in" 25 | }, 26 | { 27 | "name": "server_address", 28 | "type": "STRING", 29 | "mode": "REQUIRED", 30 | "description": "Server address and port number" 31 | }, 32 | { 33 | "name": "server_relay_id", 34 | "type": "INT64", 35 | "mode": "REQUIRED", 36 | "description": "Relay id being pinged by the server" 37 | }, 38 | { 39 | "name": "server_relay_rtt", 40 | "type": "INT64", 41 | "mode": "REQUIRED", 42 | "description": "Round trip time ping between the server and the relay (milliseconds)" 43 | }, 44 | { 45 | "name": "server_relay_jitter", 46 | "type": "INT64", 47 | "mode": "REQUIRED", 48 | "description": "Jitter between the server and the relay (milliseconds)" 49 | }, 50 | { 51 | "name": "server_relay_packet_loss", 52 | "type": "FLOAT64", 53 | "mode": "REQUIRED", 54 | "description": "Packet loss between the server and the relay (%)" 55 | } 56 | ] 57 | -------------------------------------------------------------------------------- /schemas/bigquery/server_update.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "timestamp", 4 | "type": "TIMESTAMP", 5 | "mode": "REQUIRED", 6 | "description": "The timestamp when the server update occurred" 7 | }, 8 | { 9 | "name": "sdk_version_major", 10 | "type": "INT64", 11 | "mode": "REQUIRED", 12 | "description": "The major SDK version number on the server" 13 | }, 14 | { 15 | "name": "sdk_version_minor", 16 | "type": "INT64", 17 | "mode": "REQUIRED", 18 | "description": "The minor SDK version number on the server" 19 | }, 20 | { 21 | "name": "sdk_version_patch", 22 | "type": "INT64", 23 | "mode": "REQUIRED", 24 | "description": "The patch SDK version number on the server" 25 | }, 26 | { 27 | "name": "buyer_id", 28 | "type": "INT64", 29 | "mode": "REQUIRED", 30 | "description": "The buyer this server belongs to" 31 | }, 32 | { 33 | "name": "datacenter_id", 34 | "type": "INT64", 35 | "mode": "REQUIRED", 36 | "description": "The datacenter this server is in" 37 | }, 38 | { 39 | "name": "server_address", 40 | "type": "STRING", 41 | "mode": "REQUIRED", 42 | "description": "The address and port of the server, for example: '123.254.10.5:40000'" 43 | }, 44 | { 45 | "name": "num_sessions", 46 | "type": "INT64", 47 | "mode": "REQUIRED", 48 | "description": "The number of client sessions currently connected to the server" 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /schemas/pubsub/client_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "client_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "buyer_id", "type": "long"}, 8 | {"name": "session_id", "type": "long"}, 9 | {"name": "user_hash", "type": "long"}, 10 | {"name": "latitude", "type": "float"}, 11 | {"name": "longitude", "type": "float"}, 12 | {"name": "client_address", "type": "string"}, 13 | {"name": "connection_type", "type": "int"}, 14 | {"name": "platform_type", "type": "int"}, 15 | {"name": "client_relay_id", "type": "long"}, 16 | {"name": "client_relay_rtt", "type": "int"}, 17 | {"name": "client_relay_jitter", "type": "int"}, 18 | {"name": "client_relay_packet_loss", "type": "float"} 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /schemas/pubsub/relay_to_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "relay_to_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "source_relay_id", "type": "long"}, 8 | {"name": "destination_relay_id", "type": "long"}, 9 | {"name": "rtt", "type": "int"}, 10 | {"name": "jitter", "type": "int"}, 11 | {"name": "packet_loss", "type": "float"} 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /schemas/pubsub/relay_update.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "relay_update", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "relay_id", "type": "long"}, 8 | {"name": "session_count", "type": "int"}, 9 | {"name": "max_sessions", "type": "int"}, 10 | {"name": "envelope_bandwidth_up_kbps", "type": "long"}, 11 | {"name": "envelope_bandwidth_down_kbps", "type": "long"}, 12 | {"name": "packets_sent_per_second", "type": "float"}, 13 | {"name": "packets_received_per_second", "type": "float"}, 14 | {"name": "bandwidth_sent_kbps", "type": "float"}, 15 | {"name": "bandwidth_received_kbps", "type": "float"}, 16 | {"name": "client_pings_per_second", "type": "float"}, 17 | {"name": "server_pings_per_second", "type": "float"}, 18 | {"name": "relay_pings_per_second", "type": "float"}, 19 | {"name": "relay_flags", "type": "long"}, 20 | {"name": "num_routable", "type": "int"}, 21 | {"name": "num_unroutable", "type": "int"}, 22 | {"name": "start_time", "type": "long"}, 23 | {"name": "current_time", "type": "long"}, 24 | {"name": "relay_counters", "type": {"type": "array", "items": "long"}} 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /schemas/pubsub/server_init.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_init", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "sdk_version_major", "type": "int"}, 8 | {"name": "sdk_version_minor", "type": "int"}, 9 | {"name": "sdk_version_patch", "type": "int"}, 10 | {"name": "buyer_id", "type": "long"}, 11 | {"name": "datacenter_id", "type": "long"}, 12 | {"name": "datacenter_name", "type": "string"}, 13 | {"name": "server_address", "type": "string"} 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /schemas/pubsub/server_relay_ping.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_relay_ping", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "buyer_id", "type": "long"}, 8 | {"name": "session_id", "type": "long"}, 9 | {"name": "datacenter_id", "type": "long"}, 10 | {"name": "server_address", "type": "string"}, 11 | {"name": "server_relay_id", "type": "long"}, 12 | {"name": "server_relay_rtt", "type": "int"}, 13 | {"name": "server_relay_jitter", "type": "int"}, 14 | {"name": "server_relay_packet_loss", "type": "float"} 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /schemas/pubsub/server_update.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "record", 3 | "name": "server_update", 4 | "namespace": "com.networknext.avro", 5 | "fields" : [ 6 | {"name": "timestamp", "type": {"type": "long", "logicalType": "timestamp-micros"}}, 7 | {"name": "sdk_version_major", "type": "int"}, 8 | {"name": "sdk_version_minor", "type": "int"}, 9 | {"name": "sdk_version_patch", "type": "int"}, 10 | {"name": "buyer_id", "type": "long"}, 11 | {"name": "datacenter_id", "type": "long"}, 12 | {"name": "num_sessions", "type": "int"}, 13 | {"name": "server_address", "type": "string"} 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /schemas/sql/destroy.sql: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE IF EXISTS buyers CASCADE; 3 | DROP TABLE IF EXISTS sellers CASCADE; 4 | DROP TABLE IF EXISTS route_shaders CASCADE; 5 | DROP TABLE IF EXISTS datacenters CASCADE; 6 | DROP TABLE IF EXISTS relays CASCADE; 7 | DROP TABLE IF EXISTS buyer_datacenter_settings CASCADE; 8 | DROP TABLE IF EXISTS buyer_keypairs CASCADE; 9 | DROP TABLE IF EXISTS relay_keypairs CASCADE; 10 | -------------------------------------------------------------------------------- /scripts/all_commands.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | find cmd -type f -name '*.go' | sed -r 's|[^/]+$||' | sed -r 's|cmd/||' | sed -r 's|/$||' | sort | uniq | awk '{printf "dist/%s\n", $0}' 3 | -------------------------------------------------------------------------------- /scripts/tabs2spaces.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | find . -name "*.cpp" | xargs sed -i .original -e 's/\t/ /g' 3 | find . -name "*.c" | xargs sed -i .original -e 's/\t/ /g' 4 | find . -name "*.h" | xargs sed -i .original -e 's/\t/ /g' 5 | find . -name "*.original" -delete 6 | -------------------------------------------------------------------------------- /sdk/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .DS_Store 3 | *.swp 4 | *.o 5 | *.d 6 | bin 7 | obj 8 | Makefile 9 | *.make 10 | *.txt 11 | Debug 12 | Release 13 | *_Debug 14 | *_Release 15 | .vs 16 | *.vcproj.* 17 | *.vcxproj.* 18 | *.prx -------------------------------------------------------------------------------- /sdk/README.md: -------------------------------------------------------------------------------- 1 | Network Next 2 | 3 |
4 | 5 | [![Build Status](https://networknext.semaphoreci.com/badges/sdk/branches/main.svg?style=shields&key=d4176cdc-3556-4890-b988-95ee6d019b76)](https://networknext.semaphoreci.com/projects/sdk) 6 | [![Documentation Status](https://readthedocs.com/projects/network-next-sdk/badge/?version=latest)](https://network-next-sdk.readthedocs-hosted.com/en/latest/?badge=latest) 7 | 8 | ## Network Next SDK 9 | 10 | Documentation: 11 | 12 | * https://network-next-sdk.readthedocs-hosted.com/en/latest/ 13 | 14 | Supported platforms: 15 | 16 | * Windows 17 | * Linux 18 | * Mac 19 | * PS4 20 | * PS5 21 | * XBox One 22 | * XBox Series X 23 | * Nintendo Switch 24 | -------------------------------------------------------------------------------- /sdk/build/gdk/Icon-150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/Icon-150.png -------------------------------------------------------------------------------- /sdk/build/gdk/Icon-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/Icon-44.png -------------------------------------------------------------------------------- /sdk/build/gdk/Icon-480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/Icon-480.png -------------------------------------------------------------------------------- /sdk/build/gdk/MicrosoftGame.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 13 | 14 | 15 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sdk/build/gdk/SplashScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/SplashScreen.png -------------------------------------------------------------------------------- /sdk/build/gdk/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/StoreLogo.png -------------------------------------------------------------------------------- /sdk/build/gdk/WideLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/WideLogo.png -------------------------------------------------------------------------------- /sdk/build/gdk/client.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/gdk/client.cpp -------------------------------------------------------------------------------- /sdk/build/gdk/pch.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // pch.cpp 3 | // Include the standard header and generate the precompiled header. 4 | // 5 | 6 | #include "pch.h" 7 | -------------------------------------------------------------------------------- /sdk/build/gdk/pch.h: -------------------------------------------------------------------------------- 1 | // 2 | // pch.h 3 | // Header for standard system include files. 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | #define _WIN32_WINNT 0x0A00 10 | #include 11 | 12 | // Use the C++ standard templated min/max 13 | #define NOMINMAX 14 | 15 | // DirectX apps don't need GDI 16 | #define NODRAWTEXT 17 | #define NOGDI 18 | #define NOBITMAP 19 | 20 | // Include if you need this 21 | #define NOMCX 22 | 23 | // Include if you need this 24 | #define NOSERVICE 25 | 26 | // WinHelp is deprecated 27 | #define NOHELP 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #ifdef _GAMING_XBOX_SCARLETT 35 | #include 36 | #include 37 | #else 38 | #include 39 | #include 40 | #endif 41 | 42 | #include 43 | 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #include 53 | #include 54 | 55 | #include 56 | 57 | #include "next.h" 58 | #include "next_tests.h" 59 | #include "next_platform.h" -------------------------------------------------------------------------------- /sdk/build/ps4/client.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/ps4/client.cpp -------------------------------------------------------------------------------- /sdk/build/ps4/ps4.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "next", "next.vcxproj", "{B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client.vcxproj", "{02A0BE82-AAD0-4ADE-983F-E301E8F25C55}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} = {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|ORBIS = Debug|ORBIS 16 | Release|ORBIS = Release|ORBIS 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|ORBIS.ActiveCfg = Debug|ORBIS 20 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|ORBIS.Build.0 = Debug|ORBIS 21 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|ORBIS.ActiveCfg = Release|ORBIS 22 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|ORBIS.Build.0 = Release|ORBIS 23 | {02A0BE82-AAD0-4ADE-983F-E301E8F25C55}.Debug|ORBIS.ActiveCfg = Debug|ORBIS 24 | {02A0BE82-AAD0-4ADE-983F-E301E8F25C55}.Debug|ORBIS.Build.0 = Debug|ORBIS 25 | {02A0BE82-AAD0-4ADE-983F-E301E8F25C55}.Release|ORBIS.ActiveCfg = Release|ORBIS 26 | {02A0BE82-AAD0-4ADE-983F-E301E8F25C55}.Release|ORBIS.Build.0 = Release|ORBIS 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {2B2A9720-D0B0-4107-B517-6CD9B0C3F4D0} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /sdk/build/ps5/client.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/ps5/client.cpp -------------------------------------------------------------------------------- /sdk/build/ps5/ps5.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "next", "next.vcxproj", "{07557A06-FB1F-400F-879E-FBA6BA863732}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client.vcxproj", "{E0041F5E-3BA5-479A-8923-1675DC5009AB}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {07557A06-FB1F-400F-879E-FBA6BA863732} = {07557A06-FB1F-400F-879E-FBA6BA863732} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Prospero = Debug|Prospero 16 | Release|Prospero = Release|Prospero 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {07557A06-FB1F-400F-879E-FBA6BA863732}.Debug|Prospero.ActiveCfg = Debug|Prospero 20 | {07557A06-FB1F-400F-879E-FBA6BA863732}.Debug|Prospero.Build.0 = Debug|Prospero 21 | {07557A06-FB1F-400F-879E-FBA6BA863732}.Release|Prospero.ActiveCfg = Release|Prospero 22 | {07557A06-FB1F-400F-879E-FBA6BA863732}.Release|Prospero.Build.0 = Release|Prospero 23 | {E0041F5E-3BA5-479A-8923-1675DC5009AB}.Debug|Prospero.ActiveCfg = Debug|Prospero 24 | {E0041F5E-3BA5-479A-8923-1675DC5009AB}.Debug|Prospero.Build.0 = Debug|Prospero 25 | {E0041F5E-3BA5-479A-8923-1675DC5009AB}.Release|Prospero.ActiveCfg = Release|Prospero 26 | {E0041F5E-3BA5-479A-8923-1675DC5009AB}.Release|Prospero.Build.0 = Release|Prospero 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {753A2603-524B-40FE-910E-F3359F94A952} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /sdk/build/switch/Application.aarch64.lp64.nmeta: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Network Next 5 | True 6 | 0x01004b9000490000 7 | 0x00100000 8 | AddressSpace64Bit 9 | 10 | 11 | 12 | <Language>AmericanEnglish</Language> 13 | <Name>Network Next</Name> 14 | <Publisher>Network Next, Inc.</Publisher> 15 | 16 | 17 | AmericanEnglish 18 | NintendoSDK_Application.bmp 19 | 20 | 0 21 | 1.0.0 22 | None 23 | AmericanEnglish 24 | Allow 25 | None 26 | 0x0000000000400000 27 | 0x0000000000100000 28 | LicensedByNintendo 29 | Auto 30 | 31 | ESRB 32 | 0 33 | 34 | Enable 35 | Deny 36 | Deny 37 | None 38 | 39 | -------------------------------------------------------------------------------- /sdk/build/switch/ImportNintendoSdk.props: -------------------------------------------------------------------------------- 1 |  2 | 13 | 14 | 17 | 18 | 21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sdk/build/switch/NintendoSDK_Application.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/build/switch/NintendoSDK_Application.bmp -------------------------------------------------------------------------------- /sdk/build/switch/switch.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34525.116 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "next", "next.vcxproj", "{B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client.vcxproj", "{11E96471-142F-4770-B4DC-C861C1F26077}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} = {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|NX64 = Debug|NX64 16 | Release|NX64 = Release|NX64 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|NX64.ActiveCfg = Debug|NX64 20 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|NX64.Build.0 = Debug|NX64 21 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|NX64.ActiveCfg = Release|NX64 22 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|NX64.Build.0 = Release|NX64 23 | {11E96471-142F-4770-B4DC-C861C1F26077}.Debug|NX64.ActiveCfg = Debug|NX64 24 | {11E96471-142F-4770-B4DC-C861C1F26077}.Debug|NX64.Build.0 = Debug|NX64 25 | {11E96471-142F-4770-B4DC-C861C1F26077}.Release|NX64.ActiveCfg = Release|NX64 26 | {11E96471-142F-4770-B4DC-C861C1F26077}.Release|NX64.Build.0 = Release|NX64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {2B2A9720-D0B0-4107-B517-6CD9B0C3F4D0} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /sdk/build/win32/win32.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "next", "next.vcxproj", "{B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client.vcxproj", "{71DAABCE-CD14-4A7B-9DD0-9D764A938012}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} = {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x86 = Debug|x86 16 | Release|x86 = Release|x86 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|x86.ActiveCfg = Debug|Win32 20 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Debug|x86.Build.0 = Debug|Win32 21 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|x86.ActiveCfg = Release|Win32 22 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5EC4}.Release|x86.Build.0 = Release|Win32 23 | {71DAABCE-CD14-4A7B-9DD0-9D764A938012}.Debug|x86.ActiveCfg = Debug|Win32 24 | {71DAABCE-CD14-4A7B-9DD0-9D764A938012}.Debug|x86.Build.0 = Debug|Win32 25 | {71DAABCE-CD14-4A7B-9DD0-9D764A938012}.Release|x86.ActiveCfg = Release|Win32 26 | {71DAABCE-CD14-4A7B-9DD0-9D764A938012}.Release|x86.Build.0 = Release|Win32 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {2B2A9720-D0B0-4107-B517-6CD9B0C3F4D0} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /sdk/build/win64/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | #include "next_tests.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | printf("\nRunning tests...\n\n"); 17 | 18 | next_log_level(NEXT_LOG_LEVEL_NONE); 19 | 20 | if (next_init(NULL, NULL) != NEXT_OK) 21 | { 22 | printf("error: failed to initialize network next\n"); 23 | } 24 | 25 | next_log_level(NEXT_LOG_LEVEL_NONE); 26 | 27 | next_run_tests(); 28 | 29 | next_term(); 30 | 31 | fflush(stdout); 32 | 33 | printf("\nAll tests completed successfully!\n\n"); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /sdk/build/win64/win64.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "next", "next.vcxproj", "{E650B123-793B-4AFB-82DD-2EF900B47C01}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client.vcxproj", "{B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5E13}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {E650B123-793B-4AFB-82DD-2EF900B47C01} = {E650B123-793B-4AFB-82DD-2EF900B47C01} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x64 = Debug|x64 16 | Release|x64 = Release|x64 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {E650B123-793B-4AFB-82DD-2EF900B47C01}.Debug|x64.ActiveCfg = Debug|x64 20 | {E650B123-793B-4AFB-82DD-2EF900B47C01}.Debug|x64.Build.0 = Debug|x64 21 | {E650B123-793B-4AFB-82DD-2EF900B47C01}.Release|x64.ActiveCfg = Release|x64 22 | {E650B123-793B-4AFB-82DD-2EF900B47C01}.Release|x64.Build.0 = Release|x64 23 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5E13}.Debug|x64.ActiveCfg = Debug|x64 24 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5E13}.Debug|x64.Build.0 = Debug|x64 25 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5E13}.Release|x64.ActiveCfg = Release|x64 26 | {B967AF8F-9BA7-4EF8-8ADC-BA0FFBDA5E13}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {2B2A9720-D0B0-4107-B517-6CD9B0C3F4D0} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /sdk/docs/source/building_the_sdk.rst: -------------------------------------------------------------------------------- 1 | 2 | Building the SDK 3 | ================ 4 | 5 | To build the example programs, see the instructions for your platform below: 6 | 7 | Windows 8 | ------- 9 | 10 | Install *premake5* from https://premake.github.io/download.html 11 | 12 | Generate a visual studio solution by running premake at the root directory of the SDK: 13 | 14 | .. code-block:: console 15 | 16 | $ premake5 vs2019 17 | 18 | Open the generated solution file under the "visualstudio" directory and build all. 19 | 20 | Mac 21 | --- 22 | 23 | Make sure the XCode command line tools are installed: 24 | 25 | .. code-block:: console 26 | 27 | $ xcode-select --install 28 | 29 | Install *premake5* from https://premake.github.io/download.html 30 | 31 | Generate makefiles by running premake at the root directory of the SDK: 32 | 33 | .. code-block:: console 34 | 35 | $ premake5 gmake 36 | 37 | Build the SDK: 38 | 39 | .. code-block:: console 40 | 41 | $ make -j 42 | 43 | Run the unit tests: 44 | 45 | .. code-block:: console 46 | 47 | $ ./bin/test 48 | 49 | Linux 50 | ----- 51 | 52 | Make sure the build essential package is installed: 53 | 54 | .. code-block:: console 55 | 56 | $ sudo apt install build-essential 57 | 58 | Install *premake5* from https://premake.github.io/download.html 59 | 60 | Generate makefiles by running premake at the root directory of the SDK: 61 | 62 | .. code-block:: console 63 | 64 | $ premake5 gmake 65 | 66 | Build the SDK: 67 | 68 | .. code-block:: console 69 | 70 | $ make -j 71 | 72 | Run the unit tests: 73 | 74 | .. code-block:: console 75 | 76 | $ ./bin/test 77 | -------------------------------------------------------------------------------- /sdk/docs/source/contents.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | Welcome to the Network Next SDK! 5 | 6 | To get started, build the SDK and check out the example programs below. 7 | 8 | Read more 9 | --------- 10 | 11 | .. toctree:: 12 | :maxdepth: 1 13 | 14 | building_the_sdk 15 | simple_client_example 16 | simple_server_example 17 | upgraded_client_example 18 | upgraded_server_example 19 | complex_client_example 20 | complex_server_example 21 | reference 22 | -------------------------------------------------------------------------------- /sdk/docs/source/images/client_server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/client_server.png -------------------------------------------------------------------------------- /sdk/docs/source/images/downloads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/downloads.png -------------------------------------------------------------------------------- /sdk/docs/source/images/get_access.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/get_access.png -------------------------------------------------------------------------------- /sdk/docs/source/images/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/map.png -------------------------------------------------------------------------------- /sdk/docs/source/images/public_key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/public_key.png -------------------------------------------------------------------------------- /sdk/docs/source/images/session_drill_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/session_drill_in.png -------------------------------------------------------------------------------- /sdk/docs/source/images/sessions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/sessions.png -------------------------------------------------------------------------------- /sdk/docs/source/images/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknext/next/ed60de48abe4aebace2038d03a0543d1239335cc/sdk/docs/source/images/settings.png -------------------------------------------------------------------------------- /sdk/docs/source/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. include:: contents.rst -------------------------------------------------------------------------------- /sdk/docs/source/reference.rst: -------------------------------------------------------------------------------- 1 | 2 | Reference 3 | --------- 4 | 5 | To use the Network Next SDK, replace the socket on your client with *next_client_t* and the socket on your server with *next_server_t*. 6 | 7 | The client and server objects provide an interface for sending and receiving packets, much like sendto and recvfrom, extend that they monitor each player's network connection, and steer packets across Network Next, when we find a route that meets your network optimization requirements. 8 | 9 | If our system is down for any reason, the client and server simply fall back to sending packets over the public internet, without any disruption for your players. 10 | 11 | .. toctree:: 12 | :maxdepth: 1 13 | 14 | next_client_t 15 | next_server_t 16 | next_address_t 17 | globals 18 | env -------------------------------------------------------------------------------- /sdk/docs/source/requirements.txt: -------------------------------------------------------------------------------- 1 | # Defining the exact version will make sure things don't break 2 | sphinx==5.3.0 3 | sphinx_rtd_theme==1.1.1 4 | readthedocs-sphinx-search==0.3.2 5 | -------------------------------------------------------------------------------- /sdk/docs/source/simple_server_example.rst: -------------------------------------------------------------------------------- 1 | 2 | Simple Server Example 3 | --------------------- 4 | 5 | In this example we setup the simplest possible server using Network Next. 6 | 7 | First, initialize the SDK: 8 | 9 | .. code-block:: c++ 10 | 11 | if ( next_init( NULL, NULL ) != NEXT_OK ) 12 | { 13 | printf( "error: could not initialize network next\n" ); 14 | return 1; 15 | } 16 | 17 | Next, define a function to be called when packets are received from clients. 18 | 19 | Here is one that reflects the packet back to the client that sent it: 20 | 21 | .. code-block:: c++ 22 | 23 | void server_packet_received( next_server_t * server, void * context, const next_address_t * from, const uint8_t * packet_data, int packet_bytes ) 24 | { 25 | next_server_send_packet( server, from, packet_data, packet_bytes ); 26 | } 27 | 28 | Now create the server. 29 | 30 | In this example, we bind the server to port 50000 on 127.0.0.1 IPv4 address (localhost) and set the datacenter where your server is running to "local": 31 | 32 | .. code-block:: c++ 33 | 34 | next_server_t * server = next_server_create( NULL, "127.0.0.1:50000", "0.0.0.0:50000", "local", server_packet_received ); 35 | if ( server == NULL ) 36 | { 37 | printf( "error: failed to create server\n" ); 38 | return 1; 39 | } 40 | 41 | Make sure the server gets updated every frame: 42 | 43 | .. code-block:: c++ 44 | 45 | next_server_update( server ); 46 | 47 | When you have finished using your server, please flush and destroy it: 48 | 49 | .. code-block:: c++ 50 | 51 | next_server_flush( server); 52 | 53 | next_server_destroy( server ); 54 | 55 | Before your application terminates, please shut down the SDK: 56 | 57 | .. code-block:: c++ 58 | 59 | next_term(); 60 | -------------------------------------------------------------------------------- /sdk/include/next_address.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_ADDRESS_H 8 | #define NEXT_ADDRESS_H 9 | 10 | #include "next.h" 11 | 12 | #include 13 | 14 | #ifndef NEXT_ADDRESS_ALREADY_DEFINED 15 | #define NEXT_ADDRESS_ALREADY_DEFINED 16 | struct next_address_t 17 | { 18 | union { uint32_t ip; uint8_t ipv4[4]; uint16_t ipv6[8]; } data; 19 | uint16_t port; 20 | uint8_t type; 21 | }; 22 | #endif 23 | 24 | NEXT_EXPORT_FUNC int next_address_parse( struct next_address_t * address, const char * address_string ); 25 | 26 | NEXT_EXPORT_FUNC const char * next_address_to_string( const struct next_address_t * address, char * buffer ); 27 | 28 | NEXT_EXPORT_FUNC const char * next_address_to_string_without_port( const struct next_address_t * address, char * buffer ); 29 | 30 | NEXT_EXPORT_FUNC bool next_address_equal( const struct next_address_t * a, const struct next_address_t * b ); 31 | 32 | NEXT_EXPORT_FUNC void next_address_anonymize( struct next_address_t * address ); 33 | 34 | NEXT_EXPORT_FUNC bool next_address_is_ipv4_in_ipv6( struct next_address_t * address ); 35 | 36 | NEXT_EXPORT_FUNC void next_address_convert_ipv6_to_ipv4( struct next_address_t * address ); 37 | 38 | NEXT_EXPORT_FUNC void next_address_convert_ipv4_to_ipv6( struct next_address_t * address ); 39 | 40 | #endif // #ifndef NEXT_ADDRESS_H 41 | -------------------------------------------------------------------------------- /sdk/include/next_autodetect.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_AUTODETECT_H 8 | #define NEXT_AUTODETECT_H 9 | 10 | #include "next.h" 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_LINUX || NEXT_PLATFORM == NEXT_PLATFORM_MAC || NEXT_PLATFORM == NEXT_PLATFORM_WINDOWS 13 | 14 | bool next_autodetect_google( char * output, size_t output_size ); 15 | 16 | bool next_autodetect_amazon( char * output, size_t output_size ); 17 | 18 | bool next_autodetect_multiplay( const char * input_datacenter, const char * address, char * output, size_t output_size ); 19 | 20 | bool next_autodetect_datacenter( const char * input_datacenter, const char * public_address, char * output, size_t output_size ); 21 | 22 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_LINUX || NEXT_PLATFORM == NEXT_PLATFORM_MAC || NEXT_PLATFORM == NEXT_PLATFORM_WINDOWS 23 | 24 | #endif // #ifndef NEXT_AUTODETECT_H 25 | -------------------------------------------------------------------------------- /sdk/include/next_base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_BASE64_H 8 | #define NEXT_BASE64_H 9 | 10 | #include "next.h" 11 | 12 | int next_base64_encode_data( const uint8_t * input, size_t input_length, char * output, size_t output_size ); 13 | 14 | int next_base64_decode_data( const char * input, uint8_t * output, size_t output_size ); 15 | 16 | int next_base64_encode_string( const char * input, char * output, size_t output_size ); 17 | 18 | int next_base64_decode_string( const char * input, char * output, size_t output_size ); 19 | 20 | #endif // #if NEXT_BASE64_H 21 | -------------------------------------------------------------------------------- /sdk/include/next_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_CONFIG_H 8 | #define NEXT_CONFIG_H 9 | 10 | #include "next.h" 11 | #include "next_constants.h" 12 | 13 | #define NEXT_PROD_SERVER_BACKEND_HOSTNAME "server.virtualgo.net" 14 | #define NEXT_PROD_SERVER_BACKEND_PUBLIC_KEY "Uycn3KibCfXJo1uM+NNWgCySRzM2Ti3bhvom9XBkxfE=" 15 | #define NEXT_PROD_RELAY_BACKEND_PUBLIC_KEY "unH/Yxm0C6JCZ1dTGZH2BTBOFhGMcYsOEDURd9qY72w=" 16 | 17 | #define NEXT_DEV_SERVER_BACKEND_HOSTNAME "server-dev.virtualgo.net" 18 | #define NEXT_DEV_SERVER_BACKEND_PUBLIC_KEY "9ShrWyUWRm+twHzd5xJuO3kpH1j9hGuxK2MlfI44x38=" 19 | #define NEXT_DEV_RELAY_BACKEND_PUBLIC_KEY "XMZGJsM6tHP2vFBXQZBmXguSNa9Czs8V/pcCfhF2KhU=" 20 | 21 | #if !NEXT_DEVELOPMENT 22 | #define NEXT_SERVER_BACKEND_HOSTNAME NEXT_PROD_SERVER_BACKEND_HOSTNAME 23 | #define NEXT_SERVER_BACKEND_PUBLIC_KEY NEXT_PROD_SERVER_BACKEND_PUBLIC_KEY 24 | #define NEXT_RELAY_BACKEND_PUBLIC_KEY NEXT_PROD_RELAY_BACKEND_PUBLIC_KEY 25 | #else // #if !NEXT_DEVELOPMENT 26 | #define NEXT_SERVER_BACKEND_HOSTNAME NEXT_DEV_SERVER_BACKEND_HOSTNAME 27 | #define NEXT_SERVER_BACKEND_PUBLIC_KEY NEXT_DEV_SERVER_BACKEND_PUBLIC_KEY 28 | #define NEXT_RELAY_BACKEND_PUBLIC_KEY NEXT_DEV_RELAY_BACKEND_PUBLIC_KEY 29 | #endif // #if !NEXT_DEVELOPMENT 30 | 31 | #define NEXT_CONFIG_BUCKET_NAME "next_network_next_sdk_config" 32 | 33 | extern uint8_t next_server_backend_public_key[]; 34 | 35 | extern uint8_t next_relay_backend_public_key[]; 36 | 37 | #endif // #ifndef NEXT_CONFIG_H 38 | -------------------------------------------------------------------------------- /sdk/include/next_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_HASH_H 8 | #define NEXT_HASH_H 9 | 10 | #include "next.h" 11 | 12 | uint64_t next_hash_string( const char * string ); 13 | 14 | uint64_t next_relay_id( const char * name ); 15 | 16 | uint64_t next_datacenter_id( const char * name ); 17 | 18 | typedef uint64_t next_fnv_t; 19 | 20 | void next_fnv_init( next_fnv_t * fnv ); 21 | 22 | void next_fnv_write( next_fnv_t * fnv, const uint8_t * data, size_t size ); 23 | 24 | uint64_t next_fnv_finalize( next_fnv_t * fnv ); 25 | 26 | #endif // #ifndef NEXT_HASH_H 27 | -------------------------------------------------------------------------------- /sdk/include/next_internal_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_INTERNAL_CONFIG_H 8 | #define NEXT_INTERNAL_CONFIG_H 9 | 10 | #include "next_crypto.h" 11 | 12 | struct next_internal_config_t 13 | { 14 | char server_backend_hostname[256]; 15 | uint64_t client_buyer_id; 16 | uint64_t server_buyer_id; 17 | uint8_t buyer_public_key[NEXT_CRYPTO_SIGN_PUBLICKEYBYTES]; 18 | uint8_t buyer_private_key[NEXT_CRYPTO_SIGN_SECRETKEYBYTES]; 19 | bool valid_buyer_private_key; 20 | bool valid_buyer_public_key; 21 | int socket_send_buffer_size; 22 | int socket_receive_buffer_size; 23 | bool disable_network_next; 24 | bool disable_autodetect; 25 | }; 26 | 27 | #endif // #ifndef NEXT_H 28 | -------------------------------------------------------------------------------- /sdk/include/next_memory_checks.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_MEMORY_CHECKS_H 8 | #define NEXT_MEMORY_CHECKS_H 9 | 10 | #include "next.h" 11 | 12 | #if NEXT_ENABLE_MEMORY_CHECKS 13 | 14 | #define NEXT_DECLARE_SENTINEL(n) uint32_t next_sentinel_##n[64]; 15 | 16 | #define NEXT_INITIALIZE_SENTINEL(pointer,n) for ( int i = 0; i < 64; ++i ) { pointer->next_sentinel_##n[i] = 0xBAADF00D; } 17 | 18 | #define NEXT_VERIFY_SENTINEL(pointer,n) for ( int i = 0; i < 64; ++i ) { next_assert( pointer->next_sentinel_##n[i] == 0xBAADF00D ); } 19 | 20 | #else // #if NEXT_ENABLE_MEMORY_CHECKS 21 | 22 | #define NEXT_DECLARE_SENTINEL(n) 23 | 24 | #define NEXT_INITIALIZE_SENTINEL(pointer,n) 25 | 26 | #define NEXT_VERIFY_SENTINEL(pointer,n) 27 | 28 | #endif // #if NEXT_ENABLE_MEMORY_CHECKS 29 | 30 | #endif // #ifndef NEXT_MEMORY_CHECKS_H 31 | -------------------------------------------------------------------------------- /sdk/include/next_packet_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_PACKET_FILTER_H 8 | #define NEXT_PACKET_FILTER_H 9 | 10 | #include "next.h" 11 | 12 | void next_generate_pittle( uint8_t * output, const uint8_t * from_address, const uint8_t * to_address, uint16_t packet_length ); 13 | 14 | void next_generate_chonkle( uint8_t * output, const uint8_t * magic, const uint8_t * from_address, const uint8_t * to_address, uint16_t packet_length ); 15 | 16 | bool next_basic_packet_filter( const uint8_t * data, uint16_t packet_length ); 17 | 18 | void next_address_data( const next_address_t * address, uint8_t * address_data ); 19 | 20 | bool next_advanced_packet_filter( const uint8_t * data, const uint8_t * magic, const uint8_t * from_address, const uint8_t * to_address, uint16_t packet_length ); 21 | 22 | #endif // #ifndef NEXT_PACKET_FILTER_H 23 | -------------------------------------------------------------------------------- /sdk/include/next_platform_gdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_GDK_H 10 | #define NEXT_PLATFORM_GDK_H 11 | 12 | #ifdef _GAMING_XBOX 13 | 14 | #define _WINSOCKAPI_ 15 | #include 16 | #include 17 | 18 | // ------------------------------------- 19 | 20 | #pragma warning(disable:4996) 21 | 22 | #if _WIN64 23 | typedef uint64_t next_platform_socket_handle_t; 24 | #else 25 | typedef _W64 unsigned int next_platform_socket_handle_t; 26 | #endif 27 | 28 | struct next_platform_socket_t 29 | { 30 | void * context; 31 | bool ipv6; 32 | next_platform_socket_handle_t handle; 33 | }; 34 | 35 | // ------------------------------------- 36 | 37 | struct next_platform_thread_t 38 | { 39 | void* context; 40 | HANDLE handle; 41 | }; 42 | 43 | // ------------------------------------- 44 | 45 | struct next_platform_mutex_t 46 | { 47 | bool ok; 48 | CRITICAL_SECTION handle; 49 | }; 50 | 51 | // ------------------------------------- 52 | 53 | #endif // #ifdef _GAMING_XBOX 54 | 55 | #endif // #ifndef NEXT_PLATFORM_GDK_H 56 | -------------------------------------------------------------------------------- /sdk/include/next_platform_linux.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_LINUX_H 10 | #define NEXT_PLATFORM_LINUX_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_LINUX 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | // ------------------------------------- 19 | 20 | typedef int next_platform_socket_handle_t; 21 | 22 | struct next_platform_socket_t 23 | { 24 | void * context; 25 | int type; 26 | bool ipv6; 27 | next_platform_socket_handle_t handle; 28 | }; 29 | 30 | // ------------------------------------- 31 | 32 | struct next_platform_thread_t 33 | { 34 | void * context; 35 | pthread_t handle; 36 | }; 37 | 38 | // ------------------------------------- 39 | 40 | struct next_platform_mutex_t 41 | { 42 | bool ok; 43 | pthread_mutex_t handle; 44 | }; 45 | 46 | // ------------------------------------- 47 | 48 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_LINUX 49 | 50 | #endif // #ifndef NEXT_LINUX_H 51 | -------------------------------------------------------------------------------- /sdk/include/next_platform_mac.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_MAC_H 10 | #define NEXT_PLATFORM_MAC_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_MAC 13 | 14 | #include 15 | #include 16 | 17 | // ------------------------------------- 18 | 19 | typedef int next_platform_socket_handle_t; 20 | 21 | struct next_platform_socket_t 22 | { 23 | void * context; 24 | bool ipv6; 25 | next_platform_socket_handle_t handle; 26 | }; 27 | 28 | // ------------------------------------- 29 | 30 | struct next_platform_thread_t 31 | { 32 | void * context; 33 | pthread_t handle; 34 | }; 35 | 36 | // ------------------------------------- 37 | 38 | struct next_platform_mutex_t 39 | { 40 | bool ok; 41 | pthread_mutex_t handle; 42 | }; 43 | 44 | // ------------------------------------- 45 | 46 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_MAC 47 | 48 | #endif // #ifndef NEXT_PLATFORM_MAC_H 49 | -------------------------------------------------------------------------------- /sdk/include/next_platform_ps4.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_PS4_H 10 | #define NEXT_PLATFORM_PS4_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_PS4 13 | 14 | #include 15 | #include 16 | 17 | // ------------------------------------- 18 | 19 | typedef SceNetId next_platform_socket_handle_t; 20 | 21 | struct next_platform_socket_t 22 | { 23 | next_platform_socket_handle_t handle; 24 | int type; 25 | float timeout_seconds; 26 | void * context; 27 | }; 28 | 29 | // ------------------------------------- 30 | 31 | struct next_platform_thread_t 32 | { 33 | ScePthread handle; 34 | void * context; 35 | }; 36 | 37 | // ------------------------------------- 38 | 39 | struct next_platform_mutex_t 40 | { 41 | bool ok; 42 | ScePthreadMutex handle; 43 | }; 44 | 45 | // ------------------------------------- 46 | 47 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_PS4 48 | 49 | #endif // #ifndef NEXT_PLATFORM_PS4_H 50 | -------------------------------------------------------------------------------- /sdk/include/next_platform_ps5.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_PS5_H 10 | #define NEXT_PLATFORM_PS5_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_PS5 13 | 14 | #include 15 | #include 16 | 17 | // ------------------------------------- 18 | 19 | typedef SceNetId next_platform_socket_handle_t; 20 | 21 | struct next_platform_socket_t 22 | { 23 | next_platform_socket_handle_t handle; 24 | int type; 25 | float timeout_seconds; 26 | void * context; 27 | }; 28 | 29 | // ------------------------------------- 30 | 31 | struct next_platform_thread_t 32 | { 33 | ScePthread handle; 34 | void * context; 35 | }; 36 | 37 | // ------------------------------------- 38 | 39 | struct next_platform_mutex_t 40 | { 41 | bool ok; 42 | ScePthreadMutex handle; 43 | }; 44 | 45 | // ------------------------------------- 46 | 47 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_PS5 48 | 49 | #endif // #ifndef NEXT_PS5_H 50 | -------------------------------------------------------------------------------- /sdk/include/next_platform_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_SWITCH_H 10 | #define NEXT_SWITCH_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_SWITCH 13 | 14 | #include "next_address.h" 15 | 16 | #include 17 | 18 | // ------------------------------------- 19 | 20 | typedef int next_platform_socket_handle_t; 21 | 22 | struct next_platform_socket_t 23 | { 24 | next_platform_socket_handle_t handle; 25 | next_address_t address; 26 | int type; 27 | float timeout_seconds; 28 | int send_buffer_size; 29 | int receive_buffer_size; 30 | void * context; 31 | }; 32 | 33 | // ------------------------------------- 34 | 35 | struct next_platform_thread_t 36 | { 37 | nn::os::ThreadType handle; 38 | char * stack; 39 | void * context; 40 | }; 41 | 42 | // ------------------------------------- 43 | 44 | struct next_platform_mutex_t 45 | { 46 | nn::os::MutexType handle; 47 | }; 48 | 49 | // ------------------------------------- 50 | 51 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_SWITCH 52 | 53 | #endif // #ifndef NEXT_SWITCH_H 54 | -------------------------------------------------------------------------------- /sdk/include/next_platform_windows.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | 9 | #ifndef NEXT_PLATFORM_WINDOWS_H 10 | #define NEXT_PLATFORM_WINDOWS_H 11 | 12 | #if NEXT_PLATFORM == NEXT_PLATFORM_WINDOWS 13 | 14 | #if NEXT_UNREAL_ENGINE 15 | #include "Windows/AllowWindowsPlatformTypes.h" 16 | #include "Windows/PreWindowsApi.h" 17 | #endif // #if NEXT_UNREAL_ENGINE 18 | 19 | #if !NEXT_UNREAL_ENGINE 20 | #define _WINSOCKAPI_ 21 | #include 22 | #include 23 | #else // #if !NEXT_UNREAL_ENGINE 24 | #include "Windows/MinWindows.h" 25 | #endif // #if !NEXT_UNREAL_ENGINE 26 | 27 | // ------------------------------------- 28 | 29 | #pragma warning(disable:4996) 30 | 31 | #if _WIN64 32 | typedef uint64_t next_platform_socket_handle_t; 33 | #else 34 | typedef _W64 unsigned int next_platform_socket_handle_t; 35 | #endif 36 | 37 | struct next_platform_socket_t 38 | { 39 | void * context; 40 | bool ipv6; 41 | next_platform_socket_handle_t handle; 42 | }; 43 | 44 | // ------------------------------------- 45 | 46 | struct next_platform_thread_t 47 | { 48 | void * context; 49 | HANDLE handle; 50 | }; 51 | 52 | // ------------------------------------- 53 | 54 | struct next_platform_mutex_t 55 | { 56 | bool ok; 57 | CRITICAL_SECTION handle; 58 | }; 59 | 60 | // ------------------------------------- 61 | 62 | #if NEXT_UNREAL_ENGINE 63 | #include "Windows/PostWindowsApi.h" 64 | #include "Windows/HideWindowsPlatformTypes.h" 65 | #endif // #if NEXT_UNREAL_ENGINE 66 | 67 | #endif // #if NEXT_PLATFORM == NEXT_PLATFORM_WINDOWS 68 | 69 | #endif // #ifndef NEXT_PLATFORM_WINDOWS_H 70 | -------------------------------------------------------------------------------- /sdk/include/next_tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #ifndef NEXT_TESTS_H 8 | #define NEXT_TESTS_H 9 | 10 | #include "next.h" 11 | 12 | NEXT_EXPORT_FUNC void next_run_tests(); 13 | 14 | #endif // #ifndef NEXT_TESTS_H 15 | -------------------------------------------------------------------------------- /sdk/keygen/keygen.go: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | package main 8 | 9 | import ( 10 | "crypto/ed25519" 11 | "crypto/rand" 12 | "encoding/base64" 13 | "fmt" 14 | "log" 15 | ) 16 | 17 | func main() { 18 | 19 | buyerId := make([]byte, 8) 20 | rand.Read(buyerId) 21 | 22 | publicKey, privateKey, err := ed25519.GenerateKey(nil) 23 | if err != nil { 24 | log.Fatalln(err) 25 | } 26 | 27 | buyerPublicKey := make([]byte, 0) 28 | buyerPublicKey = append(buyerPublicKey, buyerId...) 29 | buyerPublicKey = append(buyerPublicKey, publicKey...) 30 | 31 | buyerPrivateKey := make([]byte, 0) 32 | buyerPrivateKey = append(buyerPrivateKey, buyerId...) 33 | buyerPrivateKey = append(buyerPrivateKey, privateKey...) 34 | 35 | fmt.Printf("\nWelcome to Network Next!\n\n") 36 | fmt.Printf("This is your public key:\n\n %s\n\n", base64.StdEncoding.EncodeToString(buyerPublicKey[:])) 37 | fmt.Printf("This is your private key:\n\n %s\n\n", base64.StdEncoding.EncodeToString(buyerPrivateKey[:])) 38 | fmt.Printf("IMPORTANT: Save your private key in a secure place and don't share it with anybody, not even us!\n\n") 39 | } 40 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_blake2b-compress-avx2.c: -------------------------------------------------------------------------------- 1 | 2 | #define BLAKE2_USE_SSSE3 3 | #define BLAKE2_USE_SSE41 4 | #define BLAKE2_USE_AVX2 5 | 6 | #include 7 | #include 8 | 9 | #include "sodium_blake2.h" 10 | #include "sodium_private_common.h" 11 | #include "sodium_private_sse2_64_32.h" 12 | 13 | #if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \ 14 | defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H) 15 | 16 | # ifdef __GNUC__ 17 | # pragma GCC target("sse2") 18 | # pragma GCC target("ssse3") 19 | # pragma GCC target("sse4.1") 20 | # pragma GCC target("avx2") 21 | # endif 22 | 23 | # include 24 | # include 25 | # include 26 | # include 27 | 28 | # include "sodium_blake2b-compress-avx2.h" 29 | 30 | CRYPTO_ALIGN(64) 31 | static const uint64_t blake2b_IV[8] = { 32 | 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 33 | 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 34 | 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL 35 | }; 36 | 37 | int 38 | blake2b_compress_avx2(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES]) 39 | { 40 | __m256i a = LOADU(&S->h[0]); 41 | __m256i b = LOADU(&S->h[4]); 42 | BLAKE2B_COMPRESS_V1(a, b, block, S->t[0], S->t[1], S->f[0], S->f[1]); 43 | STOREU(&S->h[0], a); 44 | STOREU(&S->h[4], b); 45 | 46 | return 0; 47 | } 48 | 49 | #endif 50 | 51 | int blake2b_compress_avx2_link_warning_dummy = 0; 52 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_chacha20-ref.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_chacha20.h" 5 | #include "sodium_crypto_stream_chacha20.h" 6 | 7 | extern struct crypto_stream_chacha20_implementation 8 | crypto_stream_chacha20_ref_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_core.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_core_H 3 | #define sodium_core_H 4 | 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int sodium_init(void) 12 | __attribute__ ((warn_unused_result)); 13 | 14 | /* ---- */ 15 | 16 | int sodium_set_misuse_handler(void (*handler)(void)); 17 | 18 | void sodium_misuse(void) 19 | __attribute__ ((noreturn)); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_core_hsalsa20.c: -------------------------------------------------------------------------------- 1 | #include "sodium_crypto_core_hsalsa20.h" 2 | 3 | size_t 4 | crypto_core_hsalsa20_outputbytes(void) { 5 | return crypto_core_hsalsa20_OUTPUTBYTES; 6 | } 7 | 8 | size_t 9 | crypto_core_hsalsa20_inputbytes(void) { 10 | return crypto_core_hsalsa20_INPUTBYTES; 11 | } 12 | 13 | size_t 14 | crypto_core_hsalsa20_keybytes(void) { 15 | return crypto_core_hsalsa20_KEYBYTES; 16 | } 17 | 18 | size_t 19 | crypto_core_hsalsa20_constbytes(void) { 20 | return crypto_core_hsalsa20_CONSTBYTES; 21 | } 22 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_auth.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_auth_H 2 | #define crypto_auth_H 3 | 4 | #include 5 | 6 | #include "sodium_crypto_auth_hmacsha512256.h" 7 | #include "sodium_export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES 17 | size_t crypto_auth_bytes(void); 18 | 19 | #define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES 20 | size_t crypto_auth_keybytes(void); 21 | 22 | #define crypto_auth_PRIMITIVE "hmacsha512256" 23 | const char *crypto_auth_primitive(void); 24 | 25 | int crypto_auth(unsigned char *out, const unsigned char *in, 26 | unsigned long long inlen, const unsigned char *k) 27 | __attribute__ ((nonnull)); 28 | 29 | int crypto_auth_verify(const unsigned char *h, const unsigned char *in, 30 | unsigned long long inlen, const unsigned char *k) 31 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 32 | 33 | void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES]) 34 | __attribute__ ((nonnull)); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_box.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sodium_crypto_box.h" 3 | 4 | int 5 | crypto_box_keypair(unsigned char *pk, unsigned char *sk) 6 | { 7 | return crypto_box_curve25519xsalsa20poly1305_keypair(pk, sk); 8 | } 9 | 10 | int 11 | crypto_box_beforenm(unsigned char *k, const unsigned char *pk, 12 | const unsigned char *sk) 13 | { 14 | return crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk); 15 | } 16 | 17 | int 18 | crypto_box_afternm(unsigned char *c, const unsigned char *m, 19 | unsigned long long mlen, const unsigned char *n, 20 | const unsigned char *k) 21 | { 22 | return crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k); 23 | } 24 | 25 | int 26 | crypto_box_open_afternm(unsigned char *m, const unsigned char *c, 27 | unsigned long long clen, const unsigned char *n, 28 | const unsigned char *k) 29 | { 30 | return crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k); 31 | } 32 | 33 | int 34 | crypto_box(unsigned char *c, const unsigned char *m, 35 | unsigned long long mlen, const unsigned char *n, 36 | const unsigned char *pk, const unsigned char *sk) 37 | { 38 | return crypto_box_curve25519xsalsa20poly1305(c, m, mlen, n, pk, sk); 39 | } 40 | 41 | int 42 | crypto_box_open(unsigned char *m, const unsigned char *c, 43 | unsigned long long clen, const unsigned char *n, 44 | const unsigned char *pk, const unsigned char *sk) 45 | { 46 | return crypto_box_curve25519xsalsa20poly1305_open(m, c, clen, n, pk, sk); 47 | } 48 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_core_hchacha20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_hchacha20_H 2 | #define crypto_core_hchacha20_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_hchacha20_OUTPUTBYTES 32U 12 | size_t crypto_core_hchacha20_outputbytes(void); 13 | 14 | #define crypto_core_hchacha20_INPUTBYTES 16U 15 | size_t crypto_core_hchacha20_inputbytes(void); 16 | 17 | #define crypto_core_hchacha20_KEYBYTES 32U 18 | size_t crypto_core_hchacha20_keybytes(void); 19 | 20 | #define crypto_core_hchacha20_CONSTBYTES 16U 21 | size_t crypto_core_hchacha20_constbytes(void); 22 | 23 | int crypto_core_hchacha20(unsigned char *out, const unsigned char *in, 24 | const unsigned char *k, const unsigned char *c) 25 | __attribute__ ((nonnull(1, 2, 3))); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_core_hsalsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_hsalsa20_H 2 | #define crypto_core_hsalsa20_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_hsalsa20_OUTPUTBYTES 32U 12 | size_t crypto_core_hsalsa20_outputbytes(void); 13 | 14 | #define crypto_core_hsalsa20_INPUTBYTES 16U 15 | size_t crypto_core_hsalsa20_inputbytes(void); 16 | 17 | #define crypto_core_hsalsa20_KEYBYTES 32U 18 | size_t crypto_core_hsalsa20_keybytes(void); 19 | 20 | #define crypto_core_hsalsa20_CONSTBYTES 16U 21 | size_t crypto_core_hsalsa20_constbytes(void); 22 | 23 | int crypto_core_hsalsa20(unsigned char *out, const unsigned char *in, 24 | const unsigned char *k, const unsigned char *c) 25 | __attribute__ ((nonnull(1, 2, 3))); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_core_salsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa20_H 2 | #define crypto_core_salsa20_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa20_OUTPUTBYTES 64U 12 | size_t crypto_core_salsa20_outputbytes(void); 13 | 14 | #define crypto_core_salsa20_INPUTBYTES 16U 15 | size_t crypto_core_salsa20_inputbytes(void); 16 | 17 | #define crypto_core_salsa20_KEYBYTES 32U 18 | size_t crypto_core_salsa20_keybytes(void); 19 | 20 | #define crypto_core_salsa20_CONSTBYTES 16U 21 | size_t crypto_core_salsa20_constbytes(void); 22 | 23 | int crypto_core_salsa20(unsigned char *out, const unsigned char *in, 24 | const unsigned char *k, const unsigned char *c) 25 | __attribute__ ((nonnull(1, 2, 3))); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_core_salsa2012.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa2012_H 2 | #define crypto_core_salsa2012_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa2012_OUTPUTBYTES 64U 12 | size_t crypto_core_salsa2012_outputbytes(void); 13 | 14 | #define crypto_core_salsa2012_INPUTBYTES 16U 15 | size_t crypto_core_salsa2012_inputbytes(void); 16 | 17 | #define crypto_core_salsa2012_KEYBYTES 32U 18 | size_t crypto_core_salsa2012_keybytes(void); 19 | 20 | #define crypto_core_salsa2012_CONSTBYTES 16U 21 | size_t crypto_core_salsa2012_constbytes(void); 22 | 23 | int crypto_core_salsa2012(unsigned char *out, const unsigned char *in, 24 | const unsigned char *k, const unsigned char *c) 25 | __attribute__ ((nonnull(1, 2, 3))); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_core_salsa208.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_core_salsa208_H 2 | #define crypto_core_salsa208_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_core_salsa208_OUTPUTBYTES 64U 12 | size_t crypto_core_salsa208_outputbytes(void) 13 | __attribute__ ((deprecated)); 14 | 15 | #define crypto_core_salsa208_INPUTBYTES 16U 16 | size_t crypto_core_salsa208_inputbytes(void) 17 | __attribute__ ((deprecated)); 18 | 19 | #define crypto_core_salsa208_KEYBYTES 32U 20 | size_t crypto_core_salsa208_keybytes(void) 21 | __attribute__ ((deprecated)); 22 | 23 | #define crypto_core_salsa208_CONSTBYTES 16U 24 | size_t crypto_core_salsa208_constbytes(void) 25 | __attribute__ ((deprecated)); 26 | 27 | int crypto_core_salsa208(unsigned char *out, const unsigned char *in, 28 | const unsigned char *k, const unsigned char *c) 29 | __attribute__ ((nonnull(1, 2, 3))); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_hash.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_H 2 | #define crypto_hash_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA512 for interoperatibility, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA512, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | 13 | #include "sodium_crypto_hash_sha512.h" 14 | #include "sodium_export.h" 15 | 16 | #ifdef __cplusplus 17 | # ifdef __GNUC__ 18 | # pragma GCC diagnostic ignored "-Wlong-long" 19 | # endif 20 | extern "C" { 21 | #endif 22 | 23 | #define crypto_hash_BYTES crypto_hash_sha512_BYTES 24 | size_t crypto_hash_bytes(void); 25 | 26 | int crypto_hash(unsigned char *out, const unsigned char *in, 27 | unsigned long long inlen) __attribute__ ((nonnull)); 28 | 29 | #define crypto_hash_PRIMITIVE "sha512" 30 | const char *crypto_hash_primitive(void) 31 | __attribute__ ((warn_unused_result)); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_hash_sha256.c: -------------------------------------------------------------------------------- 1 | #include "sodium_crypto_hash_sha256.h" 2 | 3 | size_t 4 | crypto_hash_sha256_bytes(void) 5 | { 6 | return crypto_hash_sha256_BYTES; 7 | } 8 | 9 | size_t 10 | crypto_hash_sha256_statebytes(void) 11 | { 12 | return sizeof(crypto_hash_sha256_state); 13 | } 14 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_hash_sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha256_H 2 | #define crypto_hash_sha256_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA256 for interoperability, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA256, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | # ifdef __GNUC__ 17 | # pragma GCC diagnostic ignored "-Wlong-long" 18 | # endif 19 | extern "C" { 20 | #endif 21 | 22 | typedef struct crypto_hash_sha256_state { 23 | uint32_t state[8]; 24 | uint64_t count; 25 | uint8_t buf[64]; 26 | } crypto_hash_sha256_state; 27 | 28 | size_t crypto_hash_sha256_statebytes(void); 29 | 30 | #define crypto_hash_sha256_BYTES 32U 31 | size_t crypto_hash_sha256_bytes(void); 32 | 33 | int crypto_hash_sha256(unsigned char *out, const unsigned char *in, 34 | unsigned long long inlen); 35 | 36 | int crypto_hash_sha256_init(crypto_hash_sha256_state *state); 37 | 38 | int crypto_hash_sha256_update(crypto_hash_sha256_state *state, 39 | const unsigned char *in, 40 | unsigned long long inlen); 41 | 42 | int crypto_hash_sha256_final(crypto_hash_sha256_state *state, 43 | unsigned char *out); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_hash_sha512.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha512_H 2 | #define crypto_hash_sha512_H 3 | 4 | /* 5 | * WARNING: Unless you absolutely need to use SHA512 for interoperatibility, 6 | * purposes, you might want to consider crypto_generichash() instead. 7 | * Unlike SHA512, crypto_generichash() is not vulnerable to length 8 | * extension attacks. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sodium_export.h" 16 | 17 | #ifdef __cplusplus 18 | # ifdef __GNUC__ 19 | # pragma GCC diagnostic ignored "-Wlong-long" 20 | # endif 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct crypto_hash_sha512_state { 25 | uint64_t state[8]; 26 | uint64_t count[2]; 27 | uint8_t buf[128]; 28 | } crypto_hash_sha512_state; 29 | 30 | size_t crypto_hash_sha512_statebytes(void); 31 | 32 | #define crypto_hash_sha512_BYTES 64U 33 | size_t crypto_hash_sha512_bytes(void); 34 | 35 | int crypto_hash_sha512(unsigned char *out, const unsigned char *in, 36 | unsigned long long inlen) __attribute__ ((nonnull)); 37 | 38 | int crypto_hash_sha512_init(crypto_hash_sha512_state *state) 39 | __attribute__ ((nonnull)); 40 | 41 | int crypto_hash_sha512_update(crypto_hash_sha512_state *state, 42 | const unsigned char *in, 43 | unsigned long long inlen) 44 | __attribute__ ((nonnull)); 45 | 46 | int crypto_hash_sha512_final(crypto_hash_sha512_state *state, 47 | unsigned char *out) 48 | __attribute__ ((nonnull)); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_scalarmult.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sodium_crypto_scalarmult.h" 3 | 4 | const char * 5 | crypto_scalarmult_primitive(void) 6 | { 7 | return crypto_scalarmult_PRIMITIVE; 8 | } 9 | 10 | int 11 | crypto_scalarmult_base(unsigned char *q, const unsigned char *n) 12 | { 13 | return crypto_scalarmult_curve25519_base(q, n); 14 | } 15 | 16 | int 17 | crypto_scalarmult(unsigned char *q, const unsigned char *n, 18 | const unsigned char *p) 19 | { 20 | return crypto_scalarmult_curve25519(q, n, p); 21 | } 22 | 23 | size_t 24 | crypto_scalarmult_bytes(void) 25 | { 26 | return crypto_scalarmult_BYTES; 27 | } 28 | 29 | size_t 30 | crypto_scalarmult_scalarbytes(void) 31 | { 32 | return crypto_scalarmult_SCALARBYTES; 33 | } 34 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_scalarmult.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_scalarmult_H 2 | #define crypto_scalarmult_H 3 | 4 | #include 5 | 6 | #include "sodium_crypto_scalarmult_curve25519.h" 7 | #include "sodium_export.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES 14 | size_t crypto_scalarmult_bytes(void); 15 | 16 | #define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES 17 | size_t crypto_scalarmult_scalarbytes(void); 18 | 19 | #define crypto_scalarmult_PRIMITIVE "curve25519" 20 | const char *crypto_scalarmult_primitive(void); 21 | 22 | int crypto_scalarmult_base(unsigned char *q, const unsigned char *n) 23 | __attribute__ ((nonnull)); 24 | 25 | /* 26 | * NOTE: Do not use the result of this function directly. 27 | * 28 | * Hash the result with the public keys in order to compute a shared 29 | * secret key: H(q || client_pk || server_pk) 30 | * 31 | * Or unless this is not an option, use the crypto_kx() API instead. 32 | */ 33 | int crypto_scalarmult(unsigned char *q, const unsigned char *n, 34 | const unsigned char *p) 35 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_scalarmult_curve25519.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_scalarmult_curve25519_H 2 | #define crypto_scalarmult_curve25519_H 3 | 4 | #include 5 | 6 | #include "sodium_export.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define crypto_scalarmult_curve25519_BYTES 32U 13 | size_t crypto_scalarmult_curve25519_bytes(void); 14 | 15 | #define crypto_scalarmult_curve25519_SCALARBYTES 32U 16 | size_t crypto_scalarmult_curve25519_scalarbytes(void); 17 | 18 | /* 19 | * NOTE: Do not use the result of this function directly. 20 | * 21 | * Hash the result with the public keys in order to compute a shared 22 | * secret key: H(q || client_pk || server_pk) 23 | * 24 | * Or unless this is not an option, use the crypto_kx() API instead. 25 | */ 26 | int crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n, 27 | const unsigned char *p) 28 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 29 | 30 | int crypto_scalarmult_curve25519_base(unsigned char *q, 31 | const unsigned char *n) 32 | __attribute__ ((nonnull)); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_scalarmult_ed25519.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef crypto_scalarmult_ed25519_H 3 | #define crypto_scalarmult_ed25519_H 4 | 5 | #include 6 | 7 | #include "sodium_export.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define crypto_scalarmult_ed25519_BYTES 32U 14 | size_t crypto_scalarmult_ed25519_bytes(void); 15 | 16 | #define crypto_scalarmult_ed25519_SCALARBYTES 32U 17 | size_t crypto_scalarmult_ed25519_scalarbytes(void); 18 | 19 | /* 20 | * NOTE: Do not use the result of this function directly. 21 | * 22 | * Hash the result with the public keys in order to compute a shared 23 | * secret key: H(q || client_pk || server_pk) 24 | * 25 | * Or unless this is not an option, use the crypto_kx() API instead. 26 | */ 27 | int crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n, 28 | const unsigned char *p) 29 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 30 | 31 | int crypto_scalarmult_ed25519_noclamp(unsigned char *q, const unsigned char *n, 32 | const unsigned char *p) 33 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 34 | 35 | int crypto_scalarmult_ed25519_base(unsigned char *q, const unsigned char *n) 36 | __attribute__ ((nonnull)); 37 | 38 | int crypto_scalarmult_ed25519_base_noclamp(unsigned char *q, const unsigned char *n) 39 | __attribute__ ((nonnull)); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_secretbox.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sodium_crypto_secretbox.h" 3 | #include "sodium_randombytes.h" 4 | 5 | int 6 | crypto_secretbox(unsigned char *c, const unsigned char *m, 7 | unsigned long long mlen, const unsigned char *n, 8 | const unsigned char *k) 9 | { 10 | return crypto_secretbox_xsalsa20poly1305(c, m, mlen, n, k); 11 | } 12 | 13 | int 14 | crypto_secretbox_open(unsigned char *m, const unsigned char *c, 15 | unsigned long long clen, const unsigned char *n, 16 | const unsigned char *k) 17 | { 18 | return crypto_secretbox_xsalsa20poly1305_open(m, c, clen, n, k); 19 | } 20 | 21 | void 22 | crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES]) 23 | { 24 | randombytes_buf(k, crypto_secretbox_KEYBYTES); 25 | } 26 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_shorthash.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_shorthash_H 2 | #define crypto_shorthash_H 3 | 4 | #include 5 | 6 | #include "sodium_crypto_shorthash_siphash24.h" 7 | #include "sodium_export.h" 8 | 9 | #ifdef __cplusplus 10 | # ifdef __GNUC__ 11 | # pragma GCC diagnostic ignored "-Wlong-long" 12 | # endif 13 | extern "C" { 14 | #endif 15 | 16 | #define crypto_shorthash_BYTES crypto_shorthash_siphash24_BYTES 17 | size_t crypto_shorthash_bytes(void); 18 | 19 | #define crypto_shorthash_KEYBYTES crypto_shorthash_siphash24_KEYBYTES 20 | size_t crypto_shorthash_keybytes(void); 21 | 22 | #define crypto_shorthash_PRIMITIVE "siphash24" 23 | const char *crypto_shorthash_primitive(void); 24 | 25 | int crypto_shorthash(unsigned char *out, const unsigned char *in, 26 | unsigned long long inlen, const unsigned char *k) 27 | __attribute__ ((nonnull)); 28 | 29 | void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES]) 30 | __attribute__ ((nonnull)); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_shorthash_siphash24.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_shorthash_siphash24_H 2 | #define crypto_shorthash_siphash24_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | # ifdef __GNUC__ 9 | # pragma GCC diagnostic ignored "-Wlong-long" 10 | # endif 11 | extern "C" { 12 | #endif 13 | 14 | /* -- 64-bit output -- */ 15 | 16 | #define crypto_shorthash_siphash24_BYTES 8U 17 | size_t crypto_shorthash_siphash24_bytes(void); 18 | 19 | #define crypto_shorthash_siphash24_KEYBYTES 16U 20 | size_t crypto_shorthash_siphash24_keybytes(void); 21 | 22 | int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in, 23 | unsigned long long inlen, const unsigned char *k) 24 | __attribute__ ((nonnull)); 25 | 26 | #ifndef SODIUM_LIBRARY_MINIMAL 27 | /* -- 128-bit output -- */ 28 | 29 | #define crypto_shorthash_siphashx24_BYTES 16U 30 | size_t crypto_shorthash_siphashx24_bytes(void); 31 | 32 | #define crypto_shorthash_siphashx24_KEYBYTES 16U 33 | size_t crypto_shorthash_siphashx24_keybytes(void); 34 | 35 | int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in, 36 | unsigned long long inlen, const unsigned char *k) 37 | __attribute__ ((nonnull)); 38 | #endif 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_sign.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sodium_crypto_sign.h" 3 | 4 | int 5 | crypto_sign_keypair(unsigned char *pk, unsigned char *sk) 6 | { 7 | return crypto_sign_ed25519_keypair(pk, sk); 8 | } 9 | 10 | int 11 | crypto_sign(unsigned char *sm, unsigned long long *smlen_p, 12 | const unsigned char *m, unsigned long long mlen, 13 | const unsigned char *sk) 14 | { 15 | return crypto_sign_ed25519(sm, smlen_p, m, mlen, sk); 16 | } 17 | 18 | int 19 | crypto_sign_open(unsigned char *m, unsigned long long *mlen_p, 20 | const unsigned char *sm, unsigned long long smlen, 21 | const unsigned char *pk) 22 | { 23 | return crypto_sign_ed25519_open(m, mlen_p, sm, smlen, pk); 24 | } 25 | 26 | int 27 | crypto_sign_init(crypto_sign_state *state) 28 | { 29 | return crypto_sign_ed25519ph_init(state); 30 | } 31 | 32 | int 33 | crypto_sign_update(crypto_sign_state *state, const unsigned char *m, 34 | unsigned long long mlen) 35 | { 36 | return crypto_sign_ed25519ph_update(state, m, mlen); 37 | } 38 | 39 | int 40 | crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig, 41 | unsigned long long *siglen_p, const unsigned char *sk) 42 | { 43 | return crypto_sign_ed25519ph_final_create(state, sig, siglen_p, sk); 44 | } 45 | 46 | int 47 | crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig, 48 | const unsigned char *pk) 49 | { 50 | return crypto_sign_ed25519ph_final_verify(state, sig, pk); 51 | } 52 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_stream.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_H 2 | #define crypto_stream_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | 14 | #include "sodium_crypto_stream_xsalsa20.h" 15 | #include "sodium_export.h" 16 | 17 | #ifdef __cplusplus 18 | # ifdef __GNUC__ 19 | # pragma GCC diagnostic ignored "-Wlong-long" 20 | # endif 21 | extern "C" { 22 | #endif 23 | 24 | #define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES 25 | size_t crypto_stream_keybytes(void); 26 | 27 | #define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES 28 | size_t crypto_stream_noncebytes(void); 29 | 30 | #define crypto_stream_MESSAGEBYTES_MAX crypto_stream_xsalsa20_MESSAGEBYTES_MAX 31 | size_t crypto_stream_messagebytes_max(void); 32 | 33 | #define crypto_stream_PRIMITIVE "xsalsa20" 34 | const char *crypto_stream_primitive(void); 35 | 36 | int crypto_stream(unsigned char *c, unsigned long long clen, 37 | const unsigned char *n, const unsigned char *k) 38 | __attribute__ ((nonnull)); 39 | 40 | int crypto_stream_xor(unsigned char *c, const unsigned char *m, 41 | unsigned long long mlen, const unsigned char *n, 42 | const unsigned char *k) 43 | __attribute__ ((nonnull)); 44 | 45 | void crypto_stream_keygen(unsigned char k[crypto_stream_KEYBYTES]) 46 | __attribute__ ((nonnull)); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_stream_salsa2012.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_salsa2012_H 2 | #define crypto_stream_salsa2012_H 3 | 4 | /* 5 | * WARNING: This is just a stream cipher. It is NOT authenticated encryption. 6 | * While it provides some protection against eavesdropping, it does NOT 7 | * provide any security against active attacks. 8 | * Unless you know what you're doing, what you are looking for is probably 9 | * the crypto_box functions. 10 | */ 11 | 12 | #include 13 | #include "sodium_export.h" 14 | 15 | #ifdef __cplusplus 16 | # ifdef __GNUC__ 17 | # pragma GCC diagnostic ignored "-Wlong-long" 18 | # endif 19 | extern "C" { 20 | #endif 21 | 22 | #define crypto_stream_salsa2012_KEYBYTES 32U 23 | size_t crypto_stream_salsa2012_keybytes(void); 24 | 25 | #define crypto_stream_salsa2012_NONCEBYTES 8U 26 | size_t crypto_stream_salsa2012_noncebytes(void); 27 | 28 | #define crypto_stream_salsa2012_MESSAGEBYTES_MAX SODIUM_SIZE_MAX 29 | size_t crypto_stream_salsa2012_messagebytes_max(void); 30 | 31 | int crypto_stream_salsa2012(unsigned char *c, unsigned long long clen, 32 | const unsigned char *n, const unsigned char *k) 33 | __attribute__ ((nonnull)); 34 | 35 | int crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m, 36 | unsigned long long mlen, const unsigned char *n, 37 | const unsigned char *k) 38 | __attribute__ ((nonnull)); 39 | 40 | void crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES]) 41 | __attribute__ ((nonnull)); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_verify_16.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_16_H 2 | #define crypto_verify_16_H 3 | 4 | #include 5 | 6 | #include "sodium_export.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define crypto_verify_16_BYTES 16U 13 | size_t crypto_verify_16_bytes(void); 14 | 15 | int crypto_verify_16(const unsigned char *x, const unsigned char *y) 16 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_verify_32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_32_H 2 | #define crypto_verify_32_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_verify_32_BYTES 32U 12 | size_t crypto_verify_32_bytes(void); 13 | 14 | int crypto_verify_32(const unsigned char *x, const unsigned char *y) 15 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_crypto_verify_64.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_64_H 2 | #define crypto_verify_64_H 3 | 4 | #include 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define crypto_verify_64_BYTES 64U 12 | size_t crypto_verify_64_bytes(void); 13 | 14 | int crypto_verify_64(const unsigned char *x, const unsigned char *y) 15 | __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_dolbeau_chacha20-avx2.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_chacha20.h" 5 | #include "sodium_crypto_stream_chacha20.h" 6 | 7 | extern struct crypto_stream_chacha20_implementation 8 | crypto_stream_chacha20_dolbeau_avx2_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_dolbeau_chacha20-ssse3.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_chacha20.h" 5 | #include "sodium_crypto_stream_chacha20.h" 6 | 7 | extern struct crypto_stream_chacha20_implementation 8 | crypto_stream_chacha20_dolbeau_ssse3_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_export.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_export_H 3 | #define sodium_export_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #if !defined(__clang__) && !defined(__GNUC__) 10 | # ifdef __attribute__ 11 | # undef __attribute__ 12 | # endif 13 | # define __attribute__(a) 14 | #endif 15 | 16 | #ifndef CRYPTO_ALIGN 17 | # if defined(__INTEL_COMPILER) || defined(_MSC_VER) 18 | # define CRYPTO_ALIGN(x) __declspec(align(x)) 19 | # else 20 | # define CRYPTO_ALIGN(x) __attribute__ ((aligned(x))) 21 | # endif 22 | #endif 23 | 24 | #define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B)) 25 | #define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_fe_25_5_constants.h: -------------------------------------------------------------------------------- 1 | /* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */ 2 | static const fe25519 d = { 3 | -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116 4 | }; 5 | 6 | /* 2 * d = 7 | * 16295367250680780974490674513165176452449235426866156013048779062215315747161 8 | */ 9 | static const fe25519 d2 = { 10 | -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 }; 11 | 12 | /* sqrt(-1) */ 13 | static const fe25519 sqrtm1 = { 14 | -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482 15 | }; 16 | 17 | /* A = 486662 */ 18 | static const fe25519 curve25519_A = { 19 | 486662, 0, 0, 0, 0, 0, 0, 0, 0, 0 20 | }; 21 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_fe_51_constants.h: -------------------------------------------------------------------------------- 1 | /* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */ 2 | static const fe25519 d = { 3 | 929955233495203, 466365720129213, 1662059464998953, 2033849074728123, 1442794654840575 4 | }; 5 | 6 | /* 2 * d = 7 | * 16295367250680780974490674513165176452449235426866156013048779062215315747161 8 | */ 9 | static const fe25519 d2 = { 10 | 1859910466990425, 932731440258426, 1072319116312658, 1815898335770999, 633789495995903 11 | }; 12 | 13 | /* sqrt(-1) */ 14 | static const fe25519 sqrtm1 = { 15 | 1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133 16 | }; 17 | 18 | /* A = 486662 */ 19 | static const fe25519 curve25519_A = { 20 | 486662, 0, 0, 0, 0 21 | }; 22 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_generichash_blake2.c: -------------------------------------------------------------------------------- 1 | #include "sodium_crypto_generichash_blake2b.h" 2 | #include "sodium_randombytes.h" 3 | 4 | size_t 5 | crypto_generichash_blake2b_bytes_min(void) { 6 | return crypto_generichash_blake2b_BYTES_MIN; 7 | } 8 | 9 | size_t 10 | crypto_generichash_blake2b_bytes_max(void) { 11 | return crypto_generichash_blake2b_BYTES_MAX; 12 | } 13 | 14 | size_t 15 | crypto_generichash_blake2b_bytes(void) { 16 | return crypto_generichash_blake2b_BYTES; 17 | } 18 | 19 | size_t 20 | crypto_generichash_blake2b_keybytes_min(void) { 21 | return crypto_generichash_blake2b_KEYBYTES_MIN; 22 | } 23 | 24 | size_t 25 | crypto_generichash_blake2b_keybytes_max(void) { 26 | return crypto_generichash_blake2b_KEYBYTES_MAX; 27 | } 28 | 29 | size_t 30 | crypto_generichash_blake2b_keybytes(void) { 31 | return crypto_generichash_blake2b_KEYBYTES; 32 | } 33 | 34 | size_t 35 | crypto_generichash_blake2b_saltbytes(void) { 36 | return crypto_generichash_blake2b_SALTBYTES; 37 | } 38 | 39 | size_t 40 | crypto_generichash_blake2b_personalbytes(void) { 41 | return crypto_generichash_blake2b_PERSONALBYTES; 42 | } 43 | 44 | size_t 45 | crypto_generichash_blake2b_statebytes(void) 46 | { 47 | return (sizeof(crypto_generichash_blake2b_state) + (size_t) 63U) 48 | & ~(size_t) 63U; 49 | } 50 | 51 | void 52 | crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES]) 53 | { 54 | randombytes_buf(k, crypto_generichash_blake2b_KEYBYTES); 55 | } 56 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_hash_sha512.c: -------------------------------------------------------------------------------- 1 | #include "sodium_crypto_hash_sha512.h" 2 | 3 | size_t 4 | crypto_hash_sha512_bytes(void) 5 | { 6 | return crypto_hash_sha512_BYTES; 7 | } 8 | 9 | size_t 10 | crypto_hash_sha512_statebytes(void) 11 | { 12 | return sizeof(crypto_hash_sha512_state); 13 | } 14 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_onetimeauth_poly1305.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef onetimeauth_poly1305_H 3 | #define onetimeauth_poly1305_H 4 | 5 | #include "sodium_crypto_onetimeauth_poly1305.h" 6 | 7 | typedef struct crypto_onetimeauth_poly1305_implementation { 8 | int (*onetimeauth)(unsigned char *out, const unsigned char *in, 9 | unsigned long long inlen, const unsigned char *k); 10 | int (*onetimeauth_verify)(const unsigned char *h, const unsigned char *in, 11 | unsigned long long inlen, const unsigned char *k); 12 | int (*onetimeauth_init)(crypto_onetimeauth_poly1305_state *state, 13 | const unsigned char * key); 14 | int (*onetimeauth_update)(crypto_onetimeauth_poly1305_state *state, 15 | const unsigned char * in, 16 | unsigned long long inlen); 17 | int (*onetimeauth_final)(crypto_onetimeauth_poly1305_state *state, 18 | unsigned char * out); 19 | } crypto_onetimeauth_poly1305_implementation; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_poly1305-sse2.h: -------------------------------------------------------------------------------- 1 | #ifndef poly1305_sse2_H 2 | #define poly1305_sse2_H 3 | 4 | #include 5 | 6 | #include "sodium_onetimeauth_poly1305.h" 7 | #include "sodium_crypto_onetimeauth_poly1305.h" 8 | 9 | extern struct crypto_onetimeauth_poly1305_implementation 10 | crypto_onetimeauth_poly1305_sse2_implementation; 11 | 12 | #endif /* poly1305_sse2_H */ 13 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_poly1305_donna.h: -------------------------------------------------------------------------------- 1 | #ifndef poly1305_donna_H 2 | #define poly1305_donna_H 3 | 4 | #include 5 | 6 | #include "sodium_onetimeauth_poly1305.h" 7 | #include "sodium_crypto_onetimeauth_poly1305.h" 8 | 9 | extern struct crypto_onetimeauth_poly1305_implementation 10 | crypto_onetimeauth_poly1305_donna_implementation; 11 | 12 | #endif /* poly1305_donna_H */ 13 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_private_chacha20_ietf_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef chacha20_ietf_ext_H 2 | #define chacha20_ietf_ext_H 3 | 4 | #include 5 | 6 | /* The ietf_ext variant allows the internal counter to overflow into the IV */ 7 | 8 | int crypto_stream_chacha20_ietf_ext(unsigned char *c, unsigned long long clen, 9 | const unsigned char *n, const unsigned char *k); 10 | 11 | int crypto_stream_chacha20_ietf_ext_xor_ic(unsigned char *c, const unsigned char *m, 12 | unsigned long long mlen, 13 | const unsigned char *n, uint32_t ic, 14 | const unsigned char *k); 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_private_implementations.h: -------------------------------------------------------------------------------- 1 | #ifndef implementations_H 2 | #define implementations_H 3 | 4 | int _crypto_generichash_blake2b_pick_best_implementation(void); 5 | int _crypto_onetimeauth_poly1305_pick_best_implementation(void); 6 | int _crypto_scalarmult_curve25519_pick_best_implementation(void); 7 | int _crypto_stream_chacha20_pick_best_implementation(void); 8 | int _crypto_stream_salsa20_pick_best_implementation(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_private_mutex.h: -------------------------------------------------------------------------------- 1 | #ifndef mutex_H 2 | #define mutex_H 1 3 | 4 | extern int sodium_crit_enter(void); 5 | extern int sodium_crit_leave(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_private_sse2_64_32.h: -------------------------------------------------------------------------------- 1 | #ifndef sse2_64_32_H 2 | #define sse2_64_32_H 1 3 | 4 | #include "sodium_private_common.h" 5 | 6 | #ifdef HAVE_INTRIN_H 7 | # include 8 | #endif 9 | 10 | #if defined(HAVE_EMMINTRIN_H) && \ 11 | !(defined(__amd64) || defined(__amd64__) || defined(__x86_64__) || \ 12 | defined(_M_X64) || defined(_M_AMD64)) 13 | 14 | # include 15 | # include 16 | 17 | # ifndef _mm_set_epi64x 18 | # define _mm_set_epi64x(Q0, Q1) sodium__mm_set_epi64x((Q0), (Q1)) 19 | static inline __m128i 20 | sodium__mm_set_epi64x(int64_t q1, int64_t q0) 21 | { 22 | union { int64_t as64; int32_t as32[2]; } x0, x1; 23 | x0.as64 = q0; x1.as64 = q1; 24 | return _mm_set_epi32(x1.as32[1], x1.as32[0], x0.as32[1], x0.as32[0]); 25 | } 26 | # endif 27 | 28 | # ifndef _mm_set1_epi64x 29 | # define _mm_set1_epi64x(Q) sodium__mm_set1_epi64x(Q) 30 | static inline __m128i 31 | sodium__mm_set1_epi64x(int64_t q) 32 | { 33 | return _mm_set_epi64x(q, q); 34 | } 35 | # endif 36 | 37 | # ifndef _mm_cvtsi64_si128 38 | # define _mm_cvtsi64_si128(Q) sodium__mm_cvtsi64_si128(Q) 39 | static inline __m128i 40 | sodium__mm_cvtsi64_si128(int64_t q) 41 | { 42 | union { int64_t as64; int32_t as32[2]; } x; 43 | x.as64 = q; 44 | return _mm_setr_epi32(x.as32[0], x.as32[1], 0, 0); 45 | } 46 | # endif 47 | 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_randombytes_nativeclient.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_nativeclient_H 3 | #define randombytes_nativeclient_H 4 | 5 | #ifdef __native_client__ 6 | 7 | # include "sodium_export.h" 8 | # include "sodium_randombytes.h" 9 | 10 | # ifdef __cplusplus 11 | extern "C" { 12 | # endif 13 | 14 | extern struct randombytes_implementation randombytes_nativeclient_implementation; 15 | 16 | # ifdef __cplusplus 17 | } 18 | # endif 19 | 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_randombytes_salsa20_random.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_salsa20_random_H 3 | #define randombytes_salsa20_random_H 4 | 5 | #include "sodium_export.h" 6 | #include "sodium_randombytes.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | extern struct randombytes_implementation randombytes_salsa20_implementation; 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_randombytes_sysrandom.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef randombytes_sysrandom_H 3 | #define randombytes_sysrandom_H 4 | 5 | #include "sodium_export.h" 6 | #include "sodium_randombytes.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | extern struct randombytes_implementation randombytes_sysrandom_implementation; 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_ref10_sign_ed25519.h: -------------------------------------------------------------------------------- 1 | #ifndef sign_ed25519_ref10_H 2 | #define sign_ed25519_ref10_H 3 | 4 | void _crypto_sign_ed25519_ref10_hinit(crypto_hash_sha512_state *hs, 5 | int prehashed); 6 | 7 | int _crypto_sign_ed25519_detached(unsigned char *sig, 8 | unsigned long long *siglen_p, 9 | const unsigned char *m, 10 | unsigned long long mlen, 11 | const unsigned char *sk, int prehashed); 12 | 13 | int _crypto_sign_ed25519_verify_detached(const unsigned char *sig, 14 | const unsigned char *m, 15 | unsigned long long mlen, 16 | const unsigned char *pk, 17 | int prehashed); 18 | #endif 19 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_ref10_x25519.h: -------------------------------------------------------------------------------- 1 | #ifndef x25519_ref10_H 2 | #define x25519_ref10_H 3 | 4 | #include "sodium_crypto_scalarmult_curve25519.h" 5 | #include "sodium_scalarmult_curve25519.h" 6 | 7 | extern struct crypto_scalarmult_curve25519_implementation 8 | crypto_scalarmult_curve25519_ref10_implementation; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_runtime.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef sodium_runtime_H 3 | #define sodium_runtime_H 4 | 5 | #include "sodium_export.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int sodium_runtime_has_neon(void); 12 | 13 | int sodium_runtime_has_sse2(void); 14 | 15 | int sodium_runtime_has_sse3(void); 16 | 17 | int sodium_runtime_has_ssse3(void); 18 | 19 | int sodium_runtime_has_sse41(void); 20 | 21 | int sodium_runtime_has_avx(void); 22 | 23 | int sodium_runtime_has_avx2(void); 24 | 25 | int sodium_runtime_has_avx512f(void); 26 | 27 | int sodium_runtime_has_pclmul(void); 28 | 29 | int sodium_runtime_has_aesni(void); 30 | 31 | int sodium_runtime_has_rdrand(void); 32 | 33 | /* ------------------------------------------------------------------------- */ 34 | 35 | int _sodium_runtime_get_cpu_features(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_salsa20-ref.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_salsa20.h" 5 | #include "sodium_crypto_stream_salsa20.h" 6 | 7 | extern struct crypto_stream_salsa20_implementation 8 | crypto_stream_salsa20_ref_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_salsa20-xmm6.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_utils.h" 5 | #include "sodium_stream_salsa20.h" 6 | #include "sodium_salsa20-xmm6.h" 7 | #include "sodium_private_common.h" 8 | 9 | #ifdef HAVE_AMD64_ASM 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | extern int stream_salsa20_xmm6(unsigned char *c, unsigned long long clen, 15 | const unsigned char *n, const unsigned char *k); 16 | 17 | extern int stream_salsa20_xmm6_xor_ic(unsigned char *c, const unsigned char *m, 18 | unsigned long long mlen, 19 | const unsigned char *n, 20 | uint64_t ic, const unsigned char *k); 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | struct crypto_stream_salsa20_implementation 26 | crypto_stream_salsa20_xmm6_implementation = { 27 | SODIUM_C99(.stream =) stream_salsa20_xmm6, 28 | SODIUM_C99(.stream_xor_ic =) stream_salsa20_xmm6_xor_ic, 29 | }; 30 | 31 | #endif 32 | 33 | int salsa20_xmm6_link_warning_dummy = 0; 34 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_salsa20-xmm6.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_salsa20.h" 5 | #include "sodium_crypto_stream_salsa20.h" 6 | 7 | extern struct crypto_stream_salsa20_implementation 8 | crypto_stream_salsa20_xmm6_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x.S: -------------------------------------------------------------------------------- 1 | 2 | #ifdef NEXT_AVX 3 | 4 | #define IN_SANDY2X 5 | 6 | #include "sodium_sandy2x_consts.S" 7 | #include "sodium_sandy2x_fe51_mul.S" 8 | #include "sodium_sandy2x_fe51_nsquare.S" 9 | #include "sodium_sandy2x_fe51_pack.S" 10 | #include "sodium_sandy2x_ladder.S" 11 | #include "sodium_sandy2x_ladder_base.S" 12 | 13 | #if defined(__linux__) && defined(__ELF__) 14 | .section .note.GNU-stack,"",%progbits 15 | #endif 16 | 17 | #endif 18 | 19 | .globl consts_S_dummy 20 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_consts.S: -------------------------------------------------------------------------------- 1 | #ifdef IN_SANDY2X 2 | 3 | /* 4 | REDMASK51 is from amd64-51/consts.s. 5 | */ 6 | 7 | #include "sodium_sandy2x_consts_namespace.h" 8 | .data 9 | .p2align 4 10 | v0_0: .quad 0, 0 11 | v1_0: .quad 1, 0 12 | v2_1: .quad 2, 1 13 | v9_0: .quad 9, 0 14 | v9_9: .quad 9, 9 15 | v19_19: .quad 19, 19 16 | v38_1: .quad 38, 1 17 | v38_38: .quad 38, 38 18 | v121666_121666: .quad 121666, 121666 19 | m25: .quad 33554431, 33554431 20 | m26: .quad 67108863, 67108863 21 | subc0: .quad 0x07FFFFDA, 0x03FFFFFE 22 | subc2: .quad 0x07FFFFFE, 0x03FFFFFE 23 | REDMASK51: .quad 0x0007FFFFFFFFFFFF 24 | 25 | #endif 26 | 27 | .globl consts_S_dummy 28 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_consts_namespace.h: -------------------------------------------------------------------------------- 1 | #ifndef consts_namespace_H 2 | #define consts_namespace_H 3 | 4 | #define v0_0 crypto_scalarmult_curve25519_sandy2x_v0_0 5 | #define v1_0 crypto_scalarmult_curve25519_sandy2x_v1_0 6 | #define v2_1 crypto_scalarmult_curve25519_sandy2x_v2_1 7 | #define v9_0 crypto_scalarmult_curve25519_sandy2x_v9_0 8 | #define v9_9 crypto_scalarmult_curve25519_sandy2x_v9_9 9 | #define v19_19 crypto_scalarmult_curve25519_sandy2x_v19_19 10 | #define v38_1 crypto_scalarmult_curve25519_sandy2x_v38_1 11 | #define v38_38 crypto_scalarmult_curve25519_sandy2x_v38_38 12 | #define v121666_121666 crypto_scalarmult_curve25519_sandy2x_v121666_121666 13 | #define m25 crypto_scalarmult_curve25519_sandy2x_m25 14 | #define m26 crypto_scalarmult_curve25519_sandy2x_m26 15 | #define subc0 crypto_scalarmult_curve25519_sandy2x_subc0 16 | #define subc2 crypto_scalarmult_curve25519_sandy2x_subc2 17 | #define REDMASK51 crypto_scalarmult_curve25519_sandy2x_REDMASK51 18 | 19 | #endif /* ifndef consts_namespace_H */ 20 | 21 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_curve25519.h: -------------------------------------------------------------------------------- 1 | #ifndef curve25519_sandy2x_H 2 | #define curve25519_sandy2x_H 3 | 4 | #include "sodium_crypto_scalarmult_curve25519.h" 5 | 6 | extern struct crypto_scalarmult_curve25519_implementation 7 | crypto_scalarmult_curve25519_sandy2x_implementation; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_fe.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is adapted from ref10/fe.h: 3 | All the redundant functions are removed. 4 | */ 5 | 6 | #ifndef fe_H 7 | #define fe_H 8 | 9 | #include 10 | #include 11 | 12 | typedef uint64_t fe[10]; 13 | 14 | /* 15 | fe means field element. 16 | Here the field is \Z/(2^255-19). 17 | An element t, entries t[0]...t[9], represents the integer 18 | t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9]. 19 | Bounds on each t[i] vary depending on context. 20 | */ 21 | 22 | #define fe_frombytes crypto_scalarmult_curve25519_sandy2x_fe_frombytes 23 | 24 | extern void fe_frombytes(fe, const unsigned char *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_fe51.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is adapted from amd64-51/fe25519.h: 3 | 'fe25519' is renamed as 'fe51'; 4 | All the redundant functions are removed; 5 | New function fe51_nsquare is introduced. 6 | */ 7 | 8 | #ifndef fe51_H 9 | #define fe51_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | #include "sodium_sandy2x_fe51_namespace.h" 19 | 20 | typedef struct 21 | { 22 | uint64_t v[5]; 23 | } 24 | fe51; 25 | 26 | extern void fe51_pack(unsigned char *, const fe51 *); 27 | extern void fe51_mul(fe51 *, const fe51 *, const fe51 *); 28 | extern void fe51_nsquare(fe51 *, const fe51 *, int); 29 | extern void fe51_invert(fe51 *, const fe51 *); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_fe51_namespace.h: -------------------------------------------------------------------------------- 1 | #ifndef fe51_namespace_H 2 | #define fe51_namespace_H 3 | 4 | #define fe51 crypto_scalarmult_curve25519_sandy2x_fe51 5 | #define _fe51 _crypto_scalarmult_curve25519_sandy2x_fe51 6 | #define fe51_pack crypto_scalarmult_curve25519_sandy2x_fe51_pack 7 | #define _fe51_pack _crypto_scalarmult_curve25519_sandy2x_fe51_pack 8 | #define fe51_mul crypto_scalarmult_curve25519_sandy2x_fe51_mul 9 | #define _fe51_mul _crypto_scalarmult_curve25519_sandy2x_fe51_mul 10 | #define fe51_nsquare crypto_scalarmult_curve25519_sandy2x_fe51_nsquare 11 | #define _fe51_nsquare _crypto_scalarmult_curve25519_sandy2x_fe51_nsquare 12 | 13 | #define fe51_invert crypto_scalarmult_curve25519_sandy2x_fe51_invert 14 | 15 | #endif /* ifndef fe51_namespace_H */ 16 | 17 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_ladder.h: -------------------------------------------------------------------------------- 1 | #ifndef ladder_H 2 | #define ladder_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "sodium_sandy2x_fe.h" 9 | #include "sodium_sandy2x_ladder_namespace.h" 10 | 11 | extern void ladder(fe *, const unsigned char *); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* ifndef ladder_H */ 18 | 19 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_ladder_base.h: -------------------------------------------------------------------------------- 1 | #ifndef ladder_base_H 2 | #define ladder_base_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "sodium_sandy2x_fe.h" 9 | #include "sodium_sandy2x_ladder_base_namespace.h" 10 | 11 | extern void ladder_base(fe *, const unsigned char *); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* ifndef ladder_base_H */ 18 | 19 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_ladder_base_namespace.h: -------------------------------------------------------------------------------- 1 | #ifndef ladder_base_namespace_H 2 | #define ladder_base_namespace_H 3 | 4 | #define ladder_base crypto_scalarmult_curve25519_sandy2x_ladder_base 5 | #define _ladder_base _crypto_scalarmult_curve25519_sandy2x_ladder_base 6 | 7 | #endif /* ifndef ladder_base_namespace_H */ 8 | 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_sandy2x_ladder_namespace.h: -------------------------------------------------------------------------------- 1 | #ifndef ladder_namespace_H 2 | #define ladder_namespace_H 3 | 4 | #define ladder crypto_scalarmult_curve25519_sandy2x_ladder 5 | #define _ladder _crypto_scalarmult_curve25519_sandy2x_ladder 6 | 7 | #endif /* ifndef ladder_namespace_H */ 8 | 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_scalarmult_curve25519.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef scalarmult_poly1305_H 3 | #define scalarmult_poly1305_H 4 | 5 | typedef struct crypto_scalarmult_curve25519_implementation { 6 | int (*mult)(unsigned char *q, const unsigned char *n, 7 | const unsigned char *p); 8 | int (*mult_base)(unsigned char *q, const unsigned char *n); 9 | } crypto_scalarmult_curve25519_implementation; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_stream_chacha20.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef stream_chacha20_H 3 | #define stream_chacha20_H 4 | 5 | #include 6 | 7 | typedef struct crypto_stream_chacha20_implementation { 8 | int (*stream)(unsigned char *c, unsigned long long clen, 9 | const unsigned char *n, const unsigned char *k); 10 | int (*stream_ietf_ext)(unsigned char *c, unsigned long long clen, 11 | const unsigned char *n, const unsigned char *k); 12 | int (*stream_xor_ic)(unsigned char *c, const unsigned char *m, 13 | unsigned long long mlen, 14 | const unsigned char *n, uint64_t ic, 15 | const unsigned char *k); 16 | int (*stream_ietf_ext_xor_ic)(unsigned char *c, const unsigned char *m, 17 | unsigned long long mlen, 18 | const unsigned char *n, uint32_t ic, 19 | const unsigned char *k); 20 | } crypto_stream_chacha20_implementation; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_stream_salsa20.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef stream_salsa20_H 3 | #define stream_salsa20_H 4 | 5 | #include 6 | 7 | typedef struct crypto_stream_salsa20_implementation { 8 | int (*stream)(unsigned char *c, unsigned long long clen, 9 | const unsigned char *n, const unsigned char *k); 10 | int (*stream_xor_ic)(unsigned char *c, const unsigned char *m, 11 | unsigned long long mlen, 12 | const unsigned char *n, uint64_t ic, 13 | const unsigned char *k); 14 | } crypto_stream_salsa20_implementation; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_version.c: -------------------------------------------------------------------------------- 1 | 2 | #include "sodium_version.h" 3 | 4 | const char * 5 | sodium_version_string(void) 6 | { 7 | return SODIUM_VERSION_STRING; 8 | } 9 | 10 | int 11 | sodium_library_version_major(void) 12 | { 13 | return SODIUM_LIBRARY_VERSION_MAJOR; 14 | } 15 | 16 | int 17 | sodium_library_version_minor(void) 18 | { 19 | return SODIUM_LIBRARY_VERSION_MINOR; 20 | } 21 | 22 | int 23 | sodium_library_minimal(void) 24 | { 25 | #ifdef SODIUM_LIBRARY_MINIMAL 26 | return 1; 27 | #else 28 | return 0; 29 | #endif 30 | } 31 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_version.h: -------------------------------------------------------------------------------- 1 | #ifndef sodium_version_H 2 | #define sodium_version_H 3 | 4 | #include "sodium_export.h" 5 | 6 | #define SODIUM_VERSION_STRING "1.0.17" 7 | 8 | #define SODIUM_LIBRARY_VERSION_MAJOR 10 9 | #define SODIUM_LIBRARY_VERSION_MINOR 2 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | const char *sodium_version_string(void); 16 | 17 | int sodium_library_version_major(void); 18 | 19 | int sodium_library_version_minor(void); 20 | 21 | int sodium_library_minimal(void); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_xmm6int_salsa20-avx2.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_salsa20.h" 5 | #include "sodium_crypto_stream_salsa20.h" 6 | 7 | extern struct crypto_stream_salsa20_implementation 8 | crypto_stream_salsa20_xmm6int_avx2_implementation; 9 | -------------------------------------------------------------------------------- /sdk/sodium/sodium_xmm6int_salsa20-sse2.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "sodium_stream_salsa20.h" 5 | #include "sodium_crypto_stream_salsa20.h" 6 | 7 | extern struct crypto_stream_salsa20_implementation 8 | crypto_stream_salsa20_xmm6int_sse2_implementation; 9 | -------------------------------------------------------------------------------- /sdk/source/next_config.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next_config.h" 8 | 9 | uint8_t next_server_backend_public_key[32]; 10 | 11 | uint8_t next_relay_backend_public_key[32]; 12 | -------------------------------------------------------------------------------- /sdk/source/next_hash.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next_hash.h" 8 | 9 | #include 10 | 11 | typedef uint64_t next_fnv_t; 12 | 13 | void next_fnv_init( next_fnv_t * fnv ) 14 | { 15 | *fnv = 0xCBF29CE484222325; 16 | } 17 | 18 | void next_fnv_write( next_fnv_t * fnv, const uint8_t * data, size_t size ) 19 | { 20 | for ( size_t i = 0; i < size; i++ ) 21 | { 22 | (*fnv) ^= data[i]; 23 | (*fnv) *= 0x00000100000001B3; 24 | } 25 | } 26 | 27 | uint64_t next_fnv_finalize( next_fnv_t * fnv ) 28 | { 29 | return *fnv; 30 | } 31 | 32 | uint64_t next_hash_string( const char * string ) 33 | { 34 | next_fnv_t fnv; 35 | next_fnv_init( &fnv ); 36 | next_fnv_write( &fnv, (uint8_t *)( string ), strlen( string ) ); 37 | return next_fnv_finalize( &fnv ); 38 | } 39 | 40 | uint64_t next_relay_id( const char * name ) 41 | { 42 | return next_hash_string( name ); 43 | } 44 | 45 | uint64_t next_datacenter_id( const char * name ) 46 | { 47 | return next_hash_string( name ); 48 | } 49 | -------------------------------------------------------------------------------- /sdk/test.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM ubuntu:22.04 4 | 5 | RUN apt update -y && apt upgrade -y && apt install libsodium-dev build-essential -y 6 | 7 | WORKDIR /app 8 | 9 | COPY . . 10 | 11 | RUN g++ -o libnext.so -Iinclude source/*.cpp -shared -fPIC -lsodium -lpthread -lm -DNEXT_DEVELOPMENT=1 12 | RUN g++ -o complex_client -Iinclude examples/complex_client.cpp libnext.so -lpthread -lm -DNEXT_DEVELOPMENT=1 13 | RUN mv /app/libnext.so /usr/local/lib && ldconfig 14 | 15 | CMD [ "/app/complex_client" ] 16 | -------------------------------------------------------------------------------- /sdk/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Network Next. Copyright © 2017 - 2025 Network Next, Inc. 3 | 4 | Licensed under the Network Next Source Available License 1.0 5 | */ 6 | 7 | #include "next.h" 8 | #include "next_tests.h" 9 | 10 | #include 11 | #include 12 | 13 | int main() 14 | { 15 | next_quiet( true ); 16 | 17 | if ( next_init( NULL, NULL ) != NEXT_OK ) 18 | { 19 | printf( "error: failed to initialize network next\n" ); 20 | } 21 | 22 | printf( "\nRunning SDK tests:\n\n" ); 23 | 24 | next_run_tests(); 25 | 26 | next_term(); 27 | 28 | printf( "\n" ); 29 | 30 | fflush( stdout ); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /terraform/dev/backend/terraform.tfvars: -------------------------------------------------------------------------------- 1 | 2 | extra = "" 3 | 4 | vpn_address = "45.79.157.168" 5 | 6 | google_credentials = "~/secrets/terraform-dev.json" 7 | google_location = "US" 8 | google_region = "us-central1" 9 | google_zone = "us-central1-a" 10 | google_zones = ["us-central1-a", "us-central1-b", "us-central1-c"] 11 | google_artifacts_bucket = "gs://next_network_next_backend_artifacts" 12 | google_database_bucket = "gs://next_network_next_database_files" 13 | 14 | cloudflare_api_token = "~/secrets/terraform-cloudflare.txt" 15 | cloudflare_zone_id = "eba5d882ea2aa23f92dfb50fbf7e3cf4" 16 | cloudflare_domain = "virtualgo.net" 17 | 18 | test_buyer_public_key = "OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 19 | test_buyer_private_key = "OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 20 | 21 | raspberry_buyer_public_key = "YJHQ5FGeoveQMdSzLRmbOKFRVY6QeMyUX1c4kRA72anucqnPRBr8IA==" 22 | raspberry_buyer_private_key = "YJHQ5FGeovcEX0r2r9P1LH+8tnnA3oQ7RSV6f/r0ihkbC2MOLVVbsJAx1LMtGZs4oVFVjpB4zJRfVziREDvZqe5yqc9EGvwg" 23 | 24 | ip2location_bucket_name = "next_network_next_dev" 25 | 26 | relay_backend_public_key = "XMZGJsM6tHP2vFBXQZBmXguSNa9Czs8V/pcCfhF2KhU=" 27 | 28 | server_backend_public_key = "9ShrWyUWRm+twHzd5xJuO3kpH1j9hGuxK2MlfI44x38=" 29 | 30 | test_server_region = "us-central1" 31 | test_server_zone = "us-central1-a" 32 | test_server_tag = "007" # increment this each time you want to deploy the test server 33 | 34 | disable_backend = false 35 | disable_raspberry = false 36 | disable_ip2location = false 37 | -------------------------------------------------------------------------------- /terraform/dev/relays/amazon/main.tf: -------------------------------------------------------------------------------- 1 | # ========================================================================== 2 | # AMAZON CLOUD 3 | # ========================================================================== 4 | 5 | /* 6 | Unfortunately, it is LITERALLY IMPOSSIBLE to work programmatically in 7 | terraform across multiple regions in AWS :( 8 | 9 | To work around this we use code generation. 10 | 11 | The set of amazon dev relays in dev are defined at the top of this file: 12 | 13 | config/amazon.go 14 | 15 | Make your edits in there, then run the amazon configuration tool: 16 | 17 | "run config-amazon" 18 | 19 | This generates the following files: 20 | 21 | config/amazon.txt 22 | terraform/dev/relays/amazon/generated.tf 23 | 24 | IMPORTANT: You need to enable some regions and zones manually in your AWS account. 25 | 26 | For more details see: 27 | 28 | https://docs.aws.amazon.com/general/latest/gr/rande-manage.html 29 | 30 | and 31 | 32 | https://aws.amazon.com/about-aws/global-infrastructure/localzones/locations/ 33 | */ 34 | 35 | # -------------------------------------------------------------------------- 36 | 37 | variable "config" { type = list(string) } 38 | variable "credentials" { type = list(string) } 39 | variable "profile" { type = string } 40 | variable "ssh_public_key_file" { type = string } 41 | variable "vpn_address" { type = string } 42 | 43 | # -------------------------------------------------------------------------- 44 | 45 | output "datacenters" { 46 | description = "Data for each amazon datacenter" 47 | value = local.datacenter_map 48 | } 49 | 50 | # -------------------------------------------------------------------------- 51 | -------------------------------------------------------------------------------- /terraform/dev/relays/amazon/region/main.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 4.0" 7 | } 8 | } 9 | } 10 | 11 | variable "ssh_public_key_file" { type = string } 12 | variable "vpn_address" { type = string } 13 | 14 | resource "aws_default_vpc" "default" { 15 | tags = { 16 | Name = "dev-default" 17 | } 18 | } 19 | 20 | resource "aws_key_pair" "ssh_key" { 21 | key_name = "dev-region-ssh-key" 22 | public_key = file(var.ssh_public_key_file) 23 | } 24 | 25 | resource "aws_security_group" "allow_ssh_and_udp" { 26 | 27 | name = "dev-region-security-group" 28 | 29 | vpc_id = aws_default_vpc.default.id 30 | 31 | ingress { 32 | protocol = "tcp" 33 | from_port = 22 34 | to_port = 22 35 | cidr_blocks = ["${var.vpn_address}/32"] 36 | } 37 | 38 | ingress { 39 | protocol = "udp" 40 | from_port = 40000 41 | to_port = 40000 42 | cidr_blocks = ["0.0.0.0/0"] 43 | } 44 | 45 | egress { 46 | from_port = 0 47 | to_port = 0 48 | protocol = "-1" 49 | cidr_blocks = ["0.0.0.0/0"] 50 | } 51 | 52 | lifecycle { 53 | create_before_destroy = true 54 | } 55 | } 56 | 57 | output "security_group_id" { 58 | description = "The id of the security group for this region" 59 | value = aws_security_group.allow_ssh_and_udp.id 60 | } 61 | -------------------------------------------------------------------------------- /terraform/dev/relays/terraform.tfvars: -------------------------------------------------------------------------------- 1 | 2 | # dev relay variables 3 | 4 | env = "dev" 5 | vpn_address = "45.79.157.168" 6 | ssh_public_key_file = "~/secrets/next_ssh.pub" 7 | ssh_private_key_file = "~/secrets/next_ssh" 8 | relay_version = "relay-release-1.0.0" 9 | relay_artifacts_bucket = "next_network_next_relay_artifacts" 10 | relay_backend_public_key = "XMZGJsM6tHP2vFBXQZBmXguSNa9Czs8V/pcCfhF2KhU=" 11 | relay_backend_url = "relay-dev.virtualgo.net" 12 | 13 | raspberry_buyer_public_key = "YJHQ5FGeoveQMdSzLRmbOKFRVY6QeMyUX1c4kRA72anucqnPRBr8IA==" 14 | 15 | raspberry_datacenters = [ 16 | "google.iowa.1", 17 | "google.iowa.2", 18 | "google.iowa.3", 19 | "google.iowa.6" 20 | ] 21 | 22 | test_buyer_public_key = "OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 23 | 24 | test_datacenters = [ 25 | "google.iowa.1", 26 | "google.iowa.2", 27 | "google.iowa.3", 28 | "google.iowa.6" 29 | ] 30 | 31 | sellers = { 32 | "Akamai" = "akamai" 33 | "Amazon" = "amazon" 34 | "Google" = "google" 35 | "Datapacket" = "datapacket" 36 | "i3D" = "i3d" 37 | "Oneqode" = "oneqode" 38 | "GCore" = "gcore" 39 | "Hivelocity" = "hivelocity" 40 | "ColoCrossing" = "colocrossing" 41 | "phoenixNAP" = "phoenixnap" 42 | "servers.com" = "serversdotcom" 43 | "Velia" = "velia" 44 | "Zenlayer" = "zenlayer" 45 | "Latitude" = "latitude" 46 | "Equinix" = "equinix" 47 | } 48 | -------------------------------------------------------------------------------- /terraform/prod/backend/terraform.tfvars: -------------------------------------------------------------------------------- 1 | 2 | extra = "" 3 | 4 | vpn_address = "45.79.157.168" 5 | 6 | google_credentials = "~/secrets/terraform-prod.json" 7 | google_location = "US" 8 | google_region = "us-central1" 9 | google_zone = "us-central1-a" 10 | google_zones = ["us-central1-a", "us-central1-b", "us-central1-c"] # IMPORTANT: c3 family is only available in these zones, not us-central1-f 11 | google_artifacts_bucket = "gs://next_network_next_backend_artifacts" 12 | google_database_bucket = "gs://next_network_next_database_files" 13 | 14 | cloudflare_api_token = "~/secrets/terraform-cloudflare.txt" 15 | cloudflare_zone_id = "eba5d882ea2aa23f92dfb50fbf7e3cf4" 16 | cloudflare_domain = "virtualgo.net" 17 | 18 | test_buyer_public_key = "OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 19 | test_buyer_private_key = "OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 20 | 21 | raspberry_buyer_public_key = "YJHQ5FGeoveQMdSzLRmbOKFRVY6QeMyUX1c4kRA72anucqnPRBr8IA==" 22 | raspberry_buyer_private_key = "YJHQ5FGeovcEX0r2r9P1LH+8tnnA3oQ7RSV6f/r0ihkbC2MOLVVbsJAx1LMtGZs4oVFVjpB4zJRfVziREDvZqe5yqc9EGvwg" 23 | 24 | ip2location_bucket_name = "next_network_next_prod" 25 | 26 | relay_backend_public_key = "unH/Yxm0C6JCZ1dTGZH2BTBOFhGMcYsOEDURd9qY72w=" 27 | 28 | server_backend_public_key = "Uycn3KibCfXJo1uM+NNWgCySRzM2Ti3bhvom9XBkxfE=" 29 | 30 | test_server_region = "us-central1" 31 | test_server_zone = "us-central1-a" 32 | test_server_tag = "001" # increment this each time you want to deploy the test server 33 | 34 | disable_backend = false 35 | disable_raspberry = false 36 | disable_ip2location = false 37 | -------------------------------------------------------------------------------- /terraform/prod/relays/amazon/main.tf: -------------------------------------------------------------------------------- 1 | # ========================================================================== 2 | # AMAZON CLOUD 3 | # ========================================================================== 4 | 5 | /* 6 | Unfortunately, it is LITERALLY IMPOSSIBLE to work programmatically in 7 | terraform across multiple regions in AWS :( 8 | 9 | To work around this we use code generation. 10 | 11 | The set of amazon dev relays in dev are defined at the top of this file: 12 | 13 | config/amazon.go 14 | 15 | Make your edits in there, then run the amazon configuration tool: 16 | 17 | "run config-amazon" 18 | 19 | This generates the following files: 20 | 21 | config/amazon.txt 22 | terraform/dev/relays/amazon/generated.tf 23 | 24 | IMPORTANT: You need to enable some regions and zones manually in your AWS account. 25 | 26 | For more details see: 27 | 28 | https://docs.aws.amazon.com/general/latest/gr/rande-manage.html 29 | 30 | and 31 | 32 | https://aws.amazon.com/about-aws/global-infrastructure/localzones/locations/ 33 | */ 34 | 35 | # -------------------------------------------------------------------------- 36 | 37 | variable "config" { type = list(string) } 38 | variable "credentials" { type = list(string) } 39 | variable "profile" { type = string } 40 | variable "ssh_public_key_file" { type = string } 41 | variable "vpn_address" { type = string } 42 | 43 | # -------------------------------------------------------------------------- 44 | 45 | output "datacenters" { 46 | description = "Data for each amazon datacenter" 47 | value = local.datacenter_map 48 | } 49 | 50 | # -------------------------------------------------------------------------- 51 | -------------------------------------------------------------------------------- /terraform/prod/relays/amazon/region/main.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = "~> 4.0" 7 | } 8 | } 9 | } 10 | 11 | variable "ssh_public_key_file" { type = string } 12 | variable "vpn_address" { type = string } 13 | 14 | resource "aws_default_vpc" "default" { 15 | tags = { 16 | Name = "prod-default" 17 | } 18 | } 19 | 20 | resource "aws_key_pair" "ssh_key" { 21 | key_name = "prod-region-ssh-key" 22 | public_key = file(var.ssh_public_key_file) 23 | } 24 | 25 | resource "aws_security_group" "allow_ssh_and_udp" { 26 | 27 | name = "prod-region-security-group" 28 | 29 | vpc_id = aws_default_vpc.default.id 30 | 31 | ingress { 32 | protocol = "tcp" 33 | from_port = 22 34 | to_port = 22 35 | cidr_blocks = ["${var.vpn_address}/32"] 36 | } 37 | 38 | ingress { 39 | protocol = "udp" 40 | from_port = 40000 41 | to_port = 40000 42 | cidr_blocks = ["0.0.0.0/0"] 43 | } 44 | 45 | egress { 46 | from_port = 0 47 | to_port = 0 48 | protocol = "-1" 49 | cidr_blocks = ["0.0.0.0/0"] 50 | } 51 | 52 | lifecycle { 53 | create_before_destroy = true 54 | } 55 | } 56 | 57 | output "security_group_id" { 58 | description = "The id of the security group for this region" 59 | value = aws_security_group.allow_ssh_and_udp.id 60 | } 61 | -------------------------------------------------------------------------------- /terraform/prod/relays/terraform.tfvars: -------------------------------------------------------------------------------- 1 | 2 | # prod relay variables 3 | 4 | env = "prod" 5 | vpn_address = "45.79.157.168" 6 | ssh_public_key_file = "~/secrets/next_ssh.pub" 7 | ssh_private_key_file = "~/secrets/next_ssh" 8 | relay_version = "relay-release-1.0.0" 9 | relay_artifacts_bucket = "next_network_next_relay_artifacts" 10 | relay_backend_public_key = "unH/Yxm0C6JCZ1dTGZH2BTBOFhGMcYsOEDURd9qY72w=" 11 | relay_backend_url = "relay.virtualgo.net" 12 | 13 | raspberry_buyer_public_key = "YJHQ5FGeoveQMdSzLRmbOKFRVY6QeMyUX1c4kRA72anucqnPRBr8IA==" 14 | 15 | raspberry_datacenters = [ 16 | "google.iowa.1", 17 | "google.iowa.2", 18 | "google.iowa.3", 19 | "google.iowa.6" 20 | ] 21 | 22 | test_buyer_public_key = "OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 23 | 24 | test_datacenters = [ 25 | "google.iowa.1", 26 | "google.iowa.2", 27 | "google.iowa.3", 28 | "google.iowa.6" 29 | ] 30 | 31 | sellers = { 32 | "Akamai" = "akamai" 33 | "Amazon" = "amazon" 34 | "Google" = "google" 35 | "Datapacket" = "datapacket" 36 | "i3D" = "i3d" 37 | "Oneqode" = "oneqode" 38 | "GCore" = "gcore" 39 | "Hivelocity" = "hivelocity" 40 | "ColoCrossing" = "colocrossing" 41 | "phoenixNAP" = "phoenixnap" 42 | "servers.com" = "serversdotcom" 43 | "Velia" = "velia" 44 | "Zenlayer" = "zenlayer" 45 | "Latitude" = "latitude" 46 | "Equinix" = "equinix" 47 | } 48 | -------------------------------------------------------------------------------- /terraform/sellers/bare_metal/main.tf: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------------------- 2 | 3 | variable "relays" { type = map(map(string)) } 4 | 5 | locals { 6 | 7 | seller_name = "" 8 | 9 | seller_code = "" 10 | 11 | ssh_user = "root" 12 | 13 | datacenter_map = { 14 | 15 | "seller.cityname" = { 16 | latitude = 10.00 17 | longitude = 20.00 18 | native_name = "" 19 | seller_name = local.seller_name 20 | seller_code = local.seller_code 21 | } 22 | 23 | } 24 | 25 | } 26 | 27 | output "relays" { 28 | description = "All relays for " 29 | value = { 30 | for k, v in var.relays : k => zipmap( 31 | [ 32 | "relay_name", 33 | "datacenter_name", 34 | "seller_name", 35 | "seller_code", 36 | "public_ip", 37 | "public_port", 38 | "internal_ip", 39 | "internal_port", 40 | "internal_group", 41 | "ssh_ip", 42 | "ssh_port", 43 | "ssh_user", 44 | ], 45 | [ 46 | k, 47 | v.datacenter_name, 48 | local.seller_name, 49 | local.seller_code, 50 | v.public_address, 51 | 40000, 52 | "0.0.0.0", 53 | 0, 54 | "", 55 | v.public_address, 56 | 22, 57 | local.ssh_user, 58 | ] 59 | ) 60 | } 61 | } 62 | 63 | output "datacenters" { 64 | description = "All datacenters for " 65 | value = locals.datacenter_map 66 | } 67 | 68 | # -------------------------------------------------------------------------- 69 | -------------------------------------------------------------------------------- /terraform/staging/backend/terraform.tfvars: -------------------------------------------------------------------------------- 1 | 2 | extra = "" 3 | 4 | vpn_address = "45.79.157.168" 5 | 6 | google_credentials = "~/secrets/terraform-staging.json" 7 | google_location = "US" 8 | google_region = "us-central1" 9 | google_zone = "us-central1-a" 10 | google_zones = ["us-central1-a", "us-central1-b", "us-central1-c"] # IMPORTANT: c3 family is only available in these zones, not us-central1-f 11 | google_artifacts_bucket = "gs://next_network_next_backend_artifacts" 12 | google_database_bucket = "gs://next_network_next_database_files" 13 | 14 | cloudflare_api_token = "~/secrets/terraform-cloudflare.txt" 15 | cloudflare_zone_id = "eba5d882ea2aa23f92dfb50fbf7e3cf4" 16 | cloudflare_domain = "virtualgo.net" 17 | 18 | relay_backend_public_key = "GwcGxScFxwc6pipXazWOQlz3aTVaNseThiNYtIyd10k=" 19 | 20 | server_backend_public_key = "P3/d3jmPGQof1jjmF7/1aBd6ytd3bJ8rBp4qdkPlr/M=" 21 | 22 | load_test_buyer_public_key = "OPsJ/biQrnQEgoJr2oo9zeJG9vVkOUpWklw2+O2nfyy1BljyFxrU8Q==" 23 | load_test_buyer_private_key = "OPsJ/biQrnQWRDrCHrOYPpYR/aRkRJA3IhJKx1ZZu95p59UokTB6/gSCgmvaij3N4kb29WQ5SlaSXDb47ad/LLUGWPIXGtTx" 24 | 25 | ip2location_bucket_name = "next_network_next_staging" 26 | 27 | relay_public_key = "peLF27fnP8pXz6AqgH6SM7s90iCOgEI+2rjGrACgGCU=" 28 | 29 | relay_private_key = "ACQytjHVJca67Tp5RFCe9f/IKEwQLCxjr8xSymqu09E=" 30 | -------------------------------------------------------------------------------- /tools/artifact/artifact.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "os/exec" 8 | "regexp" 9 | ) 10 | 11 | func bash(command string) (string, string) { 12 | var stdout bytes.Buffer 13 | var stderr bytes.Buffer 14 | cmd := exec.Command("bash", "-c", command) 15 | cmd.Stdout = &stdout 16 | cmd.Stderr = &stderr 17 | err := cmd.Run() 18 | if err != nil { 19 | panic(err) 20 | } 21 | return stdout.String(), stderr.String() 22 | } 23 | 24 | func main() { 25 | 26 | artifact := os.Args[1] 27 | 28 | r, _ := regexp.Compile("^dist/(.*).tar.gz$") 29 | matches := r.FindStringSubmatch(artifact) 30 | service := matches[1] 31 | 32 | fmt.Printf("Building %s\n", artifact) 33 | 34 | bash(fmt.Sprintf("mkdir -p dist/artifact/%s", service)) 35 | 36 | bash(fmt.Sprintf("cp dist/%s dist/artifact/%s/app", service, service)) 37 | 38 | bash(fmt.Sprintf("cp deploy/app.service dist/artifact/%s/app.service", service)) 39 | 40 | if artifact == "raspberry_client" || artifact == "raspberry_server" { 41 | bash(fmt.Sprintf("cp dist/libnext.so dist/artifact/%s/libnext.so", service)) 42 | } 43 | 44 | bash(fmt.Sprintf("cd dist/artifact/%s && tar -zcf ../../%s.tar.gz *", service, service)) 45 | } 46 | -------------------------------------------------------------------------------- /tools/build_portal/build_portal.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | "strings" 8 | ) 9 | 10 | func bash(command string) { 11 | cmd := exec.Command("bash", "-c", command) 12 | cmd.Stdout = os.Stdout 13 | cmd.Stderr = os.Stderr 14 | err := cmd.Run() 15 | if err != nil { 16 | panic(err) 17 | } 18 | } 19 | 20 | func main() { 21 | 22 | envs := []string{"dev", "staging", "prod"} 23 | 24 | for i := range envs { 25 | for j := 1; j < len(os.Args); j++ { 26 | if strings.Contains(os.Args[j], envs[i]) { 27 | bash(fmt.Sprintf("cd portal && yarn build-%s", envs[i])) 28 | return 29 | } 30 | } 31 | } 32 | 33 | bash(fmt.Sprintf("cd portal && yarn build-local")) 34 | } 35 | -------------------------------------------------------------------------------- /tools/extract_database/extract_database.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | db "github.com/networknext/next/modules/database" 8 | ) 9 | 10 | func main() { 11 | 12 | database, err := db.ExtractDatabase("host=127.0.0.1 port=5432 user=developer dbname=postgres sslmode=disable") 13 | 14 | if err != nil { 15 | fmt.Printf("error: failed to extract database: %v\n", err) 16 | os.Exit(1) 17 | } 18 | 19 | err = database.Validate() 20 | if err != nil { 21 | fmt.Printf("error: database did not validate: %v\n", err) 22 | os.Exit(1) 23 | } 24 | 25 | database.Save("database.bin") 26 | 27 | loaded, err := db.LoadDatabase("database.bin") 28 | if err != nil { 29 | fmt.Printf("error: could not load database.bin: %v\n", err) 30 | os.Exit(1) 31 | } 32 | 33 | err = loaded.Validate() 34 | if err != nil { 35 | fmt.Printf("error: loaded database did not validate: %v\n", err) 36 | os.Exit(1) 37 | } 38 | 39 | fmt.Println(loaded.String()) 40 | 41 | fmt.Printf("\n") 42 | } 43 | -------------------------------------------------------------------------------- /tools/load_test_optimize/load_test_optimize.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "time" 7 | 8 | "github.com/networknext/next/modules/common" 9 | "github.com/networknext/next/modules/constants" 10 | "github.com/networknext/next/modules/core" 11 | ) 12 | 13 | func RunOptimizeThread(ctx context.Context) { 14 | 15 | go func() { 16 | 17 | ticker := time.NewTicker(time.Second) 18 | 19 | iteration := uint64(0) 20 | 21 | for { 22 | 23 | select { 24 | 25 | case <-ctx.Done(): 26 | return 27 | 28 | case <-ticker.C: 29 | 30 | numRelays := constants.MaxRelays 31 | 32 | size := core.TriMatrixLength(numRelays) 33 | 34 | costs := make([]uint8, size) 35 | 36 | for i := 0; i < numRelays; i++ { 37 | for j := 0; j < i; j++ { 38 | index := core.TriMatrixIndex(i, j) 39 | costs[index] = uint8(common.RandomInt(0, 255)) 40 | } 41 | } 42 | 43 | numSegments := 256 44 | 45 | relayDatacenterIds := make([]uint64, numRelays) 46 | for i := range relayDatacenterIds { 47 | relayDatacenterIds[i] = uint64(i) 48 | } 49 | 50 | destRelays := make([]bool, numRelays) 51 | for i := range destRelays { 52 | destRelays[i] = true 53 | } 54 | 55 | start := time.Now() 56 | 57 | core.Optimize2(numRelays, numSegments, costs, relayDatacenterIds, destRelays) 58 | 59 | fmt.Printf("iteration %d: optimize %d relays (%dms)\n", iteration, numRelays, time.Since(start).Milliseconds()) 60 | 61 | iteration++ 62 | } 63 | } 64 | }() 65 | } 66 | 67 | func main() { 68 | 69 | RunOptimizeThread(context.Background()) 70 | 71 | time.Sleep(time.Minute) 72 | } 73 | -------------------------------------------------------------------------------- /tools/load_test_route_matrix/load_test_route_matrix.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "time" 7 | 8 | "github.com/networknext/next/modules/common" 9 | "github.com/networknext/next/modules/constants" 10 | ) 11 | 12 | func RunRouteMatrixThread(ctx context.Context) { 13 | 14 | go func() { 15 | 16 | ticker := time.NewTicker(time.Second) 17 | 18 | iteration := uint64(0) 19 | 20 | for { 21 | 22 | select { 23 | 24 | case <-ctx.Done(): 25 | return 26 | 27 | case <-ticker.C: 28 | 29 | numRelays := constants.MaxRelays 30 | 31 | routeMatrix := common.GenerateRandomRouteMatrix(numRelays) 32 | 33 | start := time.Now() 34 | 35 | routeMatrixData, err := routeMatrix.Write() 36 | if err != nil { 37 | panic(fmt.Sprintf("could not write route matrix: %v", err)) 38 | } 39 | 40 | routeMatrixRead := common.RouteMatrix{} 41 | err = routeMatrixRead.Read(routeMatrixData) 42 | if err != nil { 43 | panic(fmt.Sprintf("could not read route matrix: %v", err)) 44 | } 45 | 46 | fmt.Printf("iteration %d: read/write route matrix - %d relays, %d bytes (%dms)\n", iteration, numRelays, len(routeMatrixData), time.Since(start).Milliseconds()) 47 | 48 | iteration++ 49 | } 50 | } 51 | }() 52 | } 53 | 54 | func main() { 55 | 56 | RunRouteMatrixThread(context.Background()) 57 | 58 | time.Sleep(time.Minute) 59 | } 60 | -------------------------------------------------------------------------------- /tools/redis_cluster/redis_cluster.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | "time" 8 | ) 9 | 10 | func runCommand(command string, args []string) bool { 11 | cmd := exec.Command(command, args...) 12 | cmd.Stdout = os.Stdout 13 | cmd.Stderr = os.Stderr 14 | err := cmd.Start() 15 | return err != nil 16 | } 17 | 18 | func bash(command string) bool { 19 | return runCommand("bash", []string{"-c", command}) 20 | } 21 | 22 | func main() { 23 | 24 | fmt.Printf("\nstarting redis cluster\n\n") 25 | 26 | for i := 0; i < 6; i++ { 27 | bash(fmt.Sprintf("cd redis/%03d && redis-server ./redis.conf", 10000+i)) 28 | } 29 | 30 | time.Sleep(time.Second) 31 | 32 | bash("redis-cli --cluster create 127.0.0.1:10000 127.0.0.1:10001 127.0.0.1:10002 127.0.0.1:10003 127.0.0.1:10004 127.0.0.1:10005 --cluster-replicas 1 --cluster-yes") 33 | 34 | for { 35 | time.Sleep(time.Hour) 36 | } 37 | } 38 | --------------------------------------------------------------------------------