github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/archive/options.go (about)

     1  // Copyright (C) 2021-2022 Talos, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package archive
    16  
    17  import (
    18  	"time"
    19  
    20  	"github.com/lirm/aeron-go/aeron/idlestrategy"
    21  	"go.uber.org/zap/zapcore"
    22  )
    23  
    24  // Options are set by NewArchive() with the default options specified below
    25  //
    26  // Some options may be changed dynamically by setting their values in Archive.Context.Options.*
    27  // Those attributes marked [compile] must be changed at compile time
    28  // Those attributes marked [init] must be changed before calling ArchiveConnect()
    29  // Those attributes marked [runtime] may be changed at any time
    30  // Those attributes marked [enable] may be changed when the feature is not enabled
    31  type Options struct {
    32  	RequestChannel         string             // [init] Control request publication channel
    33  	RequestStream          int32              // [init] and stream
    34  	ResponseChannel        string             // [init] Control response subscription channel
    35  	ResponseStream         int32              // [init] and stream
    36  	RecordingEventsChannel string             // [enable] Recording progress events
    37  	RecordingEventsStream  int32              // [enable] and stream
    38  	ArchiveLoglevel        zapcore.Level      // [runtime] via logging.SetLevel()
    39  	AeronLoglevel          zapcore.Level      // [runtime] via logging.SetLevel()
    40  	Timeout                time.Duration      // [runtime] How long to try sending/receiving control messages
    41  	IdleStrategy           idlestrategy.Idler // [runtime] Idlestrategy for sending/receiving control messages
    42  	RangeChecking          bool               // [runtime] archive protocol marshalling checks
    43  	AuthEnabled            bool               // [init] enable to require AuthConnect() over Connect()
    44  	AuthCredentials        []uint8            // [init] The credentials to be provided to AuthConnect()
    45  	AuthChallenge          []uint8            // [init] The challenge string we are to expect (checked iff not nil)
    46  	AuthResponse           []uint8            // [init] The challengeResponse we should provide
    47  }
    48  
    49  // These are the Options used by default for an Archive object
    50  var defaultOptions = Options{
    51  	RequestChannel:         "aeron:udp?endpoint=localhost:8010",
    52  	RequestStream:          10,
    53  	ResponseChannel:        "aeron:udp?endpoint=localhost:0",
    54  	ResponseStream:         20,
    55  	RecordingEventsChannel: "aeron:udp?control-mode=dynamic|control=localhost:8030",
    56  	RecordingEventsStream:  30,
    57  	ArchiveLoglevel:        zapcore.WarnLevel,
    58  	AeronLoglevel:          zapcore.WarnLevel,
    59  	Timeout:                time.Second * 5,
    60  	IdleStrategy:           idlestrategy.Sleeping{SleepFor: time.Millisecond * 50}, // FIXME: tune
    61  	RangeChecking:          false,
    62  	AuthEnabled:            false,
    63  	AuthCredentials:        nil,
    64  	AuthChallenge:          nil,
    65  	AuthResponse:           nil,
    66  }
    67  
    68  // DefaultOptions creates and returns a new Options from the defaults.
    69  func DefaultOptions() *Options {
    70  	options := defaultOptions
    71  	return &options
    72  }