protobuf for net

This commit is contained in:
Darien Raymond
2016-08-27 00:04:35 +02:00
parent 64e38ba851
commit cdb4c56546
20 changed files with 323 additions and 77 deletions
+4 -4
View File
@@ -13,9 +13,9 @@ import (
func (this *ClientConfig) UnmarshalJSON(data []byte) error {
type ServerConfig struct {
Address *v2net.AddressJson `json:"address"`
Port v2net.Port `json:"port"`
Users []json.RawMessage `json:"users"`
Address *v2net.AddressPB `json:"address"`
Port v2net.Port `json:"port"`
Users []json.RawMessage `json:"users"`
}
type JsonConfig struct {
Servers []*ServerConfig `json:"servers"`
@@ -26,7 +26,7 @@ func (this *ClientConfig) UnmarshalJSON(data []byte) error {
}
this.Servers = make([]*protocol.ServerSpec, len(jsonConfig.Servers))
for idx, serverConfig := range jsonConfig.Servers {
server := protocol.NewServerSpec(v2net.TCPDestination(serverConfig.Address.Address, serverConfig.Port), protocol.AlwaysValid())
server := protocol.NewServerSpec(v2net.TCPDestination(serverConfig.Address.AsAddress(), serverConfig.Port), protocol.AlwaysValid())
for _, rawUser := range serverConfig.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
+6 -6
View File
@@ -19,11 +19,11 @@ const (
func (this *Config) UnmarshalJSON(data []byte) error {
type SocksConfig struct {
AuthMethod string `json:"auth"`
Accounts []*Account `json:"accounts"`
UDP bool `json:"udp"`
Host *v2net.AddressJson `json:"ip"`
Timeout uint32 `json:"timeout"`
AuthMethod string `json:"auth"`
Accounts []*Account `json:"accounts"`
UDP bool `json:"udp"`
Host *v2net.AddressPB `json:"ip"`
Timeout uint32 `json:"timeout"`
}
rawConfig := new(SocksConfig)
@@ -48,7 +48,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.UDPEnabled = rawConfig.UDP
if rawConfig.Host != nil {
this.Address = rawConfig.Host.Address
this.Address = rawConfig.Host.AsAddress()
} else {
this.Address = v2net.LocalHostIP
}