From 1ae117166a24fb7935a7d04aa2f0056de20964c3 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 21 Oct 2018 07:54:59 -0700 Subject: [PATCH] add config default --- go.mod | 1 + src/croc/config.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/croc/config.go diff --git a/go.mod b/go.mod index 50cadb6f..177934f9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/schollz/croc require ( + github.com/BurntSushi/toml v0.3.1 // indirect github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 github.com/dustin/go-humanize v1.0.0 github.com/fatih/color v1.7.0 // indirect diff --git a/src/croc/config.go b/src/croc/config.go new file mode 100644 index 00000000..0e433427 --- /dev/null +++ b/src/croc/config.go @@ -0,0 +1,59 @@ +package croc + +import ( + "bytes" + "time" + + "github.com/BurntSushi/toml" +) + +type Config struct { + // Relay parameters + RelayWebsocketPort string + RelayTCPPorts []string + + // Sender parameters + CurveType string + + // Options for connecting to server + PublicServerIP string + AddressTCPPorts []string + AddressWebsocketPort string + Timeout time.Duration + LocalOnly bool + NoLocal bool + + // Options for file transfering + UseEncryption bool + UseCompression bool + AllowLocalDiscovery bool + NoRecipientPrompt bool + ForceTCP bool + ForceWebsockets bool + Codephrase string +} + +// DefaultConfig returns the default config +func DefaultConfig() string { + c := Config{} + cr := Init(false) + c.RelayWebsocketPort = cr.RelayWebsocketPort + c.RelayTCPPorts = cr.RelayTCPPorts + c.CurveType = cr.CurveType + c.PublicServerIP = cr.Address + c.AddressTCPPorts = cr.AddressTCPPorts + c.AddressWebsocketPort = cr.AddressWebsocketPort + c.Timeout = cr.Timeout + c.LocalOnly = cr.LocalOnly + c.NoLocal = cr.NoLocal + c.UseEncryption = cr.UseEncryption + c.UseCompression = cr.UseCompression + c.AllowLocalDiscovery = cr.AllowLocalDiscovery + c.NoRecipientPrompt = cr.NoRecipientPrompt + c.ForceTCP = false + c.ForceWebsockets = false + c.Codephrase = "" + buf := new(bytes.Buffer) + toml.NewEncoder(buf).Encode(c) + return buf.String() +}