mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 16:30:27 +00:00
Really use the correct endpoint
This commit is contained in:
parent
d29b5a074a
commit
b4b3609678
@ -27,7 +27,7 @@ func main() {
|
|||||||
logbuffer := &bytes.Buffer{}
|
logbuffer := &bytes.Buffer{}
|
||||||
logger := log.New(logbuffer, "", log.Flags())
|
logger := log.New(logbuffer, "", log.Flags())
|
||||||
|
|
||||||
defaultEndpoint := defaults.GetDefaults().DefaultAdminListen
|
endpoint := defaults.GetDefaults().DefaultAdminListen
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0])
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0])
|
||||||
@ -41,7 +41,7 @@ func main() {
|
|||||||
fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT")
|
fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT")
|
||||||
fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT")
|
fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT")
|
||||||
}
|
}
|
||||||
server := flag.String("endpoint", defaultEndpoint, "Admin socket endpoint")
|
server := flag.String("endpoint", endpoint, "Admin socket endpoint")
|
||||||
injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)")
|
injson := flag.Bool("json", false, "Output in JSON format (as opposed to pretty-print)")
|
||||||
verbose := flag.Bool("v", false, "Verbose output (includes public keys)")
|
verbose := flag.Bool("v", false, "Verbose output (includes public keys)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -52,7 +52,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if *server == defaultEndpoint {
|
if *server == endpoint {
|
||||||
if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
|
if config, err := ioutil.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
|
||||||
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 ||
|
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 ||
|
||||||
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 {
|
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 {
|
||||||
@ -68,9 +68,9 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") {
|
if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") {
|
||||||
defaultEndpoint = ep
|
endpoint = ep
|
||||||
logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile)
|
logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile)
|
||||||
logger.Println("Using endpoint", defaultEndpoint, "from AdminListen")
|
logger.Println("Using endpoint", endpoint, "from AdminListen")
|
||||||
} else {
|
} else {
|
||||||
logger.Println("Configuration file doesn't contain appropriate AdminListen option")
|
logger.Println("Configuration file doesn't contain appropriate AdminListen option")
|
||||||
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
||||||
@ -80,16 +80,16 @@ func main() {
|
|||||||
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Println("Using endpoint", *server, "from command line")
|
logger.Println("Using endpoint", endpoint, "from command line")
|
||||||
}
|
}
|
||||||
|
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
u, err := url.Parse(*server)
|
u, err := url.Parse(endpoint)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
switch strings.ToLower(u.Scheme) {
|
switch strings.ToLower(u.Scheme) {
|
||||||
case "unix":
|
case "unix":
|
||||||
logger.Println("Connecting to UNIX socket", (*server)[7:])
|
logger.Println("Connecting to UNIX socket", endpoint[7:])
|
||||||
conn, err = net.Dial("unix", (*server)[7:])
|
conn, err = net.Dial("unix", endpoint[7:])
|
||||||
case "tcp":
|
case "tcp":
|
||||||
logger.Println("Connecting to TCP socket", u.Host)
|
logger.Println("Connecting to TCP socket", u.Host)
|
||||||
conn, err = net.Dial("tcp", u.Host)
|
conn, err = net.Dial("tcp", u.Host)
|
||||||
@ -99,7 +99,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Println("Connecting to TCP socket", u.Host)
|
logger.Println("Connecting to TCP socket", u.Host)
|
||||||
conn, err = net.Dial("tcp", *server)
|
conn, err = net.Dial("tcp", endpoint)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print(logbuffer)
|
fmt.Print(logbuffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user