have --local flag bypass public server

This commit is contained in:
Zack Scholl 2018-04-25 00:20:09 -07:00
parent 7f5e3f50a0
commit 90809a80a1
2 changed files with 12 additions and 2 deletions

View File

@ -72,6 +72,12 @@ func NewConnection(config *AppConfig) (*Connection, error) {
c.UseStdout = config.UseStdout
c.Yes = config.Yes
c.rate = config.Rate
c.Local = config.Local
if c.Local {
c.Yes = true
c.DontEncrypt = true
}
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
@ -268,7 +274,9 @@ func (c *Connection) Run() error {
}
}
go func() { runClientError <- c.runClient(c.Server) }()
if !c.Local {
go func() { runClientError <- c.runClient(c.Server) }()
}
return <-runClientError
}
@ -304,10 +312,11 @@ func (c *Connection) runClient(serverName string) error {
connection, err := net.Dial("tcp", serverName+":"+port)
if err != nil {
if serverName == "cowyo.com" {
fmt.Println("\nCheck http://bit.ly/croc-relay to see if the public server is down or contact the webmaster: @yakczar")
fmt.Fprintf(os.Stderr, "\nCheck http://bit.ly/croc-relay to see if the public server is down or contact the webmaster: @yakczar")
} else {
fmt.Fprintf(os.Stderr, "\nCould not connect to relay %s\n", serverName)
}
fmt.Fprintf(os.Stderr, "Use --local to run locally")
os.Exit(1)
}
defer connection.Close()

View File

@ -20,6 +20,7 @@ type AppConfig struct {
DontEncrypt bool `yaml:"no-encrypt" flagName:"no-encrypt" flagSName:"g" flagDescribe:"Turn off encryption" default:"false"`
UseStdout bool `yaml:"stdout" flagName:"stdout" flagSName:"o" flagDescribe:"Use stdout" default:"false"`
Yes bool `yaml:"yes" flagName:"yes" flagSName:"y" flagDescribe:"Automatically accept file" default:"false"`
Local bool `yaml:"local" flagName:"local" flagSName:"lo" flagDescribe:"Use local relay when sending" default:"false"`
Server string `yaml:"server" flagName:"server" flagSName:"l" flagDescribe:"Croc relay to use" default:"cowyo.com"`
File string `yaml:"send" flagName:"send" flagSName:"s" flagDescribe:"File to send default:""`
Path string `yaml:"save" flagName:"save" flagSName:"p" flagDescribe:"Path to save to" default:""`