aboutsummaryrefslogtreecommitdiff
path: root/src/feature/nodelist/nodefamily_st.h
blob: c581c917a9a7bf5e26faf66d13fdfda6a19d3896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * @file nodefamily_st.h
 * @brief Compact node-family structure
 **/

#ifndef TOR_NODEFAMILY_ST_H
#define TOR_NODEFAMILY_ST_H

#include "orconfig.h"
#include "ht.h"

struct nodefamily_t {
  /** Entry for this nodefamily_t within the hashtable. */
  HT_ENTRY(nodefamily_t) ht_ent;
  /** Reference count.  (The hashtable is not treated as a reference */
  uint32_t refcnt;
  /** Number of items encoded in <b>family_members</b>. */
  uint32_t n_members;
  /* A byte-array encoding the members of this family.  We encode each member
   * as one byte to indicate whether it's a nickname or a fingerprint, plus
   * DIGEST_LEN bytes of data.  The entries are lexically sorted.
   */
  uint8_t family_members[FLEXIBLE_ARRAY_MEMBER];
};

#define NODEFAMILY_MEMBER_LEN (1+DIGEST_LEN)

/** Tag byte, indicates that the following bytes are a RSA1024 SHA1 ID.
 */
#define NODEFAMILY_BY_RSA_ID 0
/** Tag byte, indicates that the following bytes are a NUL-padded nickname.
 */
#define NODEFAMILY_BY_NICKNAME 1

/**
 * Number of bytes to allocate in the array for a nodefamily_t with N members.
 **/
#define NODEFAMILY_ARRAY_SIZE(n) \
  ((n) * NODEFAMILY_MEMBER_LEN)

/**
 * Pointer to the i'th member of <b>nf</b>, as encoded.
 */
#define NODEFAMILY_MEMBER_PTR(nf, i) \
  (&((nf)->family_members[(i) * NODEFAMILY_MEMBER_LEN]))

#endif /* !defined(TOR_NODEFAMILY_ST_H) */