diff options
author | Chelsea Holland Komlo <me@chelseakomlo.com> | 2017-09-27 19:48:07 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-10-27 10:02:08 -0400 |
commit | d1820c1516a31a149fc51a9e5126bf899e4c4e08 (patch) | |
tree | ea2ed5c2259f87ca078378eff4f78c9bf0aa50da /src/or | |
parent | 5418aa84eec9f08af7ab7b68cbc9145750ad0a1b (diff) | |
download | tor-d1820c1516a31a149fc51a9e5126bf899e4c4e08.tar.gz tor-d1820c1516a31a149fc51a9e5126bf899e4c4e08.zip |
rust implementation of protover
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/include.am | 1 | ||||
-rw-r--r-- | src/or/protover.c | 4 | ||||
-rw-r--r-- | src/or/protover.h | 6 | ||||
-rw-r--r-- | src/or/protover_rust.c | 111 |
4 files changed, 121 insertions, 1 deletions
diff --git a/src/or/include.am b/src/or/include.am index 7216aba9af..bf3715e95e 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -78,6 +78,7 @@ LIBTOR_A_SOURCES = \ src/or/parsecommon.c \ src/or/periodic.c \ src/or/protover.c \ + src/or/protover_rust.c \ src/or/proto_cell.c \ src/or/proto_control0.c \ src/or/proto_ext_or.c \ diff --git a/src/or/protover.c b/src/or/protover.c index 1a3e69be10..0e74deb112 100644 --- a/src/or/protover.c +++ b/src/or/protover.c @@ -27,6 +27,8 @@ #include "protover.h" #include "routerparse.h" +#ifndef HAVE_RUST + static const smartlist_t *get_supported_protocol_list(void); static int protocol_list_contains(const smartlist_t *protos, protocol_type_t pr, uint32_t ver); @@ -735,3 +737,5 @@ protover_free_all(void) } } +#endif + diff --git a/src/or/protover.h b/src/or/protover.h index 657977279e..7f1938e0c9 100644 --- a/src/or/protover.h +++ b/src/or/protover.h @@ -70,11 +70,15 @@ typedef struct proto_entry_t { smartlist_t *ranges; } proto_entry_t; +#if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) STATIC smartlist_t *parse_protocol_list(const char *s); -STATIC void proto_entry_free(proto_entry_t *entry); STATIC char *encode_protocol_list(const smartlist_t *sl); STATIC const char *protocol_type_to_str(protocol_type_t pr); STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out); +STATIC void proto_entry_free(proto_entry_t *entry); + +#endif + #endif /* defined(PROTOVER_PRIVATE) */ #endif /* !defined(TOR_PROTOVER_H) */ diff --git a/src/or/protover_rust.c b/src/or/protover_rust.c new file mode 100644 index 0000000000..ebe815357b --- /dev/null +++ b/src/or/protover_rust.c @@ -0,0 +1,111 @@ +/* Copyright (c) 2016-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/* + * \file protover_rust.c + * \brief Provide a C wrapper for functions exposed in /src/rust/protover, + * and safe translation/handling between the Rust/C boundary. + */ + +#include "or.h" +#include "protover.h" +#include "rust_types.h" + +#ifdef HAVE_RUST + +int rust_protover_all_supported(const char *s, char **missing); +rust_str_ref_t rust_protover_compute_for_old_tor(const char *version); +rust_str_ref_t rust_protover_compute_vote(const smartlist_t *proto_votes, + int threshold); +rust_str_ref_t rust_protover_get_supported_protocols(void); +int rust_protocol_list_supports_protocol(const char *list, protocol_type_t tp, + uint32_t version); +int rust_protover_is_supported_here(protocol_type_t pr, uint32_t ver); + +/* Define for compatibility, used in main.c */ +void protover_free_all(void) {}; + +/* + * Wrap rust_protover_is_supported_here, located in /src/rust/protover + */ +int +protover_is_supported_here(protocol_type_t pr, uint32_t ver) +{ + return rust_protover_is_supported_here(pr, ver); +} + +/* + * Wrap rust_protover_list_supports_protocol, located in /src/rust/protover + */ +int +protocol_list_supports_protocol(const char *list, protocol_type_t tp, + uint32_t version) +{ + return rust_protocol_list_supports_protocol(list, tp, version); +} + +/* + * Wrap rust_protover_get_supported_protocols, located in /src/rust/protover + */ +const char * +protover_get_supported_protocols(void) +{ + rust_str_ref_t rust_protocols = rust_protover_get_supported_protocols(); + + char *protocols = NULL; + if (rust_protocols != NULL) { + move_rust_str_to_c_and_free(rust_protocols, &protocols); + } + return protocols; +} + +/* + * Wrap rust_protover_compute_vote, located in /src/rust/protover + */ +char * +protover_compute_vote(const smartlist_t *proto_strings, + int threshold) +{ + rust_str_ref_t rust_protocols = rust_protover_compute_vote(proto_strings, + threshold); + + char *protocols = NULL; + if (rust_protocols != NULL) { + move_rust_str_to_c_and_free(rust_protocols, &protocols); + } + return protocols; +} + +/* + * Wrap rust_protover_all_supported, located in /src/rust/protover + */ +int +protover_all_supported(const char *s, char **missing_out) +{ + rust_str_ref_t missing_out_copy = NULL; + int is_supported = rust_protover_all_supported(s, &missing_out_copy); + + if (!is_supported) { + move_rust_str_to_c_and_free(missing_out_copy, missing_out); + } + + return is_supported; +} + +/* + * Wrap rust_compute_for_old_tor, located in /src/rust/protover + */ +const char * +protover_compute_for_old_tor(const char *version) +{ + rust_str_ref_t rust_protocols = rust_protover_compute_for_old_tor(version); + + char *protocols = NULL; + if (rust_protocols != NULL) { + move_rust_str_to_c_and_free(rust_protocols, &protocols); + } + return protocols; +} + +#endif + |