in swim/join_sender.go [118:168]
func newJoinSender(node *Node, opts *joinOpts) (*joinSender, error) {
if opts == nil {
opts = &joinOpts{}
}
if node.discoverProvider == nil {
return nil, errors.New("no discover provider")
}
// Resolve/retrieve bootstrap hosts from the provider specified in the
// join options.
bootstrapHosts, err := node.discoverProvider.Hosts()
if err != nil {
return nil, err
}
// Check we're in the bootstrap host list and add ourselves if we're not
// there. If the host list is empty, this will create a single-node
// cluster.
if !util.StringInSlice(bootstrapHosts, node.Address()) {
bootstrapHosts = append(bootstrapHosts, node.Address())
}
js := &joinSender{
node: node,
logger: logging.Logger("join").WithField("local", node.Address()),
}
// Parse bootstrap hosts into a map
js.parseHosts(bootstrapHosts)
js.potentialNodes = js.CollectPotentialNodes(nil)
js.timeout = util.SelectDuration(opts.timeout, defaultJoinTimeout)
js.maxJoinDuration = util.SelectDuration(opts.maxJoinDuration, defaultMaxJoinDuration)
js.parallelismFactor = util.SelectInt(opts.parallelismFactor, defaultParallelismFactor)
js.size = util.SelectInt(opts.size, defaultJoinSize)
js.size = util.Min(js.size, len(js.potentialNodes))
js.delayer = opts.delayer
if js.delayer == nil {
// Create and use exponential delayer as the delay mechanism. Create it
// with nil opts which uses default delayOpts.
js.delayer, err = newExponentialDelayer(js.node.address, nil)
if err != nil {
return nil, err
}
}
return js, nil
}