forked from w910820618/shadowsocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wu
committed
Jan 12, 2021
1 parent
75d4327
commit 7440cd0
Showing
7 changed files
with
151 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
.idea | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"client": "192.168.2.235", | ||
"server": "192.168.2.235", | ||
"cipher": "192.168.2.235", | ||
"key": "192.168.2.235", | ||
"password": "192.168.2.235", | ||
"keygen": 10, | ||
"socks": "192.168.2.235", | ||
"redir_tcp": "192.168.2.235", | ||
"redir_tcp_6": "192.168.2.235", | ||
"tcp_tun": "192.168.2.235", | ||
"udp_tun": "192.168.2.235", | ||
"udp_socks": true, | ||
"udp": true, | ||
"tcp": false, | ||
"plugin": "192.168.2.235", | ||
"plugin_opts": "192.168.2.235", | ||
"verbose": true, | ||
"udp_timeout": "1h", | ||
"tcp_cork": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type Configure struct { | ||
Client string `json:"client"` | ||
Server string `json:"server"` | ||
Cipher string `json:"cipher"` | ||
Key string `json:"key"` | ||
Password string `json:"password"` | ||
Keygen int `json:"keygen"` | ||
Socks string `json:"socks"` | ||
RedirTCP string `json:"redir_tcp"` | ||
RedirTCP6 string `json:"redir_tcp_6"` | ||
TCPTun string `json:"tcp_tun"` | ||
UDPTun string `json:"udp_tun"` | ||
UDPSocks bool `json:"udp_socks"` | ||
UDP bool `json:"udp"` | ||
TCP bool `json:"tcp"` | ||
Plugin string `json:"plugin"` | ||
PluginOpts string `json:"plugin_opts"` | ||
Verbose bool `json:"verbose"` | ||
UDPTimeout Duration `json:"udp_timeout"` | ||
TCPCork bool `json:"tcp_cork"` | ||
} | ||
|
||
var ( | ||
config Configure | ||
) | ||
|
||
func loadConfigure(filePath string) *Configure { | ||
|
||
var ( | ||
content []byte | ||
err error | ||
) | ||
|
||
if !exists(filePath) { | ||
logf(filePath + " is not exits") | ||
return nil | ||
} | ||
|
||
if content, err = ioutil.ReadFile(filePath); err != nil { | ||
logf("Error reading configuration file, err is " + err.Error()) | ||
return nil | ||
} | ||
|
||
if err := json.Unmarshal(content, &config); err != nil { | ||
logf("Error decoding json file, err is :" + err.Error()) | ||
return nil | ||
} | ||
|
||
return &config | ||
} | ||
|
||
func exists(path string) bool { | ||
_, err := os.Stat(path) | ||
if err != nil { | ||
if os.IsExist(err) { | ||
return true | ||
} | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestConfigure(t *testing.T) { | ||
configure := loadConfigure("/home/wu/go/src/shadowsocks/conf/configure.json") | ||
t.Log(configure.UDPTimeout.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"time" | ||
) | ||
|
||
type Duration struct { | ||
time.Duration | ||
} | ||
|
||
func (d Duration) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(d.String()) | ||
} | ||
|
||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var v interface{} | ||
if err := json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
switch value := v.(type) { | ||
case float64: | ||
d.Duration = time.Duration(value) | ||
return nil | ||
case string: | ||
var err error | ||
d.Duration, err = time.ParseDuration(value) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
default: | ||
return errors.New("invalid duration") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters