monotone

monotone Mtn Source Tree

Root/constants.cc

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10// this file contains magic constants which you could, in theory, tweak.
11// probably best not to tweak them though.
12
13#include "base.hh"
14#include "constants.hh"
15#include "numeric_vocab.hh"
16
17using std::string;
18
19namespace constants
20{
21
22 // number of bits in an RSA key we use
23 size_t const keylen = 1024;
24
25 // number of seconds in window, in which to consider CVS commits equivalent
26 // if they have otherwise compatible contents (author, changelog)
27 time_t const cvs_window = 60 * 5;
28
29 // size of a line of database traffic logging, beyond which lines will be
30 // truncated.
31 size_t const db_log_line_sz = 70;
32
33 size_t const default_terminal_width = 72;
34
35 // size in bytes of the database xdelta version reconstruction cache.
36 // the value of 7 MB was determined as the optimal point after timing
37 // various values with a pull of the monotone repository - it could
38 // be tweaked further.
39 size_t const db_version_cache_sz = 7 * (1 << 20);
40
41 // the value of 7 MB was determined by blindly copying the line above and
42 // not doing any testing at all - it could be tweaked further.
43 size_t const db_roster_cache_sz = 7 * (1 << 20);
44
45 // this value is very much an estimate. the calculation is:
46 // -- 40 bytes content hash
47 // -- a path component, maybe 10 or 15 bytes
48 // -- 40 bytes birth revision
49 // -- 40 bytes name marking hash
50 // -- 40 bytes content marking hash
51 // -- plus internal pointers, etc., for strings, sets, shared_ptrs, heap
52 // overhead, ...
53 // -- plus any space taken for attrs
54 // so ~175 bytes for a file node, plus internal slop, plus attrs (another
55 // 60 bytes per attr, or so), minus 80 bytes for dir nodes. So this just
56 // picks a number that seems a reasonable amount over 175.
57 size_t const db_estimated_roster_node_sz = 210;
58
59 unsigned long const db_max_delayed_file_bytes = 16 * 1024 * 1024;
60
61 // size of a line of text in the log buffer, beyond which log lines will be
62 // truncated.
63 size_t const log_line_sz = 0x300;
64
65 // all the ASCII characters (bytes) which are legal in a packet.
66 char const * const legal_packet_bytes =
67 // LDH characters
68 "abcdefghijklmnopqrstuvwxyz"
69 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
70 "0123456789"
71 "-"
72 // extra base64 codes
73 "+/="
74 // separators
75 ".@[]"
76 // whitespace
77 " \r\n\t"
78 ;
79
80 string const regex_legal_packet_bytes("([a-zA-Z0-9+/=[:space:]]+)");
81
82 // all the ASCII characters (bytes) which are legal in a SHA1 hex id
83 char const * const legal_id_bytes =
84 "0123456789abcdef"
85 ;
86
87 string const regex_legal_id_bytes("([0-9a-f]{40})");
88
89 // all the ASCII characters (bytes) which are legal in an ACE string
90 char const * const legal_ace_bytes =
91 // LDH characters
92 "abcdefghijklmnopqrstuvwxyz"
93 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
94 "0123456789"
95 "-"
96 // label separators
97 ".@"
98 ;
99
100 // all the ASCII characters (bytes) which can occur in cert names
101 char const * const legal_cert_name_bytes =
102 // LDH characters
103 "abcdefghijklmnopqrstuvwxyz"
104 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
105 "0123456789"
106 "-"
107 ;
108
109 string const regex_legal_cert_name_bytes("([-a-zA-Z0-9]+)");
110
111 // all the ASCII characters (bytes) which can occur in key names
112 char const * const legal_key_name_bytes =
113 // LDH characters
114 "abcdefghijklmnopqrstuvwxyz"
115 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
116 "0123456789"
117 "-"
118 // other non-shell, non-selector metacharacters allowed in (unquoted) local
119 // parts by RFC2821/RFC2822. The full list is !#$%&'*+-/=?^_`|{}~.
120 "+_."
121 // label and component separators
122 ".@"
123 ;
124
125 string const regex_legal_key_name_bytes("([-a-zA-Z0-9\\.@\\+_]+)");
126
127 // merkle tree / netcmd / netsync related stuff
128
129 size_t const merkle_fanout_bits = 4;
130
131 // all other merkle constants are derived
132 size_t const merkle_hash_length_in_bits = merkle_hash_length_in_bytes * 8;
133 size_t const merkle_num_tree_levels = merkle_hash_length_in_bits / merkle_fanout_bits;
134 size_t const merkle_num_slots = 1 << merkle_fanout_bits;
135 size_t const merkle_bitmap_length_in_bits = merkle_num_slots * 2;
136 size_t const merkle_bitmap_length_in_bytes = merkle_bitmap_length_in_bits / 8;
137
138 u8 const netcmd_current_protocol_version = 6;
139
140 size_t const netcmd_minimum_bytes_to_bother_with_gzip = 0xfff;
141
142 size_t const netsync_session_key_length_in_bytes = 20; // 160 bits
143 size_t const netsync_hmac_value_length_in_bytes = 20; // 160 bits
144
145 netsync_session_key const netsync_key_initializer(string(netsync_session_key_length_in_bytes, 0));
146
147 // attributes
148 string const encoding_attribute("mtn:encoding");
149 string const manual_merge_attribute("mtn:manual_merge");
150 string const binary_encoding("binary");
151 string const default_encoding("default");
152}
153
154#include <boost/static_assert.hpp>
155
156// constraint checks for fundamental types
157// n.b. sizeof([unsigned] char) is *defined* to be 1 by the C++ standard.
158BOOST_STATIC_ASSERT(std::numeric_limits<unsigned char>::digits == 8);
159BOOST_STATIC_ASSERT(sizeof(u8) == 1);
160BOOST_STATIC_ASSERT(sizeof(u16) == 2);
161BOOST_STATIC_ASSERT(sizeof(u32) == 4);
162BOOST_STATIC_ASSERT(sizeof(u64) == 8);
163
164// constraint checks for relations between constants above
165using namespace constants;
166BOOST_STATIC_ASSERT(merkle_num_tree_levels > 0);
167BOOST_STATIC_ASSERT(merkle_num_tree_levels < 256);
168BOOST_STATIC_ASSERT(merkle_fanout_bits > 0);
169BOOST_STATIC_ASSERT(merkle_fanout_bits < 32);
170BOOST_STATIC_ASSERT(merkle_hash_length_in_bits > 0);
171BOOST_STATIC_ASSERT((merkle_hash_length_in_bits % merkle_fanout_bits) == 0);
172BOOST_STATIC_ASSERT(merkle_bitmap_length_in_bits > 0);
173BOOST_STATIC_ASSERT((merkle_bitmap_length_in_bits % 8) == 0);
174
175// Local Variables:
176// mode: C++
177// fill-column: 76
178// c-file-style: "gnu"
179// indent-tabs-mode: nil
180// End:
181// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status