diff --git a/config.go b/config.go index a680c4a..ebeb6f7 100644 --- a/config.go +++ b/config.go @@ -48,7 +48,10 @@ func (c *Config) add(app AppConfig) { func (c *Config) save() { data, _ := json.MarshalIndent(c, "", "") - ioutil.WriteFile("config.json", data, 0644) + err := ioutil.WriteFile("config.json", data, 0644) + if err != nil { + gLog.Println(LevelERROR, "save config.json error:", err) + } } func (c *Config) load() error { diff --git a/daemon.go b/daemon.go index 16f5339..8352730 100644 --- a/daemon.go +++ b/daemon.go @@ -148,11 +148,15 @@ func install() { config.SrcPort = *srcPort config.Protocol = *protocol gConf.add(config) - os.Chdir(defaultInstallPath) + os.MkdirAll(defaultInstallPath, 0775) + err := os.Chdir(defaultInstallPath) + if err != nil { + gLog.Println(LevelERROR, "cd error:", err) + } gConf.save() // copy files - os.MkdirAll(defaultInstallPath, 0775) + targetPath := filepath.Join(defaultInstallPath, defaultBinName) binPath, _ := os.Executable() src, errFiles := os.Open(binPath) // can not use args[0], on Windows call openp2p is ok(=openp2p.exe) @@ -180,7 +184,7 @@ func install() { // args := []string{""} gLog.Println(LevelINFO, "targetPath:", targetPath) - err := d.Control("install", targetPath, []string{"-d", "-f"}) + err = d.Control("install", targetPath, []string{"-d", "-f"}) if err != nil { gLog.Println(LevelERROR, "install system service error:", err) } else { diff --git a/errorcode.go b/errorcode.go new file mode 100644 index 0000000..f588882 --- /dev/null +++ b/errorcode.go @@ -0,0 +1,13 @@ +package main + +import ( + "errors" +) + +// error message +var ( + // ErrorS2S string = "s2s is not supported" + // ErrorHandshake string = "handshake error" + ErrorS2S = errors.New("s2s is not supported") + ErrorHandshake = errors.New("handshake error") +) diff --git a/protocol.go b/protocol.go index de4575b..ac18471 100644 --- a/protocol.go +++ b/protocol.go @@ -4,14 +4,13 @@ import ( "bytes" "encoding/binary" "encoding/json" - "errors" "hash/crc64" "math/big" "net" "time" ) -const OpenP2PVersion = "0.97.0" +const OpenP2PVersion = "0.97.1" const ProducnName string = "openp2p" type openP2PHeader struct { @@ -131,14 +130,6 @@ const ( NatTestTimeout = time.Second * 10 ) -// error message -var ( - // ErrorS2S string = "s2s is not supported" - // ErrorHandshake string = "handshake error" - ErrorS2S = errors.New("s2s is not supported") - ErrorHandshake = errors.New("handshake error") -) - // NATNone has public ip const ( NATNone = 0