Skip to content

Commit

Permalink
Client: support IPv6 server.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Mar 25, 2013
1 parent 24dd810 commit 76d5be3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
0.6.1 (2013-03-15)
0.6.3 (not released)
* Support IPv6 server

0.6.2 (2013-03-15)
* Connect to multiple servers in the order specified in config
* More information in server error log to help error diagnosing

Expand Down
18 changes: 13 additions & 5 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) {
host = addrIp.String()
}
port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen])
host += ":" + strconv.Itoa(int(port))
host = net.JoinHostPort(host, strconv.Itoa(int(port)))
}

return
Expand All @@ -156,6 +156,14 @@ var servers struct {
}

func parseServerConfig(config *ss.Config) {
hasPort := func(s string) bool {
_, port, err := net.SplitHostPort(s)
if err != nil {
return false
}
return port != ""
}

if len(config.ServerPassword) == 0 {
// only one encryption table
cipher, err := ss.NewCipher(config.Method, config.Password)
Expand All @@ -168,11 +176,11 @@ func parseServerConfig(config *ss.Config) {
servers.srvCipher = make([]*ServerCipher, n)

for i, s := range srvArr {
if ss.HasPort(s) {
if hasPort(s) {
log.Println("ignore server_port option for server", s)
servers.srvCipher[i] = &ServerCipher{s, cipher}
} else {
servers.srvCipher[i] = &ServerCipher{s + ":" + srvPort, cipher}
servers.srvCipher[i] = &ServerCipher{net.JoinHostPort(s, srvPort), cipher}
}
}
} else {
Expand All @@ -192,8 +200,8 @@ func parseServerConfig(config *ss.Config) {
if len(serverInfo) == 3 {
encmethod = serverInfo[2]
}
if !ss.HasPort(server) {
log.Fatalf("no port for server %s, please specify port in the form of %s:port\n", server, server)
if !hasPort(server) {
log.Fatalf("no port for server %s\n", server)
}
cipher, ok := cipherCache[passwd]
if !ok {
Expand Down
8 changes: 3 additions & 5 deletions shadowsocks/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net"
"strconv"
"strings"
)

type Conn struct {
Expand All @@ -19,12 +18,11 @@ func NewConn(cn net.Conn, cipher Cipher) *Conn {
}

func RawAddr(addr string) (buf []byte, err error) {
arr := strings.Split(addr, ":")
if len(arr) != 2 {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, errors.New(
fmt.Sprintf("shadowsocks: malformed address %s", addr))
fmt.Sprintf("shadowsocks: address error %s %v", addr, err))
}
host, portStr := arr[0], arr[1]
port, err := strconv.Atoi(portStr)
if err != nil {
return nil, errors.New(
Expand Down
9 changes: 0 additions & 9 deletions shadowsocks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,3 @@ func IsFileExists(path string) (bool, error) {
}
return false, err
}

func HasPort(s string) bool {
for i := len(s) - 1; i > 0; i-- {
if s[i] == ':' {
return true
}
}
return false
}

0 comments on commit 76d5be3

Please sign in to comment.