2
conflux - Distributed database synchronization library
3
Based on the algorithm described in
4
"Set Reconciliation with Nearly Optimal Communication Complexity",
5
Yaron Minsky, Ari Trachtenberg, and Richard Zippel, 2004.
7
Copyright (C) 2012 Casey Marshall <casey.marshall@gmail.com>
9
This program is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Affero General Public License as published by
11
the Free Software Foundation, version 3.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU Affero General Public License for more details.
18
You should have received a copy of the GNU Affero General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
// Package recon provides the SKS reconciliation protocol, prefix tree interface
23
// and an in-memory prefix-tree implementation.
29
"github.com/pelletier/go-toml"
35
type Settings struct {
42
func (s *Settings) GetString(key string, defaultValue string) string {
43
if s, is := s.GetDefault(key, defaultValue).(string); is {
49
func (s *Settings) GetStrings(key string) (value []string) {
50
if strs, is := s.Get(key).([]interface{}); is {
51
for _, v := range strs {
52
if str, is := v.(string); is {
53
value = append(value, str)
60
func (s *Settings) GetInt(key string, defaultValue int) int {
61
switch v := s.GetDefault(key, defaultValue).(type) {
67
i, err := strconv.Atoi(fmt.Sprintf("%v", v))
77
func (s *Settings) Version() string {
78
return s.GetString("conflux.recon.version", "1.1.3")
81
func (s *Settings) LogName() string {
82
return s.GetString("conflux.recon.logname", "conflux.recon")
85
func (s *Settings) HttpPort() int {
86
return s.GetInt("conflux.recon.httpPort", 11371)
89
func (s *Settings) ReconPort() int {
90
return s.GetInt("conflux.recon.reconPort", 11370)
93
func (s *Settings) Partners() []string {
94
return s.GetStrings("conflux.recon.partners")
97
func (s *Settings) Filters() []string {
98
return s.GetStrings("conflux.recon.filters")
101
func (s *Settings) ThreshMult() int {
102
return s.GetInt("conflux.recon.threshMult", DefaultThreshMult)
105
func (s *Settings) BitQuantum() int {
106
return s.GetInt("conflux.recon.bitQuantum", DefaultBitQuantum)
109
func (s *Settings) MBar() int {
110
return s.GetInt("conflux.recon.mBar", DefaultMBar)
113
func (s *Settings) SplitThreshold() int {
114
return s.splitThreshold
117
func (s *Settings) JoinThreshold() int {
118
return s.joinThreshold
121
func (s *Settings) NumSamples() int {
125
func (s *Settings) GossipIntervalSecs() int {
126
return s.GetInt("conflux.recon.gossipIntervalSecs", 60)
129
func (s *Settings) MaxOutstandingReconRequests() int {
130
return s.GetInt("conflux.recon.maxOutstandingReconRequests", 100)
133
func (s *Settings) ConnTimeout() int {
134
return s.GetInt("conflux.recon.connTimeout", 0)
137
func (s *Settings) ReadTimeout() int {
138
return s.GetInt("conflux.recon.readTimeout", 0)
141
func DefaultSettings() (settings *Settings) {
142
buf := bytes.NewBuffer(nil)
143
var tree *toml.TomlTree
145
if tree, err = toml.Load(buf.String()); err != nil {
146
panic(err) // unlikely
148
return NewSettings(tree)
151
func NewSettings(tree *toml.TomlTree) (settings *Settings) {
152
settings = &Settings{tree, DefaultSplitThreshold, DefaultJoinThreshold, DefaultNumSamples}
153
settings.UpdateDerived()
157
func (s *Settings) Config() *Config {
159
Version: s.Version(),
160
HttpPort: s.HttpPort(),
161
BitQuantum: s.BitQuantum(),
163
Filters: strings.Join(s.Filters(), ",")}
166
func (s *Settings) UpdateDerived() {
167
s.splitThreshold = s.ThreshMult() * s.MBar()
168
s.joinThreshold = s.splitThreshold / 2
169
s.numSamples = s.MBar() + 1
172
func LoadSettings(path string) (*Settings, error) {
173
var tree *toml.TomlTree
175
if tree, err = toml.LoadFile(path); err != nil {
178
return NewSettings(tree), nil
181
func (s *Settings) PartnerAddrs() (addrs []net.Addr, err error) {
182
for _, partner := range s.Partners() {
186
addr, err := net.ResolveTCPAddr("tcp", partner)
190
addrs = append(addrs, addr)