Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudnuY committed Apr 15, 2018
1 parent 80b9b13 commit 3f43582
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 54 deletions.
11 changes: 6 additions & 5 deletions flora/config.go
Expand Up @@ -2,14 +2,15 @@ package flora

import (
"fmt"
"github.com/go-ini/ini"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
"log"
"math/rand"
"net"
"os"
"strconv"
"strings"
"math/rand"

"github.com/go-ini/ini"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
)

const (
Expand Down Expand Up @@ -38,7 +39,7 @@ type proxyGroup struct {
proxyServers []ProxyServer
}

func LoadConfig(cfgFile string, geoFile string) (*ProxyConfig) {
func LoadConfig(cfgFile string, geoFile string) *ProxyConfig {
proxyConfig := ProxyConfig{}
var iniOpts = ini.LoadOptions{
AllowBooleanKeys: true,
Expand Down Expand Up @@ -148,7 +149,7 @@ func loadProxy(config *ProxyConfig) {

}

func (c *ProxyConfig) GetProxyServer(action string) (ProxyServer) {
func (c *ProxyConfig) GetProxyServer(action string) ProxyServer {
const maxFailCnt = 30
var server ProxyServer
var ok bool
Expand Down
3 changes: 2 additions & 1 deletion flora/geoip.go
@@ -1,10 +1,11 @@
package flora

import (
"github.com/oschwald/geoip2-golang"
"log"
"net"
"strings"

"github.com/oschwald/geoip2-golang"
)

var geoDB *geoip2.Reader
Expand Down
11 changes: 5 additions & 6 deletions flora/http.go
@@ -1,11 +1,11 @@
package flora

import (
"net"
"io"
"net/http"
"bufio"
"bytes"
"io"
"net"
"net/http"
"net/http/httputil"
)

Expand Down Expand Up @@ -50,16 +50,15 @@ func httpProxyConnect(conn net.Conn, first byte) (addr string, hostType int, raw
return
}

func getRequestType(addr string) int {
host,_,_ := net.SplitHostPort(addr)
func getRequestType(addr string) int {
host, _, _ := net.SplitHostPort(addr)
ip := net.ParseIP(host)
if nil != ip {
return typeIPv4
}
return typeDm
}


func removeHeaders(req *http.Request) {
req.RequestURI = ""
req.Header.Del("Accept-Encoding")
Expand Down
14 changes: 7 additions & 7 deletions flora/network_setup.go
@@ -1,11 +1,11 @@
package flora

import (
"os/signal"
"syscall"
"os"
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"
)

Expand All @@ -21,7 +21,7 @@ func resetProxySettings(proxySettings SystemProxySettings) {
select {
case <-sigs:
log.Print("Flora-kit is shutdown now ...")
if nil != proxySettings{
if nil != proxySettings {
proxySettings.TurnOffGlobProxy()
}
time.Sleep(time.Duration(2000))
Expand All @@ -30,17 +30,17 @@ func resetProxySettings(proxySettings SystemProxySettings) {
}
}

func initProxySettings(bypass []string, addr string) {
func initProxySettings(bypass []string, addr string) {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
var proxySettings SystemProxySettings
if runtime.GOOS == "windows" {
w := &windows{addr}
proxySettings = w
} else if runtime.GOOS == "darwin" {
d := &darwin{bypass,addr}
d := &darwin{bypass, addr}
proxySettings = d
}
if nil != proxySettings{
if nil != proxySettings {
proxySettings.TurnOnGlobProxy()
}
go resetProxySettings(proxySettings)
Expand Down
2 changes: 1 addition & 1 deletion flora/network_setup_mac.go
Expand Up @@ -3,9 +3,9 @@ package flora
import (
"bytes"
"log"
"net"
"os/exec"
"strings"
"net"
)

type darwin struct {
Expand Down
18 changes: 9 additions & 9 deletions flora/network_setup_win.go
@@ -1,22 +1,22 @@
package flora

import (
"os/exec"
"log"
"os/exec"
)

type windows struct {
address string
}

const (
cmdRegistry = `reg`
cmdRegistryAdd = `add`
internetSettingsKey = `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings`
keyProxyEnable = `ProxyEnable`
keyProxyServer = `ProxyServer`
dataTypeDWord = `REG_DWORD`
dataTypeRegSZ = `REG_SZ`
cmdRegistry = `reg`
cmdRegistryAdd = `add`
internetSettingsKey = `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings`
keyProxyEnable = `ProxyEnable`
keyProxyServer = `ProxyServer`
dataTypeDWord = `REG_DWORD`
dataTypeRegSZ = `REG_SZ`
)

func (w *windows) TurnOnGlobProxy() {
Expand All @@ -41,7 +41,7 @@ func (w *windows) TurnOffGlobProxy() {
if _, err = c.CombinedOutput(); err != nil {
log.Printf("disable windows proxy has error %s", err)
}
if nil == err{
if nil == err {
log.Print("disable windows proxy settings are successful ...")
}
}
10 changes: 5 additions & 5 deletions flora/proxy_direct.go
Expand Up @@ -6,15 +6,15 @@ type DirectServer struct {
proxyType string
}

func NewDirect() (*DirectServer) {
func NewDirect() *DirectServer {
return &DirectServer{proxyType: ServerTypeDirect}
}

func (s *DirectServer) FailCount() int {
return 0
}

func (s *DirectServer) ResetFailCount() {
func (s *DirectServer) ResetFailCount() {

}

Expand All @@ -28,10 +28,10 @@ func (s *DirectServer) ProxyType() string {

func (s *DirectServer) DialWithRawAddr(raw []byte, host string) (remote net.Conn, err error) {
conn, err := net.Dial("tcp", host)
if nil != err{
return nil,err
if nil != err {
return nil, err
}
if nil != raw && len(raw) > 0 {
if nil != raw && len(raw) > 0 {
conn.Write(raw)
}
return conn, err
Expand Down
2 changes: 1 addition & 1 deletion flora/proxy_reject.go
Expand Up @@ -6,7 +6,7 @@ type Reject struct {
proxyType string
}

func NewReject() (*Reject) {
func NewReject() *Reject {
return &Reject{proxyType: ServerTypeReject}
}

Expand Down
6 changes: 3 additions & 3 deletions flora/proxy_shadowsocks.go
@@ -1,8 +1,8 @@
package flora

import (
"net"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
"net"
"sync"
)

Expand All @@ -14,7 +14,7 @@ type ShadowSocksServer struct {
lock sync.RWMutex
}

func NewShadowSocks(server string, cipher *ss.Cipher) (*ShadowSocksServer) {
func NewShadowSocks(server string, cipher *ss.Cipher) *ShadowSocksServer {
return &ShadowSocksServer{
proxyType: ServerTypeShadowSocks,
server: server,
Expand All @@ -29,7 +29,7 @@ func (s *ShadowSocksServer) ResetFailCount() {
}

func (s *ShadowSocksServer) AddFail() {
s.failCount ++
s.failCount++
}

func (s *ShadowSocksServer) FailCount() int {
Expand Down
12 changes: 6 additions & 6 deletions flora/socks4.go
@@ -1,10 +1,10 @@
package flora

import (
"io"
"net"
"encoding/binary"
"fmt"
"io"
"net"
)

/*
Expand Down Expand Up @@ -32,7 +32,7 @@ byte | 0 | 1 | 2 | 3 | 4 | 5 | 6| 7 |
*/

// local socks server connect
func socks4Connect(conn net.Conn,first byte ) (addr string, hostType int, err error) {
func socks4Connect(conn net.Conn, first byte) (addr string, hostType int, err error) {
const (
idVer = 0
idStatus = 1
Expand All @@ -53,16 +53,16 @@ func socks4Connect(conn net.Conn,first byte ) (addr string, hostType int, err er
if n, err = io.ReadAtLeast(conn, buf[1:], id4aFixLen); err != nil {
return
}
n ++
n++
// command only support connect
if buf[idStatus] != cmdConnect {
return
}
// get port
port := binary.BigEndian.Uint16(buf[idPort:idPort+idPortLen])
port := binary.BigEndian.Uint16(buf[idPort : idPort+idPortLen])

// get ip
ip := net.IP(buf[idIP:idIP+idIPLen])
ip := net.IP(buf[idIP : idIP+idIPLen])
hostType = typeIPv4
var host = ip.String()

Expand Down
18 changes: 9 additions & 9 deletions flora/socks5.go
@@ -1,12 +1,12 @@
package flora

import (
"encoding/binary"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
"io"
"log"
"net"
"strconv"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
"encoding/binary"
"log"
)

/*
Expand Down Expand Up @@ -46,7 +46,7 @@ byte |0 | 1 | 2 | 3 | 4 | .. | n-2 | n-1 | n |
*/

//local socks server auth
func handshake(conn net.Conn,first byte ) (err error) {
func handshake(conn net.Conn, first byte) (err error) {
const (
idVer = 0
idNmethod = 1
Expand All @@ -64,7 +64,7 @@ func handshake(conn net.Conn,first byte ) (err error) {
if n, err = io.ReadAtLeast(conn, buf[1:], idNmethod+1); err != nil {
return
}
n ++
n++
//if buf[idVer] != socksVer5 {
// return errVer
//}
Expand Down Expand Up @@ -145,13 +145,13 @@ func socks5Connect(conn net.Conn) (host string, hostType int, err error) {
//raw := buf[idType:reqLen]
switch hostType {
case typeIPv4:
host = net.IP(buf[idIP0: idIP0+net.IPv4len]).String()
host = net.IP(buf[idIP0 : idIP0+net.IPv4len]).String()
case typeIPv6:
host = net.IP(buf[idIP0: idIP0+net.IPv6len]).String()
host = net.IP(buf[idIP0 : idIP0+net.IPv6len]).String()
case typeDm:
host = string(buf[idDm0: idDm0+buf[idDmLen]])
host = string(buf[idDm0 : idDm0+buf[idDmLen]])
}
port := binary.BigEndian.Uint16(buf[reqLen-2: reqLen])
port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen])
host = net.JoinHostPort(host, strconv.Itoa(int(port)))
_, err = conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x43})
return
Expand Down
2 changes: 1 addition & 1 deletion geoip_test.go
Expand Up @@ -2,8 +2,8 @@ package main_test

import (
"flora-kit/flora"
"testing"
"os"
"testing"
)

func TestGeoIP(t *testing.T) {
Expand Down

0 comments on commit 3f43582

Please sign in to comment.