Loading src/core/include.am +2 −0 Original line number Original line Diff line number Diff line Loading @@ -93,6 +93,7 @@ LIBTOR_APP_A_SOURCES = \ src/feature/nodelist/dirlist.c \ src/feature/nodelist/dirlist.c \ src/feature/nodelist/microdesc.c \ src/feature/nodelist/microdesc.c \ src/feature/nodelist/networkstatus.c \ src/feature/nodelist/networkstatus.c \ src/feature/nodelist/nickname.c \ src/feature/nodelist/nodelist.c \ src/feature/nodelist/nodelist.c \ src/feature/nodelist/node_select.c \ src/feature/nodelist/node_select.c \ src/feature/nodelist/parsecommon.c \ src/feature/nodelist/parsecommon.c \ Loading Loading @@ -309,6 +310,7 @@ noinst_HEADERS += \ src/feature/nodelist/networkstatus_sr_info_st.h \ src/feature/nodelist/networkstatus_sr_info_st.h \ src/feature/nodelist/networkstatus_st.h \ src/feature/nodelist/networkstatus_st.h \ src/feature/nodelist/networkstatus_voter_info_st.h \ src/feature/nodelist/networkstatus_voter_info_st.h \ src/feature/nodelist/nickname.h \ src/feature/nodelist/node_st.h \ src/feature/nodelist/node_st.h \ src/feature/nodelist/nodelist.h \ src/feature/nodelist/nodelist.h \ src/feature/nodelist/node_select.h \ src/feature/nodelist/node_select.h \ Loading src/feature/nodelist/describe.c +5 −0 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,11 @@ * Copyright (c) 2007-2018, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /* See LICENSE for licensing information */ /** * \file describe.c * \brief Format short descriptions of relays. */ #include "core/or/or.h" #include "core/or/or.h" #include "feature/nodelist/describe.h" #include "feature/nodelist/describe.h" #include "feature/relay/router.h" #include "feature/relay/router.h" Loading src/feature/nodelist/nickname.c 0 → 100644 +62 −0 Original line number Original line Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** * \file nickname.c * \brief Check and manipulate relay nicknames. */ #include "core/or/or.h" #include "feature/nodelist/nickname.h" /** Return true iff <b>s</b> is a valid server nickname. (That is, a string * containing between 1 and MAX_NICKNAME_LEN characters from * LEGAL_NICKNAME_CHARACTERS.) */ int is_legal_nickname(const char *s) { size_t len; tor_assert(s); len = strlen(s); return len > 0 && len <= MAX_NICKNAME_LEN && strspn(s,LEGAL_NICKNAME_CHARACTERS) == len; } /** Return true iff <b>s</b> is a valid server nickname or * hex-encoded identity-key digest. */ int is_legal_nickname_or_hexdigest(const char *s) { if (*s!='$') return is_legal_nickname(s); else return is_legal_hexdigest(s); } /** Return true iff <b>s</b> is a valid hex-encoded identity-key * digest. (That is, an optional $, followed by 40 hex characters, * followed by either nothing, or = or ~ followed by a nickname, or * a character other than =, ~, or a hex character.) */ int is_legal_hexdigest(const char *s) { size_t len; tor_assert(s); if (s[0] == '$') s++; len = strlen(s); if (len > HEX_DIGEST_LEN) { if (s[HEX_DIGEST_LEN] == '=' || s[HEX_DIGEST_LEN] == '~') { if (!is_legal_nickname(s+HEX_DIGEST_LEN+1)) return 0; } else { return 0; } } return (len >= HEX_DIGEST_LEN && strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN); } src/feature/nodelist/nickname.h 0 → 100644 +19 −0 Original line number Original line Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** * \file nickname.h * \brief Header file for nickname.c. **/ #ifndef TOR_NICKNAME_H #define TOR_NICKNAME_H int is_legal_nickname(const char *s); int is_legal_nickname_or_hexdigest(const char *s); int is_legal_hexdigest(const char *s); #endif src/feature/relay/router.c +0 −49 Original line number Original line Diff line number Diff line Loading @@ -3104,55 +3104,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo, return result; return result; } } /** Return true iff <b>s</b> is a valid server nickname. (That is, a string * containing between 1 and MAX_NICKNAME_LEN characters from * LEGAL_NICKNAME_CHARACTERS.) */ int is_legal_nickname(const char *s) { size_t len; tor_assert(s); len = strlen(s); return len > 0 && len <= MAX_NICKNAME_LEN && strspn(s,LEGAL_NICKNAME_CHARACTERS) == len; } /** Return true iff <b>s</b> is a valid server nickname or * hex-encoded identity-key digest. */ int is_legal_nickname_or_hexdigest(const char *s) { if (*s!='$') return is_legal_nickname(s); else return is_legal_hexdigest(s); } /** Return true iff <b>s</b> is a valid hex-encoded identity-key * digest. (That is, an optional $, followed by 40 hex characters, * followed by either nothing, or = or ~ followed by a nickname, or * a character other than =, ~, or a hex character.) */ int is_legal_hexdigest(const char *s) { size_t len; tor_assert(s); if (s[0] == '$') s++; len = strlen(s); if (len > HEX_DIGEST_LEN) { if (s[HEX_DIGEST_LEN] == '=' || s[HEX_DIGEST_LEN] == '~') { if (!is_legal_nickname(s+HEX_DIGEST_LEN+1)) return 0; } else { return 0; } } return (len >= HEX_DIGEST_LEN && strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN); } /** Forget that we have issued any router-related warnings, so that we'll /** Forget that we have issued any router-related warnings, so that we'll * warn again if we see the same errors. */ * warn again if we see the same errors. */ void void Loading Loading
src/core/include.am +2 −0 Original line number Original line Diff line number Diff line Loading @@ -93,6 +93,7 @@ LIBTOR_APP_A_SOURCES = \ src/feature/nodelist/dirlist.c \ src/feature/nodelist/dirlist.c \ src/feature/nodelist/microdesc.c \ src/feature/nodelist/microdesc.c \ src/feature/nodelist/networkstatus.c \ src/feature/nodelist/networkstatus.c \ src/feature/nodelist/nickname.c \ src/feature/nodelist/nodelist.c \ src/feature/nodelist/nodelist.c \ src/feature/nodelist/node_select.c \ src/feature/nodelist/node_select.c \ src/feature/nodelist/parsecommon.c \ src/feature/nodelist/parsecommon.c \ Loading Loading @@ -309,6 +310,7 @@ noinst_HEADERS += \ src/feature/nodelist/networkstatus_sr_info_st.h \ src/feature/nodelist/networkstatus_sr_info_st.h \ src/feature/nodelist/networkstatus_st.h \ src/feature/nodelist/networkstatus_st.h \ src/feature/nodelist/networkstatus_voter_info_st.h \ src/feature/nodelist/networkstatus_voter_info_st.h \ src/feature/nodelist/nickname.h \ src/feature/nodelist/node_st.h \ src/feature/nodelist/node_st.h \ src/feature/nodelist/nodelist.h \ src/feature/nodelist/nodelist.h \ src/feature/nodelist/node_select.h \ src/feature/nodelist/node_select.h \ Loading
src/feature/nodelist/describe.c +5 −0 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,11 @@ * Copyright (c) 2007-2018, The Tor Project, Inc. */ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /* See LICENSE for licensing information */ /** * \file describe.c * \brief Format short descriptions of relays. */ #include "core/or/or.h" #include "core/or/or.h" #include "feature/nodelist/describe.h" #include "feature/nodelist/describe.h" #include "feature/relay/router.h" #include "feature/relay/router.h" Loading
src/feature/nodelist/nickname.c 0 → 100644 +62 −0 Original line number Original line Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** * \file nickname.c * \brief Check and manipulate relay nicknames. */ #include "core/or/or.h" #include "feature/nodelist/nickname.h" /** Return true iff <b>s</b> is a valid server nickname. (That is, a string * containing between 1 and MAX_NICKNAME_LEN characters from * LEGAL_NICKNAME_CHARACTERS.) */ int is_legal_nickname(const char *s) { size_t len; tor_assert(s); len = strlen(s); return len > 0 && len <= MAX_NICKNAME_LEN && strspn(s,LEGAL_NICKNAME_CHARACTERS) == len; } /** Return true iff <b>s</b> is a valid server nickname or * hex-encoded identity-key digest. */ int is_legal_nickname_or_hexdigest(const char *s) { if (*s!='$') return is_legal_nickname(s); else return is_legal_hexdigest(s); } /** Return true iff <b>s</b> is a valid hex-encoded identity-key * digest. (That is, an optional $, followed by 40 hex characters, * followed by either nothing, or = or ~ followed by a nickname, or * a character other than =, ~, or a hex character.) */ int is_legal_hexdigest(const char *s) { size_t len; tor_assert(s); if (s[0] == '$') s++; len = strlen(s); if (len > HEX_DIGEST_LEN) { if (s[HEX_DIGEST_LEN] == '=' || s[HEX_DIGEST_LEN] == '~') { if (!is_legal_nickname(s+HEX_DIGEST_LEN+1)) return 0; } else { return 0; } } return (len >= HEX_DIGEST_LEN && strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN); }
src/feature/nodelist/nickname.h 0 → 100644 +19 −0 Original line number Original line Diff line number Diff line /* Copyright (c) 2001 Matej Pfajfar. * Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** * \file nickname.h * \brief Header file for nickname.c. **/ #ifndef TOR_NICKNAME_H #define TOR_NICKNAME_H int is_legal_nickname(const char *s); int is_legal_nickname_or_hexdigest(const char *s); int is_legal_hexdigest(const char *s); #endif
src/feature/relay/router.c +0 −49 Original line number Original line Diff line number Diff line Loading @@ -3104,55 +3104,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo, return result; return result; } } /** Return true iff <b>s</b> is a valid server nickname. (That is, a string * containing between 1 and MAX_NICKNAME_LEN characters from * LEGAL_NICKNAME_CHARACTERS.) */ int is_legal_nickname(const char *s) { size_t len; tor_assert(s); len = strlen(s); return len > 0 && len <= MAX_NICKNAME_LEN && strspn(s,LEGAL_NICKNAME_CHARACTERS) == len; } /** Return true iff <b>s</b> is a valid server nickname or * hex-encoded identity-key digest. */ int is_legal_nickname_or_hexdigest(const char *s) { if (*s!='$') return is_legal_nickname(s); else return is_legal_hexdigest(s); } /** Return true iff <b>s</b> is a valid hex-encoded identity-key * digest. (That is, an optional $, followed by 40 hex characters, * followed by either nothing, or = or ~ followed by a nickname, or * a character other than =, ~, or a hex character.) */ int is_legal_hexdigest(const char *s) { size_t len; tor_assert(s); if (s[0] == '$') s++; len = strlen(s); if (len > HEX_DIGEST_LEN) { if (s[HEX_DIGEST_LEN] == '=' || s[HEX_DIGEST_LEN] == '~') { if (!is_legal_nickname(s+HEX_DIGEST_LEN+1)) return 0; } else { return 0; } } return (len >= HEX_DIGEST_LEN && strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN); } /** Forget that we have issued any router-related warnings, so that we'll /** Forget that we have issued any router-related warnings, so that we'll * warn again if we see the same errors. */ * warn again if we see the same errors. */ void void Loading