croc/src/croc/croc.go

97 lines
2.1 KiB
Go
Raw Normal View History

2018-09-22 05:17:57 +02:00
package croc
2018-09-22 05:51:43 +02:00
import (
2018-09-25 21:33:51 +02:00
"runtime"
2018-09-22 05:51:43 +02:00
"time"
"github.com/schollz/croc/src/logger"
2018-10-17 15:19:01 +02:00
"github.com/schollz/croc/src/models"
2018-09-22 05:51:43 +02:00
"github.com/schollz/croc/src/relay"
2018-09-22 06:50:20 +02:00
"github.com/schollz/croc/src/zipper"
2018-10-17 19:20:09 +02:00
"github.com/schollz/progressbar/v2"
2018-09-22 05:51:43 +02:00
)
2018-09-22 05:17:57 +02:00
2018-09-25 21:33:51 +02:00
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
2018-09-22 05:17:57 +02:00
// Croc options
type Croc struct {
2018-10-21 16:20:23 +02:00
// Version is the version of croc
Version string
2018-09-22 05:17:57 +02:00
// Options for all
Debug bool
2018-09-22 07:31:13 +02:00
// ShowText will display text on the stderr
ShowText bool
2018-09-22 05:17:57 +02:00
// Options for relay
2018-09-23 21:34:29 +02:00
RelayWebsocketPort string
2018-09-26 00:14:58 +02:00
RelayTCPPorts []string
2018-09-23 21:34:29 +02:00
CurveType string
2018-09-22 05:17:57 +02:00
// Options for connecting to server
2018-09-23 21:34:29 +02:00
Address string
2018-09-26 00:14:58 +02:00
AddressTCPPorts []string
2018-09-23 21:34:29 +02:00
AddressWebsocketPort string
Timeout time.Duration
LocalOnly bool
NoLocal bool
2018-09-22 05:17:57 +02:00
// Options for file transfering
UseEncryption bool
UseCompression bool
AllowLocalDiscovery bool
2018-09-22 15:32:44 +02:00
NoRecipientPrompt bool
2018-09-22 05:17:57 +02:00
Stdout bool
2018-09-24 16:17:35 +02:00
ForceSend int // 0: ignore, 1: websockets, 2: TCP
2018-09-22 05:17:57 +02:00
2018-09-22 05:51:43 +02:00
// Parameters for file transfer
Filename string
Codephrase string
2018-09-22 05:17:57 +02:00
// localIP address
localIP string
// is using local relay
isLocal bool
normalFinish bool
2018-10-15 03:26:18 +02:00
2018-10-17 15:19:01 +02:00
// state variables
StateString string
Bar *progressbar.ProgressBar
FileInfo models.FileStats
2018-10-19 15:36:45 +02:00
OtherIP string
2018-10-18 03:14:45 +02:00
// special for window
WindowRecipientPrompt bool
WindowRecipientAccept bool
2018-10-18 06:38:29 +02:00
WindowReceivingString string
2018-09-22 05:17:57 +02:00
}
2018-09-22 05:51:43 +02:00
// Init will initiate with the default parameters
func Init(debug bool) (c *Croc) {
c = new(Croc)
c.UseCompression = true
c.UseEncryption = true
c.AllowLocalDiscovery = true
2018-09-24 16:00:48 +02:00
c.RelayWebsocketPort = "8153"
2018-10-11 19:55:46 +02:00
c.RelayTCPPorts = []string{"8154", "8155", "8156", "8157", "8158", "8159", "8160", "8161"}
2018-09-24 16:00:48 +02:00
c.CurveType = "siec"
2018-10-17 15:39:02 +02:00
c.Address = "croc4.schollz.com"
2018-09-24 17:35:24 +02:00
c.AddressWebsocketPort = "8153"
2018-10-11 19:55:46 +02:00
c.AddressTCPPorts = []string{"8154", "8155", "8156", "8157", "8158", "8159", "8160", "8161"}
2018-09-24 16:00:48 +02:00
c.NoRecipientPrompt = true
2018-09-22 05:51:43 +02:00
debugLevel := "info"
if debug {
debugLevel = "debug"
c.Debug = true
}
SetDebugLevel(debugLevel)
return
}
func SetDebugLevel(debugLevel string) {
2018-09-22 05:51:43 +02:00
logger.SetLogLevel(debugLevel)
relay.DebugLevel = debugLevel
2018-09-22 06:50:20 +02:00
zipper.DebugLevel = debugLevel
2018-09-22 05:51:43 +02:00
}