load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")

exports_files(
    srcs = [
        "tox.h",
        "tox_attributes.h",
        "tox_dispatch.h",
        "tox_events.h",
        "tox_log_level.h",
        "tox_options.h",
        "tox_private.h",
    ],
    visibility = ["//c-toxcore:__subpackages__"],
)

cc_library(
    name = "test_util",
    testonly = True,
    srcs = ["test_util.cc"],
    hdrs = ["test_util.hh"],
    deps = [
        ":attributes",
    ],
)

cc_test(
    name = "test_util_test",
    size = "small",
    srcs = ["test_util_test.cc"],
    deps = [
        ":crypto_core",
        ":test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "attributes",
    hdrs = ["attributes.h"],
    visibility = ["//c-toxcore:__subpackages__"],
)

cc_library(
    name = "tox_attributes",
    hdrs = ["tox_attributes.h"],
    visibility = ["//c-toxcore:__subpackages__"],
)

cc_library(
    name = "ccompat",
    srcs = ["ccompat.c"],
    hdrs = ["ccompat.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [":attributes"],
)

cc_library(
    name = "mem",
    srcs = ["mem.c"],
    hdrs = ["mem.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
    ],
)

cc_library(
    name = "os_memory",
    srcs = ["os_memory.c"],
    hdrs = ["os_memory.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":mem",
    ],
)

cc_library(
    name = "os_random",
    srcs = ["os_random.c"],
    hdrs = ["os_random.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":rng",
        "@libsodium",
    ],
)

cc_library(
    name = "rng",
    srcs = ["rng.c"],
    hdrs = ["rng.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
    ],
)

cc_library(
    name = "ev",
    srcs = ["ev.c"],
    hdrs = ["ev.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":net",
    ],
)

cc_library(
    name = "os_event",
    srcs = ["os_event.c"],
    hdrs = ["os_event.h"],
    copts = select({
        "//tools/config:linux": ["-DEV_USE_EPOLL=1"],
        "//conditions:default": [],
    }),
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":ccompat",
        ":ev",
        ":logger",
        ":mem",
        ":net",
        ":os_network",
    ],
)

cc_library(
    name = "ev_test_util",
    testonly = True,
    srcs = ["ev_test_util.cc"],
    hdrs = ["ev_test_util.hh"],
    deps = [":net"],
)

cc_test(
    name = "ev_test",
    size = "small",
    srcs = ["ev_test.cc"],
    deps = [
        ":ev",
        ":ev_test_util",
        ":logger",
        ":net",
        ":os_event",
        ":os_memory",
        ":os_network",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_binary(
    name = "ev_bench",
    testonly = True,
    srcs = ["ev_bench.cc"],
    deps = [
        ":ev",
        ":ev_test_util",
        ":logger",
        ":net",
        ":os_event",
        ":os_memory",
        ":os_network",
        "@benchmark",
    ],
)

cc_test(
    name = "mem_test",
    size = "small",
    srcs = ["mem_test.cc"],
    deps = [
        ":attributes",
        ":mem",
        ":os_memory",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "util",
    srcs = ["util.c"],
    hdrs = ["util.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing/fuzzing:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
        "@pthread",
    ],
)

cc_test(
    name = "util_test",
    size = "small",
    srcs = ["util_test.cc"],
    deps = [
        ":util",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "sort",
    srcs = ["sort.c"],
    hdrs = ["sort.h"],
    deps = [
        ":attributes",
        ":ccompat",
        ":util",
    ],
)

cc_library(
    name = "sort_test_util",
    testonly = True,
    srcs = ["sort_test_util.cc"],
    hdrs = ["sort_test_util.hh"],
    deps = [
        ":attributes",
        ":sort",
        ":util",
    ],
)

cc_test(
    name = "sort_test",
    size = "small",
    srcs = ["sort_test.cc"],
    deps = [
        ":sort",
        ":sort_test_util",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_binary(
    name = "sort_bench",
    testonly = True,
    srcs = ["sort_bench.cc"],
    deps = [
        ":attributes",
        ":mem",
        ":sort",
        ":sort_test_util",
        "@benchmark",
    ],
)

cc_library(
    name = "logger",
    srcs = ["logger.c"],
    hdrs = ["logger.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
    ],
)

cc_library(
    name = "bin_pack",
    srcs = ["bin_pack.c"],
    hdrs = ["bin_pack.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":logger",
        "//c-toxcore/third_party:cmp",
    ],
)

cc_library(
    name = "bin_unpack",
    srcs = ["bin_unpack.c"],
    hdrs = ["bin_unpack.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
        "//c-toxcore/third_party:cmp",
    ],
)

cc_test(
    name = "bin_pack_test",
    size = "small",
    srcs = ["bin_pack_test.cc"],
    deps = [
        ":attributes",
        ":bin_pack",
        ":bin_unpack",
        ":logger",
        ":mem",
        ":os_memory",
        ":test_util",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "crypto_core",
    srcs = ["crypto_core.c"],
    hdrs = ["crypto_core.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
        ":rng",
        ":util",
        "@libsodium",
    ],
)

cc_library(
    name = "crypto_core_pack",
    srcs = ["crypto_core_pack.c"],
    hdrs = ["crypto_core_pack.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":bin_pack",
        ":bin_unpack",
        ":ccompat",
        ":crypto_core",
    ],
)

cc_library(
    name = "crypto_core_test_util",
    testonly = True,
    srcs = ["crypto_core_test_util.cc"],
    hdrs = ["crypto_core_test_util.hh"],
    deps = [
        ":attributes",
        ":crypto_core",
        ":rng",
        ":test_util",
    ],
)

cc_test(
    name = "crypto_core_test",
    size = "small",
    srcs = ["crypto_core_test.cc"],
    flaky = True,
    deps = [
        ":crypto_core",
        ":crypto_core_test_util",
        ":util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "list",
    srcs = ["list.c"],
    hdrs = ["list.h"],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
    ],
)

cc_test(
    name = "list_test",
    size = "small",
    srcs = ["list_test.cc"],
    deps = [
        ":list",
        ":mem",
        ":os_memory",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "state",
    srcs = ["state.c"],
    hdrs = ["state.h"],
    deps = [
        ":attributes",
        ":ccompat",
        ":logger",
    ],
)

cc_library(
    name = "mono_time",
    srcs = ["mono_time.c"],
    hdrs = ["mono_time.h"],
    visibility = [
        "//c-toxcore/auto_tests:__subpackages__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
        ":util",
        "@pthread",
    ],
)

cc_library(
    name = "mono_time_test_util",
    testonly = True,
    srcs = ["mono_time_test_util.cc"],
    hdrs = ["mono_time_test_util.hh"],
    deps = [
        ":attributes",
        ":mono_time",
        "//c-toxcore/testing/support",
    ],
)

cc_test(
    name = "mono_time_test",
    size = "small",
    srcs = ["mono_time_test.cc"],
    deps = [
        ":attributes",
        ":mono_time",
        ":mono_time_test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "shared_key_cache",
    srcs = ["shared_key_cache.c"],
    hdrs = ["shared_key_cache.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
    ],
)

cc_test(
    name = "shared_key_cache_test",
    size = "small",
    srcs = ["shared_key_cache_test.cc"],
    deps = [
        ":attributes",
        ":crypto_core_test_util",
        ":logger",
        ":mono_time",
        ":mono_time_test_util",
        ":os_memory",
        ":rng",
        ":shared_key_cache",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "net_profile",
    srcs = ["net_profile.c"],
    hdrs = ["net_profile.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/testing/fuzzing:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":logger",
        ":mem",
    ],
)

cc_library(
    name = "net",
    srcs = ["net.c"],
    hdrs = ["net.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":mem",
    ],
)

cc_library(
    name = "os_network",
    srcs = ["os_network.c"],
    hdrs = ["os_network.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":mem",
        ":net",
    ],
)

cc_library(
    name = "network",
    srcs = [
        "net_log.c",
        "network.c",
    ],
    hdrs = [
        "net_log.h",
        "network.h",
    ],
    visibility = [
        "//c-toxcore/auto_tests:__subpackages__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing/bench:__pkg__",
        "//c-toxcore/testing/fuzzing:__pkg__",
        "//c-toxcore/testing/support:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":attributes",
        ":bin_pack",
        ":ccompat",
        ":crypto_core",
        ":ev",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_profile",
        ":os_network",
        ":util",
        "@libsodium",
        "@psocket",
        "@pthread",
    ],
)

cc_library(
    name = "network_test_util",
    testonly = True,
    srcs = ["network_test_util.cc"],
    hdrs = ["network_test_util.hh"],
    deps = [
        ":attributes",
        ":crypto_core",
        ":mem",
        ":net",
        ":network",
        ":rng",
        ":test_util",
    ],
)

cc_test(
    name = "network_test",
    size = "small",
    srcs = ["network_test.cc"],
    deps = [
        ":network",
        ":network_test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "timed_auth",
    srcs = ["timed_auth.c"],
    hdrs = ["timed_auth.h"],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":mono_time",
    ],
)

cc_library(
    name = "ping_array",
    srcs = ["ping_array.c"],
    hdrs = ["ping_array.h"],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":mem",
        ":mono_time",
        ":rng",
        ":util",
    ],
)

cc_test(
    name = "ping_array_test",
    size = "small",
    srcs = ["ping_array_test.cc"],
    deps = [
        ":attributes",
        ":crypto_core_test_util",
        ":logger",
        ":mono_time",
        ":mono_time_test_util",
        ":os_memory",
        ":ping_array",
        ":rng",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "LAN_discovery",
    srcs = ["LAN_discovery.c"],
    hdrs = ["LAN_discovery.h"],
    visibility = [
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":mem",
        ":net",
        ":network",
        ":util",
        "@psocket",
    ],
)

cc_library(
    name = "DHT",
    srcs = [
        "DHT.c",
        "ping.c",
    ],
    hdrs = [
        "DHT.h",
        "ping.h",
    ],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
        "//c-toxcore/testing:__pkg__",
    ],
    deps = [
        ":LAN_discovery",
        ":attributes",
        ":bin_pack",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":network",
        ":ping_array",
        ":rng",
        ":shared_key_cache",
        ":sort",
        ":state",
        ":util",
    ],
)

cc_library(
    name = "DHT_test_util",
    testonly = True,
    srcs = ["DHT_test_util.cc"],
    hdrs = ["DHT_test_util.hh"],
    deps = [
        ":DHT",
        ":attributes",
        ":crypto_core",
        ":crypto_core_test_util",
        ":ev",
        ":logger",
        ":mono_time",
        ":net",
        ":net_crypto",
        ":network",
        ":network_test_util",
        ":os_event",
        ":rng",
        ":test_util",
        "//c-toxcore/testing/support",
    ],
)

cc_test(
    name = "DHT_test",
    size = "small",
    srcs = ["DHT_test.cc"],
    deps = [
        ":DHT",
        ":DHT_test_util",
        ":attributes",
        ":crypto_core",
        ":crypto_core_test_util",
        ":ev",
        ":logger",
        ":mono_time",
        ":network",
        ":network_test_util",
        ":os_event",
        ":test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "DHT_fuzz_test",
    size = "small",
    testonly = True,
    srcs = ["DHT_fuzz_test.cc"],
    corpus = ["//tools/toktok-fuzzer/corpus:DHT_fuzz_test"],
    deps = [
        ":DHT",
        ":net_profile",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "onion",
    srcs = ["onion.c"],
    hdrs = ["onion.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":network",
        ":rng",
        ":shared_key_cache",
        ":util",
    ],
)

cc_library(
    name = "forwarding",
    srcs = ["forwarding.c"],
    hdrs = ["forwarding.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":network",
        ":rng",
        ":timed_auth",
    ],
)

cc_fuzz_test(
    name = "forwarding_fuzz_test",
    size = "small",
    srcs = ["forwarding_fuzz_test.cc"],
    corpus = ["//tools/toktok-fuzzer/corpus:forwarding_fuzz_test"],
    deps = [
        ":ev",
        ":forwarding",
        ":os_event",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "announce",
    srcs = ["announce.c"],
    hdrs = ["announce.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":forwarding",
        ":logger",
        ":mem",
        ":mono_time",
        ":network",
        ":rng",
        ":shared_key_cache",
        ":timed_auth",
        ":util",
    ],
)

cc_library(
    name = "TCP_common",
    srcs = ["TCP_common.c"],
    hdrs = ["TCP_common.h"],
    visibility = ["//c-toxcore/auto_tests:__pkg__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":net",
        ":net_profile",
        ":network",
        ":rng",
    ],
)

cc_library(
    name = "TCP_server",
    srcs = ["TCP_server.c"],
    hdrs = ["TCP_server.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":TCP_common",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":ev",
        ":forwarding",
        ":list",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_profile",
        ":network",
        ":onion",
        ":rng",
        ":util",
        "@psocket",
    ],
)

cc_library(
    name = "TCP_client",
    srcs = ["TCP_client.c"],
    hdrs = ["TCP_client.h"],
    visibility = ["//c-toxcore/auto_tests:__pkg__"],
    deps = [
        ":TCP_common",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":forwarding",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_profile",
        ":network",
        ":rng",
        ":util",
    ],
)

cc_library(
    name = "TCP_connection",
    srcs = ["TCP_connection.c"],
    hdrs = ["TCP_connection.h"],
    visibility = ["//c-toxcore/auto_tests:__pkg__"],
    deps = [
        ":DHT",
        ":TCP_client",
        ":TCP_common",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":forwarding",
        ":list",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_profile",
        ":network",
        ":onion",
        ":rng",
        ":util",
    ],
)

cc_test(
    name = "TCP_connection_test",
    size = "small",
    srcs = ["TCP_connection_test.cc"],
    deps = [
        ":TCP_connection",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "TCP_client_test",
    size = "small",
    srcs = ["TCP_client_test.cc"],
    deps = [
        ":TCP_client",
        ":TCP_common",
        ":attributes",
        ":crypto_core",
        ":logger",
        ":mono_time",
        ":net_profile",
        ":network",
        ":os_event",
        ":os_memory",
        ":rng",
        ":test_util",
        ":util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "TCP_common_test",
    size = "small",
    srcs = ["TCP_common_test.cc"],
    deps = [
        ":TCP_common",
        ":crypto_core",
        ":logger",
        ":os_memory",
        ":os_random",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "net_crypto",
    srcs = ["net_crypto.c"],
    hdrs = ["net_crypto.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":TCP_client",
        ":TCP_connection",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":list",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_profile",
        ":network",
        ":rng",
        ":util",
        "@pthread",
    ],
)

cc_test(
    name = "net_crypto_test",
    size = "small",
    srcs = ["net_crypto_test.cc"],
    deps = [
        ":DHT_test_util",
        ":attributes",
        ":crypto_core",
        ":logger",
        ":mono_time",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "friend_connection_test",
    size = "small",
    srcs = ["friend_connection_test.cc"],
    deps = [
        ":DHT_test_util",
        ":attributes",
        ":crypto_core",
        ":friend_connection",
        ":logger",
        ":mono_time",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":onion_client",
        ":test_util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "net_crypto_fuzz_test",
    size = "small",
    srcs = ["net_crypto_fuzz_test.cc"],
    copts = ["-UNDEBUG"],
    deps = [
        ":DHT",
        ":TCP_client",
        ":attributes",
        ":ev",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":os_event",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "onion_announce",
    srcs = ["onion_announce.c"],
    hdrs = ["onion_announce.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":network",
        ":onion",
        ":rng",
        ":shared_key_cache",
        ":sort",
        ":timed_auth",
        ":util",
    ],
)

cc_library(
    name = "group_announce",
    srcs = ["group_announce.c"],
    hdrs = ["group_announce.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":network",
        ":util",
    ],
)

cc_test(
    name = "group_announce_test",
    size = "small",
    srcs = ["group_announce_test.cc"],
    deps = [
        ":DHT",
        ":attributes",
        ":crypto_core",
        ":group_announce",
        ":logger",
        ":mono_time",
        ":mono_time_test_util",
        ":network",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "group_announce_fuzz_test",
    size = "small",
    srcs = ["group_announce_fuzz_test.cc"],
    copts = ["-UNDEBUG"],
    deps = [
        ":attributes",
        ":group_announce",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "group_onion_announce",
    srcs = ["group_onion_announce.c"],
    hdrs = ["group_onion_announce.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/other/bootstrap_daemon:__pkg__",
    ],
    deps = [
        ":DHT",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":group_announce",
        ":logger",
        ":mem",
        ":mono_time",
        ":network",
        ":onion_announce",
        ":rng",
        ":timed_auth",
    ],
)

cc_library(
    name = "onion_client",
    srcs = ["onion_client.c"],
    hdrs = ["onion_client.h"],
    visibility = ["//c-toxcore/auto_tests:__pkg__"],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":TCP_connection",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":group_announce",
        ":group_onion_announce",
        ":list",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_crypto",
        ":network",
        ":onion",
        ":onion_announce",
        ":ping_array",
        ":rng",
        ":sort",
        ":timed_auth",
        ":util",
    ],
)

cc_test(
    name = "onion_client_test",
    size = "medium",
    srcs = ["onion_client_test.cc"],
    deps = [
        ":DHT_test_util",
        ":attributes",
        ":crypto_core",
        ":logger",
        ":mono_time",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":onion",
        ":onion_announce",
        ":onion_client",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "onion_client_fuzz_test",
    size = "small",
    testonly = True,
    srcs = ["onion_client_fuzz_test.cc"],
    copts = ["-UNDEBUG"],
    deps = [
        ":DHT",
        ":attributes",
        ":ev",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":onion_client",
        ":os_event",
        ":test_util",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "friend_connection",
    srcs = ["friend_connection.c"],
    hdrs = ["friend_connection.h"],
    visibility = ["//c-toxcore/auto_tests:__pkg__"],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":TCP_connection",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_crypto",
        ":network",
        ":onion",
        ":onion_announce",
        ":onion_client",
        ":rng",
        ":util",
    ],
)

cc_library(
    name = "friend_requests",
    srcs = ["friend_requests.c"],
    hdrs = ["friend_requests.h"],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/testing:__pkg__",
    ],
    deps = [
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":friend_connection",
        ":mem",
        ":network",
        ":onion",
        ":onion_announce",
        ":onion_client",
        ":rng",
        ":util",
    ],
)

cc_library(
    name = "group_moderation",
    srcs = ["group_moderation.c"],
    hdrs = ["group_moderation.h"],
    deps = [
        ":DHT",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":logger",
        ":mem",
        ":mono_time",
        ":network",
        ":util",
        "@libsodium",
    ],
)

cc_test(
    name = "group_moderation_test",
    size = "small",
    srcs = ["group_moderation_test.cc"],
    deps = [
        ":DHT",
        ":crypto_core",
        ":crypto_core_test_util",
        ":group_moderation",
        ":logger",
        ":util",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "group_moderation_fuzz_test",
    size = "small",
    testonly = True,
    srcs = ["group_moderation_fuzz_test.cc"],
    corpus = ["//tools/toktok-fuzzer/corpus:group_moderation_fuzz_test"],
    deps = [
        ":group_moderation",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "Messenger",
    srcs = [
        "Messenger.c",
        "group_chats.c",
        "group_connection.c",
        "group_pack.c",
    ],
    hdrs = [
        "Messenger.h",
        "group_chats.h",
        "group_common.h",
        "group_connection.h",
        "group_pack.h",
    ],
    visibility = [
        "//c-toxcore/auto_tests:__pkg__",
        "//c-toxcore/other:__pkg__",
        "//c-toxcore/testing:__pkg__",
        "//c-toxcore/toxav:__pkg__",
    ],
    deps = [
        ":DHT",
        ":LAN_discovery",
        ":TCP_client",
        ":TCP_connection",
        ":TCP_server",
        ":announce",
        ":attributes",
        ":bin_pack",
        ":bin_unpack",
        ":ccompat",
        ":crypto_core",
        ":crypto_core_pack",
        ":ev",
        ":forwarding",
        ":friend_connection",
        ":friend_requests",
        ":group_announce",
        ":group_moderation",
        ":group_onion_announce",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":onion",
        ":onion_announce",
        ":onion_client",
        ":rng",
        ":state",
        ":util",
        "@libsodium",
    ],
)

cc_test(
    name = "group_chats_test",
    size = "small",
    srcs = ["group_chats_test.cc"],
    deps = [
        ":Messenger",
        ":logger",
        ":net",
        ":os_memory",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "group",
    srcs = ["group.c"],
    hdrs = ["group.h"],
    visibility = ["//c-toxcore/toxav:__pkg__"],
    deps = [
        ":DHT",
        ":Messenger",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":friend_connection",
        ":logger",
        ":mem",
        ":mono_time",
        ":net_crypto",
        ":network",
        ":rng",
        ":sort",
        ":state",
        ":util",
    ],
)

cc_library(
    name = "tox_options",
    srcs = ["tox_options.c"],
    hdrs = ["tox_options.h"],
    copts = ["-UTOX_HIDE_DEPRECATED"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":ccompat",
        ":tox_log_level",
    ],
)

cc_library(
    name = "tox_log_level",
    srcs = ["tox_log_level.c"],
    hdrs = ["tox_log_level.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [":attributes"],
)

cc_library(
    name = "tox",
    srcs = [
        "tox.c",
        "tox_api.c",
        "tox_private.c",
    ],
    hdrs = [
        "tox.h",
        "tox_private.h",
        "tox_struct.h",
    ],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":DHT",
        ":Messenger",
        ":TCP_client",
        ":TCP_server",
        ":attributes",
        ":ccompat",
        ":crypto_core",
        ":ev",
        ":friend_requests",
        ":group",
        ":group_moderation",
        ":logger",
        ":mem",
        ":mono_time",
        ":net",
        ":net_crypto",
        ":net_profile",
        ":network",
        ":onion_client",
        ":os_event",
        ":os_memory",
        ":os_network",
        ":os_random",
        ":state",
        ":tox_attributes",
        ":tox_log_level",
        ":tox_options",
        ":util",
        "//c-toxcore/toxencryptsave:defines",
        "@pthread",
    ],
)

cc_test(
    name = "tox_test",
    size = "small",
    srcs = ["tox_test.cc"],
    deps = [
        ":attributes",
        ":crypto_core",
        ":os_random",
        ":tox",
        ":tox_log_level",
        ":tox_options",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "tox_pack",
    srcs = ["tox_pack.c"],
    hdrs = ["tox_pack.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":bin_pack",
        ":ccompat",
        ":tox",
    ],
)

cc_library(
    name = "tox_unpack",
    srcs = ["tox_unpack.c"],
    hdrs = ["tox_unpack.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":bin_unpack",
        ":ccompat",
        ":tox",
    ],
)

cc_library(
    name = "tox_events",
    srcs = [
        "tox_event.c",
        "tox_events.c",
    ] + glob([
        "events/*.c",
    ]),
    hdrs = [
        "events/events_alloc.h",
        "tox_event.h",
        "tox_events.h",
    ],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":bin_pack",
        ":bin_unpack",
        ":ccompat",
        ":logger",
        ":mem",
        ":tox",
        ":tox_attributes",
        ":tox_pack",
        ":tox_unpack",
        "//c-toxcore/third_party:cmp",
    ],
)

cc_test(
    name = "tox_events_test",
    size = "small",
    srcs = ["tox_events_test.cc"],
    deps = [
        ":crypto_core",
        ":tox",
        ":tox_events",
        "//c-toxcore/testing/support",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_fuzz_test(
    name = "tox_events_fuzz_test",
    size = "small",
    srcs = ["tox_events_fuzz_test.cc"],
    corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
    deps = [
        ":tox_dispatch",
        ":tox_events",
        "//c-toxcore/testing/support",
    ],
)

cc_library(
    name = "tox_dispatch",
    srcs = ["tox_dispatch.c"],
    hdrs = ["tox_dispatch.h"],
    visibility = ["//c-toxcore:__subpackages__"],
    deps = [
        ":attributes",
        ":ccompat",
        ":tox",
        ":tox_events",
    ],
)

alias(
    name = "toxcore",
    actual = ":tox_dispatch",
    visibility = ["//c-toxcore:__subpackages__"],
)

sh_library(
    name = "cimple_files",
    srcs = glob([
        "events/*.c",
        "events/*.h",
        "*.c",
        "*.h",
    ]),
    visibility = ["//c-toxcore/testing:__pkg__"],
)
