Browse Source

style: gofmt

gwuhaolin 7 years ago
parent
commit
83af3c6aad

+ 5 - 5
cmd/config.go

@@ -1,17 +1,17 @@
 package cmd
 
 import (
-	"fmt"
-	"os"
 	"encoding/json"
+	"fmt"
+	"github.com/mitchellh/go-homedir"
+	"io/ioutil"
 	"log"
+	"os"
 	"path"
-	"io/ioutil"
-	"github.com/mitchellh/go-homedir"
 )
 
 const (
-	ConfigFileName    = ".lightsocks.json"
+	ConfigFileName = ".lightsocks.json"
 )
 
 type Config struct {

+ 2 - 2
cmd/config_test.go

@@ -1,10 +1,10 @@
 package cmd
 
 import (
-	"testing"
-	"os"
 	"encoding/json"
 	"io/ioutil"
+	"os"
+	"testing"
 )
 
 func clearConfigFile() {

+ 6 - 6
cmd/e2e_test.go

@@ -1,17 +1,17 @@
 package cmd
 
 import (
-	"net"
+	"github.com/gwuhaolin/lightsocks/core"
+	"github.com/gwuhaolin/lightsocks/local"
+	"github.com/gwuhaolin/lightsocks/server"
+	"golang.org/x/net/proxy"
 	"io"
 	"log"
-	"golang.org/x/net/proxy"
 	"math/rand"
-	"testing"
+	"net"
 	"reflect"
 	"sync"
-	"github.com/gwuhaolin/lightsocks/core"
-	"github.com/gwuhaolin/lightsocks/server"
-	"github.com/gwuhaolin/lightsocks/local"
+	"testing"
 	"time"
 )
 

+ 3 - 3
cmd/lightsocks-local/main.go

@@ -1,12 +1,12 @@
 package main
 
 import (
-	"log"
-	"net"
 	"fmt"
-	"github.com/gwuhaolin/lightsocks/local"
 	"github.com/gwuhaolin/lightsocks/cmd"
 	"github.com/gwuhaolin/lightsocks/core"
+	"github.com/gwuhaolin/lightsocks/local"
+	"log"
+	"net"
 )
 
 const (

+ 3 - 3
cmd/lightsocks-server/main.go

@@ -1,13 +1,13 @@
 package main
 
 import (
-	"log"
-	"net"
 	"fmt"
-	"github.com/gwuhaolin/lightsocks/server"
 	"github.com/gwuhaolin/lightsocks/cmd"
 	"github.com/gwuhaolin/lightsocks/core"
+	"github.com/gwuhaolin/lightsocks/server"
 	"github.com/phayes/freeport"
+	"log"
+	"net"
 )
 
 var version = "master"

+ 2 - 2
core/cipher_test.go

@@ -1,9 +1,9 @@
 package core
 
 import (
-	"testing"
-	"reflect"
 	"crypto/rand"
+	"reflect"
+	"testing"
 )
 
 const (

+ 2 - 2
core/password.go

@@ -1,11 +1,11 @@
 package core
 
 import (
-	"math/rand"
+	"encoding/base64"
 	"errors"
+	"math/rand"
 	"strings"
 	"time"
-	"encoding/base64"
 )
 
 const PasswordLength = 256

+ 2 - 2
core/password_test.go

@@ -1,9 +1,9 @@
 package core
 
 import (
-	"testing"
-	"sort"
 	"reflect"
+	"sort"
+	"testing"
 )
 
 func (password *Password) Len() int {

+ 1 - 1
core/securesocket.go

@@ -1,10 +1,10 @@
 package core
 
 import (
-	"net"
 	"errors"
 	"fmt"
 	"io"
+	"net"
 )
 
 const (

+ 2 - 2
local/local.go

@@ -1,9 +1,9 @@
 package local
 
 import (
-	"net"
-	"log"
 	"github.com/gwuhaolin/lightsocks/core"
+	"log"
+	"net"
 )
 
 type LsLocal struct {

+ 36 - 36
server/server.go

@@ -1,10 +1,10 @@
 package server
 
 import (
-	"net"
 	"encoding/binary"
-	"log"
 	"github.com/gwuhaolin/lightsocks/core"
+	"log"
+	"net"
 )
 
 type LsServer struct {
@@ -59,17 +59,17 @@ func (lsServer *LsServer) handleConn(localConn *net.TCPConn) {
 	buf := make([]byte, 256)
 
 	/**
-	The localConn connects to the dstServer, and sends a ver
-   	identifier/method selection message:
-		   +----+----------+----------+
-                   |VER | NMETHODS | METHODS  |
-                   +----+----------+----------+
-                   | 1  |    1     | 1 to 255 |
-                   +----+----------+----------+
-	The VER field is set to X'05' for this ver of the protocol.  The
-   	NMETHODS field contains the number of method identifier octets that
-   	appear in the METHODS field.
-	 */
+		The localConn connects to the dstServer, and sends a ver
+	   	identifier/method selection message:
+			   +----+----------+----------+
+	                   |VER | NMETHODS | METHODS  |
+	                   +----+----------+----------+
+	                   | 1  |    1     | 1 to 255 |
+	                   +----+----------+----------+
+		The VER field is set to X'05' for this ver of the protocol.  The
+	   	NMETHODS field contains the number of method identifier octets that
+	   	appear in the METHODS field.
+	*/
 	// 第一个字段VER代表Socks的版本,Socks5默认为0x05,其固定长度为1个字节
 	_, err := lsServer.DecodeRead(localConn, buf)
 	// 只支持版本5
@@ -78,25 +78,25 @@ func (lsServer *LsServer) handleConn(localConn *net.TCPConn) {
 	}
 
 	/**
-	The dstServer selects from one of the methods given in METHODS, and
-   	sends a METHOD selection message:
-
-                         +----+--------+
-                         |VER | METHOD |
-                         +----+--------+
-                         | 1  |   1    |
-                         +----+--------+
-	 */
+		The dstServer selects from one of the methods given in METHODS, and
+	   	sends a METHOD selection message:
+
+	                         +----+--------+
+	                         |VER | METHOD |
+	                         +----+--------+
+	                         | 1  |   1    |
+	                         +----+--------+
+	*/
 	// 不需要验证,直接验证通过
 	lsServer.EncodeWrite(localConn, []byte{0x05, 0x00})
 
 	/**
-	+----+-----+-------+------+----------+----------+
-        |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
-        +----+-----+-------+------+----------+----------+
-        | 1  |  1  | X'00' |  1   | Variable |    2     |
-        +----+-----+-------+------+----------+----------+
-	 */
+		+----+-----+-------+------+----------+----------+
+	        |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
+	        +----+-----+-------+------+----------+----------+
+	        | 1  |  1  | X'00' |  1   | Variable |    2     |
+	        +----+-----+-------+------+----------+----------+
+	*/
 
 	// CMD代表客户端请求的类型,值长度也是1个字节,有三种类型
 	// CONNECT X'01'
@@ -116,7 +116,7 @@ func (lsServer *LsServer) handleConn(localConn *net.TCPConn) {
 	switch buf[3] {
 	case 0x01:
 		//	IP V4 address: X'01'
-		dIP = buf[4:4+net.IPv4len]
+		dIP = buf[4 : 4+net.IPv4len]
 	case 0x03:
 		//	DOMAINNAME: X'03'
 		ipAddr, err := net.ResolveIPAddr("ip", string(buf[5:n-2]))
@@ -126,7 +126,7 @@ func (lsServer *LsServer) handleConn(localConn *net.TCPConn) {
 		dIP = ipAddr.IP
 	case 0x04:
 		//	IP V6 address: X'04'
-		dIP = buf[4:4+net.IPv6len]
+		dIP = buf[4 : 4+net.IPv6len]
 	default:
 		return
 	}
@@ -147,12 +147,12 @@ func (lsServer *LsServer) handleConn(localConn *net.TCPConn) {
 
 		// 响应客户端连接成功
 		/**
-	 		+----+-----+-------+------+----------+----------+
-         	|VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
-        	+----+-----+-------+------+----------+----------+
-        	| 1  |  1  | X'00' |  1   | Variable |    2     |
-        	+----+-----+-------+------+----------+----------+
-	 	*/
+			 		+----+-----+-------+------+----------+----------+
+		         	|VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
+		        	+----+-----+-------+------+----------+----------+
+		        	| 1  |  1  | X'00' |  1   | Variable |    2     |
+		        	+----+-----+-------+------+----------+----------+
+		*/
 		// 响应客户端连接成功
 		lsServer.EncodeWrite(localConn, []byte{0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
 	}